//
// Fixes Akai MPK49 external MIDI pitchbend issue (LSB/MSB byteswap)
//  see here: http://community.akaipro.com/akai_professional/topics/mpk49-external-midi-pitch-bend-wheel-mapping-bug
//

function OnProcess(MIDIPipeFrame framePlay,
                   MIDIPipeFrame frameRec,
                   boolean       bMuted,
                   boolean       bPlaySeq
                   ) {
   if(!bMuted)
   {
      int numEvents = frameRec.getNumEventsPitchbendByFlt(io_dev, -1/*io_ch*/); 
      int evIdx = 0; 
      loop(numEvents)
      { 
         MIDIPipeEvent ev;
         frameRec.getEventByIdxAndFlt(evIdx, ev, MIDIPIPE_EVENT_TYPE_PITCHBEND, io_dev, -1/*io_ch*/); 
         short pb = ev.pitchbend;
         pb = ((pb >> 7) & 127) | ((pb & 127) << 7);
         frameRec.pitchbend(true/*bSet*/, io_dev, ev.midiCh, pb);
         evIdx++;
      }

   }
}
