-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNordModularPatch.java
More file actions
2761 lines (2536 loc) · 88.9 KB
/
NordModularPatch.java
File metadata and controls
2761 lines (2536 loc) · 88.9 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Synth Patch Conversion for Clavia Nord Modular patches
* 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;
/**
* Convert generic patch XML to Nord Modular v3 patch
*
* Notes:
* - envelopes provide 0-64 unipolar units of modulation
* - lfos provide -64 to +64 bipolar units of modulation
* - keyboard "CV" is 0 at midi note 64 (E4), -64 at note 0, +63 at note 127
* - Patch Settings/Octave Shift doesn't do anything on the Micro Modular
*
* Fix soon:
* - 1.04 in progress. Patch level is expo; converted - need to test
* - Morph: if CV mixer used, need to separate morph so it's on CV mixer not
* original control
* - Can I create NM patch cable "daisy-chain" routine? All cables now are
* "home runs" from source to each dest, making the screen look cluttered.
* (Is there a down side to daisy-chaining?)
*
* Version history:
* 1.04 Patch gain moved from final VCA to output module. Added gain morph.
* Changed max resonance without self-oscillating from 114 to 123.
* 1.03 Convert separate mod jacks & attenuators to parm morph.
* Limit module name to 16 characters; longer name gives load error.
* 1.02 Handle new module type mod_vca
* 1.01 Increased NM3InputsMixer levels (50% was less than half volume).
* NMXFade mix setting was backwards
* 1.00 First major release of converted Nord Lead 2 sounds
*
* @author Kenneth L. Martinez
*/
import java.io.*;
import java.util.*;
import java.text.*;
public class NordModularPatch /*extends SynthPatchAbstract*/ {
private boolean valid;
private String version = "1.01";
private String synthGenericVersion;
// protected GenericPatch genPatch;
private ArrayList nmModules;
private ArrayList nmCables;
private ArrayList nmControls;
private Module voiceParms;
private int numVoices;
private int portamento;
private int fingeredPortamento;
private int transpose;
private int unison;
private ArrayList nmMorphMap;
private boolean keyVelocityMorph;
private String inputFile;
private String patchName;
private String patchNumber;
private String patchBank;
private String patchComment;
public static void main(String args[]) throws IOException, PatchDefinitionException {
if (args.length == 3) {
System.out.println("----------------------------------------");
System.out.println("NordModularPatch " + args[0] + " " + args[1] +
" " + args[2]);
if (args[0].equalsIgnoreCase("toSysex")) {
try {
BufferedReader in = new BufferedReader(new FileReader(args[1]));
String s;
StringBuffer sb = new StringBuffer();
while ((s = in.readLine()) != null) {
sb.append(s + System.getProperty("line.separator"));
}
in.close();
NordModularPatch nm = new NordModularPatch(args[1]);
nm.fromXML(sb.toString());
if (nm.isValid()) {
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(args[2])));
nm.writePatchFile(out);
out.close();
} else {
System.out.println("input file " + args[1] + " did not contain valid XML: "/* + nm.getInvalidMsg()*/);
}
} catch (FileNotFoundException e) {
System.out.println("unable to open input file " + args[1]);
}
System.out.println(" done.");
return;
} else {
System.out.println("invalid run type '" + args[0] + "'");
}
}
System.out.println("please specify toSysex followed by input and output filenames");
}
NordModularPatch(String s) {
valid = false;
// genPatch = new GenericPatch();
nmModules = new ArrayList();
nmCables = new ArrayList();
nmControls = new ArrayList();
numVoices = 16;
portamento = 0;
fingeredPortamento = 0;
transpose = 2;
nmMorphMap = new ArrayList();
keyVelocityMorph = false;
inputFile = s;
}
public boolean isValid() {
return valid;
}
// public ArrayList getNmMorphMap() {
// return nmMorphMap;
// }
public void addMorph(String s) {
if (nmMorphMap.size() < 25) {
nmMorphMap.add(s);
} else if (nmMorphMap.size() == 25) {
System.out.println("Warning: Can't add more than 25 morphs - the rest will be ignored");
}
}
public void fromXML(String xml) throws PatchDefinitionException {
if (xml.indexOf("generic_patch") == -1) {
System.out.println("input file has no generic patch");
return;
}
MyGenericPatch mgp = new MyGenericPatch(this);
if (mgp.readXML(xml)) {
valid = true;
patchName = mgp.getPatchName();
patchNumber = mgp.getPatchNumber();
patchBank = mgp.getPatchBank();
patchComment = mgp.getPatchComment();
}
}
void writePatchFile(PrintWriter out) throws PatchDefinitionException {
String s, ls = System.getProperty("line.separator");
NMModule nmMod;
NMControl nmCon;
int i;
s = voiceParms.findParm("Transpose").getValue();
transpose = new Integer(s).intValue() + 2;
s = voiceParms.findParm("Voice Mode").getValue();
if (s.equalsIgnoreCase("Poly")) {
numVoices = 16;
} else {
numVoices = 1;
}
out.println("[Header]");
out.println("Version=Nord Modular patch 3.0");
out.println("0 127 0 127 2 " + portamento + " " + fingeredPortamento + " " +
numVoices + " 600 " + transpose + " 1 1 1 1 1 1 1 1 1 1 1 1 1 ");
out.println("[/Header]");
out.println("[ModuleDump]");
out.println("1 ");
for (i = 0; i < nmModules.size(); i++) {
nmMod = (NMModule)nmModules.get(i);
out.println((i + 1) + " " + nmMod.writeModuleDump());
}
out.println("[/ModuleDump]");
out.println("[ModuleDump]");
out.println("0 ");
out.println("[/ModuleDump]");
out.println("[CurrentNoteDump]");
out.println("64 0 0 64 0 0 ");
out.println("[/CurrentNoteDump]");
out.println("[CableDump]");
out.println("1 ");
for (i = 0; i < nmCables.size(); i++) {
out.println((String)nmCables.get(i));
}
out.println("[/CableDump]");
out.println("[CableDump]");
out.println("0 ");
out.println("[/CableDump]");
out.println("[ParameterDump]");
out.println("1 ");
for (i = 0; i < nmModules.size(); i++) {
nmMod = (NMModule)nmModules.get(i);
s = nmMod.writeParameterDump();
if (s != null) {
out.println((i + 1) + " " + s);
}
}
out.println("[/ParameterDump]");
out.println("[ParameterDump]");
out.println("0 ");
out.println("[/ParameterDump]");
if (nmMorphMap.size() > 0) {
out.println("[MorphMapDump]");
out.println("0 0 0 0 ");
for (i = 0; i < nmMorphMap.size(); i++) {
out.print((String)nmMorphMap.get(i));
}
out.println("");
out.println("[/MorphMapDump]");
if (keyVelocityMorph == true) {
out.println("[KeyboardAssignment]");
out.println("1 0 0 0 ");
out.println("[/KeyboardAssignment]");
}
}
if (nmControls.size() > 0) {
out.println("[CtrlMapDump]");
for (i = 0; i < nmControls.size(); i++) {
nmCon = (NMControl)nmControls.get(i);
out.println(nmCon.getSection() + " " + nmCon.getModIndex() + " " + nmCon.getParmIndex() +
" " + nmCon.getCcNumber() + " ");
}
out.println("[/CtrlMapDump]");
}
out.println("[CustomDump]");
out.println("1 ");
for (i = 0; i < nmModules.size(); i++) {
nmMod = (NMModule)nmModules.get(i);
s = nmMod.writeCustomDump();
if (s != null) {
out.println((i + 1) + " " + s);
}
}
out.println("[/CustomDump]");
out.println("[CustomDump]");
out.println("0 ");
out.println("[/CustomDump]");
out.println("[NameDump]");
out.println("1 ");
for (i = 0; i < nmModules.size(); i++) {
nmMod = (NMModule)nmModules.get(i);
out.println((i + 1) + " " + nmMod.writeNameDump());
}
out.println("[/NameDump]");
out.println("[NameDump]");
out.println("0 ");
out.println("[/NameDump]");
out.println("[Notes]");
out.println("Produced by PatchConversion.NordModularPatch version 1.04");
out.println("Converted from: " + inputFile);
if (patchName != null) {
out.println("Patch Name: " + patchName);
}
if (patchNumber != null) {
out.println("Patch Number: " + patchNumber);
}
if (patchBank != null) {
out.println("Patch Bank: " + patchBank);
}
if (patchComment != null) {
out.println("Patch Comment: " + patchComment);
}
out.println("[/Notes]");
}
/**
* Find module, return its index in module table (first entry = 1)
*/
public int findNMModule(String name) {
int i;
NMModule m;
// with few modules, a sequential search is fast enough
for (i = 0; i < nmModules.size(); i++) {
m = (NMModule)nmModules.get(i);
if (m.getName().equalsIgnoreCase(name)) {
return i + 1;
}
}
return -1;
}
class MyGenericPatch extends GenericPatch {
private int mixerNum;
private NordModularPatch nmp;
MyGenericPatch(NordModularPatch pNmp) {
super("0.07");
nmp = pNmp;
mixerNum = 0;
}
/**
* read XML into internal variables
*/
public boolean readXML(String xml) throws PatchDefinitionException {
if (matchXML(xml) == false) {
System.out.println("input file has no generic patch");
return false;
}
// Read XML into temp patch structure of modules/jacks/connections
GenericPatch tempGP = new GenericPatch("1.01");
String tag[], sourceModule, sourceJack, targetModule, targetJack;
Module mod, mod2;
Connection conn;
XMLReader xr = new XMLReader(XMLReader.getTagValue(xml, "generic_patch"));
while ((tag = xr.getNextTag()) != null) {
if (tag[0].equalsIgnoreCase("version")) {
if (tag[1].equalsIgnoreCase(version) == false) {
System.out.println("Warning: Expected generic patch version " +
version + ", input is " + tag[1]);
}
} else if (tag[0].equalsIgnoreCase("synth_generic_version")) {
// do anything with this?
} else if (tag[0].equalsIgnoreCase("patch_name")) {
setPatchName(tag[1]);
} else if (tag[0].equalsIgnoreCase("patch_number")) {
setPatchNumber(tag[1]);
} else if (tag[0].equalsIgnoreCase("patch_bank")) {
setPatchBank(tag[1]);
} else if (tag[0].equalsIgnoreCase("patch_comment")) {
setPatchComment(tag[1]);
} else if (tag[0].equalsIgnoreCase("module")) {
mod = new Module(tag[1]);
mod.setUsed(3);
tempGP.addModule(mod);
} else {
System.out.println("unknown tag " + tag[0]);
return false;
}
}
for (int i = 0; i < tempGP.getModules().size(); i++) {
mod = (Module)tempGP.getModules().get(i);
for (int j = 0; j < mod.getInputJacks().size(); j++) {
ModuleInputJack mij = (ModuleInputJack)mod.getInputJacks().get(j);
tempGP.addConnection(mij.buildConnection());
}
}
// Make substitutions of some generic modules so they map better
// to NM modules.
String s;
String src, srcJack, dest, destJack;
ModuleOutputJack moj, moj2;
ModuleInputJack mij;
ModuleParm mp, mp2;
int i, j, y1 = 1, y2 = 1, y3 = 1, y4 = 1;
// Convert mod_vca mod jack name if there's no base jack
for (i = 0; i < tempGP.getModules().size(); i++) {
mod = (Module)tempGP.getModules().get(i);
if (mod.getType().equalsIgnoreCase("mod_vca") == false) {
continue;
}
if (mod.findInputJack("Level In1") != null) {
continue;
}
mij = mod.findInputJack("Level Amt1 Mod In");
if (mij != null) {
mij.setName("Level In1");
mij.getAttenuator().setName("Level Amt1");
}
}
convertModsToMorphs(tempGP);
// Add portamento module if needed
mod = tempGP.findModule("Voice Parms");
mp = mod.findParm("Portamento");
if (mp != null && (mp.getValue().equals("0") == false ||
(mp.getMorph() != null && mp.getMorph().getValue().equals("0") == false))) {
if (mod.findParm("Voice Mode").getValue().equalsIgnoreCase("Mono")) {
if (mod.findParm("Fingered Portamento").getValue().equalsIgnoreCase("On")) {
mod2 = new Module("Patch", "patch_parms", 0);
i = tempGP.findModuleIndex("Voice Parms");
tempGP.addModule(i, mod2); // insert before voice parms
moj = new ModuleOutputJack("Gate Out", "control_output");
mod2.addOutputJack(moj);
mod2 = new Module("Portamento", "portamento_fingered", 0);
i = tempGP.findModuleIndex("Voice Parms");
tempGP.addModule(i, mod2); // insert before voice parms
mij = new ModuleInputJack("Jmp In", "control_input");
mod2.addInputJack(mij);
tempGP.addConnection(new Connection(moj, mij));
} else {
mod2 = new Module("Portamento", "portamento_full", 0);
i = tempGP.findModuleIndex("Voice Parms");
tempGP.addModule(i, mod2); // insert before voice parms
}
mij = new ModuleInputJack("Note In", "control_input");
mod2.addInputJack(mij);
moj = new ModuleOutputJack("Note Out", "control_output");
mod2.addOutputJack(moj);
mp2 = new ModuleParm("Time", null, mp.getValue());
mp2.setMorph(mp.getMorph());
mod2.addParm(mp2);
moj2 = new ModuleOutputJack("Note Out", "control_output");
mod.addOutputJack(moj2);
tempGP.addConnection(new Connection(moj2, mij));
for (i = 0; i < tempGP.getModules().size(); i++) {
mod2 = (Module)tempGP.getModules().get(i);
if (mod2.getType().equalsIgnoreCase("osc")) {
if (mod2.findParm("Key Track").getValue().equals("100") == false) {
System.out.println("Warning: Module " + mod2.getName() +
" Key Track is " + mod2.findParm("Key Track").getValue() +
" - expected 100 for use with Portamento");
}
mod2.findParm("Key Track").setValue("0");
mij = new ModuleInputJack("Expo FM In9", "audio_input");
mp2 = new ModuleParm("Expo FM Amt9", null, "60.01");
mod2.addParm(mp2);
mod2.addInputJack(mij, mp2);
tempGP.addConnection(new Connection(moj, mij));
}
}
} else {
System.out.println("Warning: Poly portamento not supported");
}
}
// Convert mod_vca to vca plus constant
for (i = 0; i < tempGP.getModules().size(); i++) {
mod = (Module)tempGP.getModules().get(i);
if (mod.getType().equalsIgnoreCase("mod_vca")) {
mod.setType("vca");
mij = new ModuleInputJack("Level In2", "control_input");
mp = mod.findParm("Mod Offset");
mp.setName("Level Amt2");
mod.addInputJack(mij, mp);
mod2 = new Module(mod.getName() + "Const", "constant", 0);
i = tempGP.findModuleIndex(mod.getName());
tempGP.addModule(i, mod2); // insert before vca
moj = new ModuleOutputJack("Value Out", "control_output");
mod2.addOutputJack(moj);
tempGP.addConnection(new Connection(moj, mij));
}
}
// Reduce numbers for modules, jacks and parms as needed, and add
// CV mixers as needed.
reduceModNumbers(tempGP);
// Mod Wheel must be attached to Constant module
mod = tempGP.findModule("Voice Parms");
moj = mod.findOutputJack("Mod Wheel Out");
// Make sure morph conversion didn't remove all connections
if (moj != null && moj.getFirstConn() != null) {
mod2 = new Module("Mod Wheel", "constant", 0);
i = tempGP.findModuleIndex("Voice Parms");
tempGP.addModule(i + 1, mod2); // insert after voice parms
mod2.addParm(new ModuleParm("Value", null, "0"));
moj.setName("Value Out");
mod2.addOutputJack(moj);
nmControls.add(new NMControl(i + 2, 0, 1));
}
// Merge final VCA into NM's Amp Envelope module (which incorporates
// a VCA); if that VCA is only controlled by the envelope, remove it.
mod = tempGP.findModule("VCA");
moj = mod.findOutputJack("VCA Out");
if (moj != null &&
tempGP.findConnectionFromSource(moj).getTargetJack().getMod().getName().equalsIgnoreCase("Audio Out") &&
mod.findInputJack("Level In1") != null &&
tempGP.findConnection("Amp Envelope", "Env Out", "VCA", "Level In1") != null) {
// Not needed: the build-in VCA is hardwired to the envelope inside the module
tempGP.removeConnection("Amp Envelope", "Env Out", "VCA", "Level In1");
mod2 = tempGP.findModule("Amp Envelope");
// Find connections that went into & out of separate VCA, and
// redirect to Amp Envelope module
conn = tempGP.findConnectionToTarget(mod.findInputJack("VCA In"));
moj2 = conn.getSourceJack();
tempGP.removeConnection(conn);
mij = new ModuleInputJack("VCA In", "audio_input");
mod2.addInputJack(mij);
tempGP.addConnection(new Connection(moj2, mij));
conn = tempGP.findConnectionFromSource(moj);
moj2 = new ModuleOutputJack("VCA Out", "audio_output");
mod2.addOutputJack(moj2);
if (mod.findInputJack("Level In2") == null) {
tempGP.removeConnection(conn);
mij = conn.getTargetJack();
tempGP.addConnection(new Connection(moj2, mij));
// Remove separate VCA module from the patch
tempGP.removeModule(mod);
} else {
mij = mod.findInputJack("VCA In");
tempGP.addConnection(new Connection(moj2, mij));
mod.removeInputJack(mod.findInputJack("Level In1"));
reduceJackNumbers(mod, tempGP);
}
}
// Audio Out module only has one input, but NM has two; add a second
mod = tempGP.findModule("Audio Out");
mij = new ModuleInputJack("Level In2", "audio_input");
mod.addInputJack(mij);
moj = tempGP.findModuleOutputJack("Amp Envelope", "VCA Out");
if (moj == null) {
moj = tempGP.findModuleOutputJack("VCA", "VCA Out");
}
tempGP.addConnection(new Connection(moj, mij));
voiceParms = tempGP.findModule("Voice Parms");
s = voiceParms.findParm("Unison").getValue();
if (s.equalsIgnoreCase("On") == false) {
unison = 0;
} else {
unison = 1;
// Duplicate Oscs to make unison sound
for (i = 0; i < tempGP.getModules().size(); i++) {
mod = (Module)tempGP.getModules().get(i);
if (mod.getType().equalsIgnoreCase("osc") &&
mod.findParm("CloneOf") == null) {
mod2 = (Module)mod.clone();
mod2.setName(mod.getName() + "U");
j = tempGP.findModuleIndex(mod.getName());
tempGP.addModule(j + 1, mod2); // insert after osc
mod2.addParm(new ModuleParm("CloneOf", null, mod.getName()));
mp = mod2.findParm("Fine Tune");
// default will be 17 cents for unison detune
double d2 = 17, d = new Double(mp.getValue()).doubleValue();
// look for Unison Detune value from Voice Parms
mp2 = voiceParms.findParm("Unison Detune");
if (mp2 != null) {
d2 = new Double(mp2.getValue()).doubleValue();
if (voiceParms.findParm("Unison Voices").getValue().equals("2") == false) {
// If more than 2 voices stacked, first will have twice the detune
d2 *= 2;
}
}
mp.setValue(Double.toString(d + d2));
if (mp.getMorph() != null) {
d = new Double(mp.getMorph().getValue()).doubleValue();
mp.getMorph().setValue(Double.toString(d + d2));
}
// Creating submixer for unison oscs, so that Xfade mixer can still be used
Module modMix = new Module(mod.getName() + "UniMix", "mixer", 0);
tempGP.addModule(j + 2, modMix); // insert after unison osc
ModuleOutputJack mixMoj = new ModuleOutputJack("Mixer Out", "audio_output");
modMix.addOutputJack(mixMoj);
mp = new ModuleParm("Audio Amt1", "percent", null, "100");
modMix.addParm(mp);
ModuleInputJack mixMij1 = new ModuleInputJack("Audio In1", "audio_input");
modMix.addInputJack(mixMij1, mp);
mp = new ModuleParm("Audio Amt2", "percent", null, "100");
modMix.addParm(mp);
ModuleInputJack mixMij2 = new ModuleInputJack("Audio In2", "audio_input");
modMix.addInputJack(mixMij2, mp);
// Move mixer connection
moj = mod.findOutputJack("Wave Out");
Connection conns[] = moj.getConn();
for (j = 0; j < conns.length; j++) {
mij = conns[j].getTargetJack();
if (mij.getPrefix().equalsIgnoreCase("Audio In") &&
mij.getMod().getType().equalsIgnoreCase("mixer")) {
tempGP.removeConnection(conns[j]);
tempGP.addConnection(new Connection(mixMoj, mij));
tempGP.addConnection(new Connection(moj, mixMij1));
tempGP.addConnection(new Connection(mod2.findOutputJack("Wave Out"), mixMij2));
break;
}
}
// If more than 2 voices stacked, simulate with 3 osc stack
mp = voiceParms.findParm("Unison Voices");
if (mp.getValue().equals("2") == false) {
mod2 = (Module)mod.clone();
mod2.setName(mod.getName() + "V");
j = tempGP.findModuleIndex(mod.getName() + "U");
tempGP.addModule(j + 1, mod2); // insert after other unison osc
mod2.addParm(new ModuleParm("CloneOf", null, mod.getName()));
mp = mod2.findParm("Fine Tune");
// default will be -9 cents for second unison osc
d2 = -9;
d = new Double(mp.getValue()).doubleValue();
// look for Unison Detune value from Voice Parms
mp2 = voiceParms.findParm("Unison Detune");
if (mp2 != null) {
d2 = new Double(mp2.getValue()).doubleValue() / -1;
}
mp.setValue(Double.toString(d + d2));
if (mp.getMorph() != null) {
d = new Double(mp.getMorph().getValue()).doubleValue();
mp.getMorph().setValue(Double.toString(d + d2));
}
mp = new ModuleParm("Audio Amt3", "percent", null, "100");
modMix.addParm(mp);
ModuleInputJack mixMij3 = new ModuleInputJack("Audio In3", "audio_input");
modMix.addInputJack(mixMij3, mp);
tempGP.addConnection(new Connection(mod2.findOutputJack("Wave Out"), mixMij3));
}
}
}
for (i = 0; i < tempGP.getModules().size(); i++) {
mod2 = (Module)tempGP.getModules().get(i);
mp = mod2.findParm("CloneOf");
if (mp != null) {
// Loop thru each jack, adding corresponding connections.
// Sync & FM connections must go to corresponding Uni osc
Module mod3;
mod = tempGP.findModule(mp.getValue());
for (j = 0; j < mod.getInputJacks().size(); j++) {
mij = (ModuleInputJack)mod.getInputJacks().get(j);
conn = mij.getConn();
moj = conn.getSourceJack();
if (moj.getMod().getType().equalsIgnoreCase("osc")) {
mod3 = tempGP.findModule(moj.getMod().getName() + "U");
moj = mod3.findOutputJack(moj.getName());
}
tempGP.addConnection(new Connection(moj,
mod2.findInputJack(mij.getName())));
}
}
}
}
// LFOs, Mod Env may need polarity change
for (i = 0; i < tempGP.getModules().size(); i++) {
mod = (Module)tempGP.getModules().get(i);
if (mod.getType().equalsIgnoreCase("lfo")) {
moj = mod.findOutputJack("Wave Out");
if (moj.getPolarity().equalsIgnoreCase("bipolar") == false) {
mod2 = new Module("Unipolar" + mod.getNumber(), "level_shift", mod.getNumber());
j = tempGP.findModuleIndex(mod.getName());
tempGP.addModule(j + 1, mod2); // insert after lfo
mod2.addParm(new ModuleParm("Invert", null, "Off"));
mod2.addParm(new ModuleParm("Polarity", null, "negative"));
mij = new ModuleInputJack("Audio In", "audio_input");
mod2.addInputJack(mij);
moj2 = new ModuleOutputJack("Audio Out", "audio_output", moj.getPolarity());
mod2.addOutputJack(moj2);
Connection conns[] = moj.getConn();
for (j = 0; j < conns.length; j++) {
tempGP.removeConnection(conns[j]);
tempGP.addConnection(new Connection(moj2, conns[j].getTargetJack()));
}
tempGP.addConnection(new Connection(moj, mij));
}
} else if (mod.getType().equalsIgnoreCase("env_ar")) {
moj = mod.findOutputJack("Env Out");
// FIXME shouldn't just check first jack and assume all others are the same
mij = moj.getFirstConn().getTargetJack();
mp = mij.getAttenuator();
double d = new Double(mp.getValue()).doubleValue();
if (mij.getMod().getType().equalsIgnoreCase("cv_mixer") == false &&
((moj.getPolarity().equalsIgnoreCase("negative") && d >= 0) ||
(moj.getPolarity().equalsIgnoreCase("positive") && d <= 0))) {
mod2 = new Module("Unipolar" + mod.getNumber(), "level_shift", mod.getNumber());
j = tempGP.findModuleIndex(mod.getName());
tempGP.addModule(j + 1, mod2); // insert after lfo
mod2.addParm(new ModuleParm("Invert", null, "On"));
mod2.addParm(new ModuleParm("Polarity", null, "bipolar"));
mij = new ModuleInputJack("Audio In", "audio_input");
mod2.addInputJack(mij);
moj2 = new ModuleOutputJack("Audio Out", "audio_output", moj.getPolarity());
mod2.addOutputJack(moj2);
Connection conns[] = moj.getConn();
for (j = 0; j < conns.length; j++) {
tempGP.removeConnection(conns[j]);
tempGP.addConnection(new Connection(moj2, conns[j].getTargetJack()));
if (d < 0) {
double val = new Double(conns[j].getTargetJack().getAttenuator().getValue()).doubleValue();
conns[j].getTargetJack().getAttenuator().setValue(Double.toString(val * -1));
}
}
tempGP.addConnection(new Connection(moj, mij));
}
} else if (mod.getType().equalsIgnoreCase("env_adsr")) {
moj = mod.findOutputJack("Env Out");
if (moj.getPolarity().equalsIgnoreCase("negative")) {
mod.addParm(new ModuleParm("Invert", null, "On"));
}
}
}
// FIXME polarity change may apply to Osc (for P5-style positive-only expo FM)
// FIXME add gain control (attenuator) to VCAs with 1 level in
// create NM patch from tempGP
NMModule nmMod;
String nmc;
for (i = 0; i < tempGP.getModules().size(); i++) {
mod = (Module)tempGP.getModules().get(i);
if (mod.getType().equalsIgnoreCase("voice_parms")) {
nmMod = new NMKeyboardVoice(mod.getName(), 3, y4, mod, nmp);
y4 += 3;
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("patch_parms")) {
nmMod = new NMKeyboardPatch(mod.getName(), 3, y4, mod, nmp);
y4 += 4;
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("constant")) {
nmMod = new NMConstant(mod.getName(), 2, y3, mod, nmp);
y3 += 3;
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("osc")) {
if (mod.findParm("CloneOf") == null) {
nmMod = new NMOscA(mod.getName(), 1, y2, mod, nmp);
y2 += 7;
} else {
nmMod = new NMOscA(mod.getName(), 1, y2 - 1, mod, nmp);
y2 += 6;
}
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("noise")) {
nmMod = new NMNoise(mod.getName(), 1, y2, mod, nmp);
y2 += 3;
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("filter")) {
nmMod = new NMFilterE(mod.getName(), 2, y3, mod, nmp);
y3 += 7;
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("cv_mixer")) {
if (((ModuleOutputJack)mod.getOutputJacks().get(0)).getFirstConn().getTargetJack().getMod().getType().equalsIgnoreCase("vca")) {
nmMod = new NMControlMixer(mod.getName(), 2, y3, mod, nmp);
y3 += 3;
} else {
nmMod = new NMControlMixer(mod.getName(), 1, y2, mod, nmp);
y2 += 3;
}
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("mixer")) {
// look for crossfade mixer first
if (mod.getInputJacks().size() == 2 && mod.getParms().size() == 2 &&
((ModuleParm)mod.getParms().get(1)).getMorph() != null /*&&
((ModuleParm)mod.getParms().get(1)).getMorph().getSource().equals(mod.getName())*/) {
nmMod = new NMXFade(mod.getName(), 2, y3, mod, nmp);
y3 += 4;
} else {
// FIXME if more than 3 inputs, need 8InputMixer
if (mod.getName().endsWith("UniMix")) {
nmMod = new NM3InputsMixer(mod.getName(), 1, y2 - 1, mod, nmp);
y2 += 2;
} else {
nmMod = new NM3InputsMixer(mod.getName(), 2, y3, mod, nmp);
y3 += 3;
}
}
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("crossfade_mixer")) {
nmMod = new NMXFade(mod.getName(), 2, y3, mod, nmp);
y3 += 4;
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("env_adsr")) {
nmMod = new NMADSREnvelope(mod.getName(), 3, y4, mod, nmp);
y4 += 6;
nmModules.add(nmMod);
nmc = matchJacks("Voice Parms", "Gate Out", mod.getName(), "Gate In", 2);
nmCables.add(nmc);
} else if (mod.getType().equalsIgnoreCase("env_ar")) {
nmMod = new NMADEnvelope(mod.getName(), 2, y3, mod, nmp);
y3 += 4;
nmModules.add(nmMod);
nmc = matchJacks("Voice Parms", "Gate Out", mod.getName(), "Gate In", 2);
nmCables.add(nmc);
} else if (mod.getType().equalsIgnoreCase("lfo")) {
s = mod.findParm("Waveform").getValue();
if (s.equalsIgnoreCase("S&H")) {
nmMod = new NMRndStepGen(mod.getName(), 0, y1, mod, nmp);
y1 += 3;
} else if (s.equalsIgnoreCase("S&G")) {
nmMod = new NMRandomGen(mod.getName(), 0, y1, mod, nmp);
y1 += 3;
} else {
nmMod = new NMLFOA(mod.getName(), 0, y1, mod, nmp);
y1 += 6;
}
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("vca")) {
nmMod = new NMGainControl(mod.getName(), 2, y3, mod, nmp);
y3 += 3;
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("portamento_full")) {
nmMod = new NMPortamentoA(mod.getName(), 0, y1, mod, nmp);
y1 += 3;
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("portamento_fingered")) {
nmMod = new NMPortamentoB(mod.getName(), 0, y1, mod, nmp);
y1 += 3;
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("stereo_chorus")) {
nmMod = new NMStereoChorus(mod.getName(), 3, y4, mod, nmp);
y4 += 4;
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("level_shift")) {
if (mod.findInputJack("Audio In").getConn().getSourceJack().getMod().getType().equalsIgnoreCase("env_ar")) {
nmMod = new NMInvLevShift(mod.getName(), 2, y3, mod, nmp);
y3 += 3;
} else {
nmMod = new NMInvLevShift(mod.getName(), 1, y2, mod, nmp);
y2 += 3;
}
nmModules.add(nmMod);
} else if (mod.getType().equalsIgnoreCase("audio_out")) {
nmMod = new NM2Outputs(mod.getName(), 3, y4, mod, nmp);
y4 += 4;
nmModules.add(nmMod);
} else {
System.out.println("can't handle module " + mod.getName() +
" type " + mod.getType());
}
}
// add connections
for (i = 0; i < tempGP.getConnections().size(); i++) {
conn = (Connection)tempGP.getConnections().get(i);
src = conn.getSourceJack().getMod().getName();
srcJack = conn.getSourceJack().getName();
if (src.equalsIgnoreCase("Voice Parms") &&
srcJack.equalsIgnoreCase("Voice Control Out")) {
continue;
}
dest = conn.getTargetJack().getMod().getName();
destJack = conn.getTargetJack().getName();
if (conn.getSourceJack().getType().equalsIgnoreCase("control_output")) {
nmc = matchJacks(src, srcJack, dest, destJack, 1);
} else {
nmc = matchJacks(src, srcJack, dest, destJack, 0);
}
if (nmc != null) {
nmCables.add(nmc);
} else {
System.out.println("unable to create cable from " + src + "," +
srcJack + " to " + dest + "," + destJack);
}
}
if (xml.indexOf("Clavia") != -1 && xml.indexOf("Nord Lead 2 program") != -1 &&
xml.indexOf("<source_patch>") != -1) {
// Implement Nord Lead 2 morphing
// FIXME this should be temporary, until morphing is
// represented in generic patch
addNordLead2Morph(xml, tempGP);
}
return true;
}
void addNordLead2Morph(String xml, GenericPatch gp) {
int i, j;
String s;
if (XMLReader.getTagValue(xml, "Mod_Wheel_Dest").equalsIgnoreCase("Morph")) {
nmControls.add(new NMControl(1, 0, 1, 2));
} else {
keyVelocityMorph = true;
}
}
int getTagIntValue(String xml, String tag) {
String s;
s = XMLReader.getTagValue(xml, tag);
if (s == null) {
return 0;
}
return new Integer(s).intValue();
}
public String matchJacks(String src, String srcJack, String dest, String destJack, int color) {
int sourceIdx = findNMModule(src);
if (sourceIdx == -1) {
return null;
}
NMModule modSource = (NMModule)nmModules.get(sourceIdx - 1);
int sourceJackIdx = modSource.findJack(srcJack);
if (sourceJackIdx == -1) {
return null;
}
int targetIdx = findNMModule(dest);
if (targetIdx == -1) {
return null;
}
NMModule modTarget = (NMModule)nmModules.get(targetIdx - 1);
int targetJackIdx = modTarget.findJack(destJack);
if (targetJackIdx == -1) {
return null;
}
return color + " " + targetIdx + " " + targetJackIdx + " 0 " +
sourceIdx + " " + sourceJackIdx + " 1 ";
}
/**
* Reduce numbering for all module types in the generic patch. First of a
* type should be 1, next is 2, etc.
*
* @param gp GenericPatch to process
*/
public void reduceModNumbers(GenericPatch gp) throws PatchDefinitionException {
int i, j, num;
String s;
Module mod, mod2;
HashMap modTypesChecked = new HashMap();
for (i = 0; i < gp.getModules().size(); i++) {
mod = (Module)gp.getModules().get(i);
// Have we processed this module type yet?
if (modTypesChecked.containsKey(mod.getType())) {
continue;
}
// No - add it to the list
modTypesChecked.put(mod.getType(), null);
// Find all modules of this type and reduce their numbers.
// This works for the first module found also (although the
// type compare is not necessary)
for (j = i, num = 0; j < gp.getModules().size(); j++) {
mod2 = (Module)gp.getModules().get(j);
if (mod2.getType().equalsIgnoreCase(mod.getType())) {
num++;
if (mod2.getNumber() != num) {
mod2.setNumber(num);
}
s = mod2.getName();
if (Character.isDigit(s.charAt(s.length() - 1))) {
mod2.setName(s.substring(0, s.length() - 1) + num);
}
reduceJackNumbers(mod2, gp);
}
}
}
}
/**
* Reduce numbering for jacks (first of a type should be 1, next is 2, etc)
* and also reduce numbers of corresponding parms when they exist.
*
* @param mod Module to process
*/
public void reduceJackNumbers(Module mod, GenericPatch gp) throws PatchDefinitionException {
int i, j, num = 0, oldNum;
String s, prefix, prefix2;
Module mod2;
ModuleJack mj, mj2;
ModuleParm mp;
HashMap jackTypesChecked = new HashMap();
for (i = 0; i < mod.getInputJacks().size(); i++) {
mj = (ModuleJack)mod.getInputJacks().get(i);
s = mj.getName();
if (Character.isDigit(s.charAt(s.length() - 1))) {
prefix = s.substring(0, s.length() - 1);
// Have we processed this jack type yet?
if (jackTypesChecked.containsKey(prefix)) {
continue;
}
// No - add it to the list
jackTypesChecked.put(prefix, null);
// Find all jacks of this type and reduce their numbers
// This works for the first jack found also (although the
// prefix compare is not necessary)
for (j = i, num = 0; j < mod.getInputJacks().size(); j++) {
mj2 = (ModuleJack)mod.getInputJacks().get(j);
s = mj2.getName();
if (Character.isDigit(s.charAt(s.length() - 1))) {
prefix2 = s.substring(0, s.length() - 1);
if (prefix2.equalsIgnoreCase(prefix)) {
num++;
oldNum = new Integer(s.substring(s.length() - 1, s.length())).intValue();
mj2.setName(prefix + num);
mp = mod.findParm(prefix.substring(0, prefix.length() - 2) + "Amt" + oldNum);
if (mp != null) {
mp.setName(prefix.substring(0, prefix.length() - 2) + "Amt" + num);
}
}
}
}
if (mod.getType().equalsIgnoreCase("osc")) {
if (prefix.equalsIgnoreCase("Expo FM In") && num > 2) {
addMixer(2, num, gp, mod, "Expo FM");
} else if (prefix.equalsIgnoreCase("Linear FM In") && num > 1) {
addMixer(1, num, gp, mod, "Linear FM");
} else if (prefix.equalsIgnoreCase("PWM In") && num > 1) {
addMixer(1, num, gp, mod, "PWM");
}
} else if (mod.getType().equalsIgnoreCase("filter") &&
prefix.equalsIgnoreCase("Expo FM In") && num > 2) {
addMixer(2, num, gp, mod, "Expo FM");
} else if (mod.getType().equalsIgnoreCase("vca") &&
prefix.equalsIgnoreCase("Level In") && num > 1) {
addMixer(1, num, gp, mod, "Level");
}
}
}
}