We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
question about OscP5 (Read 1027 times)
question about OscP5
Jul 11th, 2009, 2:35pm
 
hi

sorry for messing up the feed, but I had to delete my previous message because my pain runs deeper. aaarrrg.

here's a piece of code I just don't dig:

Code:

import oscP5.*;
import netP5.*;

void setup() {
 
 OscMessage myMessage = new OscMessage("/test");
 
 // add some stuff with add()
 myMessage.add(123); /* add an int to the osc message */
 myMessage.add(12.34); /* add a float to the osc message */
 myMessage.add("some text"); /* add a string to the osc message */
 myMessage.print();
         
 // set everything at once with setArguments()
 Object[] args = {123, 12.34, "some text"};
 myMessage.setArguments(args);
 myMessage.print();
 
}


that outputs:

Code:

-OscMessage----------
received from   null:0
addrpattern     /test
typetag ifs

---------------------
-OscMessage----------
received from   null:0
addrpattern     /test
typetag ifsifs
[0] 123
[1] 12.34
[2] some text

---------------------


so why are they different? I just don't get it. Please help. much obliged.
Re: question about OscP5
Reply #1 - Jul 11th, 2009, 10:28pm
 
hi alvaro,
in your case, setArguments does add the 3 values to the existing arguments in your osc message. setArguments might be a misleading name for what the method is doing - it actually adds arguments. what you can do though is to clear the message after you print it. by doing so, the address pattern also gets cleared and has to be set again. (this is a bit inconvenient, but a method clearArguments does not yet exist, but would be good to add, will do.)

Code:

m.clear();
m.setAddrPattern("/test");
// set everything at once with setArguments()
Object[] args = {123, 12.34, "some text"};
myMessage.setArguments(args);
myMessage.print();


doing so you will get the same result for both printed outputs.
best,
andreas

Re: question about OscP5
Reply #2 - Jul 12th, 2009, 2:41am
 
thanks Andreas. That accounts for the typetag. But what happened to the values? I got me the trunk, and I think OscMessage.print() is broken.

in add(int), you are adding the value to _myData

in setArguments(Object[]), you are adding the value to _myArguments

In the print() method, you are printing _myArguments only. So when I do an add(), the message is correct, but can't be printed.

Same thing with public Object[] arguments(), which got me confused while testing. So in the end messages get sent all right, but tests fail.

If I do this:
Code:

OscMessage m = new OscMessage("/test");
m.add(123)

This test will fail with an ArrayIndexOutOfBounds Exception:
Code:

assertEquals(new Integer(123), (Integer) m.arguments()[0]);


While if I do this:
Code:

OscMessage m = new OscMessage("/test");
Object[] args = {123};
m.setArguments(args);


The same test will pass. This only happens when you try to extend and unit test the lib, otherwise excellent lib.

best
alvaro
Page Index Toggle Pages: 1