how to use osc messages correctly ...

hi all !

i’ve a simple question regarding how to use osc messages in the ofAddon.
let’s say i need to send 2 messages, once after the other …

will be these correct ?

  
  
../..  
  
ofOscSender sender.  
  
../..  
  
ofOscMessage m;  
  
m.setAddress("A");  
m.addFloatArg(0.0);  
sender.sendMessage(m);  
  
m.setAddress("B");  
m.addFloatArg(1.0);  
sender.sendMessage(m);  
  

is it possible to “overwrite” an osc message to use it with another address or should i delete that one, and create another one ? there’s nothing like “clearMessage” ?

any tips in how could i manage massive osc messages ?

thanks a lot for any idea …

e*

I haven’t used the ofOSC addon, but I’ve programmed some OSC before, so maybe this can be of use.

OSC addresses can be thought of more as “destinations”. You create your own OSC address hierarchy using slashes “/” followed by arbitrary keywords.

e.g.
/blah/myaddress
or
/apple/pear/whatever
or just
/purple

You then pass some data with the message,
e.g.
/apple/pear/whatever 5.0f

/purple 5 bear 3.0f

The data can be int, float, or string, and the list of data (normally separated by spaces) can be as long as you want I think.

Then on the receiving end you tell OSC you are expecting messages with address /apple/pear/whatever. Once a message with that address arrives, you collect whatever data was sent.

So normally you should be able to change whatever address (or destination) the OSC message has been previously assigned.

In answer to your question, normally you have to precede your address with a forwardslash “/”. So m.setAddress("/A") should work…and it should be possible later to do m.setAddress("/B") later with same message.

What do you mean by massive OSC messages? Couldn’t you break up the data into smaller messages?

The ofxOscMessage class is really simple; the only fields appear to be

  
	std::string address;  
	std::vector<ofxOscArg*> args;  

I don’t see any reason that you can’t reuse one by changing the data in it and re-sending.

hi grimus and tom !

thanks for your answers . I do know how to use osc messages, my problem was how to send many different ones … let try to make myself clear :

What do you mean by massive OSC messages? Couldn’t you break up the data into smaller messages?

by massive i was meaning to send lots of them (not big messages, but big ammount of them) . i’ve experienced strange behaviours when re-using ofOsc messages , and that’s why i made my question… sorry i’m not native english and sometimes my english goes blurry … :slight_smile:

i was meaning if i could be able to re-use the same oscMessage object for different sendings or if i should create and destroy an ofOscMessage for each one sent.

I don’t see any reason that you can’t reuse one by changing the data in it and re-sending.

ok i’ll try it again … in some testings it seemed to me that i was needing to have different objects for sending diferent messages … The problem seemed to be that messages sent with the same object where mixed up … let me try again …

thanks

e*

well i made a simple test on my application with osc messages .

as Tom suggested i reused a ofOscMessage object to send 2 messages … so i did :

  
  
../..  
ofOscSender sender;  
../...  
  
ofOscMessage modeOsc;  
modeOsc.setAddress("/mode");  
modeOsc.addFloatArg(0.5);  
sender.sendMessage(modeOsc);  
  
modeOsc.setAddress("/delay");  
modeOsc.addFloatArg(0.25);  
sender.sendMessage(modeOsc);  
  
  

and this is what i received in Reaktor …

reaktor osc monitor ::

/delay 0.5 0.25

!! ?? !!
seems like the second message sending was being appended with the first one …
i think that there’s some problem when re-using osc messages … has anybody found this problem ?? or what i’m doing wrong ?

Oh, hah, I missed the important part of your question, which was how you could clear the message. :slight_smile: You’re right that there doesn’t appear to be a way to do that. But you could probably:

  
ofxOscSender sender;  
ofxOscMessage m;  
m.setAddress("/mode");  
m.addFloatArg(0.5);  
sender.sendMessage(m);  
  
m = ofxOscMessage();  
m.setAddress("/delay");  
m.addFloatArg(0.25);  
sender.sendMessage(m);  

Anyway, in my code (I use OSC a lot), I typically just create two ofxOscMessage objects.

As for really big OSC messages, you will probably need to break them down into smaller ones. I thought there was support for OSC over TCP (which would make sending large messages more reliable, if slower), but I don’t see support for that now that I’m looking through the code.

While checking out the OSC addon, I noticed that the oscReceiveExample and oscSendExample are identical…i.e. the latter is just a copy of the receive example. Anyone else notice this? Has it always been like this or is this an 0.05 error?

While checking out the OSC addon, I noticed that the oscReceiveExample and oscSendExample are identical…i.e. the latter is just a copy of the receive example. Anyone else notice this? Has it always been like this or is this an 0.05 error?

sorry - the addon package example is wrong in 0.05 - but check the “FAT” package for good send example code in the addonsExamples folder. thanks for catching that - we’ll change and update the svn shortly.

thanks!! - zach

hi again all :wink:

well … i tried what Tom suggested :

m = ofxOscMessage();

so now … when i try to send 2 messages something like

  
ofxOscSender sender;  
ofxOscMessage m;  
  
m = ofxOscMessage();  
m.setAddress("/mode");  
m.addFloatArg(0.5);  
sender.sendMessage(m);  
  
m = ofxOscMessage();  
m.setAddress("/mode");  
m.addFloatArg(0.25);  
sender.sendMessage(m);  

but what happens now …

i receive in the reaktor side :

/mode 0.5
/mode 0.5 0.25

seems like the m = ofxOscMessage() is not clearing the cue of arguments on the ofxOscMessage structure.
is this working properly ?

it seems to me that when u do a new message with ofxOscMessage, the arguments of that oscMessage is not clean up or even reinitialized ?¿

so what i’ve done for testing is adding a function to ofxOscMessage :

  
  
.h   
void clearMessage();  
  
.cpp   
ofxOscMessage::clearMessage()  
{  
args.clear();  
address.clear();  

}

[/code]

with this function called just instead of m = ofxOscMessage() i got normal results … that is :

/mode 0.5
/mode 0.25

is this strange behaviour just on my system or does anybody noticed some problems with osc in this sense ??

thanks a lot for attention

e*

I think the problem with that code is that since it’s not freeing the object nothing is getting changed. you might try actually creating and deleting it using new and delete.

at any rate, your clear function makes total sense.

  
  
  
ofxOscSender sender;  
ofxOscMessage * m;  
  
m = new ofxOscMessage();  
m->setAddress("/mode");  
m->addFloatArg(0.5);  
sender.sendMessage(*m);  
delete m;    // this calls the destructor where the messages are cleared.   
  
m = new ofxOscMessage();     
m->setAddress("/mode");  
m->addFloatArg(0.25);  
sender.sendMessage(*m);  
delete m;  
  
  
  

hope that helps!
zach

1 Like

that’s right … now i got it working ok !!
thanks a lot.

e*