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.
IndexProgramming Questions & HelpIntegration › trying to send osc data
Page Index Toggle Pages: 1
trying to send osc data (Read 1189 times)
trying to send osc data
Nov 25th, 2005, 3:17pm
 
hi everybody,
I'm fairly new to processing: right now i'm using the Mouse Functions example and want it to send osc data (the x and y position of the ball) to any osc receiver; in this case it is supercollider (could be max or pd as well).
now everytime i run the code, and try to drag the ball the sketch crashes on me. see below for the code of my sketch and the command line output.
is there something i'm missing or doing wrong?

thanks for your help!

////////this is my code  ////

import osc.*;
import oscP5.*;


OscP5 oscP5;
int sendToPort;
int receiveAtPort;
String host;
String oscP5event;

int r = 155;
int g = 100;
int b = 100;

float bx;
float by;
int bs = 10;
boolean bover = false;
boolean locked = false;
float bdifx = 0.0;
float bdify = 0.0;


void setup()
{
 size(300, 300);
 bx = width/2.0;
 by = height/2.0;
 smooth();
 ellipseMode(CENTER_RADIUS);  
 framerate(25);
}

// setup osc functioniality

void initOsc() {
 receiveAtPort = 12000;
 sendToPort = 57120; // supercollider
 host = "127.0.0.1";
 oscP5event = "oscEvent";
 oscP5 = new OscP5(this, host, sendToPort, receiveAtPort, oscP5event);
}

void draw()
{
 background(0);
 
 // Test if the cursor is over the box
 if (mouseX > bx-bs && mouseX < bx+bs &&
     mouseY > by-bs && mouseY < by+bs) {
   bover = true;  
   if(!locked) {
     stroke(255);
     fill(153);
   }
 } else {
   stroke(153);
   fill(153);
   bover = false;
 }
 
 // Draw the box
 ellipse(bx, by, bs, bs);
}

void mousePressed() {
 if(bover) {
   locked = true;
   fill(255, 255, 255);
 } else {
   locked = false;
 }
 bdifx = mouseX-bx;
 bdify = mouseY-by;
 
}

void mouseDragged() {
 if(locked) {
   bx = mouseX-bdifx;
   by = mouseY-bdify;
   
   Object[] xyObj;
   xyObj = new Object[] { new Float(bx), new Float(by) };
   
   oscP5.sendMsg("/xytest", xyObj);
    // println(bx);
   // println(by);
 }
}

void mouseReleased() {
 locked = false;
}

//// and this is my error:

java.lang.NullPointerException
at Temporary_6813_4454.mouseDragged(Temporary_6813_4454.java:86)
at processing.core.PApplet.handleMouseEvent(PApplet.java:1370)
at processing.core.PApplet.dequeueMouseEvents(PApplet.java:1306)
at processing.core.PApplet.display(PApplet.java:1211)
at processing.core.PGraphics.requestDisplay(PGraphics.java:520)
at processing.core.PApplet.run(PApplet.java:1009)
at java.lang.Thread.run(Thread.java:552)

Re: trying to send osc data
Reply #1 - Nov 25th, 2005, 11:29pm
 
hi,
you are not calling the initOsc() method this is why you get the nullpointerexception because oscP5 is not instantiated. put
initOsc();
into the setup() method.
also put the method

void oscEvent(OscIn theOscIn) {
}

into your code. this is the method incoming messages are forwarded to. you will find the content of the message in theOscIn object from which you can check and parse the address pattern, typetag and the data that comes with the osc message.

andi
Re: trying to send osc data
Reply #2 - Nov 26th, 2005, 12:57am
 
great!
now it works fine. i was sure, i was missing something.
thanks sojamo.
Page Index Toggle Pages: 1