gain control through mouse position
in
Core Library Questions
•
2 years ago
Hi,
have included code for a modified panning example. Question is; how would i enable moving the elipse up and down to effect the volume? ( raising the ellipse to increase the gain, turning down with lowering ellipse). Any help much appreciated,
thanks.
Josh
- import ddf.minim.*;
import ddf.minim.signals.*;
Minim minim;
AudioOutput out;
Oscillator osc;- boolean selected = false;
int pos;
float radius = 25.0f;
void setup()
{
size(512, 200);
minim = new Minim(this);
out = minim.getLineOut();
// see the example AudioOutput >> SawWaveSignal for more about this class
osc = new SawWave(100, 0.2, out.sampleRate());
// see the example Polyphonic >> addSignal for more about this
out.addSignal(osc);
- // see the example Recordable >> addListener for more about this
-
textFont(createFont("SanSerif", 12));
pos = width/2;
}
void draw()
{
background(0);
// see waveform.pde for more about this-
if ( out.hasControl(Controller.PAN) )
{
// map the mouse position to the range of the pan
float val = map(pos, 0, width, -1, 1);
// if a pan control is not available, this will do nothing
out.setPan(val);
// if a pan control is not available this will report zero
;
ellipse (pos,height/2,radius*2.0f,radius*2.0f);
}
else
{
text("The output doesn't have a pan control.", 5, 20);
}
}
void stop()
{
// always close Minim audio classes when you are finished with them
out.close();
minim.stop();
super.stop();
}
void mousePressed() {
if (sqrt(sq(mouseX-pos)+sq(mouseY-height/2))<=radius) {
selected = true;
}
}
void mouseReleased() {
selected = false;
}
void mouseDragged()
{
if (selected) {
pos = max(0,min(mouseX,width));
}
}
1