1 /*---------------------------------------------------------------------------*
2   Project:  MIDI Sequencer application for AX synthesizer
3   File:     seq.h
4 
5   Copyright (C) Nintendo.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13  *---------------------------------------------------------------------------*/
14 #ifndef __SEQ_H__
15 #define __SEQ_H__
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include <cafe/syn.h>
22 #define SEQMOVSetVolume   SEQDRCSetVolume
23 #define SEQMOVGetVolume   SEQDRCGetVolume
24 
25 #define SEQ_MAX_TRACKS 64
26 
27 /*---------------------------------------------------------------------------*
28     callback interface
29  *---------------------------------------------------------------------------*/
30 typedef void    (*SEQCALLBACK)(void *track, u8 controller);
31 
32 #ifdef  __MWERKS__
33 #pragma warn_padding off
34 #endif
35 
36 typedef struct _SEQTRACK
37 {
38     void        *sequence;              // pointer to parent
39     u8          *start;                 // pointer to start of track
40     u8          *end;                   // pointer to end of track
41     u8          *current;               // pointer to current read position
42     u8          status;                 // running status
43     f32         beatsPerSec;            // beats per sec
44     u32         defaultTicksPerFrame;   // ticks per audio frame
45     u32         ticksPerFrame;          // ticks per audio frame
46     u32         delay;                  // ticks to delay for next event
47     u32         state;                  // state of track
48 
49 } SEQTRACK;
50 
51 #ifdef  __MWERKS__
52 #pragma warn_padding reset
53 #endif
54 
55 typedef struct _SEQSEQUENCE
56 {
57     void        *next;                  // next sequence
58     u32         state;                  // stop, run, run looped, pause
59     u16         nTracks;                // number of sequencer tracks
60     s16         timeFormat;             // MIDI file time format
61     u32         tracksRunning;          // number of tracks still running
62     u32         end;                    // flag end of sequence
63     SYNSYNTH    synth;                  // synth used for this sequence
64     SEQCALLBACK callback[128];          // controller event callbacks
65     SEQTRACK    track[SEQ_MAX_TRACKS];  // sequencer tracks
66 
67 } SEQSEQUENCE;
68 
69 #define SEQ_STATE_STOP      0
70 #define SEQ_STATE_RUN       1
71 #define SEQ_STATE_RUNLOOPED 2
72 #define SEQ_STATE_PAUSE     3
73 
74 #define SEQ_ALL_TRACKS      0xFFFFFFFF
75 
76 /*---------------------------------------------------------------------------*
77     function prototypes
78  *---------------------------------------------------------------------------*/
79 void    SEQInit             (void);
80 void    SEQQuit             (void);
81 void    SEQRunAudioFrame    (void);
82 
83 void    SEQAddSequence(
84             SEQSEQUENCE     *sequence,          // user allocated SEQSEQUENCE
85             u8              *midiStream,        // pointer to MIDI stream
86             u8              *wavetable,         // pointer to wave table
87             u8              *samples,           // pointer to samples
88             u8              *zerobuffer,        // pointer to zero buffer
89             u32             priorityVoiceAlloc, // priority for allocating notes
90             u32             priorityNoteOn,     // priority for notes that are on
91             u32             priorityNoteRelease // priority for notes in release stage
92             );
93 
94 void    SEQRemoveSequence   (SEQSEQUENCE *sequence);
95 
96 void    SEQRegisterControllerCallback(
97             SEQSEQUENCE     *sequence,          // user initialized SEQSEQUENCE
98             u8              controller,         // MIDI controller
99             SEQCALLBACK     callback            // callback function
100             );
101 
102 void    SEQSetState         (SEQSEQUENCE *sequence, u32 state);
103 u32     SEQGetState         (SEQSEQUENCE *sequence);
104 void    SEQSetTempo         (SEQSEQUENCE *sequence, u32 track, f32 tempo);
105 f32     SEQGetTempo         (SEQSEQUENCE *sequence, u32 track);
106 void    SEQSetVolume        (SEQSEQUENCE *sequence, s32 dB);
107 s32     SEQGetVolume        (SEQSEQUENCE *sequence);
108 
109 // new SDK 1.5 + DRC API functions
110 void SEQDRCSetVolume(SEQSEQUENCE *sequence, s32 dB);
111 s32  SEQDRCGetVolume(SEQSEQUENCE *sequence);
112 void SEQSetMixerSelect(SEQSEQUENCE *sequence, u32 mixer);
113 u32  SEQGetMixerSelect(SEQSEQUENCE *sequence);
114 
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
120 #endif // __SEQ_H__
121