Working on a sketch that uses MIDIbus to read keystrokes which are mapped to draw/hide objects in an array. The original algorithm used a boolean value to determine whether or not to redraw, unfortunately that method caused the on/off notes to sometime be confused as to who was played last. For example, if I played a C Major chord, C, E, G, but released the keys, E, G, C, the behavior triggered by the ons of G & C would not return to the default off(keyup/key released state).
The code below activates the intended behavior using QWERTY keyboard strokes, but the MIDI business does not. I casted the expression inside the board array just in case integer math wasn’t actually occurring. midiValue is set to 21, to avoid NullPointerExceptions. In an earlier version there are println statements at the beginning of noteOn and NoteOff, inside the if statement and one last one at the conclusion of the if statement before closing the method. Those all print to the console as expected. It’s accessing the array of objects where things seem to break down.
Any ideas would be appreciated!
void noteOn(Note note) {
if (note.pitch <= 108 && note.pitch >= 21) {
midiPlayed = note.pitch;
board[int(midiPlayed - midiValue)].display(true);
}
}
void noteOff(Note note) {
if (note.pitch <= 108 && note.pitch >= 21) {
midiPlayed = note.pitch;
board[int(midiPlayed - midiValue)].display(false);
}
}
void keyPressed() {
if ((key == 'c') || (key =='C')) {
midiPlayed = 48;
board[midiPlayed - midiValue].display(true);
}
}
void keyReleased() {
if ((key == 'c') || (key =='C')) {
midiPlayed = 48;
board[midiPlayed - midiValue].display(false);
}
}