annotate Plugins/Input/timidity/libtimidity/timidity.c @ 480:c1dfb4b13be8 trunk

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