Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 1 of 1

Thread: MIDI CC88 High Resolution Velocity prefix

  1. #1
    Senior Member
    Join Date
    Nov 2012
    Location
    Boston, MA, USA
    Posts
    1,110

    MIDI CC88 High Resolution Velocity prefix

    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:
    /* 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);
      }
    }
    Last edited by Nantonos; 02-22-2013 at 09:33 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •