Skip to content

Latest commit

 

History

History
615 lines (554 loc) · 15.9 KB

timidity.c

File metadata and controls

615 lines (554 loc) · 15.9 KB
 
Oct 21, 1999
Oct 21, 1999
1
/*
Oct 18, 2017
Oct 18, 2017
2
Oct 21, 1999
Oct 21, 1999
3
4
5
TiMidity -- Experimental MIDI to WAVE converter
Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
Dec 31, 2011
Dec 31, 2011
6
7
This program is free software; you can redistribute it and/or modify
it under the terms of the Perl Artistic License, available in COPYING.
Oct 18, 2017
Oct 18, 2017
8
9
10
11
12
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
Oct 21, 1999
Oct 21, 1999
13
14
15
16
17
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Dec 21, 1999
Dec 21, 1999
18
#include "SDL.h"
Oct 18, 2017
Oct 18, 2017
19
20
21
22
#include "timidity.h"
#include "options.h"
Oct 21, 1999
Oct 21, 1999
23
24
25
26
27
28
29
30
#include "common.h"
#include "instrum.h"
#include "playmidi.h"
#include "readmidi.h"
#include "output.h"
#include "tables.h"
Oct 18, 2017
Oct 18, 2017
31
ToneBank *master_tonebank[MAXBANK], *master_drumset[MAXBANK];
Oct 21, 1999
Oct 21, 1999
32
Oct 18, 2017
Oct 18, 2017
33
static char def_instr_name[256] = "";
Oct 21, 1999
Oct 21, 1999
34
35
36
#define MAXWORDS 10
Oct 18, 2017
Oct 18, 2017
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Quick-and-dirty fgets() replacement. */
static char *RWgets(SDL_RWops *rw, char *s, int size)
{
int num_read = 0;
char *p = s;
--size;/* so that we nul terminate properly */
for (; num_read < size; ++p)
{
if (SDL_RWread(rw, p, 1, 1) != 1)
break;
num_read++;
/* Unlike fgets(), don't store newline. Under Windows/DOS we'll
* probably get an extra blank line for every line that's being
* read, but that should be ok.
*/
if (*p == '\n' || *p == '\r')
{
*p = '\0';
return s;
}
}
*p = '\0';
return (num_read != 0) ? s : NULL;
}
Oct 4, 2009
Oct 4, 2009
69
static int read_config_file(const char *name)
Oct 21, 1999
Oct 21, 1999
70
{
Oct 18, 2017
Oct 18, 2017
71
72
SDL_RWops *rw;
char tmp[1024], *w[MAXWORDS], *cp;
Oct 21, 1999
Oct 21, 1999
73
74
75
76
77
ToneBank *bank=0;
int i, j, k, line=0, words;
static int rcf_count=0;
if (rcf_count>50)
Oct 18, 2017
Oct 18, 2017
78
79
{
SNDDBG(("Probable source loop in configuration files\n"));
Oct 21, 1999
Oct 21, 1999
80
return (-1);
Oct 18, 2017
Oct 18, 2017
81
}
Oct 21, 1999
Oct 21, 1999
82
Oct 18, 2017
Oct 18, 2017
83
if (!(rw=open_file(name)))
Oct 21, 1999
Oct 21, 1999
84
85
return -1;
Oct 18, 2017
Oct 18, 2017
86
while (RWgets(rw, tmp, sizeof(tmp)))
Aug 21, 2004
Aug 21, 2004
87
88
{
line++;
Oct 18, 2017
Oct 18, 2017
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
words=0;
w[0]=strtok(tmp, " \t\240");
if (!w[0]) continue;
/* Originally the TiMidity++ extensions were prefixed like this */
if (strcmp(w[0], "#extension") == 0)
{
w[0]=strtok(0, " \t\240");
if (!w[0]) continue;
}
if (*w[0] == '#')
continue;
while (w[words] && *w[words] != '#' && (words < (MAXWORDS-1)))
w[++words]=strtok(0," \t\240");
/*
* TiMidity++ adds a number of extensions to the config file format.
* Many of them are completely irrelevant to SDL_sound, but at least
* we shouldn't choke on them.
*
* Unfortunately the documentation for these extensions is often quite
* vague, gramatically strange or completely absent.
*/
if (
!strcmp(w[0], "comm") /* "comm" program second */
|| !strcmp(w[0], "HTTPproxy") /* "HTTPproxy" hostname:port */
|| !strcmp(w[0], "FTPproxy") /* "FTPproxy" hostname:port */
|| !strcmp(w[0], "mailaddr") /* "mailaddr" your-mail-address */
|| !strcmp(w[0], "opt") /* "opt" timidity-options */
)
{
/*
* + "comm" sets some kind of comment -- the documentation is too
* vague for me to understand at this time.
* + "HTTPproxy", "FTPproxy" and "mailaddr" are for reading data
* over a network, rather than from the file system.
* + "opt" specifies default options for TiMidity++.
*
* These are all quite useless for our version of TiMidity, so
* they can safely remain no-ops.
*/
} else if (!strcmp(w[0], "timeout")) /* "timeout" program second */
{
/*
* Specifies a timeout value of the program. A number of seconds
* before TiMidity kills the note. This may be useful to implement
* later, but I don't see any urgent need for it.
*/
SNDDBG(("FIXME: Implement \"timeout\" in TiMidity config.\n"));
} else if (!strcmp(w[0], "copydrumset") /* "copydrumset" drumset */
|| !strcmp(w[0], "copybank")) /* "copybank" bank */
{
/*
* Copies all the settings of the specified drumset or bank to
* the current drumset or bank. May be useful later, but not a
* high priority.
*/
SNDDBG(("FIXME: Implement \"%s\" in TiMidity config.\n", w[0]));
} else if (!strcmp(w[0], "undef")) /* "undef" progno */
{
/*
* Undefines the tone "progno" of the current tone bank (or
* drum set?). Not a high priority.
*/
SNDDBG(("FIXME: Implement \"undef\" in TiMidity config.\n"));
} else if (!strcmp(w[0], "altassign")) /* "altassign" prog1 prog2 ... */
{
/*
* Sets the alternate assign for drum set. Whatever that's
* supposed to mean.
*/
SNDDBG(("FIXME: Implement \"altassign\" in TiMidity config.\n"));
} else if (!strcmp(w[0], "soundfont")
|| !strcmp(w[0], "font"))
{
/*
* I can't find any documentation for these, but I guess they're
* an alternative way of loading/unloading instruments.
*
* "soundfont" sf_file "remove"
* "soundfont" sf_file ["order=" order] ["cutoff=" cutoff]
* ["reso=" reso] ["amp=" amp]
* "font" "exclude" bank preset keynote
* "font" "order" order bank preset keynote
*/
SNDDBG(("FIXME: Implmement \"%s\" in TiMidity config.\n", w[0]));
} else if (!strcmp(w[0], "progbase"))
{
/*
* The documentation for this makes absolutely no sense to me, but
* apparently it sets some sort of base offset for tone numbers.
* Why anyone would want to do this is beyond me.
*/
SNDDBG(("FIXME: Implement \"progbase\" in TiMidity config.\n"));
} else if (!strcmp(w[0], "map")) /* "map" name set1 elem1 set2 elem2 */
{
/*
* This extension is the one we will need to implement, as it is
* used by the "eawpats". Unfortunately I cannot find any
* documentation whatsoever for it, but it looks like it's used
* for remapping one instrument to another somehow.
*/
SNDDBG(("FIXME: Implement \"map\" in TiMidity config.\n"));
}
/* Standard TiMidity config */
else if (!strcmp(w[0], "dir"))
Aug 21, 2004
Aug 21, 2004
199
200
{
if (words < 2)
Oct 18, 2017
Oct 18, 2017
201
202
203
204
{
SNDDBG(("%s: line %d: No directory given\n", name, line));
goto fail;
}
Aug 21, 2004
Aug 21, 2004
205
for (i=1; i<words; i++)
Oct 18, 2017
Oct 18, 2017
206
add_to_pathlist(w[i]);
Aug 21, 2004
Aug 21, 2004
207
}
Oct 18, 2017
Oct 18, 2017
208
209
210
else if (!strcmp(w[0], "source"))
{
if (words < 2)
Oct 21, 1999
Oct 21, 1999
211
{
Oct 18, 2017
Oct 18, 2017
212
213
214
215
SNDDBG(("%s: line %d: No file name given\n", name, line));
goto fail;
}
for (i=1; i<words; i++)
Oct 21, 1999
Oct 21, 1999
216
{
Oct 18, 2017
Oct 18, 2017
217
218
219
220
221
222
223
224
int status;
rcf_count++;
status = read_config_file(w[i]);
rcf_count--;
if (status != 0) {
SDL_RWclose(rw);
return status;
}
Oct 21, 1999
Oct 21, 1999
225
}
Oct 18, 2017
Oct 18, 2017
226
227
228
229
}
else if (!strcmp(w[0], "default"))
{
if (words != 2)
Oct 21, 1999
Oct 21, 1999
230
{
Oct 18, 2017
Oct 18, 2017
231
232
233
SNDDBG(("%s: line %d: Must specify exactly one patch name\n",
name, line));
goto fail;
Oct 21, 1999
Oct 21, 1999
234
}
Oct 18, 2017
Oct 18, 2017
235
236
237
strncpy(def_instr_name, w[1], 255);
def_instr_name[255]='\0';
}
Oct 21, 1999
Oct 21, 1999
238
else if (!strcmp(w[0], "drumset"))
Oct 18, 2017
Oct 18, 2017
239
240
{
if (words < 2)
Oct 21, 1999
Oct 21, 1999
241
{
Oct 18, 2017
Oct 18, 2017
242
243
SNDDBG(("%s: line %d: No drum set number given\n", name, line));
goto fail;
Oct 21, 1999
Oct 21, 1999
244
}
Oct 18, 2017
Oct 18, 2017
245
246
i=atoi(w[1]);
if (i<0 || i>(MAXBANK-1))
Oct 21, 1999
Oct 21, 1999
247
{
Oct 18, 2017
Oct 18, 2017
248
249
250
SNDDBG(("%s: line %d: Drum set must be between 0 and %d\n",
name, line, MAXBANK-1));
goto fail;
Oct 21, 1999
Oct 21, 1999
251
}
Oct 18, 2017
Oct 18, 2017
252
253
254
255
256
257
if (!master_drumset[i])
{
master_drumset[i] = safe_malloc(sizeof(ToneBank));
memset(master_drumset[i], 0, sizeof(ToneBank));
master_drumset[i]->tone = safe_malloc(128 * sizeof(ToneBankElement));
memset(master_drumset[i]->tone, 0, 128 * sizeof(ToneBankElement));
Oct 21, 1999
Oct 21, 1999
258
}
Oct 18, 2017
Oct 18, 2017
259
bank=master_drumset[i];
Oct 21, 1999
Oct 21, 1999
260
}
Oct 18, 2017
Oct 18, 2017
261
else if (!strcmp(w[0], "bank"))
Oct 21, 1999
Oct 21, 1999
262
{
Oct 18, 2017
Oct 18, 2017
263
if (words < 2)
Oct 21, 1999
Oct 21, 1999
264
{
Oct 18, 2017
Oct 18, 2017
265
266
SNDDBG(("%s: line %d: No bank number given\n", name, line));
goto fail;
Oct 21, 1999
Oct 21, 1999
267
}
Oct 18, 2017
Oct 18, 2017
268
269
i=atoi(w[1]);
if (i<0 || i>(MAXBANK-1))
Oct 21, 1999
Oct 21, 1999
270
{
Oct 18, 2017
Oct 18, 2017
271
272
273
SNDDBG(("%s: line %d: Tone bank must be between 0 and %d\n",
name, line, MAXBANK-1));
goto fail;
Oct 21, 1999
Oct 21, 1999
274
}
Oct 18, 2017
Oct 18, 2017
275
if (!master_tonebank[i])
Oct 21, 1999
Oct 21, 1999
276
{
Oct 18, 2017
Oct 18, 2017
277
278
279
280
master_tonebank[i] = safe_malloc(sizeof(ToneBank));
memset(master_tonebank[i], 0, sizeof(ToneBank));
master_tonebank[i]->tone = safe_malloc(128 * sizeof(ToneBankElement));
memset(master_tonebank[i]->tone, 0, 128 * sizeof(ToneBankElement));
Oct 21, 1999
Oct 21, 1999
281
}
Oct 18, 2017
Oct 18, 2017
282
283
bank=master_tonebank[i];
}
Oct 21, 1999
Oct 21, 1999
284
else
Oct 18, 2017
Oct 18, 2017
285
286
{
if ((words < 2) || (*w[0] < '0' || *w[0] > '9'))
Oct 21, 1999
Oct 21, 1999
287
{
Oct 18, 2017
Oct 18, 2017
288
289
SNDDBG(("%s: line %d: syntax error\n", name, line));
continue;
Oct 21, 1999
Oct 21, 1999
290
}
Oct 18, 2017
Oct 18, 2017
291
292
i=atoi(w[0]);
if (i<0 || i>127)
Oct 21, 1999
Oct 21, 1999
293
{
Oct 18, 2017
Oct 18, 2017
294
295
296
SNDDBG(("%s: line %d: Program must be between 0 and 127\n",
name, line));
goto fail;
Oct 21, 1999
Oct 21, 1999
297
}
Oct 18, 2017
Oct 18, 2017
298
299
300
301
302
if (!bank)
{
SNDDBG(("%s: line %d: Must specify tone bank or drum set before assignment\n",
name, line));
goto fail;
Oct 21, 1999
Oct 21, 1999
303
}
Oct 18, 2017
Oct 18, 2017
304
305
306
307
308
309
310
311
if (bank->tone[i].name)
free(bank->tone[i].name);
strcpy((bank->tone[i].name=safe_malloc(strlen(w[1])+1)),w[1]);
bank->tone[i].note=bank->tone[i].amp=bank->tone[i].pan=
bank->tone[i].strip_loop=bank->tone[i].strip_envelope=
bank->tone[i].strip_tail=-1;
for (j=2; j<words; j++)
Oct 21, 1999
Oct 21, 1999
312
{
Oct 18, 2017
Oct 18, 2017
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
if (!(cp=strchr(w[j], '=')))
{
SNDDBG(("%s: line %d: bad patch option %s\n", name, line, w[j]));
goto fail;
}
*cp++=0;
if (!strcmp(w[j], "amp"))
{
k=atoi(cp);
if ((k<0 || k>MAX_AMPLIFICATION) || (*cp < '0' || *cp > '9'))
{
SNDDBG(("%s: line %d: amplification must be between 0 and %d\n",
name, line, MAX_AMPLIFICATION));
goto fail;
}
bank->tone[i].amp=k;
}
else if (!strcmp(w[j], "note"))
{
k=atoi(cp);
if ((k<0 || k>127) || (*cp < '0' || *cp > '9'))
{
SNDDBG(("%s: line %d: note must be between 0 and 127\n",
name, line));
goto fail;
}
bank->tone[i].note=k;
}
else if (!strcmp(w[j], "pan"))
{
if (!strcmp(cp, "center"))
k=64;
else if (!strcmp(cp, "left"))
k=0;
else if (!strcmp(cp, "right"))
k=127;
else
k=((atoi(cp)+100) * 100) / 157;
if ((k<0 || k>127) || (k==0 && *cp!='-' && (*cp < '0' || *cp > '9')))
{
SNDDBG(("%s: line %d: panning must be left, right, center, or between -100 and 100\n",
name, line));
goto fail;
}
bank->tone[i].pan=k;
}
else if (!strcmp(w[j], "keep"))
{
if (!strcmp(cp, "env"))
bank->tone[i].strip_envelope=0;
else if (!strcmp(cp, "loop"))
bank->tone[i].strip_loop=0;
else
{
SNDDBG(("%s: line %d: keep must be env or loop\n", name, line));
goto fail;
}
}
else if (!strcmp(w[j], "strip"))
{
if (!strcmp(cp, "env"))
bank->tone[i].strip_envelope=1;
else if (!strcmp(cp, "loop"))
bank->tone[i].strip_loop=1;
else if (!strcmp(cp, "tail"))
bank->tone[i].strip_tail=1;
else
{
SNDDBG(("%s: line %d: strip must be env, loop, or tail\n",
name, line));
goto fail;
}
}
else
{
SNDDBG(("%s: line %d: bad patch option %s\n", name, line, w[j]));
goto fail;
}
Oct 21, 1999
Oct 21, 1999
391
392
}
}
Oct 18, 2017
Oct 18, 2017
393
394
}
SDL_RWclose(rw);
Oct 21, 1999
Oct 21, 1999
395
return 0;
Oct 18, 2017
Oct 18, 2017
396
397
398
fail:
SDL_RWclose(rw);
return -2;
Oct 21, 1999
Oct 21, 1999
399
400
}
Oct 18, 2017
Oct 18, 2017
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
int Timidity_Init_NoConfig()
{
/* Allocate memory for the standard tonebank and drumset */
master_tonebank[0] = safe_malloc(sizeof(ToneBank));
memset(master_tonebank[0], 0, sizeof(ToneBank));
master_tonebank[0]->tone = safe_malloc(128 * sizeof(ToneBankElement));
memset(master_tonebank[0]->tone, 0, 128 * sizeof(ToneBankElement));
master_drumset[0] = safe_malloc(sizeof(ToneBank));
memset(master_drumset[0], 0, sizeof(ToneBank));
master_drumset[0]->tone = safe_malloc(128 * sizeof(ToneBankElement));
memset(master_drumset[0]->tone, 0, 128 * sizeof(ToneBankElement));
return 0;
}
int Timidity_Init()
Oct 21, 1999
Oct 21, 1999
418
{
Oct 3, 2009
Oct 3, 2009
419
const char *env = getenv("TIMIDITY_CFG");
Oct 18, 2017
Oct 18, 2017
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/* !!! FIXME: This may be ugly, but slightly less so than requiring the
* default search path to have only one element. I think.
*
* We only need to include the likely locations for the config
* file itself since that file should contain any other directory
* that needs to be added to the search path.
*/
#ifdef DEFAULT_PATH
add_to_pathlist(DEFAULT_PATH);
#endif
#ifdef DEFAULT_PATH1
add_to_pathlist(DEFAULT_PATH1);
#endif
#ifdef DEFAULT_PATH2
add_to_pathlist(DEFAULT_PATH2);
#endif
#ifdef DEFAULT_PATH3
add_to_pathlist(DEFAULT_PATH3);
#endif
Timidity_Init_NoConfig();
Oct 3, 2009
Oct 3, 2009
443
444
445
if (!env || read_config_file(env)<0) {
if (read_config_file(CONFIG_FILE)<0) {
if (read_config_file(CONFIG_FILE_ETC)<0) {
Feb 15, 2013
Feb 15, 2013
446
447
448
if (read_config_file(CONFIG_FILE_ETC_TIMIDITY_FREEPATS)<0) {
return(-1);
}
Jul 13, 2005
Jul 13, 2005
449
}
Jul 4, 2005
Jul 4, 2005
450
}
Oct 21, 1999
Oct 21, 1999
451
}
Oct 18, 2017
Oct 18, 2017
452
453
return 0;
}
Oct 21, 1999
Oct 21, 1999
454
Oct 21, 2017
Oct 21, 2017
455
MidiSong *Timidity_LoadSong(SDL_RWops *rw, SDL_AudioSpec *audio)
Oct 18, 2017
Oct 18, 2017
456
457
458
{
MidiSong *song;
int i;
Aug 21, 2004
Aug 21, 2004
459
Oct 18, 2017
Oct 18, 2017
460
461
462
463
464
465
if (rw == NULL)
return NULL;
/* Allocate memory for the song */
song = (MidiSong *)safe_malloc(sizeof(*song));
memset(song, 0, sizeof(*song));
Aug 21, 2004
Aug 21, 2004
466
Oct 18, 2017
Oct 18, 2017
467
468
469
470
471
472
473
474
475
476
477
478
479
480
for (i = 0; i < MAXBANK; i++)
{
if (master_tonebank[i])
{
song->tonebank[i] = safe_malloc(sizeof(ToneBank));
memset(song->tonebank[i], 0, sizeof(ToneBank));
song->tonebank[i]->tone = master_tonebank[i]->tone;
}
if (master_drumset[i])
{
song->drumset[i] = safe_malloc(sizeof(ToneBank));
memset(song->drumset[i], 0, sizeof(ToneBank));
song->drumset[i]->tone = master_drumset[i]->tone;
}
Oct 21, 1999
Oct 21, 1999
481
482
}
Oct 18, 2017
Oct 18, 2017
483
484
485
song->amplification = DEFAULT_AMPLIFICATION;
song->voices = DEFAULT_VOICES;
song->drumchannels = DEFAULT_DRUMCHANNELS;
Oct 21, 1999
Oct 21, 1999
486
Oct 18, 2017
Oct 18, 2017
487
song->rw = rw;
Oct 21, 1999
Oct 21, 1999
488
Oct 18, 2017
Oct 18, 2017
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
song->rate = audio->freq;
song->encoding = 0;
if ((audio->format & 0xFF) == 16)
song->encoding |= PE_16BIT;
if (audio->format & 0x8000)
song->encoding |= PE_SIGNED;
if (audio->channels == 1)
song->encoding |= PE_MONO;
switch (audio->format) {
case AUDIO_S8:
song->write = s32tos8;
break;
case AUDIO_U8:
song->write = s32tou8;
break;
case AUDIO_S16LSB:
song->write = s32tos16l;
break;
case AUDIO_S16MSB:
song->write = s32tos16b;
break;
case AUDIO_U16LSB:
song->write = s32tou16l;
break;
default:
SNDDBG(("Unsupported audio format"));
song->write = s32tou16l;
break;
Oct 21, 1999
Oct 21, 1999
517
518
}
Oct 18, 2017
Oct 18, 2017
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
song->buffer_size = audio->samples;
song->resample_buffer = safe_malloc(audio->samples * sizeof(sample_t));
song->common_buffer = safe_malloc(audio->samples * 2 * sizeof(Sint32));
song->control_ratio = audio->freq / CONTROLS_PER_SECOND;
if (song->control_ratio < 1)
song->control_ratio = 1;
else if (song->control_ratio > MAX_CONTROL_RATIO)
song->control_ratio = MAX_CONTROL_RATIO;
song->lost_notes = 0;
song->cut_notes = 0;
song->events = read_midi_file(song, &(song->groomed_event_count),
&song->samples);
/* The RWops can safely be closed at this point, but let's make that the
* responsibility of the caller.
*/
/* Make sure everything is okay */
if (!song->events) {
free(song);
return(NULL);
Oct 21, 1999
Oct 21, 1999
543
}
Oct 18, 2017
Oct 18, 2017
544
545
546
547
song->default_instrument = 0;
song->default_program = DEFAULT_PROGRAM;
Oct 21, 1999
Oct 21, 1999
548
if (*def_instr_name)
Oct 18, 2017
Oct 18, 2017
549
550
551
552
553
set_default_instrument(song, def_instr_name);
load_missing_instruments(song);
return(song);
Oct 21, 1999
Oct 21, 1999
554
555
}
Oct 18, 2017
Oct 18, 2017
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
void Timidity_FreeSong(MidiSong *song)
{
int i;
free_instruments(song);
for (i = 0; i < 128; i++)
{
if (song->tonebank[i])
free(song->tonebank[i]);
if (song->drumset[i])
free(song->drumset[i]);
}
free(song->common_buffer);
free(song->resample_buffer);
free(song->events);
free(song);
}
void Timidity_Exit(void)
{
int i, j;
for (i = 0; i < MAXBANK; i++)
{
if (master_tonebank[i])
{
ToneBankElement *e = master_tonebank[i]->tone;
if (e != NULL)
{
for (j = 0; j < 128; j++)
{
if (e[j].name != NULL)
free(e[j].name);
}
free(e);
}
free(master_tonebank[i]);
master_tonebank[i] = NULL;
}
if (master_drumset[i])
{
ToneBankElement *e = master_drumset[i]->tone;
if (e != NULL)
{
for (j = 0; j < 128; j++)
{
if (e[j].name != NULL)
free(e[j].name);
}
free(e);
}
free(master_drumset[i]);
master_drumset[i] = NULL;
}
}
free_pathlist();
}