home *** CD-ROM | disk | FTP | other *** search
/ Merciful 3 / Merciful_Release_3.bin / software / o / octamed / octamedv6.12.lha / programmers / MMD_FileFormat.doc < prev    next >
Text File  |  1995-05-31  |  34KB  |  873 lines

  1. -----------------------------------------------------------------------------
  2.  
  3.         MED/OctaMED MMD0/MMD1/MMD2 file formats
  4.         written by Teijo Kinnunen (31.05.1995)
  5.         Revision 5
  6.  
  7. $VER: MMD_documentation 5 (31.05.1995)
  8.  
  9. -----------------------------------------------------------------------------
  10.  
  11. Background
  12. ~~~~~~~~~~
  13. A couple of years ago, when programming MED V2.1, I needed a file format for
  14. MED modules. The only "module" format in MED V2.0 was the Sng+samples format.
  15. Although it produced compact files, it was very difficult and tricky to read
  16. in. Therefore, I designed a new file format, that would be easy to use in
  17. module player programs etc. This file format was named 'MMD0' (Med MoDule 0).
  18. The limitations in MMD0 block format forced me to create a new file format
  19. for OctaMED Professional, this format is 'MMD1'. It's mostly the same as
  20. MMD0, except the block structure is different. Another new format is called
  21. 'MMD2', this extends some of the old limits and provides a couple of new
  22. features
  23.  
  24. Design concepts
  25. ~~~~~~~~~~~~~~~
  26. One of the main goals was to make MMD's (MED modules) as extensible as
  27. possible. This would have been easy to implement with IFF-style chunks.
  28. However, this method was obviously not the best for play-routine use.
  29.  
  30. Therefore, MMD's are implemented in quite an extraordinary way. They consist
  31. of structures (similar to C structs), and pointers. In a module file,
  32. pointers are defined as offsets from the beginning of the module. This way, a
  33. particular structure can be read just by Seek()'ing using the pointer as the
  34. offset from the beginning of the file. When a module has been read into
  35. memory, it has to be relocated before it can be used (the relocation is done
  36. simply by adding the address of the module to the pointers).
  37.  
  38. As with the Amiga OS, a MMD file does not contain absolute addresses. There's
  39. a module header structure at the beginning of the file. This structure
  40. contains pointers to different parts of the module. And you *MUST* use these
  41. pointers. You may NOT expect that the song structure is at offset $00000034,
  42. for example. Although it usually is, this may change in future releases. In
  43. addition, it's possible that a structure even doesn't exist (the structure
  44. pointer is NULL). Therefore, you *MUST* check the structure pointer before
  45. accessing the structure. Finally, when writing MMD's you *MUST* set
  46. undefined/reserved fields to zeros. More finally, you *MUST* align all
  47. structures to even boundaries! (I forgot the alignment in MED V3.00 save
  48. routine, resulting Guruing modules under some conditions :-(
  49.  
  50. The module header
  51. ~~~~~~~~~~~~~~~~~
  52. This structure must exist at the beginning of each MED module file. Each of
  53. the structure members are described.
  54.  
  55. In multi-modules, there are header structs for each song. (The subsequent
  56. header pointers can be found from expdata structure. Multi-modules should
  57. have the same smplarr pointer in every header.) Older MEDs which don't
  58. recognize multi-modules consider a multi-module as an ordinary module (only
  59. the first song is loaded).
  60.  
  61. The numbers enclosed in /* */ at the beginning of each line are (decimal)
  62. offsets of each member (for assembly programmers).
  63.  
  64. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65. struct MMD0 {
  66. /* 0 */     ULONG   id;
  67. /* 4 */     ULONG   modlen;
  68. /* 8 */     struct MMD0song *song;
  69. /* 12 */    UWORD   psecnum;    /* for the player routine, MMD2 only */
  70. /* 14 */    UWORD   pseq;       /*  "   "   "   "    */
  71. /* 16 */    struct MMD0Block **blockarr;
  72. /* 20 */    ULONG   reserved1;
  73. /* 24 */    struct InstrHdr **smplarr;
  74. /* 28 */    ULONG   reserved2;
  75. /* 32 */    struct MMD0exp *expdata;
  76. /* 36 */    ULONG   reserved3;
  77. /* 40 */    UWORD   pstate;  /* some data for the player routine */
  78. /* 42 */    UWORD   pblock;
  79. /* 44 */    UWORD   pline;
  80. /* 46 */    UWORD   pseqnum;
  81. /* 48 */    WORD    actplayline;
  82. /* 50 */    UBYTE   counter;
  83. /* 51 */    UBYTE   extra_songs; /* number of songs - 1 */
  84. }; /* length = 52 bytes */
  85.  
  86. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87. id
  88. --
  89. This longword is used to identify the MMD and its version. Currently defined
  90. MMD types are MMD0 (0x4D4D4430), MMD1 (0x4D4D4431) and MMD2 (0x4D4D4432).
  91. MMD3 and upwards are reserved for future versions.
  92.  
  93. In multi-modules, the following modules usually contain id MCNT, MCN1 or
  94. MCN2. The first module always has MMD0 - MMD2 as an id.
  95.  
  96. modlen
  97. ------
  98. This longword contains the length of the entire module.
  99.  
  100. song
  101. ----
  102. Pointer to a MMD0song/MMD2song structure. This structure MUST ALWAYS EXIST!
  103.  
  104. blockarr
  105. --------
  106. Pointer to a table of block pointers. For example:
  107.     blockarr:  $00003000
  108.             block 0 ptr block 1 ptr block 2 ptr
  109. offset  $00003000:  $00002000,  $00002400,  $00002800 ....
  110.  
  111. offset  $00002000: block 0 data...
  112. offset  $00002400: block 1 data...
  113. ...
  114. The size of the table is MMD0song.numblocks longwords.
  115.  
  116. smplarr
  117. -------
  118. Pointer to a table of instrument pointers. The size of the table is
  119. MMD0song.numsamples longwords. This pointer is zero in OctaMED Pro MMD1 songs.
  120. In this case, OctaMED Pro loads the instruments from disk(s).
  121.  
  122. expdata
  123. -------
  124. Pointer to an expansion structure. The expansion structure contains a lot of
  125. extra information. The exp. structure does not exist in all MMD's. (Be sure
  126. to check the pointer before using it.)
  127.  
  128. pstate, pblock, pline, pseqnum, actplayline, counter, psecnum, pseq
  129. -------------------------------------------------------------------
  130. These are variables for the play routine. You can read these fields to get
  131. the current song position (not all versions of the play routine use these
  132. fields, however). When writing a MMD, you should leave all fields to zero,
  133. except the 'actplayline', which ought to be -1 ($FFFF).
  134.  
  135. extra_songs
  136. -----------
  137. This field contains the number of songs in the current module. For
  138. non-multi-modules, this is 0. If there are two songs, extra_songs contains 1,
  139. and so on.
  140.  
  141. reserved0,1,2,3
  142. ---------------
  143. Not currently defined. Set to zero.
  144.  
  145.  
  146. The song structure (MMD0song)
  147. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  148. This structure contains the basic information about the song. It must exist
  149. on every module file. This structure is for MMD0/MMD1 only! The MMD2 struct
  150. is documented below.
  151.  
  152. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  153. struct MMD0song {
  154.     struct MMD0sample sample[63];   /* 63 * 8 bytes = 504 bytes */
  155.     UWORD   numblocks;      /* offs: 504 */
  156.     UWORD   songlen;        /* offs: 506 */
  157.     UBYTE   playseq[256];   /* offs: 508 */
  158.     UWORD   deftempo;       /* offs: 764 */
  159.     BYTE    playtransp;     /* offs: 766 */
  160.     UBYTE   flags;          /* offs: 767 */
  161.     UBYTE   flags2;         /* offs: 768 */
  162.     UBYTE   tempo2;         /* offs: 769 */
  163.     UBYTE   trkvol[16];     /* offs: 770 */
  164.     UBYTE   mastervol;      /* offs: 786 */
  165.     UBYTE   numsamples;     /* offs: 787 */
  166. }; /* length = 788 bytes */
  167.  
  168. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  169. sample
  170. ------
  171. Contains some basic info about each sample. The structure looks like this:
  172.  
  173. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  174.     struct MMD0sample {
  175.         UWORD rep,replen;   /* offs: 0(s), 2(s) */
  176.         UBYTE midich;       /* offs: 4(s) */
  177.         UBYTE midipreset;   /* offs: 5(s) */
  178.         UBYTE svol;         /* offs: 6(s) */
  179.         BYTE strans;        /* offs: 7(s) */
  180.     };
  181.  
  182. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  183.     rep         repeat start offset, shifted right one bit (as in
  184.                 Protracker).
  185.     replen      repeat length, shifted right one bit.
  186.     midich      MIDI channel for current instrument, 0 if not MIDI.
  187.     midipreset  MIDI preset number for current instrument, 0 if no preset.
  188.     svol        default volume for current instrument (0 - 64).
  189.     strans      instrument transpose value.
  190.  
  191. More information is defined in expdata structure.
  192.  
  193. numblocks
  194. ---------
  195. Number of blocks in current song. This field also indicates the length of the
  196. blockarr table in longwords.
  197.  
  198. songlen
  199. -------
  200. Song length (number of sequence numbers in the play sequence list).
  201.  
  202. playseq
  203. -------
  204. This is the play sequence list.
  205.  
  206. deftempo
  207. --------
  208. Default song tempo (the main tempo slider in MED/OctaMED). If BPM mode is on,
  209. this value indicates BPM.
  210.  
  211. playtransp
  212. ----------
  213. The global play transpose value for current song.
  214.  
  215. flags
  216. -----
  217. Contains many single-bit flags:
  218.     FLAG_FILTERON   0x1     the hardware audio filter is on
  219.     FLAG_JUMPINGON  0x2     mouse pointer jumping on (not in OctaMED Pro)
  220.     FLAG_JUMP8TH    0x4     jump every 8th line (not in OctaMED Pro)
  221.     FLAG_INSTRSATT  0x8     sng+samples indicator (not useful in MMD's)
  222.     FLAG_VOLHEX     0x10    volumes are HEX
  223.     FLAG_STSLIDE    0x20    use ST/NT/PT compatible sliding
  224.     FLAG_8CHANNEL   0x40    this is OctaMED 5-8 channel song
  225.     FLAG_SLOWHQ     0X80    HQ V2-4 compatibility mode
  226.  
  227. flags2
  228. ------
  229. More flags, currently only BPM stuff:
  230.     FLAG2_BMASK 0x1F (bits 0-4)     BPM beat length (in lines)
  231.                                     0 = 1 line, $1F = 32 lines.
  232.                                     (OctaMED Pro Lines Per Beat slider.)
  233.     FLAG2_BPM   0x20    BPM mode on
  234.  
  235.     (bits 0x40 and 0x80 are not defined, and must be set to zero)
  236.  
  237. tempo2
  238. ------
  239. This is the "secondary tempo" (the rightmost MED/OctaMED tempo slider),
  240. indicating the number of timing pulses per line.
  241.  
  242. trkvol[16]
  243. ----------
  244. The relative track volumes (1 - 64) for each track.
  245.  
  246. mastervol
  247. ---------
  248. The relative master volume (1 - 64).
  249.  
  250. numsamples
  251. ----------
  252. Number of instruments (samples/synthsounds) in current song. Also indicates
  253. the size of the smplarr table in longwords.
  254.  
  255. The MMD2 song structure
  256. ~~~~~~~~~~~~~~~~~~~~~~~
  257. struct MMD2song {
  258.     struct MMD0sample sample[63];
  259.     UWORD   numblocks;
  260.     UWORD   songlen;    /* NOTE: number of sections in MMD2 */
  261.     struct  PlaySeq **playseqtable;
  262.     UWORD   *sectiontable;  /* UWORD section numbers */
  263.     UBYTE   *trackvols; /* UBYTE track volumes */
  264.     UWORD   numtracks;  /* max. number of tracks in the song
  265.                            (also the number of entries in
  266.                            'trackvols' table) */
  267.     UWORD   numpseqs;   /* number of PlaySeqs in 'playseqtable' */
  268.     UBYTE   pad0[240];  /* reserved for future expansion */
  269. /* Below fields are MMD0/MMD1-compatible (except pad1[]) */
  270.     UWORD   deftempo;
  271.     BYTE    playtransp;
  272.     UBYTE   flags;
  273.     UBYTE   flags2;
  274.     UBYTE   tempo2;
  275.     UBYTE   pad1[16];   /* used to be trackvols, in MMD2 reserved */
  276.     UBYTE   mastervol;
  277.     UBYTE   numsamples;
  278. };
  279.  
  280. This structure is exactly as long as the MMDsong structure. Common fields are
  281. located at same offsets. You can also see, that there's a lot of room for
  282. expansion in this structure. The new/changed fields are:
  283.  
  284. songlen
  285. -------
  286. Now expresses the number of sections (i.e. the length of 'sectiontable').
  287.  
  288. playseqtable
  289. ------------
  290. Points to a table of PlaySeq structures. This structure is:
  291.  
  292.     struct PlaySeq {
  293.         char    name[32];       /* (0)  31 chars + \0 */
  294.         ULONG   reserved[2];    /* (32) for possible extensions */
  295.         UWORD   length;         /* (40) # of entries */
  296.     /* Commented out, not all compilers may like it... */
  297.     /*  UWORD   seq[0]; */      /* (42) block numbers.. */
  298.     };
  299.  
  300. This should be self-explaining. Note: block numbers in seq[] may not be
  301. greater than 0x7FFF. These are reserved for future expansions. The current
  302. player routines skip these numbers.
  303.  
  304. trackvols
  305. ---------
  306. Points to a table of 'numtracks' UBYTEs, which contain values 1 - 64 for
  307. relative track volumes.
  308.  
  309. numtracks
  310. ---------
  311. The number of tracks this song uses (i.e. the width of the widest block).
  312.  
  313. numpseqs
  314. --------
  315. The number of PlaySeqs in 'playseqtable'.
  316.  
  317. pad[]
  318. -----
  319. Must be zero! Don't attempt to read.
  320.  
  321. The block format
  322. ~~~~~~~~~~~~~~~~
  323. As described above, MMD0 header structure contains a pointer (blockarr) to a
  324. table of block pointers. These block pointers point to the actual block data
  325. structures. The format of these data structures differ in MMD0 and MMD1 file
  326. formats.
  327.  
  328. MMD0 block format
  329. -----------------
  330. At the beginning of each block, there's a small header:
  331.  
  332. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  333.     struct MMD0Block {
  334.         UBYTE numtracks,lines;
  335.     };
  336.  
  337. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  338.     numtracks   number of tracks (4, 8, 12 or 16) on this block
  339.     lines       number of lines on this block; 0 = 1 line,
  340.                 255 = 256 lines
  341.  
  342. Following this header, there is the actual note data, consisting of 3-byte
  343. structures containing a note and its command. The data is arranged
  344. sequentially a line at a time, i.e. in the following order:
  345.     line 0 track 0
  346.     line 0 track 1
  347.     line 0 track 2
  348.     line 0 track 3
  349.     line 1 track 0
  350.     line 1 track 1
  351.     ...
  352. The 3-byte structure looks like this (each letter corresponds to one bit):
  353.  
  354.     xynnnnnn iiiicccc dddddddd
  355.  
  356.     n = note number (0 - $3F). 0 = ---, 1 = C-1, 2 = C#1...
  357.     i = the low 4 bits of the instrument number
  358.     x = the 5th bit (#4) of the instrument number
  359.     y = the 6th bit (#5) of the instrument number
  360.     c = command number (0 - $F)
  361.     d = databyte ($00 - $FF)
  362.  
  363. MMD1/MMD2 block format
  364. -----------------
  365. MMD1/MMD2 block format can contain a lot more information than MMD0's. The
  366. block header looks like this:
  367.  
  368. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  369.     struct MMD1Block {
  370.         UWORD numtracks;
  371.         UWORD lines;
  372.         struct BlockInfo *info;
  373.     };
  374.  
  375. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  376.     numtracks   Number of tracks in this block (4, 8, 12, or 16).
  377.                 (MMD2: All values between 1 - 64 are valid.)
  378.     lines       Number of lines in this block (0 = 1 line etc.).
  379.                 OctaMED Pro can handle upto 3200 lines/block, so
  380.                 this is obviously the practical upper limit.
  381.     info        Pointer to structure containing extra information.
  382.                 (Can be NULL, if no BlockInfo struct exists).
  383.  
  384.     The BlockInfo structure is:
  385.  
  386. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  387.     struct BlockInfo {
  388.         ULONG   *hlmask;
  389.         UBYTE   *blockname;
  390.         ULONG   blocknamelen;
  391.         struct  BlockCmdPageTable *pagetable;
  392.         ULONG   reserved[5];
  393.     };
  394.  
  395. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  396.     hlmask      Pointer to an array of longwords, containing info
  397.                 about line highlighting (TAB key on MED). The number
  398.                 of longwords depend on the number of lines on the
  399.                 block. (E.g: 1 line -> 1 longword, 32 lines -> 1 lw,
  400.                 33 lines -> 2 lws, 256 lines -> 4 lws)
  401.                 The bits in the longwords are arranged in reversed
  402.                 order (e.g. bit #0 = line 0, bit #31 = line 31).
  403.  
  404.     blockname   Pointer to the name of the block. Must be null-
  405.                 terminated.
  406.  
  407.     blocknamelen    Length of the block name, including the terminating
  408.                     zero. OctaMED Pro currently has the maximum length of
  409.                     41 chars (+ zero). However, this may change in the
  410.                     future. Don't read blocknames longer than you are
  411.                     able to handle!
  412.  
  413.     pagetable   OctaMED V6 supports multiple player commands per note.
  414.                 This pointer points to the BlockCmdPageTable structure,
  415.                 if this block has more than one pages. (See below.)
  416.  
  417.     reserved[5] These are reserved for future extensions. Must be set   
  418.                 to zero.
  419.  
  420.     This is the BlockCmdPageTable structure:
  421.  
  422. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  423. struct BlockCmdPageTable {
  424.     UWORD    num_pages;
  425.     UWORD    reserved;
  426.     UWORD    *page[0];
  427. };
  428.  
  429. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  430.  
  431.     num_pages   Specifies the number of additional command pages. The first
  432.                 command page that always exists is not included in this.
  433.  
  434.     reserved    Some room for future expansions, you never know..
  435.  
  436.     page        Here begins the table of command page pointers. (The table
  437.                 has num_pages entries.) Each page contains two-byte entries
  438.                 (command and data byte), which are arranged just as notes
  439.                 in blocks. (Line 0 Track 0, Line 0 Track 1...)
  440.  
  441.     The note structures, which are 4 bytes long in MMD1 modules, are
  442.     arranged exactly as in MMD0 modules (i.e. L0T0, L0T1... L1T0, L1T1..).
  443.  
  444.         xnnnnnnn xxiiiiii cccccccc dddddddd
  445.  
  446.     n = note number (0 - $7F, 0 = ---, 1 = C-1...)
  447.     i = instrument number (0 - $3F)
  448.     c = command ($00 - $FF)
  449.     d = data byte ($00 - $FF)
  450.     x = undefined, reserved for future expansion. MUST BE SET TO ZERO,
  451.         AND MASKED OUT WHEN READING THE NOTE OR INSTRUMENT NUMBER.
  452.  
  453.  
  454. The instrument format
  455. ~~~~~~~~~~~~~~~~~~~~~
  456. The MMD0 header structure contains a pointer (smplarr) to a table of
  457. instrument pointers. These pointers point to the actual instrument data
  458. structures. If an instrument pointer is zero, there's no instrument in that
  459. slot.
  460.  
  461. Every instrument has a six-byte header structure, which is the same for all
  462. instrument types (sample/synth/hybrid).
  463.  
  464. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  465.     struct InstrHdr {
  466.         ULONG   length;
  467.         WORD    type;
  468.         /* Followed by actual data */
  469.     };
  470.  
  471. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  472.     length      indicates the length of the instrument (the six byte
  473.                 header data length is not included)
  474.     type        instrument type - currently the following types are
  475.                 defined:
  476.  
  477.         HYBRID      -2
  478.         SYNTHETIC   -1
  479.         SAMPLE      0   (an ordinary 1-octave sample)
  480.         IFF5OCT     1   (5 octaves)
  481.         IFF3OCT     2   (3 octaves)
  482.         (The following ones are recognized by OctaMED Pro only)
  483.         IFF2OCT     3   (2 octaves)
  484.         IFF4OCT     4   (4 octaves)
  485.         IFF6OCT     5   (6 octaves)
  486.         IFF7OCT     6   (7 octaves)
  487.         (OctaMED Pro V5 + later)
  488.         EXTSAMPLE   7   (two extra-low octaves)
  489.  
  490. The sample-type instruments (>= 0) contain the actual sample data straight
  491. after the header structure.
  492.  
  493. Since OctaMED V6, there are also two flag bits in the type field:
  494.         S_16        0x10
  495.         STEREO      0x20
  496.  
  497. S_16 means that this is a 16-bit sample. Length still indicates the sample
  498. length in bytes, so there are actually length / 2 16-bit samples.
  499.  
  500. STEREO means that this is a stereo sample. The sample is not interleaved. The
  501. left channel comes first, followed by the right channel. Important: Length
  502. specifies the size of one channel only! The actual memory usage for both
  503. samples is length * 2 bytes.
  504.  
  505. Plus an obsolete item:
  506.         OBSOLETE_MD16    0x18
  507.  
  508. This instrument type is obsolete, and was used for V5.04 Aura support. It
  509. should be treated as type S_16|SAMPLE (0x10), with instrument's output device
  510. set to Aura.
  511.  
  512. Synthetic instruments
  513. ---------------------
  514. Synthsounds have a special structure of their own. They also contain
  515. waveforms and pointers to them. Therefore, relocation is required. However,
  516. there's an important difference: pointers are expressed as an offset from the
  517. beginning of the synthsound, NOT the beginning of the module. The 'reloc.a'
  518. routine provided with MED/OctaMED automatically handles this.
  519.  
  520. The synthsound structure is as follows (note that this structure contains the
  521. header structure):
  522.  
  523. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  524.     struct SynthInstr {
  525.         ULONG   length;     /* length of this struct */
  526.         WORD    type;       /* -1 or -2 (offs: 4) */
  527.         UBYTE   defaultdecay;
  528.         UBYTE   reserved[3];
  529.         UWORD   rep;
  530.         UWORD   replen;
  531.         UWORD   voltbllen;  /* offs: 14 */
  532.         UWORD   wftbllen;   /* offs: 16 */
  533.         UBYTE   volspeed;   /* offs: 18 */
  534.         UBYTE   wfspeed;    /* offs: 19 */
  535.         UWORD   wforms;     /* offs: 20 */
  536.         UBYTE   voltbl[128];    /* offs: 22 */
  537.         UBYTE   wftbl[128]; /* offs: 150 */
  538.         struct  SynthWF *wf[64]; /* offs: 278 */
  539.     };
  540.  
  541. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  542.     defaultdecay    = the default decay of the current synthsound. This
  543.                       is NOT used in modules. It's significant only when
  544.                       saving a single synthsound.
  545.  
  546.     reserved[3] = set to zero.
  547.  
  548.     rep, replen = repeat/rep. length for hybrid sounds. Used only
  549.                   when saving a single hybrid sound.
  550.  
  551.     voltbllen   = the length of the volume sequence table.
  552.  
  553.     wftbllen    = the length of the waveform sequence table.
  554.  
  555.     volspeed    = the initial volume table execution speed.
  556.  
  557.     wfspeed     = the initial waveform table execution speed.
  558.  
  559.     wforms      = the number of waveforms in the current synthsound.
  560.  
  561.     voltbl      = the actual volume sequence table. Values $00-$7F
  562.                   are volumes or command arguments. Values >= $80 are
  563.                   commands. The following commands are currently
  564.                   defined:
  565.                 $FF END     $F4 EN1
  566.                 $FE JMP     $F3 CHU
  567.                 $FB HLT     $F2 CHD
  568.                 $FA JWS     $F1 WAI
  569.                 $F6 EST     $F0 SPD
  570.                 $F5 EN2
  571.  
  572.     wftbl       = the actual waveform sequence table. Values $00-$7F
  573.                   are waveform numbers  or command arguments. Values
  574.                   >= $80 are commands. The following commands are
  575.                   currently defined:
  576.                 $FF END     $F6 RES
  577.                 $FE JMP     $F5 VBS
  578.                 $FD ARE     $F4 VBD
  579.                 $FC ARP     $F3 CHU
  580.                 $FB HLT     $F2 CHD
  581.                 $FA JVS     $F1 WAI
  582.                 $F7 VWF     $F0 SPD
  583.  
  584.     wf      = pointers to waveforms. (Once again: relative to the
  585.               beginning of the synthsound!) A waveform structure
  586.               is as follows:
  587.  
  588.                 struct SynthWF {
  589.                     UWORD length;   /* length in words */
  590.                     BYTE  wfdata[xx]; /* the waveform */
  591.                 };
  592.  
  593.                 (where xx = length in bytes)
  594.  
  595.               In hybrid sounds, however, wf[0] is different.
  596.  
  597. Hybrid instruments
  598. ------------------
  599. Hybrid sounds use the same structure as synthsounds, except that the first
  600. waveform (wf[0]) pointer points to a sample. (The sample header structure
  601. exists, as usual.)
  602.  
  603.  
  604. MMD0exp - the key to future expansions
  605. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  606. For possible future expansions, I designed a structure for carrying the
  607. miscellaneous things that were added to MED/OctaMED now and then. (MED V3.00
  608. was the first version, which wrote this structure.) Most of its fields are in
  609. use now, but it's possible to even expand this structure (things will get a
  610. bit more tricky, though).
  611.  
  612. In multi-modules, you should extract all data from the expansion structure of
  613. the first song. The only exceptions are currently the 'nextmod' and
  614. 'songname' fields, which are song-specific.
  615.  
  616. Also, there has been need for extending the MMD0sample structure. Both
  617. InstrExt and MMDInstrInfo provide extra information about the instruments.
  618. These are defined as structure arrays (exp_smp and iinfo point to the first
  619. structure). The extension structures don't have a constant size, instead you
  620. have to read s_ext_entrsz or i_ext_entrsz to get the structure sizes. When
  621. reading, you have to check the entrsz fields to see which structure members
  622. do exist.
  623.  
  624. The difference between InstrExt and MMDInstrInfo is that InstrExt contains
  625. information the play-routine is interested in (e.g. finetune). MMDInstrInfo
  626. contains "secondary" information, which is of no use to the player routine
  627. (e.g. instrument name).
  628.  
  629. The expansion structure follows:
  630.  
  631. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  632.     struct MMD0exp {
  633.         struct MMD0 *nextmod;
  634.         struct InstrExt *exp_smp;
  635.         UWORD  s_ext_entries;
  636.         UWORD  s_ext_entrsz;
  637.         UBYTE  *annotxt;
  638.         ULONG  annolen;
  639.         struct MMDInstrInfo *iinfo;
  640.         UWORD  i_ext_entries;
  641.         UWORD  i_ext_entrsz;
  642.         ULONG  jumpmask;
  643.         UWORD  *rgbtable;
  644.         UBYTE  channelsplit[4];
  645.         struct NotationInfo *n_info;
  646.         UBYTE  *songname;
  647.         ULONG  songnamelen;
  648.         struct MMDDumpData *dumps;
  649.         struct MMDInfo *mmdinfo;
  650.         ULONG  reserved2[6];
  651.     };
  652.  
  653. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  654.     nextmod     = pointer to the next module (or zero). (Only used in
  655.                   multi-modules!)
  656.  
  657.     exp_smp     = pointer to InstrExt. Currently the first four bytes
  658.                   of InstrExt have been defined:
  659.  
  660.                     struct InstrExt {
  661.                         UBYTE hold;
  662.                         UBYTE decay;
  663.                         UBYTE suppress_midi_off;
  664.                         BYTE  finetune;
  665.                         /* Below fields saved by >= V5 */
  666.                         UBYTE default_pitch;
  667.                         UBYTE instr_flags;
  668.                         UWORD long_midi_preset;
  669.                         /* Below fields saved by >= V5.02 */
  670.                         UBYTE output_device;
  671.                         UBYTE reserved;
  672.                     };
  673.  
  674.                     hold, decay = hold/decay values of the
  675.                                   instrument
  676.  
  677.                     suppress_midi_off = 0 (FALSE) or not (TRUE)
  678.  
  679.                     finetune    = instrument finetune (-8-+7)
  680.  
  681.                     default_pitch = instrument's default pitch
  682.                                     (0 = ---, 1 = C-1, 2 = C#1...)
  683.  
  684.                     instr_flags = some miscellaneous flags:
  685.                                   SSFLG_LOOP     0x01 (Loop On/Off)
  686.                                   SSFLG_EXTPSET  0x02 (Ext. Preset)
  687.                                   SSFLG_DISABLED 0x04 (Disabled)
  688.  
  689.                     long_midi_preset = overrides the preset in the
  690.                                        song structure (allows ext.
  691.                                        presets)
  692.  
  693.                     output_device = instrument's output device,
  694.                                     currently the following exist:
  695.                                     OUTPUT_STD  0 (standard Amiga audio)
  696.                                     OUTPUT_MD16 1 (Aura)
  697.                                     OUTPUT_TOCC 2 (Toccata)
  698.  
  699.                     reserved = zero, at the moment
  700.  
  701.     s_ext_entries   = the size of InstrExt structure array (i.e. the
  702.                       number of InstrExt structures).
  703.  
  704.     s_ext_entrsz    = the size of each InstrExt structure (in bytes).
  705.  
  706.     annotxt     = pointer to the annotation text (null-terminated).
  707.  
  708.     annolen     = length of 'annotxt', including the terminating \0.
  709.  
  710.     iinfo       = pointer to MMDInstrInfo. Currently the first forty
  711.                   bytes have been defined:
  712.  
  713.                     struct MMDInstrInfo {
  714.                         UBYTE   name[40];
  715.                     };
  716.  
  717.                   name = null-terminated instrument name
  718.  
  719.     i_ext_entries   = the size of the MMDInstrInfo struct array (i.e. the
  720.                       number of MMDInstrInfo structures).
  721.  
  722.     i_ext_entrsz    = the size of each MMDInstrInfo struct in bytes.
  723.  
  724.     jumpmask    = a mask controlling which instruments cause the
  725.                   mouse pointer to jump. E.g. bit #1 = instr. #1.
  726.                   This field has become obsolete in OctaMED Pro.
  727.  
  728.     rgbtable    = pointer to eight UWORDs (screen colors) to be
  729.                   passed to LoadRGB4() routine.
  730.  
  731.     channelsplit    = this longword is divided to four boolean bytes,
  732.                       controlling channel splitting in OctaMED 5 - 8 chnl
  733.                       modes. (A non-zero byte means that the channel is
  734.                       NOT splitted.) Currently only the following
  735.                       combinations should be used:
  736.  
  737.                       0x00000000 (8 channels (or normal 4 channel mode))
  738.                       0x000000FF (7 channels)
  739.                       0x0000FFFF (6 channels)
  740.                       0x00FFFFFF (5 channels)
  741.  
  742.     n_info      = pointer to NotationInfo structure (used only in
  743.                   OctaMED V2.0 and later). It contains some info for
  744.                   the notation editor.
  745.                 
  746.                     struct NotationInfo {
  747.                         UBYTE n_of_sharps;
  748.                         UBYTE flags;
  749.                         WORD  trksel[5];
  750.                         UBYTE trkshow[16];
  751.                         UBYTE trkghost[16];
  752.                         BYTE  notetr[63];
  753.                         UBYTE pad;
  754.                     };
  755.  
  756.                   n_of_sharps   = number of sharps or flats (0 - 6)
  757.                   flags     = misc. bits, these are defined:
  758.                               NFLG_FLAT   1
  759.                            (= use flats instead of sharps)
  760.                               NFLG_3_4    2
  761.                            (= display 12 lines instead of 16)
  762.  
  763.                   trksel    = the number of the selected track,
  764.                               for each display preset
  765.                               (-1 = no track selected)
  766.  
  767.                   trkshow   = tracks shown (five bits used in
  768.                               each byte, bit #0 = preset 1, etc.)
  769.  
  770.                   trkghost  = tracks ghosted (as in 'trkshow')
  771.  
  772.                   notetr    = note transpose value for each
  773.                               instrument (-24 - +24). If bit 6 is
  774.                               negated, the instrument is hidden.
  775.  
  776.                   pad       = possibly holding info about struct
  777.                               expansions in the future. Don't touch!
  778.  
  779.     songname    = song name of the current song (0-terminated).
  780.                   Each song of a multi-module can have a different
  781.                   name.
  782.  
  783.     songnamelen = song name length (including the terminating zero).
  784.  
  785.     dumps       = MIDI dump data (created using OctaMED Pro MIDI
  786.                   message editor). The 'dumps' field points to the
  787.                   following struct:
  788.  
  789.                     struct MMDDumpData {
  790.                         UWORD   numdumps;
  791.                         UWORD   reserved[3];
  792.                     };
  793.  
  794.                   Immediately after this struct, there are 'numdumps'
  795.                   pointers to the following struct:
  796.  
  797.                     struct MMDDump {
  798.                         ULONG   length;
  799.                         UBYTE   *data;
  800.                         UWORD   ext_len;
  801.                         /* if ext_len >= 20: */
  802.                         UBYTE   name[20];
  803.                     };
  804.  
  805.                   length    = length of the MIDI message dump.
  806.  
  807.                   data      = pointer to the actual MIDI dump
  808.                               data.
  809.  
  810.                   ext_len   = MMDDump struct extension length.
  811.                               For flexible future expansion.
  812.  
  813.                   (if ext_len >= 20, the following fields exist)
  814.  
  815.                   name      = name of the dump.
  816.  
  817.     mmdinfo     = provides more information about the song that annotxt.
  818.                   Currently allows a text file to be attached. The
  819.                   structure MMDInfo is:
  820.  
  821.                   struct MMDInfo {
  822.                       struct MMDInfo *next;
  823.                       UWORD reserved;
  824.                       UWORD type;
  825.                       ULONG length;
  826.                   /* data follows... */
  827.                   };
  828.  
  829.                   next = pointer to the next MMDInfo structure. However,
  830.                          OctaMED 6 only supports one attachment, so this
  831.                          field is not used at the moment. May change in
  832.                          the future.
  833.  
  834.                   reserved = 0
  835.  
  836.                   type = data type. This is for maximum flexibility for
  837.                          future expansions. Currently only type 1 (ASCII
  838.                          text) is supported. Other types should be ignored.
  839.  
  840.                          ASCII is standard Amiga ISO ASCII. Lines terminated
  841.                          by a single '\n'. The text is null terminated. No
  842.                          tabs allowed (ListView gadgets can't display them).
  843.  
  844.                   length = data length in bytes.
  845.  
  846.     reserved2   = future expansion fields, that MUST be zero now.
  847.  
  848. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  849. Finally, here is a collection of the most important rules you should obey
  850. when handling MMD's:
  851.  
  852.     * Always use pointers, not absolute offsets.
  853.  
  854.     * Check that a pointer is nonzero before accessing anything it
  855.       points to.
  856.  
  857.     * When writing, set undefined/reserved bits and bytes to zero.
  858.       When reading, mask out undefined bits, and don't use undefined
  859.       fields.
  860.  
  861.     * When writing, always align everything to even boundaries.
  862.  
  863.     * When writing, always write the song structure.
  864.  
  865.     * Remember to handle error situations correctly (in all programs,
  866.       not only when handling MMDs ;^)
  867.  
  868. If you don't understand some part of this file completely, try saving a
  869. module and examine the file with a file editor. This way you can learn easily
  870. about the file format of MED/OctaMED.
  871.  
  872. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  873.