-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatrixModOneSource.java
361 lines (336 loc) · 11.3 KB
/
MatrixModOneSource.java
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/* 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 matrix modulation. This can affect one of several destinations,
* even multiple input jacks per destination (all of the same type), choosing
* from one of several sources.
*
* @author Kenneth L. Martinez
*/
//import java.util.*;
public class MatrixModOneSource implements MatrixMod {
private SynthParmTable sourceParm;
private SynthParmTable destParm;
private int sourceParmMap[];
private int destParmMap[];
private GenericPatch gp;
private ModuleOutputJack sourceJacks[];
private ModuleInputJack destJacks[][];
private ParmTranslator parmTranslators[][];
private ParmTranslator morphTranslators[][];
private int sourceIndex;
private int destIndex;
private int sourceGroup;
MatrixModOneSource(SynthParmTable pSourceParm, int pSourceParmMap[],
SynthParmTable pDestParm, int pDestParmMap[], ModuleOutputJack pSourceJacks[],
ModuleInputJack pDestJacks[][], ParmTranslator pParmTranslators[][],
ParmTranslator pMorphTranslators[][]) throws PatchDefinitionException {
sourceJacks = pSourceJacks;
destJacks = pDestJacks;
parmTranslators = pParmTranslators;
morphTranslators = pMorphTranslators;
sourceParm = pSourceParm;
destParm = pDestParm;
sourceParmMap = pSourceParmMap;
destParmMap = pDestParmMap;
sourceIndex = -1;
destIndex = -1;
if ((parmTranslators != null && destJacks.length != parmTranslators.length) ||
(morphTranslators != null && destJacks.length != morphTranslators.length)) {
throw new PatchDefinitionException("Mods, jacks and parms must be same size for dest");
}
}
// Simplified, to connect one input jack to one of several output jacks
MatrixModOneSource(SynthParmTable pSourceParm, int pSourceParmMap[],
ModuleOutputJack pSourceJacks[], ModuleInputJack pDestJacks[][]) throws PatchDefinitionException {
this(pSourceParm, pSourceParmMap, null, new int[] { -1 },
pSourceJacks, pDestJacks, null, null);
}
public void setGp(GenericPatch pGp) {
gp = pGp;
}
public GenericPatch getGp() {
return gp;
}
/**
* While trying to implement an input generic patch for a specific synth,
* the input process will try to see if all connections and jacks can be
* implemented by the target synth using hard-wired modulations. If it
* cannot, it will use this routine to see if the target synth has a
* matrix mod feature which can be used to create this modulation type.
* Note that this routine only sees if matrix mod can work with the given
* type of input and output module; other processing will determine if
* there are unused matrix mods available and if they can connect to
* the specific modules requested.
*/
public boolean seeIfModTypeIsAllowed(String sourceModType, String sourceModJack,
String destModType, String destModJackPrefix) {
int i;
for (i = 0; i < sourceJacks.length; i++) {
if (sourceJacks[i].getMod().getType().equalsIgnoreCase(sourceModType) &&
sourceJacks[i].getName().equalsIgnoreCase(sourceModJack)) {
break;
}
}
if (i >= sourceJacks.length) {
return false;
}
for (i = 0; i < destJacks.length; i++) {
if (destJacks[i][0].getMod().getType().equalsIgnoreCase(destModType) &&
destJacks[i][0].getPrefix().equalsIgnoreCase(destModJackPrefix)) {
break;
}
}
if (i >= destJacks.length) {
return false;
}
return true;
}
/**
* If this matrix mod is unused and it can implement the requested mod
* connection, set source & dest indexes and create connection
*/
public ModuleInputJack createSingleDestMod(String sourceMod, String sourceJack, String destMod,
String destJackPrefix) throws PatchDefinitionException {
ModuleInputJack mij = null;
int i; // , j;
if (destIndex != -1) {
return null;
}
for (i = 0; i < sourceJacks.length; i++) {
if (sourceJacks[i].getMod().getName().equalsIgnoreCase(sourceMod) &&
sourceJacks[i].getName().equalsIgnoreCase(sourceJack)) {
sourceIndex = i;
break;
}
}
if (i >= sourceJacks.length) {
return null;
}
for (i = 0; i < destJacks.length; i++) {
if (destJacks[i].length > 1) {
continue; // only looking for single-dest mods
}
if (destJacks[i][0].getMod().getName().equalsIgnoreCase(destMod) &&
destJacks[i][0].getPrefix().equalsIgnoreCase(destJackPrefix)) {
destIndex = i;
mij = destJacks[i][0];
break;
}
}
if (i >= destJacks.length) {
sourceIndex = -1;
return null;
}
createModRoute();
return mij;
}
/**
* If this matrix mod is unused and it can implement the requested mod
* connections, set source & dest indexes and create connections
*/
public ModuleInputJack[] createMultiDestMod(String sourceMod, String sourceJack, String destMod[],
String destJackPrefix) throws PatchDefinitionException {
ModuleInputJack mij[] = new ModuleInputJack[destMod.length];
int i, j, k;
if (destIndex != -1) {
return null;
}
for (i = 0; i < sourceJacks.length; i++) {
if (sourceJacks[i].getMod().getName().equalsIgnoreCase(sourceMod) &&
sourceJacks[i].getName().equalsIgnoreCase(sourceJack)) {
sourceIndex = i;
break;
}
}
if (i >= sourceJacks.length) {
return null;
}
outer: for (i = 0; i < destJacks.length; i++) {
if (destJacks[i].length != mij.length) {
continue;
}
for (j = 0; j < mij.length; j++) {
for (k = 0; k < destJacks[i].length; k++) {
if (destJacks[i][k].getMod().getName().equalsIgnoreCase(destMod[j]) &&
destJacks[i][k].getPrefix().equalsIgnoreCase(destJackPrefix)) {
mij[j] = destJacks[i][k];
break;
}
}
if (k >= destJacks[i].length) {
continue outer;
}
}
destIndex = i;
break;
}
if (i >= destJacks.length) {
sourceIndex = -1;
return null;
}
createModRoute();
return mij;
}
/**
* If matrix mod is in use, delete connection, jack(s) and attentuator(s)
* created. This will be invoked if a trial module match fails and
* another must be attempted.
*
*/
public void removeCurrentMod() {
if (sourceIndex != -1 && destIndex != -1) {
for (int i = 0; i < destJacks[destIndex].length; i++) {
// delete connection(s)
gp.removeConnection(sourceJacks[sourceIndex].getMod().getName(),
sourceJacks[sourceIndex].getName(),
destJacks[destIndex][i].getMod().getName(),
destJacks[destIndex][i].getName());
}
}
sourceIndex = -1;
destIndex = -1;
}
private void createModRoute() throws PatchDefinitionException {
ModuleInputJack mij;
ModuleParm mp;
int i;
for (i = 0; i < destJacks[destIndex].length; i++) {
mij = destJacks[destIndex][i];
// create connection from source to dest jack
gp.addConnection(new Connection(sourceJacks[sourceIndex], mij));
}
}
public void toGeneric() throws PatchDefinitionException {
ModuleJack mj;
ModuleParm mp;
int i;
if (destIndex == -1) {
if (sourceParm == null) { // If there's no parm, there's only one source
sourceIndex = 0;
} else {
sourceIndex = sourceParmMap[sourceParm.getIntValue()];
if (sourceIndex == -1) {
return;
}
}
if (destParm == null) { // If there's no parm, there's only one dest
destIndex = 0;
} else {
destIndex = destParmMap[destParm.getIntValue()];
}
if (destIndex == -1) {
return;
}
createModRoute();
}
for (i = 0; i < destJacks[destIndex].length; i++) {
mj = destJacks[destIndex][i];
if (parmTranslators != null && parmTranslators[destIndex][i] != null) {
// set attenuator value
parmTranslators[destIndex][i].toGeneric();
}
if (morphTranslators != null && morphTranslators[destIndex][i] != null) {
morphTranslators[destIndex][i].toGeneric();
}
}
}
public void fromGeneric() {
int i;
if (destIndex == -1) {
return;
}
if (sourceParm != null) {
sourceParm.setValue(sourceIndex);
for (i = 0; i < sourceParmMap.length; i++) {
if (sourceIndex == sourceParmMap[i]) {
sourceParm.setValue(i);
break;
}
}
if (i >= sourceParmMap.length) {
System.out.println("Error: MatrixMod could not match source index " + sourceIndex);
return;
}
}
if (destParm != null) {
for (i = 0; i < destParmMap.length; i++) {
if (destIndex == destParmMap[i]) {
destParm.setValue(i);
break;
}
}
if (i >= destParmMap.length) {
System.out.println("Error: MatrixMod could not match dest index " + destIndex);
return;
}
}
if (parmTranslators == null || parmTranslators[destIndex][0] == null) {
return; // If no parm, should be no morph either
}
parmTranslators[destIndex][0].fromGeneric();
// If more than one parm, see if all have same value
for (i = 1; i < destJacks[destIndex].length; i++) {
if (destJacks[destIndex][i].getAttenuator().getValue().equalsIgnoreCase(
destJacks[destIndex][0].getAttenuator().getValue()) == false) {
System.out.println("Warning - value " + destJacks[destIndex][i].getAttenuator().getValue() +
" not equal to first value " + destJacks[destIndex][0].getAttenuator().getValue() +
"; first value used");
}
}
if (morphTranslators == null || morphTranslators[destIndex][0] == null) {
return;
}
morphTranslators[destIndex][0].fromGeneric();
// If more than one parm morph, see if all have same value
for (i = 1; i < destJacks[destIndex].length; i++) {
ParmMorph morph = destJacks[destIndex][i].getAttenuator().getMorph();
if (morph != null) { // used for morph translators
if (destJacks[destIndex][i].getAttenuator().getMorph().getValue().equalsIgnoreCase(
destJacks[destIndex][0].getAttenuator().getMorph().getValue()) == false) {
System.out.println("Warning - value " + destJacks[destIndex][i].getAttenuator().getMorph().getValue() +
" not equal to first value " + destJacks[destIndex][0].getAttenuator().getMorph().getValue() +
"; first value used");
}
} else { // used for regular parm translators
if (destJacks[destIndex][i].getAttenuator().getValue().equalsIgnoreCase(
destJacks[destIndex][0].getAttenuator().getValue()) == false) {
System.out.println("Warning - value " + destJacks[destIndex][i].getAttenuator().getValue() +
" not equal to first value " + destJacks[destIndex][0].getAttenuator().getValue() +
"; first value used");
}
}
}
}
public boolean seeIfJackCanBeAdded(String sourceModType, String sourceJack,
String destMod, String destModJackPrefix) {
return false;
}
public boolean seeIfParmCanBeAdded(String parmPrefix) {
return false;
}
public int getSourceGroup() {
return sourceGroup;
}
public void setSourceIndex(int pSourceIndex) {
System.out.println("MatrixModOneSource can't use sourceGroups");
int i = 1 / 0; // abort
}
}