//
// Analog Rytm instant program change via seq stop/start trick
//  => does not work properly
//

Buffer syx;
syx.size = 32;

function ProcessFrame(MIDIPipeFrame _frame) {
   int numEv = _frame.getNumEventsPrgChgByFlt(io_dev, io_ch);
   if(numEv > 0)
   {
      int evIdx = 0;
      loop(numEv)
      {
         MIDIPipeEvent pev;
         _frame.getEventByIdxAndFlt(evIdx, pev, MIDIPIPE_EVENT_TYPE_PRGCHG, io_dev, io_ch);
         syx.offset = 0;
         // syx.i8 = 0xFC;          // Stop

         syx.i8 = 0xF0;  // MMC Stop
         syx.i8 = 0x7F;
         syx.i8 = 0x7F;
         syx.i8 = 0x06;
         syx.i8 = 0x01;
         syx.i8 = 0xF7;

         // syx.i8 = 0xF0;  // pause
         // syx.i8 = 0x7F;
         // syx.i8 = 0x7F;
         // syx.i8 = 0x06;
         // syx.i8 = 0x08;
         // syx.i8 = 0xF7;

         // syx.i8 = 0xF0;  // MMC Rec Strobe
         // syx.i8 = 0x7F;
         // syx.i8 = 0x7F;
         // syx.i8 = 0x06;
         // syx.i8 = 0x09;
         // syx.i8 = 0xF7;

         syx.i8 = 0xC0 | io_ch;  // PrgChg
         syx.i8 = pev.prgChg;

         if(0)
         {
            syx.i8 = 0xFB;          // Continue
         }
         else
         {
            syx.i8 = 0xF0;  // MMC Start
            syx.i8 = 0x7F;
            syx.i8 = 0x7F;
            syx.i8 = 0x06;
            syx.i8 = 0x02;
            syx.i8 = 0xF7;
            syx.i8 = 0xFB;          // Continue
         }

         // trace "xxx sdjfkl";

         _frame.sysex(true/*bSet*/, io_dev, syx);

         evIdx++;
      }
   }
}

function OnProcess(MIDIPipeFrame framePlay,
                   MIDIPipeFrame frameRec,
                   boolean       bMuted,
                   boolean       bPlaySeq
                   ) {
   if(!bMuted)
   {
      ProcessFrame(framePlay);
      ProcessFrame(frameRec);
   }
}
