home *** CD-ROM | disk | FTP | other *** search
/ Audio 4.94 - Over 11,000 Files / audio-11000.iso / amiga / iff / source / newiff / smus.h < prev   
Encoding:
C/C++ Source or Header  |  1991-11-01  |  7.5 KB  |  185 lines

  1. #ifndef SMUS_H
  2. #define SMUS_H
  3. /*----------------------------------------------------------------------*
  4.  * SMUS.H  Definitions for Simple MUSical score.   2/12/86
  5.  *
  6.  * By Jerry Morrison and Steve Hayes, Electronic Arts.
  7.  * This software is in the public domain.
  8.  *
  9.  * This version for the Commodore-Amiga computer.
  10.  *----------------------------------------------------------------------*/
  11. #ifndef COMPILER_H
  12. #include "iff/compiler.h"
  13. #endif
  14.  
  15. #include "iff/iff.h"
  16.  
  17. #define ID_SMUS      MakeID('S', 'M', 'U', 'S')
  18. #define ID_SHDR      MakeID('S', 'H', 'D', 'R')
  19. #define ID_NAME      MakeID('N', 'A', 'M', 'E')
  20. #define ID_Copyright MakeID('(', 'c', ')', ' ')
  21. #define ID_AUTH      MakeID('A', 'U', 'T', 'H')
  22. #define ID_ANNO      MakeID('A', 'N', 'N', 'O')
  23.  
  24. #define ID_INS1      MakeID('I', 'N', 'S', '1')
  25. #define ID_TRAK      MakeID('T', 'R', 'A', 'K')
  26.  
  27. /* ---------- SScoreHeader ---------------------------------------------*/
  28. typedef struct {
  29.     UWORD tempo;    /* tempo, 128ths quarter note/minute */
  30.     UBYTE volume;    /* playback volume 0 through 127 */
  31.     UBYTE ctTrack;    /* count of tracks in the score */
  32.     } SScoreHeader;
  33.  
  34. /* ---------- NAME -----------------------------------------------------*/
  35. /* NAME chunk contains a CHAR[], the musical score's name. */
  36.  
  37. /* ---------- Copyright (c) --------------------------------------------*/
  38. /* "(c) " chunk contains a CHAR[], the FORM's copyright notice. */
  39.  
  40. /* ---------- AUTH -----------------------------------------------------*/
  41. /* AUTH chunk contains a CHAR[], the name of the score's author. */
  42.  
  43. /* ---------- ANNO -----------------------------------------------------*/
  44. /* ANNO chunk contains a CHAR[], the author's text annotations. */
  45.  
  46. /* ---------- INS1 -----------------------------------------------------*/
  47. /* Constants for the RefInstrument's "type" field. */
  48. #define INS1_Name  0    /* just use the name; ignore data1, data2 */
  49. #define INS1_MIDI  1    /* <data1, data2> = MIDI <channel, preset> */
  50.  
  51. typedef struct {
  52.     UBYTE iRegister;    /* set this instrument register number */
  53.     UBYTE type;        /* instrument reference type (see above) */
  54.     UBYTE data1, data2;    /* depends on the "type" field */
  55.     char name[60];    /* instrument name */
  56.     } RefInstrument;
  57.  
  58. /* ---------- TRAK -----------------------------------------------------*/
  59. /* TRAK chunk contains an SEvent[]. */
  60.  
  61. /* SEvent: Simple musical event. */
  62. typedef struct {
  63.     UBYTE sID;        /* SEvent type code */
  64.     UBYTE data;        /* sID-dependent data */
  65.     } SEvent;
  66.  
  67. /* SEvent type codes "sID". */
  68. #define SID_FirstNote     0
  69. #define SID_LastNote    127    /* sIDs in the range SID_FirstNote through
  70.                  * SID_LastNote (sign bit = 0) are notes. The
  71.                  * sID is the MIDI tone number (pitch). */
  72. #define SID_Rest        128    /* a rest; same data format as a note. */
  73.  
  74. #define SID_Instrument  129    /* set instrument number for this track. */
  75. #define SID_TimeSig     130    /* set time signature for this track. */
  76. #define SID_KeySig    131    /* set key signature for this track. */
  77. #define SID_Dynamic    132    /* set volume for this track. */
  78. #define SID_MIDI_Chnl    133    /* set MIDI channel number (sequencers) */
  79. #define SID_MIDI_Preset    134    /* set MIDI preset number (sequencers) */
  80. #define SID_Clef        135     /* inline clef change. 
  81.                                  * 0=Treble, 1=Bass, 2=Alto, 3=Tenor. */
  82. #define SID_Tempo       136     /* Inline tempo change in beats per minute.*/
  83.  
  84. /* SID values 144 through 159: reserved for Instant Music SEvents. */
  85.  
  86. /* The remaining sID values up through 254: reserved for future
  87.  * standardization. */
  88. #define SID_Mark        255    /* SID reserved for an end-mark in RAM. */
  89.  
  90. /* ---------- SEvent FirstNote..LastNote or Rest -----------------------*/
  91. typedef struct {
  92.     unsigned tone     :8,    /* MIDI tone number 0 to 127; 128 = rest */
  93.              chord    :1,    /* 1 = a chorded note */
  94.              tieOut   :1,    /* 1 = tied to the next note or chord */
  95.              nTuplet  :2,    /* 0 = none, 1 = triplet, 2 = quintuplet,
  96.                  * 3 = septuplet */
  97.              dot      :1,    /* dotted note; multiply duration by 3/2 */
  98.              division :3;    /* basic note duration is 2**-division:
  99.                  * 0 = whole note, 1 = half note, 2 = quarter
  100.                  * note, ... 7 = 128th note */
  101.     } SNote;
  102.  
  103. /* Warning: An SNote is supposed to be a 16-bit entity.
  104.  * Some C compilers will not pack bit fields into anything smaller
  105.  * than an int. So avoid the actual use of this type unless you are certain
  106.  * that the compiler packs it into a 16-bit word.
  107.  */
  108.  
  109. /* You may get better object code by masking, ORing, and shifting using the
  110.  * following definitions rather than the bit-packed fields, above. */
  111. #define noteChord  (1<<7)    /* note is chorded to next note */
  112.  
  113. #define noteTieOut (1<<6)    /* note/chord is tied to next note/chord */
  114.  
  115. #define noteNShift 4            /* shift count for nTuplet field */
  116. #define noteN3     (1<<noteNShift)    /* note is a triplet */
  117. #define noteN5     (2<<noteNShift)    /* note is a quintuplet */
  118. #define noteN7     (3<<noteNShift)    /* note is a septuplet */
  119. #define noteNMask  noteN7        /* bit mask for the nTuplet field */
  120.  
  121. #define noteDot    (1<<3)        /* note is dotted */
  122.  
  123. #define noteDShift 0            /* shift count for division field */
  124. #define noteD1     (0<<noteDShift)    /* whole note division */
  125. #define noteD2     (1<<noteDShift)    /* half note division */
  126. #define noteD4     (2<<noteDShift)    /* quarter note division */
  127. #define noteD8     (3<<noteDShift)     /* eighth note division */
  128. #define noteD16    (4<<noteDShift)     /* sixteenth note division */
  129. #define noteD32    (5<<noteDShift)     /* thirty-secondth note division */
  130. #define noteD64    (6<<noteDShift)     /* sixty-fourth note division */
  131. #define noteD128   (7<<noteDShift)     /* 1/128 note division */
  132. #define noteDMask  noteD128        /* bit mask for the division field */
  133.  
  134. #define noteDurMask 0x3F        /* bit mask for all duration fields
  135.                      * division, nTuplet, dot */
  136.  
  137. /* Field access: */
  138. #define IsChord(snote)    (((UWORD)snote) & noteChord)
  139. #define IsTied(snote)     (((UWORD)snote) & noteTieOut)
  140. #define NTuplet(snote)     ((((UWORD)snote) & noteNMask) >> noteNShift)
  141. #define IsDot(snote)     (((UWORD)snote) & noteDot)
  142. #define Division(snote) ((((UWORD)snote) & noteDMask) >> noteDShift)
  143.  
  144. /* ---------- TimeSig SEvent -------------------------------------------*/
  145. typedef struct {
  146.     unsigned type     :8,    /* = SID_TimeSig */
  147.              timeNSig :5,    /* time signature "numerator" timeNSig + 1 */
  148.              timeDSig :3;    /* time signature "denominator" is
  149.                  * 2**timeDSig: 0 = whole note, 1 = half
  150.                  * note, 2 = quarter note, ...
  151.                  * 7 = 128th note */
  152.     } STimeSig;
  153.  
  154. #define timeNMask  0xF8        /* bit mask for timeNSig field */
  155. #define timeNShift 3        /* shift count for timeNSig field */
  156.  
  157. #define timeDMask  0x07        /*  bit mask for timeDSig field */
  158.  
  159. /* Field access: */
  160. #define TimeNSig(sTime)  ((((UWORD)sTime) & timeNMask) >> timeNShift)
  161. #define TimeDSig(sTime)   (((UWORD)sTime) & timeDMask)
  162.  
  163. /* ---------- KeySig SEvent --------------------------------------------*/
  164. /* "data" value 0 = Cmaj; 1 through 7 = G,D,A,E,B,F#,C#;
  165.  * 8 through 14 = F,Bb,Eb,Ab,Db,Gb,Cb.                    */
  166.  
  167. /* ---------- Dynamic SEvent -------------------------------------------*/
  168. /* "data" value is a MIDI key velocity 0..127. */
  169.  
  170.  
  171. /* ---------- SMUS Reader Support Routines -----------------------------*/
  172.  
  173. /* Just call this to read a SHDR chunk. */
  174. #define GetSHDR(context, ssHdr)  \
  175.     IFFReadBytes(context, (BYTE *)ssHdr, sizeof(SScoreHeader))
  176.  
  177. /* ---------- SMUS Writer Support Routines -----------------------------*/
  178.  
  179. /* Just call this to write a SHDR chunk. */
  180. #define PutSHDR(context, ssHdr)  \
  181.     PutCk(context, ID_SHDR, sizeof(SScoreHeader), (BYTE *)ssHdr)
  182.  
  183. #endif
  184.  
  185.