Advertisement
csugrue

PP P5 Osc Controller Receiver

Aug 27th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import oscP5.*;
  2. import netP5.*;
  3.  
  4.  
  5. OscP5 oscP5;
  6. NetAddress myBroadcastLocation;
  7.  
  8. int [] buttons = new int[8];
  9.  
  10. void setup() {
  11.  
  12. size(400, 400);
  13.  
  14. oscP5 = new OscP5(this, 9005);
  15. myBroadcastLocation = new NetAddress("10.1.130.128", 9004);
  16.  
  17. for ( int i = 0; i < 8; i++) {
  18. buttons[i] = 0;
  19. }
  20.  
  21.  
  22. }
  23.  
  24.  
  25. void draw() {
  26. background(0);
  27.  
  28. fill(255);
  29. textSize(12);
  30. text("press 'c' to connect to server",20,20);
  31.  
  32. stroke(255);
  33.  
  34. for (int i = 0; i < 8; i++) {
  35. if ( buttons[i] == 1) {
  36. fill(255, 0, 0);
  37. } else {
  38. fill(0);
  39. }
  40. ellipse((i+1) * width/9.0, height/2, 20, 20);
  41. }
  42.  
  43. }
  44.  
  45.  
  46.  
  47.  
  48. void keyPressed() {
  49.  
  50. OscMessage m;
  51.  
  52. if( key == 'c'){
  53. m = new OscMessage("/connect");
  54. oscP5.send(m, myBroadcastLocation);
  55. }else if( key == 'd'){
  56. m = new OscMessage("/disconnect");
  57. oscP5.send(m, myBroadcastLocation);
  58. }
  59.  
  60. }
  61.  
  62.  
  63. /* incoming osc message are forwarded to the oscEvent method. */
  64. void oscEvent(OscMessage theOscMessage) {
  65.  
  66. if ( theOscMessage.checkAddrPattern("/button")) {
  67. int buttonId = theOscMessage.get(0).intValue();
  68. int val = theOscMessage.get(1).intValue();
  69. buttons[buttonId] = val;
  70. // println("button "+ buttonId + " : " + val);
  71. }
  72.  
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement