Go Down

Topic: Assistance with ArdOSC library and converting OSC Message into a string value (Read 2502 times) previous topic - next topic

CookeGMP

I'm working on a device that lights a set of LEDs based on input from a midi controller. It was fully functional when I was using Processing to act as a serial to OSC interpreter.

I am using a java application called Moco to change the MIDI signal into OSC commands. The OSC signal is formed like "\midi\noteon 0 (int) 74 (int) 127 (int)". When I was using Processing as an OSC to Serial interpreter I was able to use the OSCP5 library and grab the values as follows:
String addr = theOscMessage.addrPattern();
int stripnumber  = theOscMessage.get(0).intValue();
int Pixel  = theOscMessage.get(1).intValue();
int Intensity = theOscMessage.get(2).intValue();

I would then just run a simple check such as "if addr=\midi\noteon && note == 72 digitalwrite redled high" "if addr=\midi\noteoff a&& note == 72 digitalwrite redled low".

The string from the OSC message itself is important because that corresponds to touch and aftertouch on the keyboard.

Now that I have the Arduino connected through an Ethernet shield and the ArdOSC library I am able to get all of my values with the exception of turning that actual OSC message into a string value. Could anyone give me an idea on how to get that accomplished or point me to a different library if necessary?

I'm honestly in over my head when it comes to programming. My background is more from network engineering and music production. This is my first Arduino project.  =(

Thanks in advance for your help!

PaulS

Quote
Now that I have the Arduino connected through an Ethernet shield and the ArdOSC library I am able to get all of my values with the exception of turning that actual OSC message into a string value. Could anyone give me an idea on how to get that accomplished or point me to a different library if necessary?

Where did you get the ArdOSC library? Why isn't it capable of parsing the message the same way the Processing version is?

Where is your code?

CookeGMP

Quote
Where did you get the ArdOSC library? Why isn't it capable of parsing the message the same way the Processing version is?

Where is your code?


The ArdOSC library from Recotana appears to be the most commonly used OSC library. It's available from https://github.com/recotana/ArdOSC. I don't have any functional code as I can't figure out how to parse the actual OSC message into a string. I seem to only be able to grab the arguments after the message. My functional code from processing looks like this:

void oscEvent(OscMessage theOscMessage) {

    String addr = theOscMessage.addrPattern();
    int stripnumber  = theOscMessage.get(0).intValue();
    int Pixel  = theOscMessage.get(1).intValue();
    int Intensity = theOscMessage.get(2).intValue();
   
  print("OSC Message Recieved: ");
  print(theOscMessage.addrPattern() + " ");
  println(stripnumber + " " + Pixel + " " + Intensity);

    if(addr.equals("/midi/noteon")&& Pixel == 72) {v_RedLED = 1; }
    else if(addr.equals("/midi/noteoff")&& Pixel == 72)  { v_RedLED = 0; }

    if(addr.equals("/midi/noteon")&& Pixel == 74) {v_GreenLED = 1; }
    else if(addr.equals("/midi/noteoff")&& Pixel == 74)  { v_GreenLED = 0; }
   
    if(addr.equals("/midi/noteon")&& Pixel == 76) {v_YellowLED = 1; }
    else if(addr.equals("/midi/noteoff")&& Pixel == 76)  { v_YellowLED = 0; }

    if(addr.equals("/midi/noteon")&& Pixel == 77) {v_BlueLED = 1; }
    else if(addr.equals("/midi/noteoff")&& Pixel == 77)  { v_BlueLED = 0; }
}

Processing would then take the flag and use it to pass a character over serial write to the Arduino.

My Arduino code using an Ethernet shield currently looks like this:

void oscEvent(OSCMessage *_mes) {
   
    String addr = _mes->OSCMessage();
    int stripnumber  = _mes->getArgInt32(0);
    int Pixel  = _mes->getArgInt32(1);
    int Intensity = _mes->getArgInt32(2);
   
 
    if(addr == "/midi/noteon" && Pixel == 72) {digitalWrite (LEDRED, HIGH); }
    else if(addr == "/midi/noteoff" && Pixel == 72)  { digitalWrite (LEDRED, LOW); }

    if(addr == "/midi/noteon" && Pixel == 74) {digitalWrite (LEDGRN, HIGH); }
    else if(addr == "/midi/noteoff" && Pixel == 74)  { digitalWrite (LEDGRN, LOW); }     

    if(addr == "/midi/noteon" && Pixel == 76) {digitalWrite (LEDYEL, HIGH); }
    else if(addr == "/midi/noteoff" && Pixel == 76)  { digitalWrite (LEDYEL, LOW); }

    if(addr == "/midi/noteon" && Pixel == 77) {digitalWrite (LEDBLU, HIGH); }
    else if(addr == "/midi/noteoff" && Pixel == 77)  { digitalWrite (LEDBLU, LOW); }
}

As that code currently is I get this error when compiling:

MicStand1.ino: In function 'void oscEvent(OSCMessage*)':
MicStand1:57: error: invalid use of 'class OSCMessage'

I could use getArgString possibly but I don't see how to use that to get the actual message and not an argument. Thanks for looking my code over.



PaulS

Code: [Select]
void oscEvent(OSCMessage *_mes) {
   
    String addr = _mes->OSCMessage();

This is invoking the constructor of the OSCMessage class. The constructor is not defined to return a value. How can you assign that to a string?

The OSCMessage class has a getOSCAddress() method, that returns a char pointer, that appears to be what you want to be calling. There is no excuse, though, for wrapping that in a String.



nickgammon

@CookeGMP:

Read this before posting a programming question

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Go Up