OSC message formatting

Hello all,

i am trying to have the following OSC command sent to the desk by an arduino connected by USB

/eos/chan/1/@/randomVal0/sneak/time/fade0

where randomVal0 is a int_32t variable and fade0 is a float determined by different parts of the sketch.

Current Code---


currentMillis0 = millis();
if (currentMillis0 - prevMillis0 > varRandom0) {
dwell_0(); //function to get fade0
randomValue_0(); //function to get randomVal0
analogWrite(led[0], randomRaw0); //Output to led
OSCMessage group_801("/eos/chan/1/@");//user/0/ needs to be inserted in final code
group_801.add(randomVal0); //int_32t determined by randomValue_0()
group_801.add("/sneak/time/"); //give timing information to channel intensity move
group_801.add(fade0); //float value determined by dwell_0()
SLIPSerial.beginPacket();
group_801.send(SLIPSerial);
SLIPSerial.endPacket();
lastTimeSent = curTime;
prevMillis0 = currentMillis0;
}

When the sketch is running on an arduino hooked to the console the diagnostics tab shows-
/eos/chan/1/@, 62(i), /sneak/time/(s), 0.640(f)

So i think the message is getting to the desk but is just not formatted in a way the desk understands for the timing information.

The desk will output ch 1 to the level set by randomVal0 however the timing information is lost.

I'm not quite sure how to reformat the OSCmessage so the console will understand it correctly.

 

Any help would be greatly appriciated.

  • In the line

    OSCMessage group_801("/eos/chan/1/@");//user/0/ needs to be inserted in final code

    It may be as simple as adding in the missing / after the @ symbol , that would make the output look closer to what you said at the top /eos/chan/1/@/randomVal0/sneak/time/fade0

    But I think you will still end up with the commas in the message which are being added by your OSCMessage add function.

    If you wanted the format without the commas then you could just string the parts of the message together first into a single string variable and pass that to the OSCMessage create function, and not doing the add bits at all.

    eg depending on what language this is actually written in, something like

    mystring="/eos/chan/1/@/" + randomVal0 + "/sneak/time/" + fade0;
    OSCMessage group_801( mystring );

    I think I would test out that the message is correct and recognised by the desk by initially just hard coding the string in the function above and then experiment from there
  • This is the code that worked to send the osc string to the console. Had to add "/newcmd/" to put the message on the command line and end the message with "/enter" to have it terminate the command line.

    const String group_801_Addr = "/eos/user/0/newcmd/group/801/@";

    stringout0 = group_801_Addr + randomVal0 + stringTime + fade0 + stringEnter;
    OSCMessage group_801(stringout0.c_str());

    Thank you for your suggestions and help.
  • It looks like you got it figured out. I'm pasting a bit of code I used to combine variables on a project. Just a different way to do the same thing.

    itoa(eosSub1, msg1, 10);
    itoa(eosSub2, msg2, 10);
    msgCombined[0] = '\0';
    msgCombined2[0] = '\0';
    strcat(msgCombined, subAddress);
    strcat(msgCombined, msg1);
    strcat(msgCombined2, subAddress);
    strcat(msgCombined2, msg2);

    This part was in the "setup" portion of the sketch.

    //setup
    char subAddress[] = "/eos/sub/";
    char msg1[10];
    char msg2[10];
    char msgCombined[15];
    char msgCombined2[15];
    .......

    Hope this give you some other ideas

    strings can slow down the code and sometimes take too much memory.

    Andrew

  • Andrew, I know you realise this, but just saying it in case someone picks up that code later and tries to use it for something else.

    strcat has no buffer size protection so in your code if the msgCombined bits end up being more than 15 chars eg if someone changed the cmd from /eos/sub/ to something just a few characters longer, the strcat would overflow the end of msgCombined and probably trash the stack and result in the program crashing.

    (This is probably the most common security exploit on windows platforms - a google search for windows buffer overflow vulnerability shows just how common this sort of issue is even amongst professional programmers)
Related