Hi.. I was having some problems with this as well. I'm not sure I can tell exactly why your code isn't working but I have two working examples. I've written one step-sequencer using an array for storing the events and one that doesn't use MIDI-events at all (it does use notes
but it doesn't add() and remove() them). Both ways work, so try them both!
The Array way:
MidiEvent[] buttonEvents;
//in void setup(){
buttonEvents = new MidiEvent[16]; //Storing the "active" events of one bar.
//in void mousePressed(){
for(int i = 0 ; i < 16 ; i++){
if(buttons[i].isOver()){ //if I press the mouse when over a button
if(buttons[i].isPressed()){ //and the button is already pressed,
//then the active event will be removed
track.removeEvent(buttonEvents[i],i);
//the second argument to removeEvent() could be anything, really.
}else{ //It depends on what number of ticks you have chosen
// for your sequencer - in this case 16.
//if the mouse is clicked when over a button that is not already pressed:
// we save a Note in the buttonEvents-array,
buttonEvents[i+16] = new Note(60, 20, 2);
// and add it to the track, at tick i.
track.addEvent(buttonEvents[i],i);
}
}
}