home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 581b.lha / M2Midi / MidiD.def < prev    next >
Text File  |  1991-11-20  |  14KB  |  487 lines

  1. (***************************************************************************
  2.   :Program.       MidiL.def
  3.   :Author.        Jürgen Zimmermann
  4.   :Address.       Ringstraße 6, W-6719 Altleiningen, Germany
  5.   :Phone.         06356/1456
  6.   :ShortCut.      [JnZ]
  7.   :Support.       -
  8.   :Version.       1.03
  9.   :Date.          30. Oct 1991
  10.   :Copyright.     PD
  11.   :Language.      MODULA-II
  12.   :Translator.    M2Amiga 4.0d
  13.   :Contents.      Modula-2-interface-module for Bill Barton's
  14.   :Contents.      "midi.library" of Fish 227, c-functions in "MidiSupport"!
  15.   :Imports.       "midi.library" V2.0 in the LIBS:-directory
  16.   :Remark.        I want to get into contact with other users of the
  17.   :Remark.        "midi.library" or MIDI-programmers.
  18.   :Remark.        (If you have a new version of the library, please send
  19.   :Remark.        it to me!)
  20.   :Usage.         described in the documents of "midi.library"
  21. ****************************************************************************)
  22. DEFINITION MODULE MidiD;
  23. (*$ Implementation:=FALSE *)
  24.  
  25. (*  Definitions pertaining to MIDI are derived from MIDI 1.0 Detailed
  26.     Specification v4.0 (published by the Internation MIDI Association)
  27.     and is current as of June, 1988.
  28.  
  29.     v2.0 - 23-Oct-88 *)
  30.  
  31. FROM SYSTEM     IMPORT ADDRESS, BPTR;
  32. FROM ExecD      IMPORT List, Library, SignalSemaphore, MsgPortPtr,
  33.                        MinList, Node, MinNode, Message, TaskPtr;
  34. FROM IntuitionD IMPORT ImagePtr;
  35.  
  36.  
  37. CONST midiName = "midi.library";
  38.       midiOutName = "MidiOut";
  39.       midiInName  = "MidiIn";
  40.  
  41.  
  42. TYPE MidiBasePtr    = POINTER TO MidiBase;
  43.      MTaskInfoPtr   = POINTER TO MTaskInfo;
  44.      MNodeInfoPtr   = POINTER TO MNodeInfo;
  45.      MSourcePtr     = POINTER TO MSource;
  46.      MDestPtr       = POINTER TO MDest;
  47.      RIMatchPtr     = POINTER TO RIMatch;
  48.      MRouteInfoPtr  = POINTER TO MRouteInfo;
  49.      MRoutePtr      = POINTER TO MRoute;
  50.      MidiPacketPtr  = POINTER TO MidiPacket;
  51.      MListSignalPtr = POINTER TO MListSignal;
  52.  
  53. (* Msg Flags for MRouteInfo structure and returned by MidiMsgType *)
  54.  
  55.      MMFFlags       = (NoteOn, NoteOff, PolyPress, Ctrl, Prog, ChanPress,
  56.                        PitchBend, Mode, SysCom, SysRt, SysEx, mmf11, mmf12,
  57.                        mmf13, mmf14, mmf15);
  58.      MMFFlagSet     = SET OF MMFFlags;
  59.  
  60. (* MidiChannel-Flags, um nur bestimmte Midi-Kanäle anzusprechen *)
  61.      MidiChannels   = (Ch01, Ch02, Ch03, Ch04, Ch05, Ch06, Ch07, Ch08,
  62.                        Ch09, Ch10, Ch11, Ch12, Ch13, Ch14, Ch15, Ch16);
  63.      MidiChannelSet = SET OF MidiChannels;
  64.  
  65.      RIMFlags       = (extBit1,extBit2,rim2,rim3,rim4,rim5,extId,reverse);
  66.      RIMFlagSet     = SET OF RIMFlags;
  67.  
  68.  
  69. CONST MMFChan      = MMFFlagSet{NoteOn..Mode};
  70.       MMFAll       = MMFChan + MMFFlagSet{SysCom, SysRt, SysEx};
  71.  
  72.       AllChannels  = MidiChannelSet{Ch01..Ch16};
  73.  
  74.       RIMCountBits = RIMFlagSet{extBit1, extBit2};
  75.         (* mask for # of match values (0 for match all) *)
  76.       RIMExtId     = RIMFlagSet{extId};
  77.         (* indicates all 3 bytes of match[] == one 3 byte manuf.
  78.            id (not valid for CtrlMatch) *)
  79.       RIMExclude   = RIMFlagSet{reverse};
  80.         (* reverses logic of RIMatch so that all except those specified pass *)
  81.  
  82.  
  83.       RIMMaxCount = 3;
  84.  
  85.    (* node types for Source *)
  86.       NTMSource     = 20H;
  87.       NTMResMSource = 21H;
  88.  
  89.    (* node types for Dest *)
  90.       NTMDest       = 22H;
  91.       NTResMDest    = 23H;
  92.  
  93.    (* user flags *)
  94.       MLSFSource = 00000001H; (* causes signal when SourceList changes *)
  95.       MLSFDest   = 00000002H; (* causes signal when DestList changes *)
  96.  
  97.  
  98. TYPE MidiBase = RECORD
  99.                    libnode       : Library;
  100.                    SourceList    : List;
  101.                    DestList      : List;
  102.                    ListSemaphore : SignalSemaphore;
  103.                       (* blocks Source/Dest list management *)
  104.                    RouteSemaphore: SignalSemaphore;
  105.                       (* blocks RPList management & msg routing *)
  106.                    SegList       : LONGCARD;
  107.                    SysBase       : ADDRESS;
  108.                    DosBase       : ADDRESS;
  109.                    SignalList    : MinList;
  110.                       (* list of MListSignal's *)
  111.                 END;
  112.  
  113.      MTaskInfo = RECORD
  114.                  (* set by caller *)
  115.                     name      : ADDRESS;
  116.                     Pri       : INTEGER;
  117.                     Entry     : ADDRESS; (* Adresse des TaskCodes *)
  118.                     Stack     : CARDINAL;
  119.  
  120.                     Sources   : CARDINAL;
  121.                     SourceList: MNodeInfoPtr;
  122.                     Dests     : CARDINAL;
  123.                     DestList  :  MNodeInfoPtr;
  124.  
  125.                  (* set by midi.library *)
  126.                     Semaphore : SignalSemaphore;    (* locks task *)
  127.                     UsageCount: CARDINAL;        (* task's usage count *)
  128.                     TaskPort  : MsgPortPtr;        (* task's MsgPort *)
  129.                     Segment   : BPTR;            (* task's Segment *)
  130.                  END;
  131.  
  132.  
  133.      MNodeInfo = RECORD
  134.                     name : ADDRESS;
  135.                     image: ImagePtr;
  136.                     node : ADDRESS;
  137.                  END;
  138.  
  139.  
  140.      MSource = RECORD
  141.                   node          : Node;
  142.                   image         : ImagePtr;
  143.                   RPList        : MinList;
  144.                   userData      : ADDRESS;    (* user data extension *)
  145.  
  146.                (* new stuff for v2.0 *)
  147.                   RouteMsgFlags : MMFFlagSet;
  148.                   RouteChanFlags: MidiChannelSet;
  149.  
  150. (*  RouteMsgFlags: mask of all route->MsgFlags for this MSource;
  151.     RouteChanFlags: mask of all route->ChanFlags for this MSource *)
  152.  
  153.                END;
  154.  
  155.  
  156. TYPE RIMatch = RECORD
  157.                   flags: RIMFlagSet;
  158.                   match: ARRAY[1..RIMMaxCount] OF SHORTCARD;
  159.                END;
  160.  
  161.  
  162.  
  163.      MRouteInfo = RECORD
  164.                      MsgFlags  : MMFFlagSet;
  165.                      ChanFlags : MidiChannelSet;
  166.                      ChanOffset: SHORTINT;
  167.                      NoteOffset: SHORTINT;
  168.                      SysExMatch: RIMatch;
  169.                      CtrlMatch : RIMatch;
  170.  
  171. (* MsgFlags:  flags enabling message types defined below (MMF_) (msg filters);
  172.    ChanFlags: incoming channel enable flags (LSB = chan 1, MSB = chan 16)
  173.               (channel filters);
  174.    ChanOffset: signed offset applied to channels (simple channelizing);
  175.    NoteOffset: signed offset applied to note numbers (transposition);
  176.    SysExMatch: Sys/Ex manufacturer id filtering;
  177.    CtrlMatch: Controller number filtering *)
  178.                   END;
  179.  
  180.  
  181.      MDest = RECORD
  182.                 node            : Node;
  183.                 image           : ImagePtr;
  184.                 RPList          : MinList;
  185.                 DestPort        : MsgPortPtr;
  186.                 userData        : ADDRESS;(* user data extension *)
  187.  
  188.              (* new stuff for v2.0 *)
  189.                 DefaultRouteInfo: MRouteInfo;
  190.                    (* used when Routing function doesn't supply a RouteInfo *)
  191.              END;
  192.  
  193.  
  194.  
  195. TYPE MRoutePointer = RECORD (* alias MRoutePtr (C-Definition!) *)
  196.                         node : MinNode;
  197.                         Route: MRoutePtr;
  198.                      END;
  199.  
  200.  
  201.      MRoute = RECORD
  202.                  Source   : MSourcePtr;
  203.                  Dest     : MDestPtr;
  204.                  SRoute   : MRoutePointer;
  205.                  DRoute   : MRoutePointer; (* MRoutePtr (C-Definition!) *)
  206.                  RouteInfo: MRouteInfo;
  207.               END;
  208.  
  209.  
  210.  
  211.  
  212. (* MIDI Packet (new for v2.0) *)
  213.  
  214.        MidiPacket = RECORD        (* returned by GetMidiPacket() *)
  215.                        ExecMsg : Message;
  216.                        Type    : MMFFlagSet;
  217.                        Length  : CARDINAL;
  218.                        reserved: LONGCARD;
  219.                        MidiMsg : ARRAY[1..4] OF SHORTCARD;
  220.  
  221. (* ExecMsg: ***;
  222.    Type: MMF_ bit for this message (as returned by MidiMsgType());
  223.    Length: length of msg in bytes (as returned by MidiMsgLength());
  224.    reserved: reserved for future expansion;
  225.    MidiMsg: actual MIDI message (real length of this array is Length,
  226.             always at least this much memory allocated) *)
  227.  
  228.                     END;
  229.  
  230.  
  231. (* Public List Change Signal *)
  232.  
  233.         MListSignal = RECORD
  234.                          node   : MinNode;
  235.                          SigTask: TaskPtr;    (* task to signal *)
  236.                          SigBit : SHORTCARD;    (* signal bit to use *)
  237.                          Flags  : SHORTCARD;    (* user flags *)
  238.                       END;
  239.  
  240.  
  241.  
  242. (* MIDI message defininition *)
  243.  
  244. (* Status Bytes *)
  245.  
  246.     (* Channel Voice Messages (1sssnnnn) (OR with channel number) *)
  247. CONST
  248.  
  249.  MSNOTEOFF   = 80H;
  250.  MSNOTEON    = 90H;
  251.  MSPOLYPRESS = 0A0H;
  252.  MSCTRL      = 0B0H;
  253.  MSMODE      = 0B0H;
  254.  MSPROG      = 0C0H;
  255.  MSCHANPRESS = 0D0H;
  256.  MSPITCHBEND = 0E0H;
  257.  
  258.     (* System Common Messages (11110sss) *)
  259.  MSSYSEX      = 0F0H;
  260.  MSQTRFRAME   = 0F1H;
  261.  MSSONGPOS    = 0F2H;
  262.  MSSONGSELECT = 0F3H;
  263.  MSTUNEREQ    = 0F6H;
  264.  MSEOX          = 0F7H;
  265.  
  266.     (* System Real Time Messages (11111sss) *)
  267.  MSCLOCK     = 0F8H;
  268.  MSSTART     = 0FAH;
  269.  MSCONTINUE  = 0FBH;
  270.  MSSTOP      = 0FCH;
  271.  MSACTVSENSE = 0FEH;
  272.  MSRESET     = 0FFH;
  273.  
  274. (* Miscellaneous *)
  275.  
  276.  MIDDLEC      = 60H;     (* middle C note value *)
  277.  DEFAULTVELOCITY = 64H;     (* default Note On or Off velocity *)
  278.  PITCHBENDCENTER = 2000H;(* pitch bend center position as a 14 bit word *)
  279.  MCLKSPERQTR     = 24H;     (* MIDI clocks per qtr-note *)
  280.  MCLKSPERSP     = 6H;     (* MIDI clocks per song position index *)
  281.  MCCENTER     = 64H;  (* center value for controllers like Pan and Balance *)
  282.  
  283.  
  284. (* Standard Controllers *)
  285.  
  286.     (* continuous 14 bit - MSB: 0-1f, LSB: 20-3f *)
  287.  MCMODWHEEL   = 01H;
  288.  MCBREATH     = 02H;
  289.  MCFOOT       = 04H;
  290.  MCPORTATIME  = 05H;
  291.  MCDATAENTRY  = 06H;
  292.  MCVOLUME     = 07H;
  293.  MCBALANCE    = 08H;
  294.  MCPAN        = 0AH;
  295.  MCEXPRESSION = 0BH;
  296.  MCGENERAL1   = 10H;
  297.  MCGENERAL2   = 11H;
  298.  MCGENERAL3   = 12H;
  299.  MCGENERAL4   = 13H;
  300.  
  301.    (* continuous 7 bit (switches: 0-3f=off, 40-7f=on) *)
  302.  MCSUSTAIN      = 40H;
  303.  MCPORTA        = 41H;
  304.  MCSUSTENUTO    = 42H;
  305.  MCSOFTPEDAL    = 43H;
  306.  MCHOLD2        = 45H;
  307.  MCGENERAL5     = 50H;
  308.  MCGENERAL6     = 51H;
  309.  MCGENERAL7     = 52H;
  310.  MCGENERAL8     = 53H;
  311.  MCEXTDEPTH     = 5BH;
  312.  MCTREMOLODEPTH = 5CH;
  313.  MCCHORUSDEPTH  = 5DH;
  314.  MCCELESTEDEPTH = 5EH;
  315.  MCPHASERDEPTH  = 5FH;
  316.  MCDATAINCR     = 60H;
  317.  MCDATADECR     = 61H;
  318.  MCNRPNL        = 62H;
  319.  MCNRPNH        = 63H;
  320.  MCRPNL         = 64H;
  321.  MCRPNH         = 65H;
  322.  
  323.  MCMAX            = 78H;    (* max controller value *)
  324.  
  325.  
  326. (* Channel Modes *)
  327.  
  328.  MMMIN          = 79H;    (* min mode value *)
  329.  
  330.  MMRESETCTRL  = 79H;
  331.  MMLOCAL      = 7AH;
  332.  MMALLOFF     = 7BH;
  333.  MMOMNIOFF    = 7CH;
  334.  MMOMNION     = 7DH;
  335.  MMMONO       = 7EH;
  336.  MMPOLY       = 7FH;
  337.  
  338.  
  339. (* Registered Parameter Numbers *)
  340. (*
  341.     These are 16 bit values that need to be separated into two bytes for
  342.     use with the MC_RPNH & MC_RPNL messages using 8 bit math (hi = MRP_
  343.     >> 8, lo = MRP_ &   ff) as opposed to 7 bit math.  This is done
  344.     so that the defines match the numbers from the MMA.  See MIDI 1.0
  345.     Detailed Spec v4.0 pp 12, 23 for more info.
  346. *)
  347.  
  348.  MRPPBSENS     = 0000H;
  349.  MRPFINETUNE   = 0001H;
  350.  MRPCOURSETUNE = 0002H;
  351.  
  352.  
  353. (* MTC Quarter Frame messages *)
  354. (*
  355.     Qtr Frame message is F1 0nnndddd where
  356.  
  357.     nnn is a message type defined below
  358.     dddd is 4 bit data nibble for those message types
  359.  
  360.     Each pair of nibbles is combined by the receiver into a single byte.
  361.     There are masks and type values defined for some of these data bytes
  362.     below.
  363. *)
  364.  
  365.     (* message types *)
  366.  MTCQFRAMEL = 00H;
  367.  MTCQFRAMEH = 10H;
  368.  MTCQSECL   = 20H;
  369.  MTCQSECH   = 30H;
  370.  MTCQMINL   = 40H;
  371.  MTCQMINH   = 50H;
  372.  MTCQHOURL  = 60H;
  373.  MTCQHOURH  = 70H;    (* also contains time code type *)
  374.  
  375.     (* message masks *)
  376.  MTCQTYPEMASK = 70H;    (* mask for type bits in message *)
  377.  MTCQDATAMASK = 0FH;    (* mask for data bits in message *)
  378.  
  379.     (* hour byte *)
  380.  MTCHTYPEMASK = 60H;    (* mask for time code type *)
  381.  MTCHHOURMASK = 1FH;    (* hours mask (range 0-23) *)
  382.  
  383.     (* time code type values for hour byte *)
  384.  MTCT24FPS        = 00H;
  385.  MTCT25FPS        = 20H;
  386.  MTCT30FPSDROP    = 40H;
  387.  MTCT30FPSNONDROP = 60H;
  388.  
  389.  
  390.  
  391.  
  392. (* Sys/Ex ID numbers *)
  393.  
  394. (* Now includes 3 byte extension for the American Group.  This new
  395.    format uses a $00 as the sys/ex id followed by two additional bytes
  396.    that actually identify the manufacturer.  These new extended id
  397.    constants are 32 bit values (24 significant bits) that you will have
  398.    to break apart manually.
  399.  
  400.    You can match or filter off one of the extended id's when using the
  401.    RIMF_EXTID bit described above. *)
  402.  
  403.     (* American Group *)
  404. XAMERICA      = 00H;
  405. SEQUENTIAL    = 01H;
  406. IDP           = 02H;
  407. OCTAVEPLATEAU = 03H;
  408. MOOG          = 04H;
  409. PASSPORT      = 05H;
  410. LEXICON       = 06H;
  411. KURZWEIL      = 07H;
  412. FENDER        = 08H;
  413. AKG           = 0AH;
  414. VOYCE         = 0BH;
  415. WAVEFRAME     = 0CH;
  416. ADA           = 0DH;
  417. GARFIELD      = 0EH;
  418. ENSONIQ       = 0FH;
  419. OBERHEIM      = 10H;
  420. APPLE         = 11H;
  421. GREYMATTER    = 12H;
  422. PALMTREE      = 14H;
  423. JLCOOPER      = 15H;
  424. LOWREY        = 16H;
  425. ADAMSSMITH    = 17H;
  426. EMU           = 18H;
  427. HARMONY       = 19H;
  428. ART           = 1AH;
  429. BALDWIN       = 1BH;
  430. EVENTIDE      = 1CH;
  431. INVENTRONICS  = 1DH;
  432. CLARITY       = 1FH;
  433.  
  434.    (* American Group extened *)
  435. DIGITALMUSIC  = 0000007H;
  436. IOTA          = 0000008H;
  437. IVL           = 000000BH;
  438. SOUTHERNMUSIC = 000000CH;
  439. LAKEBUTLER    = 000000DH;
  440. DOD           = 0000010H;
  441. PERFECTFRET   = 0000014H;
  442. OPCODE        = 0000016H;
  443. SPATIALSOUND  = 0000018H;
  444. KMX           = 0000019H;
  445. AXXES         = 0000020H;
  446.  
  447.  
  448.     (* European Group *)
  449. PASSAC         = 20H;
  450. SIEL           = 21H;
  451. SYNTHAXE       = 22H;
  452. HOHNER         = 24H;
  453. TWISTER        = 25H;
  454. SOLTON         = 26H;
  455. JELLINGHAUS    = 27H;
  456. SOUTHWORTH     = 28H;
  457. PPG            = 29H;
  458. JEN            = 2AH;
  459. SSL            = 2BH;
  460. AUDIOVERITRIEB = 2CH;
  461. ELKA           = 2FH;
  462. DYNACORD       = 30H;
  463.  
  464.     (* Japanese Group *)
  465. KAWAI         = 40H;
  466. ROLAND        = 41H;
  467. KORG          = 42H;
  468. YAMAHA        = 43H;
  469. CASIO         = 44H;
  470. MORIDAIRA     = 45H;
  471. KAMIYA        = 46H;
  472. AKAI          = 47H;
  473. JAPANVICTOR   = 48H;
  474. MEISOSHA      = 49H;
  475. HOSHINOGAKKI  = 4AH;
  476. FUJITSU       = 4BH;
  477. SONY          = 4CH;
  478. NISSHINONPA   = 4DH;
  479. SYSTEMPRODUCT = 4FH;
  480.  
  481.     (* Universal ID Numbers *)
  482. NC  = 7DH;
  483. NRT = 7EH;
  484. RT  = 7FH;
  485.  
  486. END MidiD.
  487.