Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import oscP5.*;
- import netP5.*;
- OscP5 oscP5;
- NetAddress myRemoteLocation;
- float firstValue = 0;
- float secondValue = 0;
- float thirdValue = 0;
- float posx;
- float posy;
- void setup() {
- size(400, 400);
- oscP5 = new OscP5(this, 12000); //receiving port
- myRemoteLocation = new NetAddress("127.0.0.1", 12000);//sending port
- }
- void draw() {
- background(firstValue, secondValue, thirdValue);
- ellipse(posx, posy, 20, 20);
- }
- void mousePressed() {
- sendMessage();
- }
- void oscEvent(OscMessage theOscMessage) {
- println(theOscMessage);
- if (theOscMessage.checkAddrPattern("/3/xy")==true) {
- if (theOscMessage.checkTypetag("ff")) {// etiquetas del typetag
- float v1 = theOscMessage.get(0).floatValue();
- float v2 = theOscMessage.get(1).floatValue();
- posx = map(v1, 0, 1, 0, width);
- posy = map(v2, 0, 1, 0, height);
- return;
- }
- }
- if (theOscMessage.checkAddrPattern("/1/fader1")==true) {
- if (theOscMessage.checkTypetag("f")) {
- float v1 = theOscMessage.get(0).floatValue();
- firstValue = map(v1, 0, 1, 0, 255);
- }
- }
- if (theOscMessage.checkAddrPattern("/1/fader2")==true) {
- if (theOscMessage.checkTypetag("f")) {
- float v2 = theOscMessage.get(0).floatValue();
- secondValue = map(v2, 0, 1, 0, 255);
- }
- }
- if (theOscMessage.checkAddrPattern("/1/fader3")==true) {
- if (theOscMessage.checkTypetag("f")) {
- float v3 = theOscMessage.get(0).floatValue();
- thirdValue = map(v3, 0, 1, 0, 255);
- }
- }
- }
- void sendMessage() {
- OscMessage myMessage = new OscMessage("/test");
- myMessage.add(5);
- myMessage.add(12.34);
- myMessage.add("some text");
- oscP5.send(myMessage, myRemoteLocation);
- println("message sent");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement