summaryrefslogtreecommitdiff
path: root/apps/plugins/midi/midiutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/midi/midiutil.c')
-rw-r--r--apps/plugins/midi/midiutil.c222
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 @@
63extern struct plugin_api * rb; 63extern struct plugin_api * rb;
64 64
65 65
66int chVol[16] IDATA_ATTR; //Channel volume 66int chVol[16] IDATA_ATTR; /* Channel volume */
67int chPanLeft[16] IDATA_ATTR; //Channel panning 67int chPanLeft[16] IDATA_ATTR; /* Channel panning */
68int chPanRight[16] IDATA_ATTR; 68int chPanRight[16] IDATA_ATTR;
69int chPat[16]; //Channel patch 69int chPat[16]; /* Channel patch */
70int chPW[16]; //Channel pitch wheel, MSB only 70int chPW[16]; /* Channel pitch wheel, MSB only */
71 71
72 72
73/*
74unsigned char chVol[16]; //Channel volume
75unsigned char chPanLeft[16]; //Channel panning
76unsigned char chPanRight[16];
77unsigned char chPat[16]; //Channel patch
78unsigned char chPW[16]; //Channel pitch wheel, MSB only
79*/
80struct GPatch * gusload(char *); 73struct GPatch * gusload(char *);
81struct GPatch * patchSet[128]; 74struct GPatch * patchSet[128];
82struct GPatch * drumSet[128]; 75struct GPatch * drumSet[128];
83 76
84
85//char myarray[80] IDATA_ATTR;
86
87struct Event 77struct 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
95struct Track 85struct 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
105struct MIDIfile 95struct 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/*
117struct SynthObject 106struct 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
130struct SynthObject 119struct 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
143struct SynthObject voices[MAX_VOICES] IDATA_ATTR; 131struct SynthObject voices[MAX_VOICES] IDATA_ATTR;
@@ -156,91 +144,91 @@ int midimain(void * filename);
156 144
157void *alloc(int size) 145void *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/*
188void *alloc(int size) 176void *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}*/
212void * allocate(int size) 200void * allocate(int size)
213{ 201{
214 return alloc(size); 202 return alloc(size);
215} 203}
216 204
217unsigned char readChar(int file) 205unsigned 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
224unsigned char * readData(int file, int len) 212unsigned 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
231int eof(int fd) 219int 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
241void printf(char *fmt, ...) {fmt=fmt; } 229void printf(char *fmt, ...) {fmt=fmt; }
242 230
243void exit(int code) 231void 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}