Added option to disable track init events.
[epichord.git] / src / midi.cpp
blobabcd95ff8507e6417ffa2516b48066671d15de1c
1 /*
2 Epichord - a midi sequencer
3 Copyright (C) 2008 Evan Rinehart
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to
18 The Free Software Foundation, Inc.
19 51 Franklin Street, Fifth Floor
20 Boston, MA 02110-1301, USA
24 #include <stdlib.h>
25 #include "seq.h"
29 char controller_names[128][64] = {
30 "Bank Select",
31 "Modulation Wheel",
32 "Breath Contoller",
33 "Undefined",
34 "Foot Controller",
35 "Portamento Time",
36 "Data Entry MSB",
37 "Main Volume",
38 "Balance",
39 "Undefined",
40 "Pan",
41 "Expresion Controller",
42 "Effect Control 1",
43 "Effect Control 2",
44 "Undefined",
45 "Undefined",
46 "General Purpose Controller 1",
47 "General Purpose Controller 2",
48 "General Purpose Controller 3",
49 "General Purpose Controller 4",
50 "Undefined",
51 "Undefined",
52 "Undefined",
53 "Undefined",
54 "Undefined",
55 "Undefined",
56 "Undefined",
57 "Undefined",
58 "Undefined",
59 "Undefined",
60 "Undefined",
61 "Undefined",
62 "Bank Select LSB",
63 "Modulation Wheel LSB",
64 "Breath Contoller LSB",
65 "Undefined Controller 3 LSB",
66 "Foot Controller LSB",
67 "Portamento Time LSB",
68 "Data Entry LSB",
69 "Main Volume LSB",
70 "Balance LSB",
71 "Undefined Controller 9 LSB",
72 "Pan LSB",
73 "Expresion Controller LSB",
74 "Effect Control 1 LSB",
75 "Effect Control 2 LSB",
76 "Undefined Controller 14 LSB",
77 "Undefined Controller 15 LSB",
78 "General Purpose Controller 1 LSB",
79 "General Purpose Controller 2 LSB",
80 "General Purpose Controller 3 LSB",
81 "General Purpose Controller 4 LSB",
82 "Undefined Controller 20 LSB",
83 "Undefined Controller 21 LSB",
84 "Undefined Controller 22 LSB",
85 "Undefined Controller 23 LSB",
86 "Undefined Controller 24 LSB",
87 "Undefined Controller 25 LSB",
88 "Undefined Controller 26 LSB",
89 "Undefined Controller 27 LSB",
90 "Undefined Controller 28 LSB",
91 "Undefined Controller 29 LSB",
92 "Undefined Controller 30 LSB",
93 "Undefined Controller 31 LSB",
94 "Damper Pedal (Sustain)",
95 "Portamento",
96 "Sostenuto",
97 "Soft Pedal",
98 "Legato Footswitch",
99 "Hold 2",
100 "Sound Controller 1 (default: Sound Variation)",
101 "Sound Controller 2 (default: Timbre/Harmonic Content)",
102 "Sound Controller 3 (default: Release Time)",
103 "Sound Controller 4 (default: Attack Time)",
104 "Sound Controller 5 (default: Brightness)",
105 "Sound Controller 6",
106 "Sound Controller 7",
107 "Sound Controller 8",
108 "Sound Controller 9",
109 "Sound Controller 10",
110 "General Purpose Controller 5",
111 "General Purpose Controller 6",
112 "General Purpose Controller 7",
113 "General Purpose Controller 8",
114 "Portamento Control",
115 "Undefined",
116 "Undefined",
117 "Undefined",
118 "Undefined",
119 "Undefined",
120 "Undefined",
121 "Effects 1 Depth",
122 "Effects 2 Depth (previously Tremolo Depth)",
123 "Effects 3 Depth (previously Chorus Depth)",
124 "Effects 4 Depth (previously Detune Depth)",
125 "Effects 5 Depth (previously Phaser Depth)",
126 "Data Increment",
127 "Data Decrement",
128 "Non-Registered Parameter Number LSB",
129 "Non-Registered Parameter Number LSB",
130 "Registered Parameter Number LSB",
131 "Registered Parameter Number MSB",
132 "Undefined",
133 "Undefined",
134 "Undefined",
135 "Undefined",
136 "Undefined",
137 "Undefined",
138 "Undefined",
139 "Undefined",
140 "Undefined",
141 "Undefined",
142 "Undefined",
143 "Undefined",
144 "Undefined",
145 "Undefined",
146 "Undefined",
147 "Undefined",
148 "Undefined",
149 "Undefined",
150 "All Sound Off",
151 "Reset All Controllers",
152 "Local Control",
153 "All Notes Off",
154 "Omni Off",
155 "Omni On",
156 "Mono On",
157 "Poly On"
160 char controller_names_short[128][64] = {
161 "bank",
162 "modwheel",
163 "breath",
164 "undef",
165 "foot",
166 "porta_t",
167 "data",
168 "vol",
169 "bal",
170 "undef",
171 "pan",
172 "express",
173 "effect1",
174 "effect2",
175 "undef",
176 "undef",
177 "general1",
178 "general2",
179 "general3",
180 "general4",
181 "undef",
182 "undef",
183 "undef",
184 "undef",
185 "undef",
186 "undef",
187 "undef",
188 "undef",
189 "undef",
190 "undef",
191 "undef",
192 "undef",
193 "L_bank",
194 "L_modwheel",
195 "L_breath",
196 "L_undef",
197 "L_foot",
198 "L_porta_t",
199 "L_data",
200 "L_vol",
201 "L_bal",
202 "L_undef",
203 "L_pan",
204 "L_express",
205 "L_effect1",
206 "L_effect2",
207 "L_undef",
208 "L_undef",
209 "L_general1",
210 "L_general2",
211 "L_general3",
212 "L_general4",
213 "L_undef",
214 "L_undef",
215 "L_undef",
216 "L_undef",
217 "L_undef",
218 "L_undef",
219 "L_undef",
220 "L_undef",
221 "L_undef",
222 "L_undef",
223 "L_undef",
224 "L_undef",
225 "sustain",
226 "porta",
227 "sostenuto",
228 "soft",
229 "legato",
230 "hold2",
231 "sound",
232 "timbre",
233 "release",
234 "attack",
235 "brightness",
236 "sound6",
237 "sound7",
238 "sound8",
239 "sound9",
240 "sound10",
241 "general5",
242 "general6",
243 "general7",
244 "general8",
245 "porta_c",
246 "undef",
247 "undef",
248 "undef",
249 "undef",
250 "undef",
251 "undef",
252 "depth",
253 "tremolo",
254 "chorus",
255 "detune",
256 "phaser",
257 "data+",
258 "data-",
259 "L_NRPN",
260 "M_NRPN",
261 "L_RPN",
262 "M_RPN",
263 "undef",
264 "undef",
265 "undef",
266 "undef",
267 "undef",
268 "undef",
269 "undef",
270 "undef",
271 "undef",
272 "undef",
273 "undef",
274 "undef",
275 "undef",
276 "undef",
277 "undef",
278 "undef",
279 "undef",
280 "undef",
281 "sound_off",
282 "ctrl_reset",
283 "ctrl_local",
284 "notes_off",
285 "omni_off",
286 "omni_on",
287 "poly_off",
288 "poly_on"
291 char gm_names[128][64] = {
292 "Acoustic Grand Piano",
293 "Bright Acoustic Piano",
294 "Electric Grand Piano",
295 "Honky-tonk Piano",
296 "Rhodes Piano",
297 "Chorused Piano",
298 "Harpsichord",
299 "Clavinet",
300 "Celesta",
301 "Glockenspiel",
302 "Music Box",
303 "Vibraphone",
304 "Marimba",
305 "Xylophone",
306 "Tubular Bells",
307 "Dulcimer",
308 "Hammond Organ",
309 "Percussive Organ",
310 "Rock Organ",
311 "Church Organ",
312 "Reed Organ",
313 "Accordion",
314 "Harmonica",
315 "Tango Accordion",
316 "Acoustic Guitar (nylon)",
317 "Acoustic Guitar (steel)",
318 "Electric Guitar (jazz)",
319 "Electric Guitar (clean)",
320 "Electric Guitar (muted)",
321 "Overdriven Guitar",
322 "Distortion Guitar",
323 "Guitar Harmonics",
324 "Acoustic Bass",
325 "Electric Bass (finger)",
326 "Electric Bass (pick)",
327 "Fretless Bass",
328 "Slap Bass 1",
329 "Slap Bass 2",
330 "Synth Bass 1",
331 "Synth Bass 2",
332 "Violin",
333 "Viola",
334 "Cello",
335 "Contrabass",
336 "Tremolo Strings",
337 "Pizzicato Strings",
338 "Orchestral Harp",
339 "Timpani",
340 "String Ensemble 1",
341 "String Ensemble 2",
342 "SynthStrings 1",
343 "SynthStrings 2",
344 "Choir Aahs",
345 "Voice Oohs",
346 "Synth Voice",
347 "Orchestra Hit",
348 "Trumpet",
349 "Trombone",
350 "Tuba",
351 "Muted Trumpet",
352 "French Horn",
353 "Brass Section",
354 "Synth Brass 1",
355 "Synth Brass 2",
356 "Soprano Sax",
357 "Alto Sax",
358 "Tenor Sax",
359 "Baritone Sax",
360 "Oboe",
361 "English Horn",
362 "Bassoon",
363 "Clarinet",
364 "Piccolo",
365 "Flute",
366 "Recorder",
367 "Pan Flute",
368 "Bottle Blow",
369 "Shakuhachi",
370 "Whistle",
371 "Ocarina",
372 "Lead 1 (square)",
373 "Lead 2 (sawtooth)",
374 "Lead 3 (calliope lead)",
375 "Lead 4 (chiff lead)",
376 "Lead 5 (charang)",
377 "Lead 6 (voice)",
378 "Lead 7 (fifths)",
379 "Lead 8 (bass + lead)",
380 "Pad 1 (new age)",
381 "Pad 2 (warm)",
382 "Pad 3 (polysynth)",
383 "Pad 4 (choir)",
384 "Pad 5 (bowed)",
385 "Pad 6 (metallic)",
386 "Pad 7 (halo)",
387 "Pad 8 (sweep)",
388 "FX 1 (rain)",
389 "FX 2 (soundtrack)",
390 "FX 3 (crystal)",
391 "FX 4 (atmosphere)",
392 "FX 5 (brightness)",
393 "FX 6 (goblins)",
394 "FX 7 (echoes)",
395 "FX 8 (sci-fi)",
396 "Sitar",
397 "Banjo",
398 "Shamisen",
399 "Koto",
400 "Kalimba",
401 "Bagpipe",
402 "Fiddle",
403 "Shanai",
404 "Tinkle Bell",
405 "Agogo",
406 "Steel Drums",
407 "Woodblock",
408 "Taiko Drum",
409 "Melodic Tom",
410 "Synth Drum",
411 "Reverse Cymbal",
412 "Guitar Fret Noise",
413 "Breath Noise",
414 "Seashore",
415 "Bird Tweet",
416 "Telephone Ring",
417 "Helicopter",
418 "Applause",
419 "Gunshot"
423 #include <stdio.h>
424 //encodes data in e as a midi event placed in buf
425 int midi_encode(mevent* e, int chan, unsigned char* buf, size_t* n){
427 buf[0] = e->type | chan;
428 buf[1] = e->value1;
430 //printf("%u %u %u\n",e->type,chan,e->type | chan);
432 switch(e->type){
433 case -1:
434 return -1;
435 case 0xC0:
436 case 0xD0:
437 *n = 2;
438 break;
441 buf[2] = e->value2;
443 *n = 3;
445 return 0;
448 //decodes midi data and creates a new mevent
449 int midi_decode(char* buf, mevent* e){
450 e->type = buf[0] & 0xf0;
451 e->value1 = buf[1];
453 switch(e->type){//messages with no third byte
454 case 0xC0:
455 case 0xD0:
456 return 0;
459 e->value2 = buf[2];