pico-example-midi
pico-example-midi copied to clipboard
Simplification
You could avoid calculation the previous note by sending NOTE OFF before incrementing the counter, like that :
// Send Note Off for actual note.
tud_midi_write24(0, 0, 0x80, note_sequence[note_pos], 0);
// Increment position
note_pos++;
// If we are at the end of the sequence, start over.
if (note_pos >= sizeof(note_sequence)) note_pos = 0;
// Send Note On for current position at full velocity (127) on channel 1.
tud_midi_write24(0, 0, 0x90, note_sequence[note_pos], 127);