I am making a program to make music. However the playfunction has the problem, that I can’t interrupt it. So I wanted to implement a key to abort the play function.
Here is a example to show the problem. It also has the things implemented, that I tried:
boolean abort=false;
void setup() {
size(200, 200);
}
void doSomeThing() {
for (int i=0; i<10; i++) if (!abort) {
//here the note is played.
println(i);
delay(500);
redraw();
if(keyPressed) if (key=='a') abort=true;
} else {
println("Process was aborted");
}
abort=false;
}
void draw() {
if(keyPressed) if (key=='a') abort=true;
}
void keyPressed() {
if (key=='d') doSomeThing();
if (key=='a') abort=true;