Advertisement
csugrue

PP P5 ProController Broadcast

Aug 27th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. // proController
  2. // http://creativecomputing.cc/p5libs/procontroll/
  3. // get 64 bit lib:
  4. // https://github.com/samaaron/jinput/blob/master/native/macosx/x86_64/libjinput-osx.jnilib
  5.  
  6.  
  7. import oscP5.*;
  8. import netP5.*;
  9. import procontroll.*;
  10. import java.io.*;
  11.  
  12. OscP5 oscP5;
  13. NetAddressList myNetAddressList = new NetAddressList();
  14. int myListeningPort = 9004;
  15. int myBroadcastPort = 9005;
  16.  
  17. String myConnectPattern = "/connect";
  18. String myDisconnectPattern = "/disconnect";
  19.  
  20.  
  21. ControllIO controll;
  22. ControllStick stick;
  23. ControllButton [] buttons = new ControllButton[8];
  24.  
  25. void setup(){
  26.  
  27. size(400,400);
  28.  
  29. oscP5 = new OscP5(this, myListeningPort);
  30.  
  31. controll = ControllIO.getInstance(this);
  32. //controll.printDevices();
  33.  
  34. int deviceID = 2;
  35. ControllDevice device = controll.getDevice(deviceID);
  36.  
  37. println(device.getName()+" has:");
  38. println(" " + device.getNumberOfSliders() + " sliders");
  39. println(" " + device.getNumberOfButtons() + " buttons");
  40. println(" " + device.getNumberOfSticks() + " sticks");
  41.  
  42. device.printSliders();
  43. device.printButtons();
  44. device.printSticks();
  45.  
  46. for(int i = 0; i < 8; i++){
  47. buttons[i] = device.getButton(i);
  48. }
  49.  
  50. stick = device.getStick(0);
  51.  
  52.  
  53. }
  54.  
  55.  
  56. void draw(){
  57.  
  58. background(255);
  59.  
  60. fill(0);
  61. textSize(12);
  62.  
  63. ArrayList<NetAddress> addresses = myNetAddressList.list();
  64. println(addresses);
  65.  
  66. for( int i = 0; i < addresses.size(); i++){
  67. text(addresses.get(i).address(),30,(i+1)*20);
  68. }
  69.  
  70. for(int i = 0; i < 8; i++){
  71. if( buttons[i].pressed()){
  72. fill(255,0,0);
  73. sendButton(i,1);
  74. }else{
  75. sendButton(i,0);
  76. fill(0);
  77. }
  78.  
  79. ellipse((i+1) * width/9.0,height/2,20,20);
  80.  
  81. }
  82.  
  83.  
  84.  
  85.  
  86. //println(stick.getX());
  87.  
  88. }
  89.  
  90. void sendButton( int buttonNum, int val ){
  91. OscMessage m = new OscMessage("/button");
  92. m.add(buttonNum); /* add an int to the osc message */
  93. m.add(val); /* add an int to the osc message */
  94. oscP5.send(m, myNetAddressList);
  95.  
  96. }
  97.  
  98. void oscEvent(OscMessage theOscMessage) {
  99.  
  100. /* check if the address pattern fits any of our patterns */
  101. if (theOscMessage.addrPattern().equals(myConnectPattern)) {
  102. connect(theOscMessage.netAddress().address());
  103. }
  104. else if (theOscMessage.addrPattern().equals(myDisconnectPattern)) {
  105. disconnect(theOscMessage.netAddress().address());
  106. }
  107. /**
  108. * if pattern matching was not successful, then broadcast the incoming
  109. * message to all addresses in the netAddresList.
  110. */
  111. else {
  112. //oscP5.send(theOscMessage, myNetAddressList);
  113. }
  114. }
  115.  
  116.  
  117. private void connect(String theIPaddress) {
  118. if (!myNetAddressList.contains(theIPaddress, myBroadcastPort)) {
  119. myNetAddressList.add(new NetAddress(theIPaddress, myBroadcastPort));
  120. println("### adding "+theIPaddress+" to the list.");
  121. } else {
  122. println("### "+theIPaddress+" is already connected.");
  123. }
  124. println("### currently there are "+myNetAddressList.list().size()+" remote locations connected.");
  125. }
  126.  
  127.  
  128.  
  129. private void disconnect(String theIPaddress) {
  130. if (myNetAddressList.contains(theIPaddress, myBroadcastPort)) {
  131. myNetAddressList.remove(theIPaddress, myBroadcastPort);
  132. println("### removing "+theIPaddress+" from the list.");
  133. } else {
  134. println("### "+theIPaddress+" is not connected.");
  135. }
  136. println("### currently there are "+myNetAddressList.list().size());
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement