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.
Pages: 1 2 
OSCp5 (Read 7863 times)
OSCp5
Oct 24th, 2006, 4:09pm
 
hi list

i'm new to processing and i've got some little problems using OSCp5 lib.
I'd like to send messages from Max to Processing using OpenSoundControl, but i only able to print wrong messages.

i'm trying to do that with this example:

//////////////////////////////////////////////////////////////////////

/**
* oscP5parsing by andreas schlegel
* example shows how to parse incoming osc messages "by hand".
* it is recommended to take a look at oscP5plug for an
* alternative way to parse messages.
*/

import oscP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

void setup() {
 size(400,400);
 frameRate(25);
 /* start oscP5, listening for incoming messages at port 12000 */
 oscP5 = new OscP5(this,12000);
 
 /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
  * an ip address and a port number. myRemoteLocation is used as parameter in
  * oscP5.send() when sending osc packets to another computer, device,
  * application. usage see below. for testing purposes the listening port
  * and the port of the remote location address are the same, hence you will
  * send messages back to this sketch.
  */
 myRemoteLocation = new NetAddress("127.0.0.1",12000);
}

void draw() {
 background(0);  
}

void oscEvent(OscMessage theOscMessage) {
 /* check if theOscMessage has the address pattern we are looking for. */
 
 if(theOscMessage.checkAddrPattern("/test")==true) {
   /* check if the typetag is the right one. */
   if(theOscMessage.checkTypetag("ifs")) {
     /* parse theOscMessage and extract the values from the osc message arguments. */
     int firstValue = theOscMessage.get(0).intValue();  
     float secondValue = theOscMessage.get(1).floatValue();
     String thirdValue = theOscMessage.get(2).stringValue();
     print("### received an osc message /test with typetag ifs.");
     println(" values: "+firstValue+", "+secondValue+", "+thirdValue);
   }  
 } else {
       println("### received an osc message. address pattern didnt match /test .");
 }
}

//////////////////////////////////////////////////////////////////////

if i send non-/test messages the output is obviously

### received an osc message. address pattern didnt match /test .

but if i send a /test message i've no output while i'm expetcing to see the number sent by /test message printed. I'm sure that i'm doing something wrong...

thank you very much for help
Re: OSCp5
Reply #1 - Oct 25th, 2006, 11:01am
 
hi,
the reason why you dont get any output when sending a /test message with a typetag different than ifs is, that this message will be caught by the first if statement in the oscEvent method. right after the fist if statement the program goes on with the second if statement to check the typetag of the message.if the typetag of your /test message does not euqal the typetag that is checked (here checkTypetag("ifs")) then the program will leave the if statements and the method without giving an output. so your /test message did arrive at the oscEvent method by the typetag did not correspond with the one that's being checked.
you would need to put some code after
if(theOscMessage.checkAddrPattern("/test")==true) {
like e.g.
println("### got a /test message with typetag "+theOscMessage.typetag());

best,
andi

Re: OSCp5
Reply #2 - May 13th, 2007, 5:30pm
 
Hi.

Have got a question about oscp5. Hope a answer will help me and others.
I'm new to osc and processing but have a lingo background.
I'm trying to use a wiimote on my pc. I'm using osc to make glovepie and processing chatting. But I can't get the message out of oscevent.

So glovepie is doing this:

SendOsc("localhost", 12000, "/wiimote1", wiimote1.Roll, wiimote1.gy )

and I'm using your example "oscP5oscArgument":

import oscP5.*;
import netP5.*;
//Declaration de mes variables
float wiimote1Roll;
float wiimote1Y;
OscP5 oscP5;
NetAddress myRemoteLocation;

void setup() {
 size(400,400);
 //frameRate(25);
 /* start oscP5, listening for incoming messages at port 12000 */
 oscP5 = new OscP5(this,12000);
 myRemoteLocation = new NetAddress("localhost",12000);
}

void draw(){
 background(0);
}

void oscEvent(OscMessage theOscMessage) {

 if(theOscMessage.checkAddrPattern("/wiimote1")==true) {
   float wiimote1Roll = theOscMessage.get(0).floatValue();
   float wiimote1Y = theOscMessage.get(1).floatValue();
   println(" Axe X = " + wiimote1Roll + " Axe Y = " + wiimote1Y);
   return;
 }

}

So that's good ( I think ) but I can't manage to use "wiimote1Roll" in draw(). I am sure it's really silly and that it's just me who doesn't know processing enough.
It would nice to have a "wiimote library" but I understand that there is more important things to do.

Thank you for your future answer, and thanks for the oscp5 library.
Re: OSCp5
Reply #3 - May 13th, 2007, 5:48pm
 
hi again,

Just found a solution but it seems a bit slow.... is that the "right" way of doing it ?

import oscP5.*;
import netP5.*;
//Declaration de mes variables
float wiimote1Roll;
float wiimote1Y;
OscP5 oscP5;
NetAddress myRemoteLocation;

void setup() {
 size(400,400);
 /* start oscP5, listening for incoming messages at port 12000 */
 oscP5 = new OscP5(this,12000);
 myRemoteLocation = new NetAddress("localhost",12000);
}

void draw(){
 background(250);
 smooth();
 point(wiimote1Roll,200);
}

void oscEvent(OscMessage theOscMessage) {

 if(theOscMessage.checkAddrPattern("/wiimote1")==true) {
   float wiimote10 = theOscMessage.get(0).floatValue();
   float wiimote11 = theOscMessage.get(1).floatValue();
   wiimote1Roll = wiimote10+180;
   //println(" Axe X = " + wiimote1Roll + " Axe Y = " + wiimote1Y);
   return;
 }

}
Re: OSCp5
Reply #4 - May 13th, 2007, 6:11pm
 
thats the right way to do it. oscP5 is running in its own thread, so every message that comes in from oscP5 is not in sync with your sketch thread. therefore, the way you are doing it is the right way to go - using an extra variable to store incoming osc values. i am not sure why this should be slow though. but you can also try the plug method:

in setup put this line after you create oscP5
Code:

oscP5.plug(this, "wiimote","/wiimote1");

see the documentation and the example oscP5plug for further information how the plug method works.


then create a method wiimote
Code:

public void wiimote(float theValueA, float theValueB) {
wiimote1Roll = theValueA;
wiimote1Y = theValueB;
}


now you dont need to parse the incoming osc message /wiimote1 anymore because it will be forwarded to the method wiimote automatically.

andi
Re: OSCp5
Reply #5 - May 13th, 2007, 6:25pm
 
Thank you for your quick answer Smiley

I am going to try the plug thing. I have to understand it know.

hehe...
Re: OSCp5
Reply #6 - May 13th, 2007, 6:34pm
 
That's great!! Cleaner and simpler then the first version.
Thank you very much for your advises.

Have a good day.
Re: OSCp5
Reply #7 - Jan 30th, 2008, 11:02pm
 
Hey quick question. What exactly is netP5? I have a program that is trying to import it, but processing says it can't locate it.

Thanks
Re: OSCp5
Reply #8 - Jan 31st, 2008, 5:41am
 
netP5 is an additional lib to oscP5 that handles the network communication over tcp, udp, or multicast. netP5 is included in the latest oscP5.jar distribution. if in your case processing says it can not locate it, i am assuming you are using an older version of oscP5. what can you do?
(1)download the latest version from the website
(2) stick to the old version of oscP5 and just delete import netP5.*; from you code.
Re: OSCp5
Reply #9 - Feb 29th, 2008, 10:23am
 
Hi, I just downloaded version 0.9.3 of oscP5 and getting the "can't find netP5 error".  I don't know what I am doing wrong.  Is there anything else I need to do to run the demos besides put the contents of the extracted zip files into the sketches directory?
Re: OSCp5
Reply #10 - Feb 29th, 2008, 4:15pm
 
odd that you get this error. netP5 is included in the oscP5.jar and works fine with the environments i tested.
what setup are you using (processing version, os)?
do you have any other (older) oscP5 library installed e.g. in one of your sketch folders or the libraries folder?
Re: OSCp5
Reply #11 - Feb 29th, 2008, 5:36pm
 
I'm new to Processing so Processing 0135 (I'm on a Mac, 10.4.11) is the only build I have on my system.

I get the following netP5 error:

Semantic Error: You need to modify your classpath, sourcepath, bootclasspath, and/or extdirs setup. Jikes could not find package "netP5"

The application can find oscP5 okay so I'm not sure what I am doing wrong.  Any help would be greatly appreciated, thanks for your time.
Re: OSCp5
Reply #12 - Feb 29th, 2008, 8:43pm
 
i tested with processing 135 on osx 10.4.11 and worked for me (i made sure there is no other oscP5 and/or netP5 in the classpath), i guess i cant give you a positive solution to the problem you encounter so far. i put a netP5.jar for download  here.  put the netP5.jar next to the oscP5.jar in the library folder of oscP5. if that doesnt work, create a netP5/library folder, put netP5.jar in there.
hope this solves the problem, still weird,
andi
Re: OSCp5
Reply #13 - Mar 1st, 2008, 4:24am
 
That worked!  Thanks.  If I find out why it wasn't working before, I'll be sure to post it here. Thanks again.
Re: OSCp5
Reply #14 - May 5th, 2008, 10:42pm
 
Hi, ive got a question, im trying to make processing talk to glovePie, no the other way around. is just that the way im handling things i cant tell the wiimote to do something from processing, on top of that im on a pc. ----- Or can u tell me some way to make the wiimote vibrate from processing, cuzz i have processing reading the OSC input from another program. (wiimoteOSC V0.2b). Maybe theres a way to send something from processing via OSC but i dont know how to read from GlovePIE. Thx

NEVERMIND FIGURED IT OUT, GUESS ITS BETTER TO LOOK IN THE DOCUMENTATION BEFORE ASKING DULL QUESTIONS ^^
Pages: 1 2