PDA

View Full Version : MIDI CC88 High Resolution Velocity prefix



Nantonos
02-22-2013, 09:29 PM
I recently implemented MIDI CC88 High Resolution Velocity prefix, which is an official MIDI extension giving 14 bit velocity values with fallback to the most significant 7 bits if the receiver doesn't understand. It is very simple, but in case it is useful for anyone:



/* Try out MIDI CC88 High Resolution Velocity prefix
2007 addition to allow 14-bit velocity values from 0x0080H to 0x03FFF.
For compatibility with the running-status note-off hack, 0x00 to 0x7F all mean 'note off'
http://www.midi.org/techspecs/ca31.pdf
Chris Lilley 2013
This example code is in the public domain.
*/

#define middleC 60 // midi note 60 is C4

void sendNoteOnHRV(uint32_t note, uint32_t velocity, uint32_t channel) {
if (velocity < 256)
{
usbMIDI.sendNoteOn(note, 0, channel);
}
else
{
usbMIDI.sendControlChange(0x058, (velocity & 0x7F),channel);
usbMIDI.sendNoteOn(note, ((velocity >>7) & 0x7F), channel);
}
}

void sendNoteOffHRV(uint32_t note, uint32_t velocity, uint32_t channel) {
if (velocity < 256)
{
usbMIDI.sendNoteOff(note, 0, channel);
}
else
{
usbMIDI.sendControlChange(0x058, (velocity & 0x7F),channel);
usbMIDI.sendNoteOff(note, ((velocity >>7) & 0x7F), channel);
}
}

void setup(){
}

void loop() {
int i = 0;
delay(5000);
for (i=0; i< 0x04000; i+=16)
{
sendNoteOnHRV(middleC, i, 1);
delay (500);
usbMIDI.sendNoteOff(middleC, 0, 1);
delay (200);
}
}