Hi,
Here my program that retrieves a value from the Arduino card and plays a sound based on that value.
The value varies according to the position of a potentiometer: an Arduino program transforms the voltage across the potentiometer into 3 digital values: 1, 2 and 3.
The Processing program must play sound 1 when the recovered value is 1, play sound 2 when the recovered value is 2 and play sound 3 when the value is 3, etc.
It works but I want that when you switch from sound 1 to sound 2 (or from sound 2 to 3, etc.), sound 1 is not stopped but only muted. Once the sound has been played in its entirety, it must be automatically restarted.
I don’t know how to do it, I think I have to know when the sound is done, but I didn’t find a function like that.
import processing.serial.*;
import ddf.minim.*;
Serial port;
Minim minim;
AudioPlayer radio1;
AudioPlayer radio2;
AudioPlayer radio3;
AudioPlayer bruitage;
int value=0;
void setup() {
background(0, 60, 60);
size(200,200);
port = new Serial(this, Serial.list()[0], 9600);
port.bufferUntil('\n');
minim = new Minim(this);
radio1 = minim.loadFile("radio1.mp3");
radio2 = minim.loadFile("radio2.mp3");
radio3 = minim.loadFile("radio3.mp3");
bruitage = minim.loadFile("bruitage.mp3");
}
void draw() {
radio();
delay(100);
}
void radio() {
println("canal " + value);
if (value==1) {
bruitage.mute();
radio1.unmute();
radio1.play();
}
if (!radio1.isPlaying() && value==1) {
radio1.rewind();
radio1.play();
}
if (value==2) {
radio1.mute();
bruitage.unmute();
bruitage.play();
}
if (!bruitage.isPlaying() && value==2) {
bruitage.rewind();
bruitage.play();
//...
}
void serialEvent(Serial port){
String serialStr = port.readStringUntil('\n');
serialStr=trim(serialStr);
int values[]=int(split(serialStr,','));
if(values.length==1){
value=values[0];
}
}
Could someone please help me?