OSC receiver on iPad

Hi all :

I use Mr.stephanschulz`s source code,wanna make a OSC send & receive APP on iPad.

http://forum.openframeworks.cc/t/iphone-to-arduino/2279/6">iphone to arduino]http://forum.openframeworks.cc/t/iphone-to-arduino/2279/6

thanks,
craftweak

Hi,

Had a quick look at your code and didn’t see anything immediately wrong. E.g. you look to be setting up the receive port number ok… Are you sure the sender is sending OSC ok to the iPad on the right address and on your port 8000?

My sender is working in OF app or maxmsp on my computer.

Or is there any solution to print out any incoming messages on iPad?

Hi, this is what I do to print out the received OSC messages to the debug console:

  
// assemble incoming message into a string  
  
NSMutableString *incomingOSCMessage = [[NSMutableString alloc] initWithFormat:ofxStringToNSString(m.getAddress().c_str())];  
  
for (int i=0; i < m.getNumArgs(); i++) {  
  
	[incomingOSCMessage appendString:@" "];  
  
	switch (m.getArgType(i)) {  
  
		case OFXOSC_TYPE_INT32:  
		[incomingOSCMessage appendString:ofxStringToNSString(ofToString(m.getArgAsInt32(i))) ];  
		break;  
  
		case OFXOSC_TYPE_FLOAT:  
		[incomingOSCMessage appendString:ofxStringToNSString(ofToString(m.getArgAsFloat(i),2)) ];		  
		break;  
  
		case OFXOSC_TYPE_STRING:  
		[incomingOSCMessage appendString:ofxStringToNSString(m.getArgAsString(i).c_str()) ];  
		break;  
  
		default:  
		DLog("Unknown type");  
		break;  
  
	}  
}  
  
// Print message  
  
printf("%s", ofxNSStringToString(incomingOSCMessage).c_str() );   
  
[incomingOSCMessage release];  
  
  

By this, do you mean that it works ok locally using the iPad simulator, but it doesn’t work remotely using the iPad device?

It works both Simulator and Device,but only sender.
I just can`t send OSC to my app.

Dose anyone send OSC to his i-Device Before?

Yes, me! :wink: )… so it should work…

It also works that send OSC between iphone and ipad via touchOSC.
Or from maxmsp to touchOSC.

But never works on my iPad OF APP(Receive part)…

[quote author=“craftweak”]It also works that send OSC between iphone and ipad via touchOSC.
Or from maxmsp to touchOSC.

But never works on my iPad OF APP(Receive part)…[/quote]
OK, that’s good information… I’ll take another look at your code if I get time…

Yes, me! :wink: )… so it should work…[/quote]

I have not try my OSCulator yet.
But Isn`t it the same as Max/msp in OSC signal?

Yes, as long as e.g. TouchOSC on the iPad’s receiving your OSC messages ok, then it looks like your sender on your computer is ok.

Have you tried putting a debug printf just after the while( receiver.hasWaitingMessages() ) statement to see if you’re actually receiving anything at all…?

Took another quick look at your code, but didn’t see anything awry, sorry…

[quote author=“Gwydion”]Yes, as long as e.g. TouchOSC on the iPad’s receiving your OSC messages ok, then it looks like your sender on your computer is ok.

Have you tried putting a debug printf just after the while( receiver.hasWaitingMessages() ) statement to see if you’re actually receiving anything at all…?

Took another quick look at your code, but didn’t see anything awry, sorry…[/quote]

  
	while( receiver.hasWaitingMessages() )  
	{  
		// get the next message  
		ofxOscMessage m;  
		receiver.getNextMessage( &m );  
		//printf(m.getAddress());  
		// check for mouse moved message  
		if ( m.getAddress() == "/playhead" )  
		{  
			// both the arguments are int32's  
			rX = m.getArgAsInt32( 0 );  
			rY = m.getArgAsInt32( 1 );  
			cout << rX<<endl;  
			  
		}  
		// check for mouse button message  
  
		  
  
	}  

Unfortunately,it prints NOTHING…

Or may I have your source code that you have try to receive OSC form OSCulator?

Here’s the relevant code from my app…

testApp.h

  
#include "ofxOsc.h"  
  
class testApp : public ofxiPhoneApp {  
	  
public:  
  
	ofxOscReceiver receiver;  
  
...  
  

My view controller sets my port number…

  
myApp->receiver.setup( ofToInt(ofxNSStringToString(incomingPortNumberField.text)) );  

…but you can just hardcode it as you’ve done.

testApp.mm

  
void testApp::update() {  
	  
// OSC: check for incoming  
if (receiver.hasWaitingMessages() ) {  
			  
	ofxOscMessage m;  
	receiver.getNextMessage( &m );  
			  
	// assemble incoming message into a string  
	NSMutableString *incomingOSCMessage = [[NSMutableString alloc] initWithFormat:ofxStringToNSString(m.getAddress().c_str())];  
  
	for (int i=0; i < m.getNumArgs(); i++) {  
		[incomingOSCMessage appendString:@" "];  
  
		switch (m.getArgType(i)) {  
			case OFXOSC_TYPE_INT32:  
			[incomingOSCMessage appendString:ofxStringToNSString(ofToString(m.getArgAsInt32(i))) ];  
			break;  
			case OFXOSC_TYPE_FLOAT:  
			[incomingOSCMessage appendString:ofxStringToNSString(ofToString(m.getArgAsFloat(i),2)) ];		  
			break;  
			case OFXOSC_TYPE_STRING:  
			[incomingOSCMessage appendString:ofxStringToNSString(m.getArgAsString(i).c_str()) ];  
			break;  
			default:  
			printf("Unknown type");  
			break;  
		}  
	}  
  
	[incomingOSCMessage release];  
}  
  
// do actions based on incoming message  
	  
}  

See… based on my code, it looks pretty much the same as yours. I add the standard OF 0061 addons/ofxOsc library to the project and haven’t touched the contents of those ofxOsc files, it all worked out of the box…

source code update

http://craftweak.iolab.tw/osc2.zip

  
while( receiver.hasWaitingMessages() )  
	{  
		// get the next message  
		ofxOscMessage m;  
		receiver.getNextMessage( &m );  
		printf(m.getAddress());  
		  
		// check for mouse moved message  
		if ( m.getAddress() == "/playhead" )  
		{  
			// both the arguments are int32's  
			rXX = m.getArgAsInt32( 0 ) ;  
			rYY = m.getArgAsInt32( 1 ) ;  
			cout << rXX<<endl;  
			  
			  
		}  
		else if ( m.getAddress() == "/n1" )  
		{  
			// the single argument is a string  
			n1 = m.getArgAsFloat( 0 ) ;  
			cout << n1<<endl;  
		}  

Now i can print getAddress(),but only address…

Seems like m.getArgAsInt32( 0 ) doesn`t work.

Well, that’s much better! :smiley: What did you change? How come it’s at least getting an incoming OSC message now?

Try printing out m.getNumArgs() and m.getArgType(0) to see if your arguments are ok.

I copy src folder from ofxOsc for computer in place of the ofxOsciPhone`s one.

And it works…

So the problem is my ofxOsc source code in fxOsciPhone is out of date…

But It is gotton from here…

http://forum.openframeworks.cc/t/iphone-to-arduino/2279/5">iphone to arduino]http://forum.openframeworks.cc/t/iphone-to-arduino/2279/5

So the difference between ofxOsc and ofxOsciPhone is only oscpack?

Or there is no difference beside the name?

Yay, congrats on getting it working!

No idea about the other code… just stick with what works… :wink: