-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.java
More file actions
335 lines (292 loc) · 7.96 KB
/
Module.java
File metadata and controls
335 lines (292 loc) · 7.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/* Synth Patch Conversion
* Copyright (C) 2003-4, Kenneth L. Martinez (kmartin@users.sourceforge.net)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package PatchConversion;
/**
* Describes a synth module (oscillator, filter, etc)
*
* @author Kenneth L. Martinez
*/
import java.util.*;
public class Module implements Cloneable {
public static final String MODULE_USED[] = { "not_checked", "unused",
"possible_modulator", "required" };
private String name;
private String type;
private int number;
private int used;
private GenericPatch gp;
// private boolean checked;
private ArrayList parms; // fixed and variable parms
private ArrayList inputJacks;
private ArrayList outputJacks;
Module(String pName, String pType, int pNumber) {
name = pName;
type = pType;
number = pNumber;
parms = new ArrayList();
inputJacks = new ArrayList();
outputJacks = new ArrayList();
}
Module(String xml) throws PatchDefinitionException {
ModuleJack mj;
parms = new ArrayList();
inputJacks = new ArrayList();
outputJacks = new ArrayList();
XMLReader xr = new XMLReader(xml);
String tag[];
while ((tag = xr.getNextTag()) != null) {
if (tag[0].equalsIgnoreCase("name")) {
name = tag[1];
} else if (tag[0].equalsIgnoreCase("type")) {
type = tag[1];
} else if (tag[0].equalsIgnoreCase("number")) {
if (tag[1] == null) {
number = 0;
} else {
number = new Integer(tag[1]).intValue();
}
} else if (tag[0].equalsIgnoreCase("parm")) {
parms.add(new ModuleParm(tag[1]));
} else if (tag[0].equalsIgnoreCase("input_jack")) {
addInputJack(new ModuleInputJack(tag[1], this));
} else if (tag[0].equalsIgnoreCase("output_jack")) {
addOutputJack(new ModuleOutputJack(tag[1], this));
}
}
}
/**
* Creates deep copy of module. Cloned jacks won't have any connections.
*/
public Object clone() {
Module mod = new Module(getName(), getType(), getNumber());
ModuleParm mp;
ModuleInputJack mij, mij2;
ModuleOutputJack moj;
int i;
for (i = 0; i < parms.size(); i++) {
mod.addParm( (ModuleParm) ((ModuleParm)parms.get(i)).clone() );
}
for (i = 0; i < inputJacks.size(); i++) {
mij = (ModuleInputJack)inputJacks.get(i);
mij2 = new ModuleInputJack(mij.getName(), mij.getType());
mp = mij.getAttenuator();
if (mp == null) {
mod.addInputJack(mij2);
} else {
mod.addInputJack(mij2, mod.findParm(mp.getName()));
}
}
for (i = 0; i < outputJacks.size(); i++) {
moj = (ModuleOutputJack)outputJacks.get(i);
mod.addOutputJack(new ModuleOutputJack(moj.getName(), moj.getType(),
moj.getPolarity()));
}
return mod;
}
public void setGp(GenericPatch pGp) {
gp = pGp;
}
public GenericPatch getGp() {
return gp;
}
public void initialize() {
// checked = false;
for (int i = 0; i < parms.size(); i++) {
((ModuleParm)parms.get(i)).initialize();
}
}
public void addParm(ModuleParm mp) {
parms.add(mp);
mp.setMod(this);
}
public void removeParm(ModuleParm mp) {
parms.remove(mp);
mp.setMod(null);
}
public void addInputJack(ModuleInputJack mj) {
inputJacks.add(mj);
mj.setMod(this);
}
public void addInputJack(ModuleInputJack mj, ModuleParm mp) {
addInputJack(mj);
mj.setAttenuator(mp);
mp.setAttenuatedJack(mj);
}
public void addInputJackAndRenumber(ModuleInputJack mj) {
String prefix;
int i, num = 0;
Module mod;
ModuleInputJack mij;
prefix = mj.getPrefix();
for (i = 0; i < inputJacks.size(); i++) {
mij = (ModuleInputJack)inputJacks.get(i);
if (mij.getPrefix().equalsIgnoreCase(prefix) &&
num < mij.getNumber()) {
num = mij.getNumber();
}
}
mj.setNumber(num + 1);
addInputJack(mj);
}
public void addInputJackAndRenumber(ModuleInputJack mj, ModuleParm mp) {
addInputJackAndRenumber(mj);
mp.setNumber(mj.getNumber());
mj.setAttenuator(mp);
mp.setAttenuatedJack(mj);
}
public void removeInputJack(ModuleInputJack mj) {
inputJacks.remove(mj);
mj.setMod(null);
}
public void addOutputJack(ModuleOutputJack mj) {
outputJacks.add(mj);
mj.setMod(this);
}
public void removeOutputJack(ModuleOutputJack mj) {
outputJacks.remove(mj);
mj.setMod(null);
}
public String getName() {
return name;
}
void setName(String s) {
name = s;
}
public String getType() {
return type;
}
void setType(String s) {
type = s;
}
public int getNumber() {
return number;
}
void setNumber(int i) {
number = i;
}
public int getUsed() {
return used;
}
public void setUsed(int i) {
used = i;
}
public void seeIfUsed() {
// FIXME need to perform process to see if module is either
// in audio path or is a modulator in use (required), or if it
// could be triggered as a modulator via some controller
// (possible_modulator)
setUsed(3);
}
public void seeIfParmsUsed() {
// FIXME should do better check
ModuleParm mp;
ModuleInputJack mij;
for (int i = 0; i < parms.size(); i++) {
mp = (ModuleParm)parms.get(i);
mij = mp.getAttenuatedJack();
if (mij != null && mp.getValue().equals("0") &&
(mp.getMorph() == null || mp.getMorph().getValue().equals("0"))) {
mp.setUsed(false);
} else {
mp.setUsed(true);
}
}
}
public ArrayList getParms() {
return parms;
}
public ArrayList getInputJacks() {
return inputJacks;
}
public ArrayList getOutputJacks() {
return outputJacks;
}
public ModuleInputJack findInputJack(String jack) {
ModuleInputJack mij;
// with few jacks, a sequential search is fast enough
for (int i = 0; i < inputJacks.size(); i++) {
mij = (ModuleInputJack)inputJacks.get(i);
if (mij.getName().equalsIgnoreCase(jack)) {
return mij;
}
}
return null;
}
public ModuleOutputJack findOutputJack(String jack) {
ModuleOutputJack moj;
// with few jacks, a sequential search is fast enough
for (int i = 0; i < outputJacks.size(); i++) {
moj = (ModuleOutputJack)outputJacks.get(i);
if (moj.getName().equalsIgnoreCase(jack)) {
return moj;
}
}
return null;
}
public ModuleParm findParm(String parm) {
ModuleParm mp;
// with few parms, a sequential search is fast enough
for (int i = 0; i < parms.size(); i++) {
mp = (ModuleParm)parms.get(i);
if (mp.getName().equalsIgnoreCase(parm)) {
return mp;
}
}
return null;
}
// public boolean isChecked() {
// return checked;
// }
//
// public void setChecked(boolean b) {
// checked = b;
// }
public String writeXML() throws PatchDefinitionException {
// FIXME later change so possible_modulator triggers print
if (used < 3) {
return "";
}
StringBuffer sb = new StringBuffer("<module>");
sb.append("<name>" + name + "</name>");
sb.append("<type>" + type + "</type>");
if (number != 0) {
sb.append("<number>" + number + "</number>");
}
sb.append("<used>" + MODULE_USED[used] + "</used>");
sb.append(writeValue());
sb.append("</module>");
return sb.toString();
}
/**
* Write XML for all module parms and jacks
*/
String writeValue() throws PatchDefinitionException {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < parms.size(); i++) {
sb.append(((ModuleParm)parms.get(i)).writeXML());
}
for (int i = 0; i < inputJacks.size(); i++) {
sb.append(((ModuleInputJack)inputJacks.get(i)).writeXML());
}
for (int i = 0; i < outputJacks.size(); i++) {
sb.append(((ModuleOutputJack)outputJacks.get(i)).writeXML());
}
return sb.toString();
}
}