home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / Devices / iffp / smus.h < prev   
Encoding:
C/C++ Source or Header  |  1992-08-21  |  7.4 KB  |  188 lines

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