View Full Version : OSC to MIDI simple script
ljekio
05-14-2017, 12:00 AM
Hello, Im noob in scripting and almost all examples of scripts for OSCIIbot inaccessible now.
Can I request to help me create simple script what receive one parameter from OSC and translate it to custom MIDI port as CC#100 and midi channel 16?
goldenarpharazon
05-16-2017, 02:28 AM
Take a look at the simple "alphatrack.txt" example script bundled with OSCII-bot itself. "sample_script.txt" there should also be helpful. Try them out whilst looking at the associated Midi and OSC traffic in OSCII-bot's console window, or along with a Midi monitor and one can see what they do. Modify these examples one step at a time to gradually become what is wished.
For more complex fully worked script examples that have plenty of explanatory comments see the scripts for the Peavey StudioMix available at http://forum.cockos.com/showpost.php?p=1401937&postcount=284 or the Akai MIDIMIX at http://forum.cockos.com/showthread.php?t=172908
ljekio
05-16-2017, 10:56 PM
Thanks, but I did not succeed. I do not know how to write functions correctly to receive the osc parameter that I need.
These examples are too complicated for me, I can not achieve the elementary thing yet.
goldenarpharazon
05-17-2017, 02:26 AM
One needs the correct call to oscmatch(...) in the @oscmsg block of code in the script to detect i.e. match the OSC string and then within oscmatch(...) call the corresponding Midi output.
An example of this can be seen in "alphatrack.txt" where Midi output is done after the "/track/%d/volume" string is detected. The comments in "sample_script.txt" in its oscmatch() also explains how the matching works. The pattern string varieties are set out at http://www.cockos.com/oscii-bot/oscii-bot-doc.html#match.
There's also a very simple OSC example here http://forum.cockos.com/showpost.php?p=1300677&postcount=75 with hints on how to form different Midi output
What is the OSC string parameter to be detected in your wish, to then go on and create the corresponding matching pattern string for oscmatch(...)?
ljekio
05-21-2017, 11:26 PM
@goldenarpharazon, thank you for your advises.
So, in example wrote this:
(oscmatch("/track/%d/select")) && (oscparm(0,0) > 0)?
(
msg1 = 176;
msg2 = 0;
msg3 = fmt0;
midisend(bcr2000_in);
What is "/track/%d/select"? If I know name of OSC-host and OSC sending parameter, what I must write at this string?
"msg1 = 176" its first byte (CC number), "msg2 = 0" is second byte (channel) and "msg3 = fmt0" is value from oscmatch, right?
MIDI part is clear for me, but not OSC.
goldenarpharazon
05-22-2017, 03:30 AM
What is "/track/%d/select"?
%d matches any integer so this will match any string like "/track/1/select" and "/track/2/select" etc.
If I know name of OSC-host and OSC sending parameter, what I must write at this string?
In your example, what is the OSC string being sent from TouchOSC and any parameters or variable parts of the string? This string will be visible in the OSCII-bot console window. This will then be used to determine the corresponding matching format string for oscmatch(...)
The way that format strings are written in EEL2 & OSCII-bot scripts is similar to the widely used "C" programming language so this explanation of format strings (for scanf in "C") might also be helpful https://wpollock.com/CPlus/PrintfRef.htm
....and "msg3 = fmt0" is value from oscmatch, right?
Yes that is right. Note that using fmt0 is deprecated but it should still work if your example needs to catch a value for use in the Midi output. The other script examples given in the earlier posts contain examples of the current recommended way of catching the matched value.
ljekio
05-22-2017, 09:35 AM
In your example, what is the OSC string being sent from TouchOSC and any parameters or variable parts of the string? This string will be visible in the OSCII-bot console window. This will then be used to determine the corresponding matching format string for oscmatch(...)
I see osc2bot begin receive my OSC data, but I haven't yet learned how to pass the correct information.
My setup: knob in Reaktor with OSC send module with name "OSC1". Name of host is "REA".
So, I've wrote for test this:
(oscmatch("/OSC1")) && (oscparm(0,0) > 0)?
(
msg1 = 1;
msg2 = fmt0;
msg3 = 0;
midisend(midi_out);
printf("Track %d selected\n");
);
Now, If I turn knob I've see message "Track 0 selected" at osc2bot and midi monitor showing activity BF 01 00 always.
I checked msg1, msg2 & msg3. The first sends the CC number, the second sends the value. The third one does not send anything and data always has a 16 midi channel (BF).
I did not find a way to change the midi channel, but it's not so important now. The main thing is that I could not translate the value of OSC1 to midi value.
goldenarpharazon
05-22-2017, 12:19 PM
OK, so the code appears to be detecting "/OSC1" and is executing the following code block since the printf statement is executed. Great! That's progress!
Suggest all of the following that together may sort it out and get it working
Checking that the OSC data coming in looks something like "/OSC1 17" or "/OSC1 123" in the OSCII-bot console since it's those changing integer parameters i.e. 17 and 123 that should be going into fmt0
using a properly formatted printf statement that outputs all of msg1, msg2, msg3 together on a debugging line to make sure that
- fmt0 really has captured a parameter which varies with the OSC data (lots of examples of how to do this printf in code already mentioned)
and
- the three bytes together look like they will be proper Midi
checking that midisend() will correctly send any pre-set Midi output to the chosen midi output device
ljekio
05-22-2017, 02:49 PM
Checking that the OSC data coming in looks something like "/OSC1 17" or "/OSC1 123" in the OSCII-bot console since it's those changing integer parameters i.e. 17 and 123 that should be going into fmt0
I can't get value of osc messages. Confused with this.
using a properly formatted printf statement that outputs all of msg1, msg2, msg3 together on a debugging line to make sure that
I made debug line.
- the three bytes together look like they will be proper Midi
Change of third byte doesn't cause any changes of output. I tried any static value there.
checking that midisend() will correctly send any pre-set Midi output to the chosen midi output device
midisend is correct (because midi-ox received midi from that port).
BF 01 00 (control change message #01 with value 0 and midi channel 16).
goldenarpharazon
05-24-2017, 11:02 AM
I can't get value of osc messages. Confused with this.
Look at this example of OSC http://forum.cockos.com/showpost.php?p=1495935&postcount=323 This OSCII-bot console example from OSCII-bot shows the OSC string sent (in this case from Reaper) and the variable parameters.
You should see something similar, but with /OSC1 in the strings in your own console. Posting the console output might help to help?
Probably you are trying to send something like "/OSC1 100" with /OSC1 as the message pattern and say 100 as the variable parameter. It is this combination of message pattern and variable parameter(s) that forms the basis of matching - see this ebook (http://osc.justthebestparts.com/Chapter_02/02.html) and its subsequent pages for a simple explanation of OSC message formats.
Change of third byte doesn't cause any changes of output. I tried any static value there.
This is strange. Code like the example below should just work and send a midi event defined by the integers in the code provided they are small enough fit in a valid and meaningful Midi byte.
msg1 = $xBF; // status byte
msg2 = 2; // a value
msg3 = 3; // another value
midisend(midi_out);
However note that this code below may well not work properly if fmt0 is undefined in value if it has never been set to something by oscmatch();
msg1 = $xBF; // status byte
msg2 = fmt0; // danger here if fmt0 value is not correct as a byte value
msg3 = 3; // another value
midisend(midi_out);
vBulletin® v3.8.11, Copyright ©2000-2024, vBulletin Solutions Inc.