Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 23rd, 2012  |  syntax: None  |  size: 2.73 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /**
  2. * Testing LiveOSC.
  3. * Just a testing of how to control Ableton Live with Processing
  4. *
  5. * Sends PLAY or STOP message to Live
  6. * Handles 3 incoming messages:
  7. *   /live/play
  8. *   /live/clip/info
  9. *   /live/volume
  10. */
  11.  
  12. import oscP5.*;
  13. import netP5.*;
  14. import controlP5.*;
  15.  
  16. //GUI library
  17. ControlP5 controlP5;
  18.  
  19. //OSC related libraries
  20. OscP5 oscP5;
  21. NetAddress myRemoteLocation;
  22.  
  23. //Ports defined by LiveOSC,cannot be changed
  24. int inPort = 9001;
  25. int outPort = 9000;
  26.  
  27. void setup() {
  28.   size(400,400);
  29.  
  30.   //OSC Server
  31.   oscP5 = new OscP5(this,inPort);
  32.   //Remote address
  33.   myRemoteLocation = new NetAddress("localhost",outPort);
  34.  
  35.   //GUI settings and buttons
  36.   frameRate(30);
  37.   controlP5 = new ControlP5(this);
  38.   controlP5.addButton("Play");
  39.   controlP5.addButton("Stop");
  40.  
  41.   //OSC address mapping
  42.   oscP5.plug(this,"incomingHandlerPlay","/live/play");
  43.   oscP5.plug(this,"incomingHandlerClipInfo","/live/clip/info");
  44.   oscP5.plug(this,"incomingHandlerVolume","/live/volume");
  45. }
  46.  
  47. void draw() {
  48.   background(0);
  49. }
  50. /**
  51. * implements button click handler
  52. * button: play
  53. *
  54. */
  55. void Play() {
  56.   println("clicked play");
  57.   OscMessage myMessage = new OscMessage("/live/play");
  58.   oscP5.send(myMessage, myRemoteLocation);
  59. }
  60. /**
  61. * implements button click handler
  62. * button: stop
  63. *
  64. */
  65. void Stop() {
  66.   println("clicked stop");
  67.   OscMessage myMessage = new OscMessage("/live/stop");
  68.   oscP5.send(myMessage, myRemoteLocation);
  69.  
  70. }
  71. /**
  72. * implements incoming message handler.
  73. * address: /live/play
  74. *
  75. * @param int state Current state of the song
  76. */
  77. void incomingHandlerPlay(int state){
  78.   switch(state){
  79.     case 1:
  80.       println("Song STOP");
  81.       break;
  82.     case 2:
  83.       println("Song PLAY");
  84.       break;
  85.   }
  86. }
  87. /**
  88. * implements incoming message handler.
  89. * address: /live/clip/info
  90. *
  91. * @param int track Track number
  92. * @param int clip Clip number
  93. * @param int state Current state of the clip
  94. */
  95. void incomingHandlerClipInfo(int track,int clip,int state){
  96.   switch(state){
  97.       //STOP
  98.       case 1:
  99.         println("Stopped clip - Track:"+track+" Clip:"+clip);
  100.         break;
  101.       //PLAY
  102.       case 2:
  103.         println("Playing clip - Track:"+track+" Clip:"+clip);
  104.         break;
  105.       //LAUNCHED
  106.       case 3:
  107.         println("Triggered clip - Track:"+track+" Clip:"+clip);
  108.        break;
  109.     }
  110. }
  111. /**
  112. * implements incoming message handler.
  113. * address: /live/volume
  114. *
  115. * @param int track Track number
  116. * @param float value The actual volume of the track
  117. */
  118. void incomingHandlerVolume(int track,float value){
  119.   println("Track:" + track + " vol:"+value);    
  120. }
  121. /*
  122. * OSC event handler
  123. */
  124. void oscEvent(OscMessage theOscMessage) {
  125.  
  126.   if(theOscMessage.isPlugged()==false) {
  127.     //we just print the not plugged messages.
  128.     println("[NOT HANDLED] addr:" + theOscMessage.addrPattern() + " | typetag: " + theOscMessage.typetag());
  129.   }
  130. }