Hello
I'm trying to connect midi input to natural forces (following the instructions of the Nature of code book) and I wonder how I can manage to add the force Wind on input of Note 59 (it works) but also to stop using the force wind when the note is not hit. For now the wind keeps adding each time I hit note 59, however I use acceleration.mult(0) in the update() function. Thank you very much for some tips.
functions in the class
void applyForce(PVector force){
PVector f = PVector.div(force,mass);
acceleration.add(f);
}
void update(){
velocity.add(acceleration);
position.add(velocity);
acceleration.mult(0);
}
main
void draw() {
background(10,15,25);
//PVector wind = new PVector(random(0.01),random(-0.01));
PVector gravity = new PVector(0,0.1);
for (int i=0; i < tri.length; i++){
tri[i].display();
tri[i].update();
tri[i].applyForce(gravity);
//tri[i].applyForce(wind);
tri[i].checkBoundaryCollision();
}
}
void onNote59 (int vel) {
PVector wind = new PVector(10,10);
for (int i=0; i < tri.length; i++){
if (vel > 0 ) {
tri[i].applyForce(wind);
} else {
// I don't know what to put here
}
}
}
midi functions void midiMessage(MidiMessage message) {
int note = (int)(message.getMessage()[1] & 0xFF) ;
int vel = (int)(message.getMessage()[2] & 0xFF);
println("Bus " + ": Note "+ note + ", vel " + vel);
invokeNoteHandler(note, vel);
}
void invokeNoteHandler(int note, int velocity) {
try {
Class[] cls = new Class[1];
cls[0] = int.class;
Method handler = this.getClass().getMethod( "onNote" + note, cls );
handler.invoke(this, velocity);
} catch (Exception e) {
e.printStackTrace();
}
}