Go Down

Topic: MIDI Library - problem with callbacks (Read 1 time) previous topic - next topic


(Originally posted in 'programming' by mistake)

I'm just starting to use the midi library and having problems getting callbacks to work. Longer term aim is a midi filter but at the moment just trying to get the basics to work....

Code: [Select]
#include <MIDI.h>

void HandleNoteOff(byte channel, byte pitch, byte velocity) {

void setup() {
  MIDI.begin(MIDI_CHANNEL_OMNI);            // Launch MIDI with OMNI in and thro on

void loop() {
  MIDI.read() ; 

The basic midi through is working fine. Using a keyboard for input and MIDI-OX to monitor the output, you can see each note-on and note-off come through fine when a key is pressed and released BUT there is no extra note-on which the callback function should generate from each note-off.
(Long term, there will be a pile of filters programmed in the callback function)

Any idea what I'm doing wrong??


Really odd...
If I use MIDI.setHandleNoteOn instead of MIDI.setHandleNoteOff then the callback DOES work but it sends the note-off message on BOTH the incoming note-on AND on the note-off.

Makes no sense to me...


Turns out this was all to do with MIDI running status.
Many devices don't actually send a note-off signal, they send a note-on with a velocity of 0 instead - hence 'setHandleNoteOff' doesn't detect it. You need to use 'setHandleNoteOn' and check for a velocity of zero.

Many thanks for Francois, the MIDI library author, for explaining it to me.


Go Up