Shy oscP5 kissed Android at last, not really perfect
in
Android Processing
•
2 years ago
Hi,
I had some troubles with receiving incoming values from Android Emulator, but
when i replaced loopback address (127.0.0.1) with my private IP address (192.168.0.10), It works very well. Does anybody knows the reason? Or any ideas about how works with Multicast (239.0.0.1) ?
Anyway, here are working codes, I hope it will help newcomers like me.
Cheers and thanks in advance!
oscP5 on Processing:
- /**
- * oscP5sendreceive by andreas schlegel
- * example shows how to send and receive osc messages.
- * oscP5 website at http://www.sojamo.de/oscP5
- */
- import oscP5.*;
- import netP5.*;
- 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.
- */
- /*change 192.168.0.10 to your own IP address*/
- myRemoteLocation = new NetAddress(" 192.168.0.10",12000);
- }
- void draw() {
- }
- /* incoming osc message are forwarded to the oscEvent method. */
- void oscEvent(OscMessage theOscMessage) {
- if(theOscMessage.checkAddrPattern("/mousedown"))
- {
- /* print the address pattern and the typetag of the received OscMessage */
- // print("### received an osc message.");
- // print(" addrpattern: "+theOscMessage.addrPattern());
- // println(" typetag: "+theOscMessage.typetag());
- println("aha!");
- background(255);
- }
- else if(theOscMessage.checkAddrPattern("/mousedrag")) {
- println("wooooooooooooow!");
- }
- else if(theOscMessage.checkAddrPattern("/mouseup")) {
- println("yeah!");
- background(0);
- }
- }
oscP5 on
Android emulatior:
- /*
- Send mouse positions from Android emulatior to Processing sketch running on same WiFi network.
- Modification based on hva.francesco's work. http://forum.processing.org/#Topic/25080000000336005
- Version 0.1 By Lei Gao http://imlab.cc/whale (10.Nov.2010)
- */
- import oscP5.*;
- import netP5.*;
- OscP5 oscP5;
- NetAddress myRemoteLocation;
- int x;
- int y;
- void setup() {
- size(screenWidth,screenHeight);
- background(255);
- frameRate(25);
- /* set up a remote location */
- /*change 192.168.0.10 to your own IP address*/
- myRemoteLocation = new NetAddress(" 192.168.0.10",12000);
- }
- void draw() {
- }
- void mousePressed() {
- // create a new OscMessage with an address pattern, in this case /mouse_down.
- OscMessage myOscMessage = new OscMessage("/mousedown");
- // add a value (an integer) to the OscMessage
- myOscMessage.add(mouseX);
- myOscMessage.add(mouseY);
- //send the OscMessage to the remote location.
- OscP5.flush(myOscMessage,myRemoteLocation);
- x = mouseX;
- y = mouseY;
- }
- void mouseDragged() {
- // create a new OscMessage with an address pattern, in this case /mouse_down.
- OscMessage myOscMessage = new OscMessage("/mousedrag");
- // add a value (an integer) to the OscMessage
- myOscMessage.add(mouseX);
- myOscMessage.add(mouseY);
- //send the OscMessage to the remote location.
- OscP5.flush(myOscMessage,myRemoteLocation);
- // OscP5.flush(myOscMessage,myRemoteLocation);
- // draws on screen
- stroke(0);
- line(x,y,mouseX,mouseY);
- x = mouseX;
- y = mouseY;
- noStroke();
- }
- void mouseReleased() {
- // create a new OscMessage with an address pattern, in this case /mouse_down.
- OscMessage myOscMessage = new OscMessage("/mouseup");
- // add a value (an integer) to the OscMessage
- myOscMessage.add(mouseX);
- myOscMessage.add(mouseY);
- //send the OscMessage to the remote location.
- OscP5.flush(myOscMessage,myRemoteLocation);
- }
- void keyPressed() {
- if(key == CODED) {
- if (keyCode == UP) {
- OscMessage myOscMessage = new OscMessage("/margins");
- // IMPORTANTE: per android cambiare con le seguenti righe
- myOscMessage.add(screenWidth);
- myOscMessage.add(screenHeight);
- OscP5.flush(myOscMessage,myRemoteLocation);
- background(255);
- }
- }
- }
1