Apr 12 2009

Maestro Version 1.1b

Published by Michael Doyle at 23:00 under JMyron, Processing, controlP5, ess r2

I've revisted version 1.1 as the 1.2's Sine class is making it difficult to add on to at the moment. So, 1.1b is changing the pitch of a sine wave on the Y axis and changing the pitch of a triangle wave on the X axis. Here is the code:

  1. import JMyron.*;
  2. import krister.Ess.*;
  3. import controlP5.*;
  4. JMyron m; //a camera object
  5. ControlP5 controlP5;
  6. AudioChannel myChannel;
  7. AudioChannel myChannel2;
  8. SineWave myWave;
  9. TriangleWave myWave2;
  10. float volume=1;
  11. int pitch=400;
  12. int release=10000;
  13. FadeIn myFadeIn;
  14. FadeOut myFadeOut;
  15.  
  16. FadeIn myFadeIn2;
  17. FadeOut myFadeOut2;
  18.  
  19. LowPass myLowPass;
  20.  
  21. int r;
  22. int g;
  23. int b;
  24. int min_size = 50;
  25. int max_size=100;
  26. int sensitivity = 35;
  27. float objx = 160;
  28. float objy = 120;
  29. float objdestx = 160;
  30. float objdesty = 120;
  31.  
  32. void setup(){
  33. size(720,576);
  34. m = new JMyron();//make a new instance of the object
  35. m.start(width,height);//start a capture at 320x240
  36. m.findGlobs(1);//disable the intelligence to speed up frame rate
  37. controlP5 = new ControlP5(this);
  38. /*
  39.   controlP5.addSlider("sensitivity",0,255,40,10,10,10,100).setId(1);
  40.   name, low val, high val, default val, x, y, width, height,
  41.   */
  42. controlP5.addSlider("sensitivity",0,255,sensitivity,10,10,10,100).setId(1);
  43. controlP5.addSlider("min size",0,800,min_size,60,10,10,100).setId(2);
  44. //controlP5.addSlider("max size",0,400,max_size,100,10,10,100).setId(3);
  45. //println("here are the globs:" + m.globCenters());
  46. Ess.start(this);
  47. myChannel=new AudioChannel();
  48. myChannel2=new AudioChannel();
  49. myFadeIn=new FadeIn();
  50. myFadeOut=new FadeOut();
  51. myFadeIn2=new FadeIn();
  52. myFadeOut2=new FadeOut();
  53.  
  54. }
  55.  
  56. void draw(){
  57. m.update();//update the camera view
  58. m.trackColor(r,g,b,sensitivity);
  59. m.minDensity(min_size);
  60. //m.maxDensity(max_size);
  61. int[] img = m.image(); //get the normal image of the camera
  62.  
  63. loadPixels();
  64. for(int i=0;i<width*height;i++){ //loop through all the pixels
  65. pixels[i] = img[i]; //draw each pixel to the screen
  66. }
  67. updatePixels();
  68.  
  69. stroke(0,255,0);
  70. int[][][] list = m.globEdgePoints(30);//get the outlines
  71. for(int i=0;i
  72. <list.length;i++){
  73. beginShape();
  74. if(list[i]!=null){
  75. for(int ii=0;ii<list[i].length;ii++){
  76. vertex(list[i][ii][0],list[i][ii][1]);
  77. }
  78. }
  79. endShape();
  80. }
  81. int[][] centers = m.globCenters();//get the center points
  82. //draw all the dots while calculating the average.
  83. //println("Amount of globs: " + centers.length);
  84. float avX=0;
  85. float avY=0;
  86. for(int i=0;i<centers.length;i++){
  87. fill(0);
  88. rect(centers[i][0],centers[i][1],1,1);
  89. avX += centers[i][0];
  90. avY += centers[i][1];
  91. }
  92. if(centers.length-1>0){
  93. avX/=centers.length-1;
  94. avY/=centers.length-1;
  95. }
  96.  
  97. //draw the average of all the points in red.
  98. fill(255,0,0);
  99. rect(avX,avY,5,5);
  100.  
  101. //update the location of the thing on the screen.
  102. if(!(avX==0&&avY==0)&&centers.length>0){
  103. objdestx = avX;
  104. objdesty = avY;
  105. }
  106. objx += (objdestx-objx)/5.0f;
  107. objy += (objdesty-objy)/5.0f;
  108.  
  109. fill(30,100,0);
  110. ellipseMode(CENTER);
  111. ellipse(objx,objy,25,25);
  112. //println("X of Glob:" + objx + "Y of Glob:" + objy);
  113. //println("the avx variable:" + avX);
  114. myWave=new SineWave(objy,volume);
  115. myWave2=new TriangleWave(objx,1);
  116.  
  117. myChannel2.initChannel(myChannel2.frames(release));
  118. myChannel.initChannel(myChannel2.frames(release));
  119.  
  120. myWave.generate(myChannel,5,myChannel.frames(release));
  121. myWave2.generate(myChannel2,0,myChannel2.frames(release));
  122.  
  123. myFadeOut.filter(myChannel);
  124. myFadeIn.filter(myChannel);
  125.  
  126. myFadeOut2.filter(myChannel2);
  127. myFadeIn2.filter(myChannel2);
  128. }
  129.  
  130. void controlEvent(ControlEvent theEvent) {
  131. switch(theEvent.controller().id()) {
  132.  
  133. case(1):
  134. sensitivity = (int)(theEvent.controller().value());
  135. print("sensitivity changed to " + sensitivity + "\n");
  136. break;
  137.  
  138. case(2):
  139. min_size = (int)(theEvent.controller().value());
  140. break;
  141.  
  142. case(3):
  143. max_size = (int)(theEvent.controller().value());
  144. break;
  145.  
  146. }
  147.  
  148. }
  149.  
  150. void mouseClicked(MouseEvent m) {
  151. if (mouseEvent.getClickCount() == 2) {
  152. mouseX = m.getX();
  153. mouseY = m.getY();
  154. println("The co-ordinates of the mouse click are:");
  155. println("X:" + mouseX + " Y:" + mouseY);
  156. int c = get(mouseX, mouseY);
  157. r = int(red(c));
  158. g = int(green(c));
  159. b = int(blue(c));
  160. println ("R: " + r + " G: " + g + " B: " + b + " Sens: " + sensitivity);
  161.  
  162. myChannel.play();
  163. myChannel2.play();
  164. return;
  165. }
  166. }
  167.  
  168. public void stop(){
  169. Ess.stop();
  170. m.stop();//stop the object
  171. super.stop();
  172. }

No responses yet

Trackback URI | Comments RSS

Leave a Reply