diff options
Diffstat (limited to 'apps/plugins/midi/midiutil.c')
-rw-r--r-- | apps/plugins/midi/midiutil.c | 222 |
1 files changed, 105 insertions, 117 deletions
diff --git a/apps/plugins/midi/midiutil.c b/apps/plugins/midi/midiutil.c index bf25d1d277..d0b968e52c 100644 --- a/apps/plugins/midi/midiutil.c +++ b/apps/plugins/midi/midiutil.c | |||
@@ -20,39 +20,39 @@ | |||
20 | #define BYTE unsigned char | 20 | #define BYTE unsigned char |
21 | 21 | ||
22 | //Data chunk ID types, returned by readID() | 22 | //Data chunk ID types, returned by readID() |
23 | #define ID_UNKNOWN -1 | 23 | #define ID_UNKNOWN -1 |
24 | #define ID_MTHD 1 | 24 | #define ID_MTHD 1 |
25 | #define ID_MTRK 2 | 25 | #define ID_MTRK 2 |
26 | #define ID_EOF 3 | 26 | #define ID_EOF 3 |
27 | 27 | ||
28 | //MIDI Commands | 28 | //MIDI Commands |
29 | #define MIDI_NOTE_OFF 128 | 29 | #define MIDI_NOTE_OFF 128 |
30 | #define MIDI_NOTE_ON 144 | 30 | #define MIDI_NOTE_ON 144 |
31 | #define MIDI_AFTERTOUCH 160 | 31 | #define MIDI_AFTERTOUCH 160 |
32 | #define MIDI_CONTROL 176 | 32 | #define MIDI_CONTROL 176 |
33 | #define MIDI_PRGM 192 | 33 | #define MIDI_PRGM 192 |
34 | #define MIDI_PITCHW 224 | 34 | #define MIDI_PITCHW 224 |
35 | 35 | ||
36 | 36 | ||
37 | //MIDI Controllers | 37 | //MIDI Controllers |
38 | #define CTRL_VOLUME 7 | 38 | #define CTRL_VOLUME 7 |
39 | #define CTRL_BALANCE 8 | 39 | #define CTRL_BALANCE 8 |
40 | #define CTRL_PANNING 10 | 40 | #define CTRL_PANNING 10 |
41 | #define CHANNEL 1 | 41 | #define CHANNEL 1 |
42 | 42 | ||
43 | //Most of these are deprecated.. rampdown is used, maybe one other one too | 43 | //Most of these are deprecated.. rampdown is used, maybe one other one too |
44 | #define STATE_ATTACK 1 | 44 | #define STATE_ATTACK 1 |
45 | #define STATE_DECAY 2 | 45 | #define STATE_DECAY 2 |
46 | #define STATE_SUSTAIN 3 | 46 | #define STATE_SUSTAIN 3 |
47 | #define STATE_RELEASE 4 | 47 | #define STATE_RELEASE 4 |
48 | #define STATE_RAMPDOWN 5 | 48 | #define STATE_RAMPDOWN 5 |
49 | 49 | ||
50 | //Loop states | 50 | //Loop states |
51 | #define STATE_LOOPING 7 | 51 | #define STATE_LOOPING 7 |
52 | #define STATE_NONLOOPING 8 | 52 | #define STATE_NONLOOPING 8 |
53 | 53 | ||
54 | //Various bits in the GUS mode byte | 54 | //Various bits in the GUS mode byte |
55 | #define LOOP_ENABLED 4 | 55 | #define LOOP_ENABLED 4 |
56 | #define LOOP_PINGPONG 8 | 56 | #define LOOP_PINGPONG 8 |
57 | #define LOOP_REVERSE 16 | 57 | #define LOOP_REVERSE 16 |
58 | 58 | ||
@@ -63,81 +63,69 @@ | |||
63 | extern struct plugin_api * rb; | 63 | extern struct plugin_api * rb; |
64 | 64 | ||
65 | 65 | ||
66 | int chVol[16] IDATA_ATTR; //Channel volume | 66 | int chVol[16] IDATA_ATTR; /* Channel volume */ |
67 | int chPanLeft[16] IDATA_ATTR; //Channel panning | 67 | int chPanLeft[16] IDATA_ATTR; /* Channel panning */ |
68 | int chPanRight[16] IDATA_ATTR; | 68 | int chPanRight[16] IDATA_ATTR; |
69 | int chPat[16]; //Channel patch | 69 | int chPat[16]; /* Channel patch */ |
70 | int chPW[16]; //Channel pitch wheel, MSB only | 70 | int chPW[16]; /* Channel pitch wheel, MSB only */ |
71 | 71 | ||
72 | 72 | ||
73 | /* | ||
74 | unsigned char chVol[16]; //Channel volume | ||
75 | unsigned char chPanLeft[16]; //Channel panning | ||
76 | unsigned char chPanRight[16]; | ||
77 | unsigned char chPat[16]; //Channel patch | ||
78 | unsigned char chPW[16]; //Channel pitch wheel, MSB only | ||
79 | */ | ||
80 | struct GPatch * gusload(char *); | 73 | struct GPatch * gusload(char *); |
81 | struct GPatch * patchSet[128]; | 74 | struct GPatch * patchSet[128]; |
82 | struct GPatch * drumSet[128]; | 75 | struct GPatch * drumSet[128]; |
83 | 76 | ||
84 | |||
85 | //char myarray[80] IDATA_ATTR; | ||
86 | |||
87 | struct Event | 77 | struct Event |
88 | { | 78 | { |
89 | unsigned int delta; | 79 | unsigned int delta; |
90 | unsigned char status, d1, d2; | 80 | unsigned char status, d1, d2; |
91 | unsigned int len; | 81 | unsigned int len; |
92 | unsigned char * evData; | 82 | unsigned char * evData; |
93 | }; | 83 | }; |
94 | 84 | ||
95 | struct Track | 85 | struct Track |
96 | { | 86 | { |
97 | unsigned int size; | 87 | unsigned int size; |
98 | unsigned int numEvents; | 88 | unsigned int numEvents; |
99 | unsigned int delta; //For sequencing | 89 | unsigned int delta; /* For sequencing */ |
100 | unsigned int pos; //For sequencing | 90 | unsigned int pos; /* For sequencing */ |
101 | void * dataBlock; | 91 | void * dataBlock; |
102 | }; | 92 | }; |
103 | 93 | ||
104 | 94 | ||
105 | struct MIDIfile | 95 | struct MIDIfile |
106 | { | 96 | { |
107 | int Length; | 97 | int Length; |
108 | 98 | unsigned short numTracks; | |
109 | //int Format; //We don't really care what type it is | 99 | unsigned short div; /* Time division, X ticks per millisecond */ |
110 | unsigned short numTracks; | 100 | struct Track * tracks[48]; |
111 | unsigned short div; //Time division, X ticks per millisecond | 101 | unsigned char patches[128]; |
112 | struct Track * tracks[48]; | 102 | int numPatches; |
113 | unsigned char patches[128]; | ||
114 | int numPatches; | ||
115 | }; | 103 | }; |
104 | |||
116 | /* | 105 | /* |
117 | struct SynthObject | 106 | struct SynthObject |
118 | { | 107 | { |
119 | // int tmp; | 108 | struct GWaveform * wf; |
120 | struct GWaveform * wf; | 109 | unsigned int delta; |
121 | unsigned int delta; | 110 | unsigned int decay; |
122 | unsigned int decay; | 111 | unsigned int cp; |
123 | unsigned int cp; | 112 | unsigned char state, loopState, loopDir; |
124 | unsigned char state, loopState, loopDir; | 113 | unsigned char note, vol, ch, isUsed; |
125 | unsigned char note, vol, ch, isUsed; | 114 | int curRate, curOffset, targetOffset; |
126 | int curRate, curOffset, targetOffset; | 115 | unsigned int curPoint; |
127 | unsigned int curPoint; | ||
128 | }; | 116 | }; |
129 | */ | 117 | */ |
118 | |||
130 | struct SynthObject | 119 | struct SynthObject |
131 | { | 120 | { |
132 | // int tmp; | 121 | struct GWaveform * wf; |
133 | struct GWaveform * wf; | 122 | int delta; |
134 | int delta; | 123 | int decay; |
135 | int decay; | 124 | unsigned int cp; |
136 | int cp; | 125 | int state, loopState, loopDir; |
137 | int state, loopState, loopDir; | 126 | int note, vol, ch, isUsed; |
138 | int note, vol, ch, isUsed; | 127 | int curRate, curOffset, targetOffset; |
139 | int curRate, curOffset, targetOffset; | 128 | int curPoint; |
140 | int curPoint; | ||
141 | }; | 129 | }; |
142 | 130 | ||
143 | struct SynthObject voices[MAX_VOICES] IDATA_ATTR; | 131 | struct SynthObject voices[MAX_VOICES] IDATA_ATTR; |
@@ -156,91 +144,91 @@ int midimain(void * filename); | |||
156 | 144 | ||
157 | void *alloc(int size) | 145 | void *alloc(int size) |
158 | { | 146 | { |
159 | static char *offset = NULL; | 147 | static char *offset = NULL; |
160 | static int totalSize = 0; | 148 | static int totalSize = 0; |
161 | char *ret; | 149 | char *ret; |
162 | 150 | ||
163 | int remainder = size % 4; | 151 | int remainder = size % 4; |
164 | 152 | ||
165 | size = size + 4-remainder; | 153 | size = size + 4-remainder; |
166 | 154 | ||
167 | if (offset == NULL) | 155 | if (offset == NULL) |
168 | { | 156 | { |
169 | offset = rb->plugin_get_audio_buffer(&totalSize); | 157 | offset = rb->plugin_get_audio_buffer(&totalSize); |
170 | } | 158 | } |
171 | 159 | ||
172 | if (size + 4 > totalSize) | 160 | if (size + 4 > totalSize) |
173 | { | 161 | { |
174 | return NULL; | 162 | return NULL; |
175 | } | 163 | } |
176 | 164 | ||
177 | ret = offset + 4; | 165 | ret = offset + 4; |
178 | *((unsigned int *)offset) = size; | 166 | *((unsigned int *)offset) = size; |
179 | 167 | ||
180 | offset += size + 4; | 168 | offset += size + 4; |
181 | totalSize -= size + 4; | 169 | totalSize -= size + 4; |
182 | return ret; | 170 | return ret; |
183 | } | 171 | } |
184 | 172 | ||
185 | 173 | ||
186 | //Rick's code | 174 | /* Rick's code */ |
187 | /* | 175 | /* |
188 | void *alloc(int size) | 176 | void *alloc(int size) |
189 | { | 177 | { |
190 | static char *offset = NULL; | 178 | static char *offset = NULL; |
191 | static int totalSize = 0; | 179 | static int totalSize = 0; |
192 | char *ret; | 180 | char *ret; |
193 | 181 | ||
194 | 182 | ||
195 | if (offset == NULL) | 183 | if (offset == NULL) |
196 | { | 184 | { |
197 | offset = rb->plugin_get_audio_buffer(&totalSize); | 185 | offset = rb->plugin_get_audio_buffer(&totalSize); |
198 | } | 186 | } |
199 | 187 | ||
200 | if (size + 4 > totalSize) | 188 | if (size + 4 > totalSize) |
201 | { | 189 | { |
202 | return NULL; | 190 | return NULL; |
203 | } | 191 | } |
204 | 192 | ||
205 | ret = offset + 4; | 193 | ret = offset + 4; |
206 | *((unsigned int *)offset) = size; | 194 | *((unsigned int *)offset) = size; |
207 | 195 | ||
208 | offset += size + 4; | 196 | offset += size + 4; |
209 | totalSize -= size + 4; | 197 | totalSize -= size + 4; |
210 | return ret; | 198 | return ret; |
211 | }*/ | 199 | }*/ |
212 | void * allocate(int size) | 200 | void * allocate(int size) |
213 | { | 201 | { |
214 | return alloc(size); | 202 | return alloc(size); |
215 | } | 203 | } |
216 | 204 | ||
217 | unsigned char readChar(int file) | 205 | unsigned char readChar(int file) |
218 | { | 206 | { |
219 | char buf[2]; | 207 | char buf[2]; |
220 | rb->read(file, &buf, 1); | 208 | rb->read(file, &buf, 1); |
221 | return buf[0]; | 209 | return buf[0]; |
222 | } | 210 | } |
223 | 211 | ||
224 | unsigned char * readData(int file, int len) | 212 | unsigned char * readData(int file, int len) |
225 | { | 213 | { |
226 | unsigned char * dat = allocate(len); | 214 | unsigned char * dat = allocate(len); |
227 | rb->read(file, dat, len); | 215 | rb->read(file, dat, len); |
228 | return dat; | 216 | return dat; |
229 | } | 217 | } |
230 | 218 | ||
231 | int eof(int fd) | 219 | int eof(int fd) |
232 | { | 220 | { |
233 | int curPos = rb->lseek(fd, 0, SEEK_CUR); | 221 | int curPos = rb->lseek(fd, 0, SEEK_CUR); |
234 | 222 | ||
235 | int size = rb->lseek(fd, 0, SEEK_END); | 223 | int size = rb->lseek(fd, 0, SEEK_END); |
236 | 224 | ||
237 | rb->lseek(fd, curPos, SEEK_SET); | 225 | rb->lseek(fd, curPos, SEEK_SET); |
238 | return size+1 == rb->lseek(fd, 0, SEEK_CUR); | 226 | return size+1 == rb->lseek(fd, 0, SEEK_CUR); |
239 | } | 227 | } |
240 | 228 | ||
241 | void printf(char *fmt, ...) {fmt=fmt; } | 229 | void printf(char *fmt, ...) {fmt=fmt; } |
242 | 230 | ||
243 | void exit(int code) | 231 | void exit(int code) |
244 | { | 232 | { |
245 | code = code; //Stub function, kill warning for now | 233 | code = code; /* Stub function, kill warning for now */ |
246 | } | 234 | } |