stephenl
YaBB Newbies
Offline
Posts: 4
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)