MIDI CC88 High Resolution Velocity prefix

Status
Not open for further replies.

Nantonos

Well-known member
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:

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

#define middleC 60  [COLOR=#7E7E7E]// midi note 60 is C4[/COLOR]

[COLOR=#CC6600]void[/COLOR] sendNoteOnHRV([COLOR=#CC6600]uint32_t[/COLOR] note, [COLOR=#CC6600]uint32_t[/COLOR] velocity, [COLOR=#CC6600]uint32_t[/COLOR] channel) {
  [COLOR=#CC6600]if[/COLOR] (velocity < 256) 
  { 
    [COLOR=#CC6600][B]usbMIDI[/B][/COLOR].[COLOR=#CC6600]sendNoteOn[/COLOR](note, 0, channel); 
  }
  [COLOR=#CC6600]else[/COLOR]
  { 
    [COLOR=#CC6600][B]usbMIDI[/B][/COLOR].[COLOR=#CC6600]sendControlChange[/COLOR](0x058, (velocity & 0x7F),channel);
    [COLOR=#CC6600][B]usbMIDI[/B][/COLOR].[COLOR=#CC6600]sendNoteOn[/COLOR](note, ((velocity >>7) & 0x7F), channel);
  }
}

[COLOR=#CC6600]void[/COLOR] sendNoteOffHRV([COLOR=#CC6600]uint32_t[/COLOR] note, [COLOR=#CC6600]uint32_t[/COLOR] velocity, [COLOR=#CC6600]uint32_t[/COLOR] channel) {
  [COLOR=#CC6600]if[/COLOR] (velocity < 256) 
  { 
    [COLOR=#CC6600][B]usbMIDI[/B][/COLOR].[COLOR=#CC6600]sendNoteOff[/COLOR](note, 0, channel); 
  }
  [COLOR=#CC6600]else[/COLOR]
  { 
    [COLOR=#CC6600][B]usbMIDI[/B][/COLOR].[COLOR=#CC6600]sendControlChange[/COLOR](0x058, (velocity & 0x7F),channel);
    [COLOR=#CC6600][B]usbMIDI[/B][/COLOR].[COLOR=#CC6600]sendNoteOff[/COLOR](note, ((velocity >>7) & 0x7F), channel);
  }
}

[COLOR=#CC6600]void[/COLOR] [COLOR=#CC6600][B]setup[/B][/COLOR](){
}

[COLOR=#CC6600]void[/COLOR] [COLOR=#CC6600][B]loop[/B][/COLOR]() {
  [COLOR=#CC6600]int[/COLOR] i = 0;
  [COLOR=#CC6600]delay[/COLOR](5000);
  [COLOR=#CC6600]for[/COLOR] (i=0; i< 0x04000; i+=16)
  {
    sendNoteOnHRV(middleC, i, 1);
    [COLOR=#CC6600]delay[/COLOR] (500);
    [COLOR=#CC6600][B]usbMIDI[/B][/COLOR].[COLOR=#CC6600]sendNoteOff[/COLOR](middleC, 0, 1);
    [COLOR=#CC6600]delay[/COLOR] (200);
  }
}
 
Last edited:
Status
Not open for further replies.
Back
Top