Apr 12 2009
Maestro Version 1.1b
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:
import JMyron.*; import krister.Ess.*; import controlP5.*; JMyron m; //a camera object ControlP5 controlP5; AudioChannel myChannel; AudioChannel myChannel2; SineWave myWave; TriangleWave myWave2; float volume=1; int pitch=400; int release=10000; FadeIn myFadeIn; FadeOut myFadeOut; FadeIn myFadeIn2; FadeOut myFadeOut2; LowPass myLowPass; int r; int g; int b; int min_size = 50; int max_size=100; int sensitivity = 35; float objx = 160; float objy = 120; float objdestx = 160; float objdesty = 120; void setup(){ size(720,576); m = new JMyron();//make a new instance of the object m.start(width,height);//start a capture at 320x240 m.findGlobs(1);//disable the intelligence to speed up frame rate controlP5 = new ControlP5(this); /* controlP5.addSlider("sensitivity",0,255,40,10,10,10,100).setId(1); name, low val, high val, default val, x, y, width, height, */ controlP5.addSlider("sensitivity",0,255,sensitivity,10,10,10,100).setId(1); controlP5.addSlider("min size",0,800,min_size,60,10,10,100).setId(2); //controlP5.addSlider("max size",0,400,max_size,100,10,10,100).setId(3); //println("here are the globs:" + m.globCenters()); Ess.start(this); myChannel=new AudioChannel(); myChannel2=new AudioChannel(); myFadeIn=new FadeIn(); myFadeOut=new FadeOut(); myFadeIn2=new FadeIn(); myFadeOut2=new FadeOut(); } void draw(){ m.update();//update the camera view m.trackColor(r,g,b,sensitivity); m.minDensity(min_size); //m.maxDensity(max_size); int[] img = m.image(); //get the normal image of the camera loadPixels(); for(int i=0;i<width*height;i++){ //loop through all the pixels pixels[i] = img[i]; //draw each pixel to the screen } updatePixels(); stroke(0,255,0); int[][][] list = m.globEdgePoints(30);//get the outlines for(int i=0;i <list.length;i++){ beginShape(); if(list[i]!=null){ for(int ii=0;ii<list[i].length;ii++){ vertex(list[i][ii][0],list[i][ii][1]); } } endShape(); } int[][] centers = m.globCenters();//get the center points //draw all the dots while calculating the average. //println("Amount of globs: " + centers.length); float avX=0; float avY=0; for(int i=0;i<centers.length;i++){ fill(0); rect(centers[i][0],centers[i][1],1,1); avX += centers[i][0]; avY += centers[i][1]; } if(centers.length-1>0){ avX/=centers.length-1; avY/=centers.length-1; } //draw the average of all the points in red. fill(255,0,0); rect(avX,avY,5,5); //update the location of the thing on the screen. if(!(avX==0&&avY==0)&¢ers.length>0){ objdestx = avX; objdesty = avY; } objx += (objdestx-objx)/5.0f; objy += (objdesty-objy)/5.0f; fill(30,100,0); ellipseMode(CENTER); ellipse(objx,objy,25,25); //println("X of Glob:" + objx + "Y of Glob:" + objy); //println("the avx variable:" + avX); myWave=new SineWave(objy,volume); myWave2=new TriangleWave(objx,1); myChannel2.initChannel(myChannel2.frames(release)); myChannel.initChannel(myChannel2.frames(release)); myWave.generate(myChannel,5,myChannel.frames(release)); myWave2.generate(myChannel2,0,myChannel2.frames(release)); myFadeOut.filter(myChannel); myFadeIn.filter(myChannel); myFadeOut2.filter(myChannel2); myFadeIn2.filter(myChannel2); } void controlEvent(ControlEvent theEvent) { switch(theEvent.controller().id()) { case(1): sensitivity = (int)(theEvent.controller().value()); print("sensitivity changed to " + sensitivity + "\n"); break; case(2): min_size = (int)(theEvent.controller().value()); break; case(3): max_size = (int)(theEvent.controller().value()); break; } } if (mouseEvent.getClickCount() == 2) { mouseX = m.getX(); mouseY = m.getY(); println("The co-ordinates of the mouse click are:"); println("X:" + mouseX + " Y:" + mouseY); int c = get(mouseX, mouseY); r = int(red(c)); g = int(green(c)); b = int(blue(c)); println ("R: " + r + " G: " + g + " B: " + b + " Sens: " + sensitivity); myChannel.play(); myChannel2.play(); return; } } public void stop(){ Ess.stop(); m.stop();//stop the object super.stop(); }