[solved] Littlefoot: sendNoteOn frequently sends a Note Off message instead

mpe
projucer
windows

#1

I have a simple Littlefoot script I’m using with the ROLI Lightpad block that maps the playing surface to an 8x8 grid of notes. On touch start, the X-Y position is mapped to a note, and the note is mapped to the touch index (also used for the channel) using the heap, and a sendnoteon is called. On touch end, the note is pulled from the heap using the touch index and a note off is sent. All the notes values are correct, but more often then not for the touch start event, a note off message is sent instead of a note on. If I switch the sendnoteon/off functions to any other MIDI message they work perfectly.

Can anyone think why this is happening?


void touchStart (int index, float x, float y, float z, float vz)
{
setHeapByte(index + 200, int ((x * 4) + ((2 - y) * 28)));
sendNoteOn(index - 1, getHeapByte(index + 200), int (vz * 127));
}

void touchEnd (int index, float x, float y, float z, float vz)
{
sendNoteOff(index - 1, getHeapByte(index + 200), int (vz * 127));
}


#2

commenting to be notified of how programming on the Blocks is.


#3

I will note that the erroneous note offs happen more frequently when a low strike velocity is reported. It still happens at high velocities as well, but less frequently.

OK, I figured it out. If the velocity used in sendNoteOn is 0, it will send a note off event instead of a note on. Or perhaps this is just the way MIDI-OX interprets noteon events with a 0 velocity. If I set a base value higher than 0 for the noteon velocity the issue goes away. I’ll need to test another MIDI monitor tool to see if JUCE or MIDI-OX is at fault.

And after looking into this further, apparently it is common practice to treat a note on event with velocity 0 as a note off event. So it doesn’t matter who the guilty party is here, this is the expected behavior. Here’s my updated code that works:


void touchStart (int index, float x, float y, float z, float vz)
{
setHeapByte(index + 200, int ((x * 4) + ((2 - y) * 28)));
sendNoteOn(index - 1, getHeapByte(index + 200), int (1 + vz * 126));
}

void touchEnd (int index, float x, float y, float z, float vz)
{
sendNoteOff(index - 1, getHeapByte(index + 200), int (1 + vz * 126));
}