Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. import oscP5.*;
  2. import netP5.*;
  3.  
  4. OscP5 oscP5;
  5. NetAddress myRemoteLocation;
  6.  
  7. float firstValue = 0;
  8. float secondValue = 0;
  9. float thirdValue = 0;
  10. float posx;
  11. float posy;
  12.  
  13. void setup() {
  14. size(400, 400);
  15. oscP5 = new OscP5(this, 12000); //receiving port
  16. myRemoteLocation = new NetAddress("127.0.0.1", 12000);//sending port
  17. }
  18.  
  19. void draw() {
  20. background(firstValue, secondValue, thirdValue);
  21. ellipse(posx, posy, 20, 20);
  22. }
  23.  
  24. void mousePressed() {
  25. sendMessage();
  26. }
  27.  
  28.  
  29. void oscEvent(OscMessage theOscMessage) {
  30. println(theOscMessage);
  31. if (theOscMessage.checkAddrPattern("/3/xy")==true) {
  32. if (theOscMessage.checkTypetag("ff")) {// etiquetas del typetag
  33. float v1 = theOscMessage.get(0).floatValue();
  34. float v2 = theOscMessage.get(1).floatValue();
  35. posx = map(v1, 0, 1, 0, width);
  36. posy = map(v2, 0, 1, 0, height);
  37.  
  38. return;
  39. }
  40. }
  41. if (theOscMessage.checkAddrPattern("/1/fader1")==true) {
  42. if (theOscMessage.checkTypetag("f")) {
  43. float v1 = theOscMessage.get(0).floatValue();
  44. firstValue = map(v1, 0, 1, 0, 255);
  45. }
  46. }
  47. if (theOscMessage.checkAddrPattern("/1/fader2")==true) {
  48. if (theOscMessage.checkTypetag("f")) {
  49. float v2 = theOscMessage.get(0).floatValue();
  50. secondValue = map(v2, 0, 1, 0, 255);
  51. }
  52. }
  53. if (theOscMessage.checkAddrPattern("/1/fader3")==true) {
  54. if (theOscMessage.checkTypetag("f")) {
  55. float v3 = theOscMessage.get(0).floatValue();
  56. thirdValue = map(v3, 0, 1, 0, 255);
  57. }
  58. }
  59. }
  60. void sendMessage() {
  61.  
  62. OscMessage myMessage = new OscMessage("/test");
  63. myMessage.add(5);
  64. myMessage.add(12.34);
  65. myMessage.add("some text");
  66. oscP5.send(myMessage, myRemoteLocation);
  67. println("message sent");
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement