瀏覽代碼

gen_mod.py : Initial commit.

master
kevin 8 年之前
父節點
當前提交
1c428e23e1
共有 1 個檔案被更改,包括 650 行新增0 行删除
  1. 650
    0
      src/kc/data/gen_mod/gen_mod.py

+ 650
- 0
src/kc/data/gen_mod/gen_mod.py 查看文件

@@ -0,0 +1,650 @@
1
+# Generate the 'mod' file for time_line_lite.js
2
+
3
+import sys,copy
4
+
5
+# Selected presets
6
+scoreSeqL = [
7
+    (   1,"g_1_d"),
8
+    (  18,"a"),
9
+    (  43,"d"),
10
+    (  55,"g_1_a"),
11
+    (  74,"a"),
12
+    (  80,"d"),
13
+    (  91,"dry"),
14
+    (  95,"b"),
15
+    ( 102,"g_a"),
16
+    ( 126,"b"),
17
+    ( 142,"a"),
18
+    ( 156,"a"),
19
+    ( 171,"a"),
20
+    ( 186,"b"),
21
+    ( 231,"f_4"),
22
+    ( 236,"g_1_d"),
23
+    ( 264,"g_1_d"),
24
+    ( 286,"dry"),
25
+    ( 291,"f_3"),
26
+    ( 353,"f_4"),
27
+    ( 378,"g_1_a"),
28
+    ( 384,"f_4"),
29
+    ( 391,"g_1_d"),
30
+    ( 451,"f_1"),
31
+    ( 480,"f_4"),
32
+    ( 544,"f_1"),
33
+    ( 559,"dry"),
34
+    ( 610,"dry"),
35
+    ( 699,"g_a"),
36
+    ( 778,"f_3"),
37
+    ( 917,"g_1_d"),
38
+    ( 971,"f_3"),
39
+    (1025,"g_1_d"),
40
+    (1090,"g_1_d")
41
+    ]
42
+
43
+# Hard-coded presets
44
+initPresetStr = """
45
+ init: 
46
+ [
47
+   // wnd len:1=512 2=1024 3=2048 4=4096 5=8192
48
+   { loc:-1, mod:m1, var:win0, type:set, rate:100, val:3 },
49
+   {                 var:win1,           rate:100, val:2 },
50
+
51
+   // hop: 1=1 2=2 3=4 4=8 5=16
52
+   {                 var:hop0,           rate:100, val:3 },
53
+   {                 var:hop1,           rate:100, val:3 },
54
+
55
+   {                 var:mod0,           val:1   },
56
+   {                 var:mod1,           val:1  },
57
+
58
+   {                 var:thr0,           val:65 },
59
+   {                 var:thr1,           val:65 },
60
+
61
+   {                 var:upr0,           val:0 },
62
+   {                 var:upr1,           val:0 },
63
+   {                 var:lwr0,           val:2.0 },
64
+   {                 var:lwr1,           val:2.0 },
65
+   
66
+   {                 var:off0,           val:20 },
67
+   {                 var:off1,           val:20 },
68
+
69
+   {                 var:wet0,           val:0.0 },
70
+   {                 var:wet1,           val:0.0 },
71
+
72
+   {                 var:mint0,           val:55 },
73
+   {                 var:maxt0,           val:85 },
74
+   {                 var:minu0,           val:0.0 },
75
+   {                 var:maxu0,           val:0.5 },
76
+   {                 var:minl0,           val:0 },
77
+   {                 var:maxl0,           val:3 },
78
+   {                 var:mino0,           val:-100.0 },
79
+   {                 var:maxo0,           val:100.0 },
80
+
81
+
82
+   {                 var:mint1,           val:55 },
83
+   {                 var:maxt1,           val:85 },
84
+   {                 var:minu1,           val:0.0 },
85
+   {                 var:maxu1,           val:0.5 },
86
+   {                 var:minl1,           val:0 },
87
+   {                 var:maxl1,           val:3 },
88
+   {                 var:mino1,           val:-100.0 },
89
+   {                 var:maxo1,           val:100.0 },
90
+   
91
+   {                 var:xfad0,           val:100.0 },
92
+   {                 var:xfad1,           val:100.0 },
93
+   {                 var:sw0,   type:decl, val:1 },	
94
+   {                 var:sw1,   type:decl, val:1 },	
95
+
96
+   // compressor
97
+   {                 var:cbyp0,    type:set, val:0.0 },
98
+   {                 var:cigain0,            val:3.0 },
99
+   {                 var:cthrsh0,            val:-20.0 },
100
+   {                 var:cratio0,            val:2.0 },
101
+   {                 var:catkms0,            val:20.0 },
102
+   {                 var:crlsms0,            val:1000.0 },
103
+   {                 var:cmakeup0,           val:1.0 },
104
+   {                 var:cwndms0,            val:200 },
105
+
106
+   {                 var:cbyp1,              val:0.0 },
107
+   {                 var:cigain1,            val:3.0 },
108
+   {                 var:cthrsh1,            val:-20.0 },
109
+   {                 var:cratio1,            val:2.0 },
110
+   {                 var:catkms1,            val:20.0 },
111
+   {                 var:crlsms1,            val:1000.0 },
112
+   {                 var:cmakeup1,           val:1.0 },
113
+   {                 var:cwndms1,            val:200 },
114
+   
115
+   {                 var:dgain0,             val:1.0 },
116
+   {                 var:dgain1,             val:1.0 },
117
+   {                 var:wgain0,             val:1.0 },
118
+   {                 var:wgain1,             val:1.0 },
119
+  ]
120
+
121
+//  Dry 
122
+   preset_dry :
123
+   [
124
+   { loc:-1 mod:m1      var:mod0,	type:set, val:1    },
125
+   {                    var:cigain0,              val: 5.0  },
126
+   {                    var:wet0                  val: 0.0}
127
+   {                    var:sw0,                  val:0 },	
128
+
129
+   {                    var:mod1                  val:1    },
130
+   {                    var:cigain1,              val: 5.0  },
131
+   {                    var:wet1                  val: 0.0}
132
+   {                    var:sw1,                  val:0 },	
133
+   ]
134
+
135
+"""
136
+
137
+
138
+# Default labels to match the 'kc' menu.
139
+dfltLabelsL = [ "a","b","c","d","f_1", "f_2", "f_3", "f_4", "g", "g_a", "g_1_a", "g_1_d" ]
140
+
141
+# Default preset values.
142
+dfltPresetL = [
143
+     
144
+     {"a":
145
+      [
146
+          {
147
+              "mod":    1,
148
+              "thr":   60.0,
149
+              "upr":   -1.1,
150
+              "lwr":    2.0,
151
+              "off":    0.0,
152
+              "cigain": 6.0,
153
+              "wet":    1.0,
154
+              "wgain":  1.75,
155
+              "sw":     0
156
+          },
157
+          
158
+          {
159
+              "mod":    1,
160
+              "thr":   60.0,
161
+              "upr":   -0.99,
162
+              "lwr":    2.0,
163
+              "off":    0.0,
164
+              "cigain": 6.0,
165
+              "wet":    1.0,
166
+              "wgain":  1.75,
167
+              "sw":     0
168
+          }
169
+      ]
170
+     },
171
+
172
+     {"b":
173
+      [
174
+          {
175
+              "mod":    1,
176
+              "thr":   77.0,
177
+              "upr":   -0.5,
178
+              "lwr":    3.0,
179
+              "off":    0.0,
180
+              "cigain":10.0,
181
+              "wet":    1.0,
182
+              "wgain":  1.75,
183
+              "sw":     0
184
+          },
185
+          
186
+          {
187
+              "mod":    1,
188
+              "thr":   74.0,
189
+              "upr":   -0.5,
190
+              "lwr":    2.0,
191
+              "off":    0.0,
192
+              "cigain":10.0,
193
+              "wet":    1.0,
194
+              "wgain":  1.75,
195
+              "sw":     0
196
+          }
197
+      ]
198
+     },
199
+
200
+     {"c":
201
+      [
202
+          {
203
+              "mod":    1,
204
+              "thr":   80.0,
205
+              "upr":   -0.5,
206
+              "lwr":    5.0,
207
+              "off":    0.0,
208
+              "cigain":11.0,
209
+              "wet":    1.0,
210
+              "wgain":  1.0,
211
+              "sw":     0
212
+          },
213
+          
214
+          {
215
+              "mod":    1,
216
+              "thr":   80.0,
217
+              "upr":   -0.5,
218
+              "lwr":    5.0,
219
+              "off":    0.0,
220
+              "cigain":11.0,
221
+              "wet":    1.0,
222
+              "wgain":  1.0,
223
+              "sw":     0
224
+          }
225
+      ]
226
+     },
227
+
228
+
229
+     {"d":
230
+      [
231
+          {
232
+              "mod":    1,
233
+              "thr":   70.0,
234
+              "upr":   -3.9,
235
+              "lwr":    4.0,
236
+              "off":    0.0,
237
+              "cigain": 9.0,
238
+              "wet":    1.0,
239
+              "wgain":  1.0,
240
+              "sw":     0
241
+          },
242
+          
243
+          {
244
+              "mod":    1,
245
+              "thr":   70.0,
246
+              "upr":   -4.5,
247
+              "lwr":    4.0,
248
+              "off":    0.0,
249
+              "cigain": 9.0,
250
+              "wet":    1.0,
251
+              "wgain":  1.0,
252
+              "sw":     0
253
+          }
254
+      ]
255
+     },
256
+
257
+     {"f_1":
258
+      [
259
+          {
260
+              "mod":    1,
261
+              "thr":   50.0,
262
+              "upr":   -3.0,
263
+              "lwr":    1.0,
264
+              "off":    0.0,
265
+              "cigain": 6.0,
266
+              "wet":    1.0,
267
+              "wgain":  2.0,
268
+              "sw":     0
269
+          },
270
+          
271
+          {
272
+              "mod":    1,
273
+              "thr":   50.0,
274
+              "upr":   -3.0,
275
+              "lwr":    1.0,
276
+              "off":    0.0,
277
+              "cigain": 6.0,
278
+              "wet":    1.0,
279
+              "wgain":  2.0,
280
+              "sw":     0
281
+          }
282
+      ]
283
+     },
284
+
285
+     {"f_2":
286
+      [
287
+          {
288
+              "mod":    1,
289
+              "thr":   60.0,
290
+              "upr":   -3.0,
291
+              "lwr":    1.0,
292
+              "off":    0.0,
293
+              "cigain": 6.0,
294
+              "wet":    1.0,
295
+              "wgain":  2.0,
296
+              "sw":     0
297
+          },
298
+          
299
+          {
300
+              "mod":    1,
301
+              "thr":   60.0,
302
+              "upr":   -3.0,
303
+              "lwr":    1.0,
304
+              "off":    0.0,
305
+              "cigain": 6.0,
306
+              "wet":    1.0,
307
+              "wgain":  2.0,
308
+              "sw":     0
309
+          }
310
+      ]
311
+     },
312
+
313
+     {"f_3":
314
+      [
315
+          {
316
+              "mod":    1,
317
+              "thr":   55.0,
318
+              "upr":   -3.0,
319
+              "lwr":    1.0,
320
+              "off":    0.0,
321
+              "cigain": 6.0,
322
+              "wet":    1.0,
323
+              "wgain":  2.0,
324
+              "sw":     0
325
+          },
326
+          
327
+          {
328
+              "mod":    1,
329
+              "thr":   55.0,
330
+              "upr":   -3.0,
331
+              "lwr":    1.0,
332
+              "off":    0.0,
333
+              "cigain": 6.0,
334
+              "wet":    1.0,
335
+              "wgain":  2.0,
336
+              "sw":     0
337
+          }
338
+      ]
339
+     },
340
+
341
+     {"f_4":
342
+      [
343
+          {
344
+              "mod":    1,
345
+              "thr":   55.0,
346
+              "upr":   -5.0,
347
+              "lwr":    1.0,
348
+              "off":    0.0,
349
+              "cigain": 6.0,
350
+              "wet":    1.0,
351
+              "wgain":  2.0,
352
+              "sw":     0
353
+          },
354
+          
355
+          {
356
+              "mod":    1,
357
+              "thr":   55.0,
358
+              "upr":   -5.0,
359
+              "lwr":    1.0,
360
+              "off":    0.0,
361
+              "cigain": 6.0,
362
+              "wet":    1.0,
363
+              "wgain":  2.0,
364
+              "sw":     0
365
+          }
366
+      ]
367
+     },
368
+
369
+     {"g":
370
+      [
371
+          {
372
+              "mod":    4,
373
+              "thr":   60.0,
374
+              "upr":   -0.7,
375
+              "lwr":    8.0,
376
+              "off":   20.0,
377
+              "cigain":10.0,
378
+              "wet":    1.0,
379
+              "wgain":  1.0,
380
+              "sw":     0
381
+          },
382
+          
383
+          {
384
+              "mod":    4,
385
+              "thr":   64.0,
386
+              "upr":   -0.7,
387
+              "lwr":    8.0,
388
+              "off":   20.0,
389
+              "cigain":10.0,
390
+              "wet":    1.0,
391
+              "wgain":  1.0,
392
+              "sw":     0
393
+          }
394
+      ]
395
+     },
396
+
397
+     {"g_a":
398
+      [
399
+          {
400
+              "mod":    4,
401
+              "thr":   50.0,
402
+              "upr":   -0.7,
403
+              "lwr":    2.0,
404
+              "off":   40.0,
405
+              "cigain":10.0,
406
+              "wet":    1.0,
407
+              "wgain":  1.0,
408
+              "sw":     0
409
+          },
410
+          
411
+          {
412
+              "mod":    4,
413
+              "thr":   54.0,
414
+              "upr":   -0.7,
415
+              "lwr":    8.0,
416
+              "off":   40.0,
417
+              "cigain":10.0,
418
+              "wet":    1.0,
419
+              "wgain":  1.0,
420
+              "sw":     0
421
+          }
422
+      ]
423
+     },
424
+
425
+     {"g_1_a":
426
+      [
427
+          {
428
+              "mod":    4,
429
+              "thr":   50.0,
430
+              "upr":   -0.7,
431
+              "lwr":    8.0,
432
+              "off":   20.0,
433
+              "cigain":10.0,
434
+              "wet":    1.0,
435
+              "wgain":  1.0,
436
+              "sw":     0
437
+          },
438
+          
439
+          {
440
+              "mod":    4,
441
+              "thr":   54.0,
442
+              "upr":   -0.7,
443
+              "lwr":    2.0,
444
+              "off":   20.0,
445
+              "cigain":10.0,
446
+              "wet":    1.0,
447
+              "wgain":  1.0,
448
+              "sw":     0
449
+          }
450
+      ]
451
+     },
452
+     
453
+     {"g_1_d":
454
+      [
455
+          {
456
+              "mod":    4,
457
+              "thr":   40.0,
458
+              "upr":   -0.4,
459
+              "lwr":    7.0,
460
+              "off":   60.0,
461
+              "cigain":10.0,
462
+              "wet":    1.0,
463
+              "wgain":  1.0,
464
+              "sw":     0
465
+          },
466
+          
467
+          {
468
+              "mod":    4,
469
+              "thr":   34.0,
470
+              "upr":   -0.3,
471
+              "lwr":    5.0,
472
+              "off":   64.0,
473
+              "cigain":10.0,
474
+              "wet":    1.0,
475
+              "wgain":  1.0,
476
+              "sw":     0
477
+          }
478
+      ]
479
+     }
480
+     
481
+ ]
482
+
483
+
484
+def write_seq( f, label, seqL ):
485
+    """ Write a sequence preset.
486
+        seqL = [ 
487
+                 (loc preset_label)   # Set 'preset_label' to 'None' to assign the seq. label to the preset label.
488
+                 (loc var ch value)   # 'ch' is 0=left or 1=right
489
+               ]
490
+    """
491
+    
492
+    f.write("seq_%s :\n" % label)
493
+    f.write("[\n")
494
+    f.write("{ loc:-1 type:exec val:init },\n")
495
+    f.write("{ loc:-1           val:preset_dry },\n")
496
+
497
+    typ0 = 'exec'
498
+    for x in seqL:
499
+        typ1 = typ0
500
+        if len(x) == 2:
501
+            typ1 = 'exec'
502
+            preset_label = label if x[1]==None else x[1]
503
+            typeS = 'type:exec,' if typ0!=typ1 else '       '
504
+            f.write("{ loc:%5i, %s val:preset_%s },\n" % (x[0],typeS,preset_label))
505
+        elif len(x)  == 4:
506
+            typ1 = 'set'
507
+            typeS = 'type:set' if typ0!=typ1 else '        '
508
+            f.write("{ loc:%5i %s var:%s%i val:%7.2f },\n" % (x[0],typeS,x[1],x[2],x[3]))
509
+            
510
+        typ0 = typ1
511
+            
512
+    
513
+    f.write("]\n\n")
514
+
515
+def write_preset_ch( f, presetD, ch ):
516
+
517
+    fmt0 = "{ loc:-1 mode:m1 var:%6s%i, type:set, val:%7.2f },\n"
518
+    fmt1 = "{                var:%6s%i,           val:%7.2f },\n"
519
+    fmt  = fmt0 if ch==0 else fmt1
520
+    for key,val in presetD.items():
521
+        f.write(fmt % (key,ch,val))
522
+        fmt = fmt1    
523
+
524
+def write_preset( f, label, psL ):
525
+
526
+    f.write("preset_%s : \n" % label)
527
+    f.write("[\n")
528
+    write_preset_ch(f, psL[0], 0 )
529
+    f.write("\n")
530
+    write_preset_ch(f, psL[1], 1 )        
531
+    f.write("]\n")
532
+    
533
+
534
+def write_seqs( f, labelL, seqL ):
535
+    """ Assign a list of preset changes to all sequences named in labelL."""
536
+
537
+    for label in labelL:
538
+        write_seq( f, label, seqL )
539
+
540
+def write_presets( f, presetL ):
541
+
542
+    for x in presetL:
543
+        label = x.keys()[0]
544
+        psL   = x[label]
545
+        write_preset(f,label,psL)
546
+
547
+def label_to_psL( presetL, keyLabel ):
548
+    for preset in presetL:
549
+        label = preset.keys()[0]
550
+        if label == keyLabel:
551
+            return preset[label]
552
+
553
+    raise ValueError( "Preset %s not found." % keyLabel)
554
+    
555
+
556
+def dupl_preset( presetL, keyLabel, labelsL ):
557
+    """ Create a new preset list formed by duplicating the preset
558
+    identified by 'keyLabel' for each label in 'labelsL'
559
+    """
560
+    psL   = label_to_psL(presetL,keyLabel);
561
+    newL  = []
562
+
563
+    for label in labelsL:
564
+        newL.append( { label:copy.deepcopy(psL) } )
565
+    
566
+    return newL
567
+
568
+def mod_range( presetL, var, val00, val01, val10, val11 ):
569
+
570
+    N   = len(presetL)
571
+    v0L = []
572
+    v1L = []
573
+    for i in range(0,N):
574
+        v0L.append( val00 + (i*(val01-val00)/(N-1)) )
575
+        v1L.append( val10 + (i*(val11-val10)/(N-1)) )
576
+
577
+
578
+    for i,preset in enumerate(presetL):
579
+        label = preset.keys()[0]
580
+        psL   = preset[label]
581
+
582
+        #print "%i %s %f %f" % (i,label,v0L[i],v1L[i])
583
+
584
+        psL[0][var] = v0L[i]
585
+        psL[1][var] = v1L[i]
586
+
587
+
588
+        
589
+def print_preset( presetL ):
590
+
591
+    for x in presetL:
592
+        label = x.keys()[0]
593
+        psL   = x[label]
594
+        print "%s %i" % (label,len(psL))
595
+
596
+        for i,psD in enumerate(psL):
597
+            for var,val in psD.items():
598
+                print "%s%i:%f" % (var,i,val)
599
+
600
+
601
+                
602
+
603
+if __name__ == "__main__":
604
+
605
+    #print_preset( presetL )
606
+    
607
+    fn = sys.argv[1]
608
+
609
+
610
+    # 
611
+    seq0L = [
612
+        ( 961, "g_1_d"),      # (loc preset_label)
613
+        ( 967, "wnd", 0, 3 ), # (loc var channel value)
614
+        ( 967,  "f_3"),       # (loc preset_label)
615
+        (1023, None)          # (loc preset_label = seq_label)
616
+        ]
617
+
618
+    seq1L =[
619
+        (301, None) # meas 33
620
+        #(480, None) # meas 41
621
+        ]
622
+    
623
+
624
+    # make all presets identical to preset 'a'.
625
+    presetL = dupl_preset( dfltPresetL, "f_4", dfltLabelsL)
626
+
627
+    # assign a sequential range of thresholds to each preset
628
+    mod_range( presetL, "thr", 50.0, 90.0, 55.0, 95.0 )
629
+    mod_range( presetL, "cigain", 6.0, 12.0, 6.0, 12.0 )
630
+    mod_range( presetL, "upr",  2.5, -5.0, 2.3, -5.2)
631
+    mod_range( presetL, "lwr",  0.5,  2.0, 0.5,  2.0)
632
+
633
+    #mod_range( presetL, "thr", 50.0, 90.0, 55.0, 95.0 )
634
+    #mod_range( presetL, "cigain", 6.0, 12.0, 6.0, 12.0 )
635
+    #mod_range( presetL, "upr",  2.5, -8.0, 2.3, -8.2)
636
+    #mod_range( presetL, "lwr",  0.5,  3.0, 0.5,  3.0)
637
+    
638
+
639
+    with open(fn,"wt") as f:
640
+        f.write("{\n")
641
+
642
+        write_seqs(f,dfltLabelsL,seq1L) # assign seq0L to each sequence
643
+        #write_seqs(f,'a',scoreSeqL);     # the only sequence will be 'a'
644
+
645
+        f.write("%s\n" % initPresetStr)
646
+        
647
+        write_presets(f,presetL)
648
+        
649
+        f.write("}\n")
650
+        

Loading…
取消
儲存