Initial commit.
[amiga/xmodule.git] / include / libraries / songclass.h
1 #ifndef LIBRARIES_SONGCLASS_H
2 #define LIBRARIES_SONGCLASS_H
3 /*
4 **      $VER: songclass.h 3.9 (16.1.96)
5 **      Copyright (C) 1996 Bernardo Innocenti
6 **
7 **      Set TAB size to 4 chars to read this header file
8 **
9 **      Song class definition.
10 */
11
12 #ifndef EXEC_SEMAPHORES_H
13 #include <exec/semaphores.h>
14 #endif /* EXEC_SEMAPHORES_H */
15
16 #ifndef INTUITION_CLASSES_H
17 #include <intuition/classes.h>
18 #endif /* INTUITION_CLASSES_H */
19
20
21
22 /* The name of the songclass */
23 #define SONGCLASS "songclass"
24
25
26
27 /* Song methods */
28 #define SNGM_Dummy                              (TAG_USER + ('SG'<<8))
29 #define SNGM_ADDPATTERN                 (SNGM_Dummy + 1)
30 #define SNGM_SETPATTERN                 (SNGM_Dummy + 2)
31 #define SNGM_REMPATTERN                 (SNGM_Dummy + 3)
32 #define SNGM_ADDINSTRUMENT              (SNGM_Dummy + 4)
33 #define SNGM_SETINSTRUMENT              (SNGM_Dummy + 5)
34 #define SNGM_REMINSTRUMENT              (SNGM_Dummy + 6)
35 #define SNGM_SWAPINSTRUMENTS    (SNGM_Dummy + 7)
36
37
38 #define spAddPattern opSet              /* No GadgetInfo field required */
39
40 struct spSetPattern
41 {
42         ULONG                    MethodID;
43         ULONG                    spsp_PattNum;
44         struct TagItem  *spsp_AttrList;
45 };
46
47 struct spRemPattern
48 {
49         ULONG   MethodID;
50         ULONG   sprp_PattNum;
51         ULONG   sprp_NewPatt;
52 };
53
54 struct spSetInstrument
55 {
56         ULONG                    MethodID;
57         ULONG                    spsi_InstrNum;
58         struct TagItem  *spsi_AttrList;
59 };
60
61 #define spAddInstrument spSetInstrument
62
63 struct spRemInstrument
64 {
65         ULONG                    MethodID;
66         ULONG                    spri_Num;
67 };
68
69 struct spSwapInstruments
70 {
71         ULONG                    MethodID;
72         ULONG                    spsi_Num1;
73         ULONG                    spsi_Num2;
74 };
75
76
77
78 /* Song attributes */
79
80 #define SNGA_Dummy                      (TAG_USER + 'SG'<<8)    /* use  */
81
82 #define SNGA_CurrentPatt        (SNGA_Dummy + 1)                /* ISG  */
83 #define SNGA_CurrentPos         (SNGA_Dummy + 2)                /* ISG  */
84 #define SNGA_CurrentInst        (SNGA_Dummy + 3)                /* ISG  */
85 #define SNGA_CurrentLine        (SNGA_Dummy + 4)                /* ISG  */
86 #define SNGA_CurrentTrack       (SNGA_Dummy + 5)                /* ISG  */
87
88 #define SNGA_Length                     (SNGA_Dummy + 6)                /* ISG  */
89 #define SNGA_NumPatterns        (SNGA_Dummy + 7)                /* G    */
90 #define SNGA_NumInstruments     (SNGA_Dummy + 8)                /* G    */
91 #define SNGA_MaxTracks          (SNGA_Dummy + 9)                /* G    */
92
93 #define SNGA_Title                      (SNGA_Dummy + 10)               /* ISG  */
94 #define SNGA_Author                     (SNGA_Dummy + 11)               /* ISG  */
95 #define SNGA_Description        (SNGA_Dummy + 12)               /* ISG  */
96 /* (UBYTE *) Long description/comment for the
97  * song. The string may contain newlines and there is no
98  * length limit.
99  */
100
101 #define SNGA_Path                       (SNGA_Dummy + 13)               /* ISG  */
102 /* The complete path name of the file the song was
103  * loaded from.
104  */
105
106 #define SNGA_Changes            (SNGA_Dummy + 14)               /* ISG  */
107 /* (ULONG) Sets the number of changes made to the song
108  * since the last time it was saved.
109  */
110
111 #define SNGA_TotalChanges       (SNGA_Dummy + 15)               /* ISG  */
112 /* (ULONG) Total number of changes made to the song
113  * since it has been created.
114  */
115
116 #define SNGA_CreationDate       (SNGA_Dummy + 16)               /* ISG  */
117 #define SNGA_LastChanged        (SNGA_Dummy + 17)               /* ISG  */
118 /* (ULONG) Datestamp of last time the song was saved
119  */
120
121 #define SNGA_DefaultTracks      (SNGA_Dummy + 32)               /* ISG  */
122 #define SNGA_DefaultPattLen     (SNGA_Dummy + 33)               /* ISG  */
123 #define SNGA_GlobalSpeed        (SNGA_Dummy + 34)               /* ISG  */
124 #define SNGA_GlobalTempo        (SNGA_Dummy + 35)               /* ISG  */
125 #define SNGA_RestartPos         (SNGA_Dummy + 36)               /* ISG  */
126
127 #define SNGA_ReadyToUse         (SNGA_Dummy + 37)               /* I    */
128 /* (BOOL) Add one position and one pattern when
129  * creating a new song.
130  */
131
132 #define PATTA_Dummy                     (TAG_USER + 'PA'<<8)
133 #define PATTA_Lines                     (PATTA_Dummy + 1)               /* I    */
134 #define PATTA_Tracks            (PATTA_Dummy + 2)               /* I    */
135 #define PATTA_Name                      (PATTA_Dummy + 3)               /* IS   */
136 #define PATTA_Pattern           (PATTA_Dummy + 4)               /* I    */
137 #define PATTA_Num                       (PATTA_Dummy + 5)               /* I    */
138 #define PATTA_Replace           (PATTA_Dummy + 6)               /* I    */
139
140
141 #define INSTRA_Dummy            (TAG_USER + 'IN'<<8)
142 #define INSTRA_Type                     (INSTRA_Dummy + 1)              /* I    */
143 #define INSTRA_Name                     (INSTRA_Dummy + 2)              /* IS   */
144 #define INSTRA_Volume           (INSTRA_Dummy + 3)              /* IS   */
145 #define INSTRA_Sample           (INSTRA_Dummy + 4)              /* IS   */
146 #define INSTRA_Length           (INSTRA_Dummy + 5)              /* IS   */
147 #define INSTRA_Flags            (INSTRA_Dummy + 6)              /* IS   */
148 #define INSTRA_LoopStart        (INSTRA_Dummy + 7)              /* IS   */
149 #define INSTRA_LoopLen          (INSTRA_Dummy + 8)              /* IS   */
150 #define INSTRA_LoopEnd          (INSTRA_Dummy + 9)              /* IS   */
151 #define INSTRA_FineTune         (INSTRA_Dummy + 10)             /* IS   */
152
153
154 /* ProTracker-style aliases for loop tags */
155 #define INSTRA_Repeat   INSTRA_LoopStart
156 #define INSTRA_Replen   INSTRA_LoopLen
157 #define INSTRA_Repend   INSTRA_LoopEnd
158
159
160 /* Default values for some song attributes */
161 #define DEF_PATTLEN              64
162 #define DEF_NUMTRACKS     4
163 #define DEF_SONGSPEED     6
164 #define DEF_SONGTEMPO   125
165
166
167 /* Maximum values */
168 #define MAXOCTAVES                      6                       /* Number of octaves currently supported        */
169 #define MAXNOTES        (12*MAXOCTAVES+1)       /* Number of entries in notes table                     */
170 #define MAXTRACKS                       255                     /* Maximum number of tracks in a pattern        */
171 #define MAXINSTRUMENTS          255                     /* Maximum number of instruments in a song      */
172 #define MAXPATTERNS               32767                 /* Maximum number of patterns                           */
173 #define MAXPATTLINES      32767                 /* Maximum number of lines in a pattern         */
174 #define MAXPOSITIONS      32767                 /* Maximum number of song positions                     */
175
176 #define SEQUENCE_QUANTUM        32              /* Multiples of SEQUENCE_QUANTUM positions are
177                                                                          * allocated in the sequence array
178                                                                          */
179 #define PATTERNS_QUANTUM        16              /* Multiples of PATTERNS_QUANTUM pointers are
180                                                                          * allocated in the patterns array
181                                                                          */
182
183 struct Instrument
184 {
185         UWORD    Type;                          /* Instrument type (See defs)   */
186         UWORD    Volume;                        /* Volume (max $40)                             */
187         STRPTR   Name;                          /* Instrument Name                              */
188         ULONG    Length;                        /* Length of instr                              */
189         BYTE    *Sample;                        /* Sampled data                                 */
190         ULONG    Repeat;                        /* Loop start (No loop = 0)             */
191         ULONG    Replen;                        /* Loop size (No loop = 1)              */
192         WORD     FineTune;                      /* Instrument FineTune (-8..+7) */
193         UWORD    Flags;                         /* Unused                                               */
194 };
195
196
197 #ifndef LIBRARIES_XMODULECLASS_H
198
199 /* Possibile values for Instrument->InstType */
200 enum {
201         ITYPE_SAMPLE8,          /* 8 bit sampled waveform                               */
202         ITYPE_SAMPLE16,         /* TODO: 16 bit sampled waveform                */
203         ITYPE_SYNTH,            /* TODO: Synthetic instrument                   */
204         ITYPE_HYBRID,           /* TODO: Both Synth & Sample                    */
205         ITYPE_MIDI                      /* TODO: Played by external MIDI device */
206 };
207 #endif /* !LIBRARIES_XMODULECLASS_H */
208
209
210
211 /* Pass this value to AllocVec() to allocate sample memory */
212 #define MEMF_SAMPLE     MEMF_ANY
213
214
215 #ifndef LIBRARIES_XMODULECLASS_H
216 struct Note
217 {
218         UBYTE Note;                             /* See below for more info.     */
219         UBYTE Inst;                             /* Instrument number            */
220         UBYTE Vol;                              /* Volume for this note         */
221         UBYTE Pad;                              /* Unused                                       */
222         UBYTE EffNum;                   /* See definitions below.       */
223         UBYTE EffVal;                   /* Effect value ($00-$FF)       */
224 };
225 #endif /* !LIBRARIES_XMODULECLASS_H */
226
227
228
229 struct Pattern
230 {
231         UWORD   Tracks;                                 /* Support for variable number of tracks        */
232         UWORD   Lines;                                  /* Number of lines in pattern                           */
233         STRPTR  Name;                                   /* Name of this pattern                                         */
234         ULONG   Reserved[2];                    /* Reserved for future enhancements                     */
235         struct Note *Notes[0];                  /* Pointers to the lines                                        */
236
237         /* Note: dynamic size structure!        */
238 };
239
240
241
242 /*
243  * Effects
244  */
245 #ifndef LIBRARIES_XMODULECLASS_H
246 enum {
247         EFF_NULL,                               /* $00 */
248         EFF_PORTAMENTOUP,               /* $01 */
249         EFF_PORTAMENTODOWN,             /* $02 */
250         EFF_TONEPORTAMENTO,             /* $03 */
251         EFF_VIBRATO,                    /* $04 */
252         EFF_TONEPVOLSLIDE,              /* $05 */
253         EFF_VIBRATOVOLSLIDE,    /* $06 */
254         EFF_TREMOLO,                    /* $07 */
255         EFF_UNUSED,                             /* $08 */
256         EFF_SAMPLEOFFSET,               /* $09 */
257         EFF_VOLSLIDE,                   /* $0A */
258         EFF_POSJUMP,                    /* $0B */
259         EFF_SETVOLUME,                  /* $0C */
260         EFF_PATTERNBREAK,               /* $0D */
261         EFF_MISC,                               /* $0E */
262         EFF_SETSPEED,                   /* $0F */
263         EFF_SETTEMPO,                   /* $10 */
264         EFF_ARPEGGIO,                   /* $11 */
265
266         EFF_COUNT                               /* $12 */
267 };
268 #endif /* !LIBRARIES_XMODULECLASS_H */
269
270
271
272 /* Song class white box istance
273  *
274  * You can read from this structure directly for speed critical operations.
275  * Modifying the data contained in the SongInfo structure is only allowed
276  * by means of object methods.
277  *
278  * Before using a public song, please protect yourself against other tasks
279  * modifying these fields. Always obtainin a (shared) lock on the
280  * SignalSemaphore contained in the SongInfo structure before doing anything
281  * with it. The methods provided by the song class will not handle access
282  * arbitration for you.
283  */
284 struct SongInfo
285 {
286         struct Node Link;                               /* Link for the song list                                       */
287         struct SignalSemaphore Lock;    /* Prevent other tasks from disturbing you!     */
288         UWORD           Length;                         /* Number of positions in song                          */
289         UWORD           MaxTracks;                      /* Maximum number of tracks in song                     */
290         UWORD           NumPatterns;            /* Number of patterns in song                           */
291         UWORD           LastInstrument;         /* Unused                                                                       */
292         UWORD           CurrentPatt;
293         UWORD           CurrentPos;
294         UWORD           CurrentInst;
295         UWORD           CurrentLine;
296         UWORD           CurrentTrack;
297         UWORD           DefNumTracks;           /* Default number of tracks in new patterns     */
298         UWORD           DefPattLen;                     /* Default number of lines in new patterns      */
299         UWORD           GlobalSpeed;            /* Default song speed                                           */
300         UWORD           GlobalTempo;            /* Default song tempo                                           */
301         UWORD           RestartPos;                     /* Position to restart from                                     */
302         UWORD           Reserved[4];            /* Reserved for future enhancements                     */
303
304         /* Note: all data beyond this point is longword aligned */
305
306         ULONG           Flags;                          /* See definitions below                                        */
307         void            *Pool;                          /* Memory pool from which all song data
308                                                                          * must be allocated from.
309                                                                          */
310         UWORD                           *Sequence;      /* Pointer to song sequence                                     */
311         struct Pattern          **Patt;         /* Pointer to patterns array                            */
312         struct Instrument       **Instr;        /* Pointer to instruments array                         */
313         UWORD           *ActiveTracks;          /* (-1 = disabled) *yet unused*                         */
314         STRPTR          Title;                          /* Song name                                                            */
315         STRPTR          Author;                         /* Name of the author                                           */
316         STRPTR          Path;                           /* Original song path                                           */
317         STRPTR          Description;            /* Verbose song description                                     */
318
319         ULONG           Changes;                        /* Changes made since song was last saved       */
320         ULONG           TotalChanges;           /* Total number of changes made so far          */
321         ULONG           CreationDate;           /* Date of OM_NEW                                                       */
322         ULONG           LastChanged;            /* Date of last saving                                          */
323
324
325         /* PRIVATE DATA --- HANDS OFF!
326          *
327          * All fields beyond this point are subject to change and
328          * *will* change in future releases of XModule. Do not
329          * even think of using them for whatever reason. Right? :-)
330          */
331         struct Instrument *InstrumentsTable[MAXINSTRUMENTS + 1];
332 };
333
334
335
336 /* Flags for SongInfo->Flags */
337 /* No flags are defined yet */
338
339
340
341 #endif /* !LIBRARIES_SONGCLASS_H */