Pages: [1]   Go Down
Author Topic: MIDI Library - problem with callbacks  (Read 624 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

(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:
#include <MIDI.h>

void HandleNoteOff(byte channel, byte pitch, byte velocity) {
    MIDI.sendNoteOn(37,127,15);
}

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

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??
Thanks
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Steve
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Steve
Logged

Pages: [1]   Go Up
Jump to: