
{A PURE PASCAL COLLECTIONS OF MIDI ROUTINES FOR BYTE OR BIT RENDERING}
{FROM  C-64 , AMIGA  AND NOW THE ATARI ST}
{BY CHARLES COPP , ORG SRC==>JURGE, Zimmermann,BILL BARTON , FREDII}
{PASCAL !   USE THESE WHEN MIDI DATA APPEARS NOT TO BE MIDI DATA!!!}
{UNTESTED ,USE AT OWN RISK!!!}

FUNCTION MidiHiByte(data: LONGINT): SHORTINT;
 (* pack high bytes of a word into midi format (7/14 bit math) *)

   BEGIN
      MidiHiByte:=(SHORTINT(data DIV 128));
   END;


FUNCTION MidiLoByte(data: LONGINT): SHORTINT;
 (* pack low bytes of a word into midi format (7/14 bit math) *)

   BEGIN
      MidiLoByte:=(SHORTINT(data MOD 128));
   END;


FUNCTION MidiWord(hi,lo: SHORTINT): LONGINT;
 (* unpack 2 midi bytes into a word (7/14 bit math) *)

   BEGIN
      MidiWord :=(LONGINT(hi) * 128 + LONGINT(lo));
   END;


PROCEDURE SplitMidiID(id : LONGINT;VAR id0,id1,id2: SHORTINT);
 (* unpack a 3 byte sys/ex id into single bytes for argument
      lists and RIMatch initializers *)

   BEGIN
      id0:=(SHORTINT(id DIV 65536));
      id1:=(SHORTINT((id DIV 256) MOD 256));
      id2:=(SHORTINT(id MOD 256));
   END;


FUNCTION MakeMidiID(id0,id1,id2: SHORTINT): LONGINT;
 (* make a 3 byte sys/ex id from three single bytes *)

   BEGIN
      MakeMidiID:=((LONGINT(id0) * 65536) + (LONGINT(id1) * 256) + LONGINT(id2));
   END;
