home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 581b.lha / M2Midi / MidiLibrary_v2p0.LZH / MidiLibrary_v2.0 / include.h / midi / midi.h next >
C/C++ Source or Header  |  1989-06-25  |  12KB  |  418 lines

  1. #ifndef MIDI_MIDI_H
  2. #define MIDI_MIDI_H
  3.  
  4. /*
  5.     Definitions pertaining to MIDI are derived from MIDI 1.0 Detailed
  6.     Specification v4.0 (published by the Internation MIDI Association)
  7.     and is current as of June, 1988.
  8.  
  9.     v2.0 - 23-Oct-88
  10. */
  11.  
  12. #ifndef EXEC_LISTS_H
  13.  #include <exec/lists.h>
  14. #endif
  15.  
  16. #ifndef EXEC_PORTS_H
  17.  #include <exec/ports.h>
  18. #endif
  19.  
  20.  
  21. /* midi.library structures & defines */
  22.  
  23. #define MIDINAME    "midi.library"
  24. #define MIDIVERSION 7L
  25.  
  26.  
  27. /* Routes */
  28.  
  29. #define RIM_MAXCOUNT 3
  30.  
  31. struct RIMatch {
  32.     UBYTE Flags;        /* flag bits defined below */
  33.     UBYTE Match[RIM_MAXCOUNT];
  34. };
  35.  
  36. #define RIMF_COUNTBITS 0x03    /* mask for # of match values (0 for match all) */
  37. #define RIMF_EXTID     0x40    /* indicates all 3 bytes of match[] == one 3 byte manuf. id (not valid for CtrlMatch) */
  38. #define RIMF_EXCLUDE   0x80    /* reverses logic of RIMatch so that all except those specified pass */
  39.  
  40.  
  41. struct MRouteInfo {
  42.     UWORD MsgFlags;        /* flags enabling message types defined below (MMF_) (msg filters) */
  43.     UWORD ChanFlags;        /* incoming channel enable flags (LSB = chan 1, MSB = chan 16) (channel filters) */
  44.     BYTE  ChanOffset;        /* signed offset applied to channels (simple channelizing) */
  45.     BYTE  NoteOffset;        /* signed offset applied to note numbers (transposition) */
  46.     struct RIMatch SysExMatch;    /* Sys/Ex manufacturer id filtering */
  47.     struct RIMatch CtrlMatch;    /* Controller number filtering */
  48. };
  49.  
  50. /* Msg Flags for MRouteInfo structure and returned by MidiMsgType */
  51.  
  52. #define MMF_CHAN    0x00ff
  53. #define MMF_NOTEOFF    0x0001
  54. #define MMF_NOTEON    0x0002
  55. #define MMF_POLYPRESS    0x0004
  56. #define MMF_CTRL    0x0008
  57. #define MMF_PROG    0x0010
  58. #define MMF_CHANPRESS    0x0020
  59. #define MMF_PITCHBEND    0x0040
  60. #define MMF_MODE    0x0080
  61.  
  62. #define MMF_SYSCOM    0x0100
  63. #define MMF_SYSRT    0x0200
  64. #define MMF_SYSEX    0x0400
  65.  
  66. #define MMF_ALL     0x07ff        /* all normal messages */
  67.  
  68.  
  69. struct MRoutePtr {
  70.     struct MinNode node;
  71.     struct MRoute *Route;
  72. };
  73.  
  74. struct MRoute {
  75.     struct MSource *Source;
  76.     struct MDest *Dest;
  77.     struct MRoutePtr SRoutePtr, DRoutePtr;
  78.     struct MRouteInfo RouteInfo;
  79. };
  80.  
  81.  
  82. /* Nodes */
  83.  
  84. struct MSource {
  85.     struct Node Node;
  86.     struct Image *Image;
  87.     struct MinList RPList;
  88.     APTR UserData;        /* user data extension */
  89.  
  90.     /* new stuff for v2.0 */
  91.     UWORD RouteMsgFlags;    /* mask of all route->MsgFlags for this MSource */
  92.     UWORD RouteChanFlags;    /* mask of all route->ChanFlags for this MSource */
  93. };
  94.  
  95. /* node types for Source */
  96. #define NT_MSOURCE    0x20
  97. #define NT_RESMSOURCE    0x21
  98.  
  99.  
  100. struct MDest {
  101.     struct Node Node;
  102.     struct Image *Image;
  103.     struct MinList RPList;
  104.     struct MsgPort *DestPort;
  105.     APTR UserData;        /* user data extension */
  106.  
  107.     /* new stuff for v2.0 */
  108.     struct MRouteInfo DefaultRouteInfo;     /* used when Routing function doesn't supply a RouteInfo */
  109. };
  110.  
  111. /* node types for Dest */
  112. #define NT_MDEST    0x22
  113. #define NT_RESMDEST    0x23
  114.  
  115.  
  116. /* MIDI Packet (new for v2.0) */
  117.  
  118. struct MidiPacket {        /* returned by GetMidiPacket() */
  119.     struct Message ExecMsg;
  120.     UWORD Type;         /* MMF_ bit for this message (as returned by MidiMsgType()) */
  121.     UWORD Length;        /* length of msg in bytes (as returned by MidiMsgLength()) */
  122.     ULONG reserved;        /* reserved for future expansion */
  123.     UBYTE MidiMsg[4];        /* actual MIDI message (real length of this array is Length, always at least this much memory allocated) */
  124. };
  125.  
  126.  
  127. /* Public List Change Signal */
  128.  
  129. struct MListSignal {
  130.     struct MinNode Node;
  131.     struct Task *SigTask;    /* task to signal */
  132.     UBYTE SigBit;        /* signal bit to use */
  133.     UBYTE Flags;        /* flags, see below */
  134. };
  135.  
  136.     /* user flags */
  137. #define MLSF_SOURCE   0x01L    /* causes signal when SourceList changes */
  138. #define MLSF_DEST     0x02L    /* causes signal when DestList changes */
  139.  
  140.  
  141. /* MIDI message defininition */
  142.  
  143. /* Status Bytes */
  144.  
  145.     /* Channel Voice Messages (1sssnnnn) (OR with channel number) */
  146. #define MS_NOTEOFF    0x80
  147. #define MS_NOTEON     0x90
  148. #define MS_POLYPRESS  0xA0
  149. #define MS_CTRL       0xB0
  150. #define MS_MODE       0xB0
  151. #define MS_PROG       0xC0
  152. #define MS_CHANPRESS  0xD0
  153. #define MS_PITCHBEND  0xE0
  154.  
  155.     /* System Common Messages (11110sss) */
  156. #define MS_SYSEX      0xF0
  157. #define MS_QTRFRAME   0xF1
  158. #define MS_SONGPOS    0xF2
  159. #define MS_SONGSELECT 0xF3
  160. #define MS_TUNEREQ    0xF6
  161. #define MS_EOX          0xF7
  162.  
  163.     /* System Real Time Messages (11111sss) */
  164. #define MS_CLOCK      0xF8
  165. #define MS_START      0xFA
  166. #define MS_CONTINUE   0xFB
  167. #define MS_STOP       0xFC
  168. #define MS_ACTVSENSE  0xFE
  169. #define MS_RESET      0xFF
  170.  
  171. /* Miscellaneous */
  172.  
  173. #define MIDDLEC     60    /* middle C note value */
  174. #define DEFAULTVELOCITY 64    /* default Note On or Off velocity */
  175. #define PITCHBENDCENTER 0x2000    /* pitch bend center position as a 14 bit word */
  176. #define MCLKSPERQTR    24    /* MIDI clocks per qtr-note */
  177. #define MCLKSPERSP    6    /* MIDI clocks per song position index */
  178. #define MCCENTER    64    /* center value for controllers like Pan and Balance */
  179.  
  180.  
  181. /* Standard Controllers */
  182.  
  183.     /* continuous 14 bit - MSB: 0-1f, LSB: 20-3f */
  184. #define MC_MODWHEEL  0x01
  185. #define MC_BREATH    0x02
  186. #define MC_FOOT      0x04
  187. #define MC_PORTATIME 0x05
  188. #define MC_DATAENTRY 0x06
  189. #define MC_VOLUME    0x07
  190. #define MC_BALANCE   0x08
  191. #define MC_PAN         0x0a
  192. #define MC_EXPRESSION 0x0b
  193. #define MC_GENERAL1  0x10
  194. #define MC_GENERAL2  0x11
  195. #define MC_GENERAL3  0x12
  196. #define MC_GENERAL4  0x13
  197.  
  198.     /* continuous 7 bit (switches: 0-3f=off, 40-7f=on) */
  199. #define MC_SUSTAIN   0x40
  200. #define MC_PORTA     0x41
  201. #define MC_SUSTENUTO 0x42
  202. #define MC_SOFTPEDAL 0x43
  203. #define MC_HOLD2     0x45
  204. #define MC_GENERAL5  0x50
  205. #define MC_GENERAL6  0x51
  206. #define MC_GENERAL7  0x52
  207. #define MC_GENERAL8  0x53
  208. #define MC_EXTDEPTH    0x5b
  209. #define MC_TREMOLODEPTH 0x5c
  210. #define MC_CHORUSDEPTH    0x5d
  211. #define MC_CELESTEDEPTH 0x5e
  212. #define MC_PHASERDEPTH    0x5f
  213.  
  214.     /* parameters */
  215. #define MC_DATAINCR  0x60
  216. #define MC_DATADECR  0x61
  217. #define MC_NRPNL     0x62
  218. #define MC_NRPNH     0x63
  219. #define MC_RPNL      0x64
  220. #define MC_RPNH      0x65
  221.  
  222. #define MC_MAX         0x78    /* max controller value */
  223.  
  224.  
  225. /* Channel Modes */
  226.  
  227. #define MM_MIN         0x79    /* min mode value */
  228.  
  229. #define MM_RESETCTRL 0x79
  230. #define MM_LOCAL     0x7a
  231. #define MM_ALLOFF    0x7b
  232. #define MM_OMNIOFF   0x7c
  233. #define MM_OMNION    0x7d
  234. #define MM_MONO      0x7e
  235. #define MM_POLY      0x7f
  236.  
  237.  
  238. /* Registered Parameter Numbers */
  239. /*
  240.     These are 16 bit values that need to be separated into two bytes for
  241.     use with the MC_RPNH & MC_RPNL messages using 8 bit math (hi = MRP_
  242.     >> 8, lo = MRP_ & 0xff) as opposed to 7 bit math.  This is done
  243.     so that the defines match the numbers from the MMA.  See MIDI 1.0
  244.     Detailed Spec v4.0 pp 12, 23 for more info.
  245. */
  246.  
  247. #define MRP_PBSENS    0x0000
  248. #define MRP_FINETUNE    0x0001
  249. #define MRP_COURSETUNE    0x0002
  250.  
  251.  
  252. /* MTC Quarter Frame messages */
  253. /*
  254.     Qtr Frame message is F1 0nnndddd where
  255.  
  256.     nnn is a message type defined below
  257.     dddd is 4 bit data nibble for those message types
  258.  
  259.     Each pair of nibbles is combined by the receiver into a single byte.
  260.     There are masks and type values defined for some of these data bytes
  261.     below.
  262. */
  263.  
  264.     /* message types */
  265. #define MTCQ_FRAMEL 0x00
  266. #define MTCQ_FRAMEH 0x10
  267. #define MTCQ_SECL   0x20
  268. #define MTCQ_SECH   0x30
  269. #define MTCQ_MINL   0x40
  270. #define MTCQ_MINH   0x50
  271. #define MTCQ_HOURL  0x60
  272. #define MTCQ_HOURH  0x70    /* also contains time code type */
  273.  
  274.     /* message masks */
  275. #define MTCQ_TYPEMASK 0x70    /* mask for type bits in message */
  276. #define MTCQ_DATAMASK 0x0f    /* mask for data bits in message */
  277.  
  278.     /* hour byte */
  279. #define MTCH_TYPEMASK 0x60    /* mask for time code type */
  280. #define MTCH_HOURMASK 0x1f    /* hours mask (range 0-23) */
  281.  
  282.     /* time code type values for hour byte */
  283. #define MTCT_24FPS        0x00
  284. #define MTCT_25FPS        0x20
  285. #define MTCT_30FPS_DROP     0x40
  286. #define MTCT_30FPS_NONDROP  0x60
  287.  
  288.  
  289. /* Sys/Ex ID numbers */
  290. /*
  291.     Now includes 3 byte extension for the American Group.  This new
  292.     format uses a 0x00 as the sys/ex id followed by two additional bytes
  293.     that actually identify the manufacturer.  These new extended id
  294.     constants are 32 bit values (24 significant bits) that can be
  295.     managed using SPLIT_MIDX() and MAKE_MIDX() macros defined below.
  296.  
  297.     You can match or filter off one of the extended id's when using the
  298.     RIMF_EXTID bit described above.
  299.  
  300.     example RIMatch
  301.     {
  302.         RIMF_EXTID | 1,        extend id, match one manufacturer
  303.         SPLIT_MIDX (MIDX_IOTA)  splits id into 3 bytes
  304.     }
  305. */
  306.  
  307.     /* American Group */
  308. #define MID_XAMERICA        0x00
  309. #define MID_SEQUENTIAL        0x01
  310. #define MID_IDP         0x02
  311. #define MID_OCTAVEPLATEAU   0x03
  312. #define MID_MOOG        0x04
  313. #define MID_PASSPORT        0x05
  314. #define MID_LEXICON        0x06
  315. #define MID_KURZWEIL        0x07
  316. #define MID_FENDER        0x08
  317. #define MID_AKG         0x0a
  318. #define MID_VOYCE        0x0b
  319. #define MID_WAVEFRAME        0x0c
  320. #define MID_ADA         0x0d
  321. #define MID_GARFIELD        0x0e
  322. #define MID_ENSONIQ        0x0f
  323. #define MID_OBERHEIM        0x10
  324. #define MID_APPLE        0x11
  325. #define MID_GREYMATTER        0x12
  326. #define MID_PALMTREE        0x14
  327. #define MID_JLCOOPER        0x15
  328. #define MID_LOWREY        0x16
  329. #define MID_ADAMSSMITH        0x17
  330. #define MID_EMU         0x18
  331. #define MID_HARMONY        0x19
  332. #define MID_ART         0x1a
  333. #define MID_BALDWIN        0x1b
  334. #define MID_EVENTIDE        0x1c
  335. #define MID_INVENTRONICS    0x1d
  336. #define MID_CLARITY        0x1f
  337.  
  338. #define MIDX_DIGITALMUSIC   0x000007L
  339. #define MIDX_IOTA        0x000008L
  340. #define MIDX_IVL        0x00000bL
  341. #define MIDX_SOUTHERNMUSIC  0x00000cL
  342. #define MIDX_LAKEBUTLER     0x00000dL
  343. #define MIDX_DOD        0x000010L
  344. #define MIDX_PERFECTFRET    0x000014L
  345. #define MIDX_OPCODE        0x000016L
  346. #define MIDX_SPATIALSOUND   0x000018L
  347. #define MIDX_KMX        0x000019L
  348. #define MIDX_AXXES        0x000020L
  349.  
  350.     /* European Group */
  351. #define MID_PASSAC        0x20
  352. #define MID_SIEL        0x21
  353. #define MID_SYNTHAXE        0x22
  354. #define MID_HOHNER        0x24
  355. #define MID_TWISTER        0x25
  356. #define MID_SOLTON        0x26
  357. #define MID_JELLINGHAUS     0x27
  358. #define MID_SOUTHWORTH        0x28
  359. #define MID_PPG         0x29
  360. #define MID_JEN         0x2a
  361. #define MID_SSL         0x2b
  362. #define MID_AUDIOVERITRIEB  0x2c
  363. #define MID_ELKA        0x2f
  364. #define MID_DYNACORD        0x30
  365.  
  366.     /* Japanese Group */
  367. #define MID_KAWAI        0x40
  368. #define MID_ROLAND        0x41
  369. #define MID_KORG        0x42
  370. #define MID_YAMAHA        0x43
  371. #define MID_CASIO        0x44
  372. #define MID_MORIDAIRA        0x45
  373. #define MID_KAMIYA        0x46
  374. #define MID_AKAI        0x47
  375. #define MID_JAPANVICTOR     0x48
  376. #define MID_MEISOSHA        0x49
  377. #define MID_HOSHINOGAKKI    0x4a
  378. #define MID_FUJITSU        0x4b
  379. #define MID_SONY        0x4c
  380. #define MID_NISSHINONPA     0x4d
  381. #define MID_SYSTEMPRODUCT   0x4f
  382.  
  383.     /* Universal ID Numbers */
  384. #define MID_UNC     0x7d
  385. #define MID_UNRT    0x7e
  386. #define MID_URT     0x7f
  387.  
  388.  
  389. /* handy macros */
  390.  
  391.     /* pack high/low bytes of a word into midi format (7/14 bit math) */
  392. #define MIDI_HIBYTE(word) ( (word) >> 7 & 0x7f )
  393. #define MIDI_LOBYTE(word) ( (word) & 0x7f )
  394.  
  395.     /* unpack 2 midi bytes into a word (7/14 bit math) */
  396. #define MIDI_WORD(hi,lo) ( (hi & 0x7f) << 7 | (lo & 0x7f) )
  397.  
  398.     /* unpack a 3 byte sys/ex id into single bytes for argument lists and RIMatch initializers */
  399. #define SPLIT_MIDX(id)         (UBYTE)((id)>>16), (UBYTE)((id)>>8), (UBYTE)(id)
  400.  
  401.     /* make a 3 byte sys/ex id from single bytes (MAKE_MIDX(msg[1],msg[2],msg[3]) */
  402. #define MAKE_MIDX(id0,id1,id2) ((ULONG)((id0) & 0xff)<<16 | (ULONG)((id1) & 0xff)<<8 | (ULONG)((id2) & 0xff))
  403.  
  404.  
  405.  
  406. /* midi.library function declarations */
  407.  
  408. struct MSource *CreateMSource(), *FindMSource();
  409. struct MDest *CreateMDest(), *FindMDest();
  410. struct MRoute *CreateMRoute(), *MRouteSource(), *MRouteDest(), *MRoutePublic();
  411. UBYTE *GetMidiMsg();
  412. struct MidiPacket *GetMidiPacket();
  413. ULONG MidiMsgLength();
  414. UWORD MidiMsgType();
  415. struct MListSignal *CreateMListSignal();
  416.  
  417. #endif
  418.