We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › controlP5 and Ess
Page Index Toggle Pages: 1
controlP5 and Ess (Read 1191 times)
controlP5 and Ess
Mar 29th, 2009, 11:32am
 
Hi, I've been trying to use controlP5 to manipulate sine waves generated by Ess. It all works fine, but I'm having problems with controlP5. The slider values stay on screen. Here's the code:

As you'll guess from the code, this is my first time trying out processing  Embarrassed

Code:
import krister.Ess.*;
import controlP5.*;
ControlP5 controlP5;
AudioChannel myChannel;
SineWave myWave;
float volume=0.5;
int pitch=400;
int release=1000;

void setup() {
 background(0);
 //frameRate(25);
 size(256,200);
 Ess.start(this);
 myChannel=new AudioChannel();
 controlP5 = new ControlP5(this);
 controlP5.addSlider("Pitch",200,2000,40,10,10,10,100).setId(1);
 controlP5.addSlider("Volume",0,2,40,70,10,10,100).setId(2);
 controlP5.addSlider("Release",1000,8000,40,120,10,10,100).setId(3);
}

void controlEvent (ControlEvent theEvent) {
 switch(theEvent.controller().id()) {
   
   case(1):
   pitch = (int)(theEvent.controller().value());
   //print("the pitch changed to " + pitch + "\n");
   break;
   
   case(2):
   volume = (float)(theEvent.controller().value());
   //print("the VOLUME changed to " + volume + "\n");
   break;
   
   case(3):
   release = (int)(theEvent.controller().value());
   //print("the note length changed to " + release + "\n");
   break;
 }
   myWave=new SineWave(pitch,volume);
   myChannel.initChannel(myChannel.frames(release));
   myWave.generate(myChannel,5,myChannel.frames(release));
   myChannel.play();  
}

void draw() {
 controlP5.draw();
}

public void stop() {
 Ess.stop();
 super.stop();
}


Re: controlP5 and Ess
Reply #1 - Mar 29th, 2009, 11:57pm
 
adding background(0) (fills the display window black) right after void draw() { will do the trick. you actually dont need controlP5.draw() inside of draw() since controlP5's draw function is called automatically (if not in P3D mode or autoDraw is disabled).

Code:

void draw() {
 background(0);
}


andreas
Re: controlP5 and Ess
Reply #2 - Mar 30th, 2009, 11:04am
 
Thanks! Works great Smiley
Re: controlP5 and Ess
Reply #3 - Mar 30th, 2009, 11:09pm
 
This Topic was moved here from Libraries,  Tool Development by sojamo.
Page Index Toggle Pages: 1