diff --git a/src/kc/data/gen_mod/gen_mod.py b/src/kc/data/gen_mod/gen_mod.py new file mode 100644 index 0000000..a0c5380 --- /dev/null +++ b/src/kc/data/gen_mod/gen_mod.py @@ -0,0 +1,650 @@ +# Generate the 'mod' file for time_line_lite.js + +import sys,copy + +# Selected presets +scoreSeqL = [ + ( 1,"g_1_d"), + ( 18,"a"), + ( 43,"d"), + ( 55,"g_1_a"), + ( 74,"a"), + ( 80,"d"), + ( 91,"dry"), + ( 95,"b"), + ( 102,"g_a"), + ( 126,"b"), + ( 142,"a"), + ( 156,"a"), + ( 171,"a"), + ( 186,"b"), + ( 231,"f_4"), + ( 236,"g_1_d"), + ( 264,"g_1_d"), + ( 286,"dry"), + ( 291,"f_3"), + ( 353,"f_4"), + ( 378,"g_1_a"), + ( 384,"f_4"), + ( 391,"g_1_d"), + ( 451,"f_1"), + ( 480,"f_4"), + ( 544,"f_1"), + ( 559,"dry"), + ( 610,"dry"), + ( 699,"g_a"), + ( 778,"f_3"), + ( 917,"g_1_d"), + ( 971,"f_3"), + (1025,"g_1_d"), + (1090,"g_1_d") + ] + +# Hard-coded presets +initPresetStr = """ + init: + [ + // wnd len:1=512 2=1024 3=2048 4=4096 5=8192 + { loc:-1, mod:m1, var:win0, type:set, rate:100, val:3 }, + { var:win1, rate:100, val:2 }, + + // hop: 1=1 2=2 3=4 4=8 5=16 + { var:hop0, rate:100, val:3 }, + { var:hop1, rate:100, val:3 }, + + { var:mod0, val:1 }, + { var:mod1, val:1 }, + + { var:thr0, val:65 }, + { var:thr1, val:65 }, + + { var:upr0, val:0 }, + { var:upr1, val:0 }, + { var:lwr0, val:2.0 }, + { var:lwr1, val:2.0 }, + + { var:off0, val:20 }, + { var:off1, val:20 }, + + { var:wet0, val:0.0 }, + { var:wet1, val:0.0 }, + + { var:mint0, val:55 }, + { var:maxt0, val:85 }, + { var:minu0, val:0.0 }, + { var:maxu0, val:0.5 }, + { var:minl0, val:0 }, + { var:maxl0, val:3 }, + { var:mino0, val:-100.0 }, + { var:maxo0, val:100.0 }, + + + { var:mint1, val:55 }, + { var:maxt1, val:85 }, + { var:minu1, val:0.0 }, + { var:maxu1, val:0.5 }, + { var:minl1, val:0 }, + { var:maxl1, val:3 }, + { var:mino1, val:-100.0 }, + { var:maxo1, val:100.0 }, + + { var:xfad0, val:100.0 }, + { var:xfad1, val:100.0 }, + { var:sw0, type:decl, val:1 }, + { var:sw1, type:decl, val:1 }, + + // compressor + { var:cbyp0, type:set, val:0.0 }, + { var:cigain0, val:3.0 }, + { var:cthrsh0, val:-20.0 }, + { var:cratio0, val:2.0 }, + { var:catkms0, val:20.0 }, + { var:crlsms0, val:1000.0 }, + { var:cmakeup0, val:1.0 }, + { var:cwndms0, val:200 }, + + { var:cbyp1, val:0.0 }, + { var:cigain1, val:3.0 }, + { var:cthrsh1, val:-20.0 }, + { var:cratio1, val:2.0 }, + { var:catkms1, val:20.0 }, + { var:crlsms1, val:1000.0 }, + { var:cmakeup1, val:1.0 }, + { var:cwndms1, val:200 }, + + { var:dgain0, val:1.0 }, + { var:dgain1, val:1.0 }, + { var:wgain0, val:1.0 }, + { var:wgain1, val:1.0 }, + ] + +// Dry + preset_dry : + [ + { loc:-1 mod:m1 var:mod0, type:set, val:1 }, + { var:cigain0, val: 5.0 }, + { var:wet0 val: 0.0} + { var:sw0, val:0 }, + + { var:mod1 val:1 }, + { var:cigain1, val: 5.0 }, + { var:wet1 val: 0.0} + { var:sw1, val:0 }, + ] + +""" + + +# Default labels to match the 'kc' menu. +dfltLabelsL = [ "a","b","c","d","f_1", "f_2", "f_3", "f_4", "g", "g_a", "g_1_a", "g_1_d" ] + +# Default preset values. +dfltPresetL = [ + + {"a": + [ + { + "mod": 1, + "thr": 60.0, + "upr": -1.1, + "lwr": 2.0, + "off": 0.0, + "cigain": 6.0, + "wet": 1.0, + "wgain": 1.75, + "sw": 0 + }, + + { + "mod": 1, + "thr": 60.0, + "upr": -0.99, + "lwr": 2.0, + "off": 0.0, + "cigain": 6.0, + "wet": 1.0, + "wgain": 1.75, + "sw": 0 + } + ] + }, + + {"b": + [ + { + "mod": 1, + "thr": 77.0, + "upr": -0.5, + "lwr": 3.0, + "off": 0.0, + "cigain":10.0, + "wet": 1.0, + "wgain": 1.75, + "sw": 0 + }, + + { + "mod": 1, + "thr": 74.0, + "upr": -0.5, + "lwr": 2.0, + "off": 0.0, + "cigain":10.0, + "wet": 1.0, + "wgain": 1.75, + "sw": 0 + } + ] + }, + + {"c": + [ + { + "mod": 1, + "thr": 80.0, + "upr": -0.5, + "lwr": 5.0, + "off": 0.0, + "cigain":11.0, + "wet": 1.0, + "wgain": 1.0, + "sw": 0 + }, + + { + "mod": 1, + "thr": 80.0, + "upr": -0.5, + "lwr": 5.0, + "off": 0.0, + "cigain":11.0, + "wet": 1.0, + "wgain": 1.0, + "sw": 0 + } + ] + }, + + + {"d": + [ + { + "mod": 1, + "thr": 70.0, + "upr": -3.9, + "lwr": 4.0, + "off": 0.0, + "cigain": 9.0, + "wet": 1.0, + "wgain": 1.0, + "sw": 0 + }, + + { + "mod": 1, + "thr": 70.0, + "upr": -4.5, + "lwr": 4.0, + "off": 0.0, + "cigain": 9.0, + "wet": 1.0, + "wgain": 1.0, + "sw": 0 + } + ] + }, + + {"f_1": + [ + { + "mod": 1, + "thr": 50.0, + "upr": -3.0, + "lwr": 1.0, + "off": 0.0, + "cigain": 6.0, + "wet": 1.0, + "wgain": 2.0, + "sw": 0 + }, + + { + "mod": 1, + "thr": 50.0, + "upr": -3.0, + "lwr": 1.0, + "off": 0.0, + "cigain": 6.0, + "wet": 1.0, + "wgain": 2.0, + "sw": 0 + } + ] + }, + + {"f_2": + [ + { + "mod": 1, + "thr": 60.0, + "upr": -3.0, + "lwr": 1.0, + "off": 0.0, + "cigain": 6.0, + "wet": 1.0, + "wgain": 2.0, + "sw": 0 + }, + + { + "mod": 1, + "thr": 60.0, + "upr": -3.0, + "lwr": 1.0, + "off": 0.0, + "cigain": 6.0, + "wet": 1.0, + "wgain": 2.0, + "sw": 0 + } + ] + }, + + {"f_3": + [ + { + "mod": 1, + "thr": 55.0, + "upr": -3.0, + "lwr": 1.0, + "off": 0.0, + "cigain": 6.0, + "wet": 1.0, + "wgain": 2.0, + "sw": 0 + }, + + { + "mod": 1, + "thr": 55.0, + "upr": -3.0, + "lwr": 1.0, + "off": 0.0, + "cigain": 6.0, + "wet": 1.0, + "wgain": 2.0, + "sw": 0 + } + ] + }, + + {"f_4": + [ + { + "mod": 1, + "thr": 55.0, + "upr": -5.0, + "lwr": 1.0, + "off": 0.0, + "cigain": 6.0, + "wet": 1.0, + "wgain": 2.0, + "sw": 0 + }, + + { + "mod": 1, + "thr": 55.0, + "upr": -5.0, + "lwr": 1.0, + "off": 0.0, + "cigain": 6.0, + "wet": 1.0, + "wgain": 2.0, + "sw": 0 + } + ] + }, + + {"g": + [ + { + "mod": 4, + "thr": 60.0, + "upr": -0.7, + "lwr": 8.0, + "off": 20.0, + "cigain":10.0, + "wet": 1.0, + "wgain": 1.0, + "sw": 0 + }, + + { + "mod": 4, + "thr": 64.0, + "upr": -0.7, + "lwr": 8.0, + "off": 20.0, + "cigain":10.0, + "wet": 1.0, + "wgain": 1.0, + "sw": 0 + } + ] + }, + + {"g_a": + [ + { + "mod": 4, + "thr": 50.0, + "upr": -0.7, + "lwr": 2.0, + "off": 40.0, + "cigain":10.0, + "wet": 1.0, + "wgain": 1.0, + "sw": 0 + }, + + { + "mod": 4, + "thr": 54.0, + "upr": -0.7, + "lwr": 8.0, + "off": 40.0, + "cigain":10.0, + "wet": 1.0, + "wgain": 1.0, + "sw": 0 + } + ] + }, + + {"g_1_a": + [ + { + "mod": 4, + "thr": 50.0, + "upr": -0.7, + "lwr": 8.0, + "off": 20.0, + "cigain":10.0, + "wet": 1.0, + "wgain": 1.0, + "sw": 0 + }, + + { + "mod": 4, + "thr": 54.0, + "upr": -0.7, + "lwr": 2.0, + "off": 20.0, + "cigain":10.0, + "wet": 1.0, + "wgain": 1.0, + "sw": 0 + } + ] + }, + + {"g_1_d": + [ + { + "mod": 4, + "thr": 40.0, + "upr": -0.4, + "lwr": 7.0, + "off": 60.0, + "cigain":10.0, + "wet": 1.0, + "wgain": 1.0, + "sw": 0 + }, + + { + "mod": 4, + "thr": 34.0, + "upr": -0.3, + "lwr": 5.0, + "off": 64.0, + "cigain":10.0, + "wet": 1.0, + "wgain": 1.0, + "sw": 0 + } + ] + } + + ] + + +def write_seq( f, label, seqL ): + """ Write a sequence preset. + seqL = [ + (loc preset_label) # Set 'preset_label' to 'None' to assign the seq. label to the preset label. + (loc var ch value) # 'ch' is 0=left or 1=right + ] + """ + + f.write("seq_%s :\n" % label) + f.write("[\n") + f.write("{ loc:-1 type:exec val:init },\n") + f.write("{ loc:-1 val:preset_dry },\n") + + typ0 = 'exec' + for x in seqL: + typ1 = typ0 + if len(x) == 2: + typ1 = 'exec' + preset_label = label if x[1]==None else x[1] + typeS = 'type:exec,' if typ0!=typ1 else ' ' + f.write("{ loc:%5i, %s val:preset_%s },\n" % (x[0],typeS,preset_label)) + elif len(x) == 4: + typ1 = 'set' + typeS = 'type:set' if typ0!=typ1 else ' ' + f.write("{ loc:%5i %s var:%s%i val:%7.2f },\n" % (x[0],typeS,x[1],x[2],x[3])) + + typ0 = typ1 + + + f.write("]\n\n") + +def write_preset_ch( f, presetD, ch ): + + fmt0 = "{ loc:-1 mode:m1 var:%6s%i, type:set, val:%7.2f },\n" + fmt1 = "{ var:%6s%i, val:%7.2f },\n" + fmt = fmt0 if ch==0 else fmt1 + for key,val in presetD.items(): + f.write(fmt % (key,ch,val)) + fmt = fmt1 + +def write_preset( f, label, psL ): + + f.write("preset_%s : \n" % label) + f.write("[\n") + write_preset_ch(f, psL[0], 0 ) + f.write("\n") + write_preset_ch(f, psL[1], 1 ) + f.write("]\n") + + +def write_seqs( f, labelL, seqL ): + """ Assign a list of preset changes to all sequences named in labelL.""" + + for label in labelL: + write_seq( f, label, seqL ) + +def write_presets( f, presetL ): + + for x in presetL: + label = x.keys()[0] + psL = x[label] + write_preset(f,label,psL) + +def label_to_psL( presetL, keyLabel ): + for preset in presetL: + label = preset.keys()[0] + if label == keyLabel: + return preset[label] + + raise ValueError( "Preset %s not found." % keyLabel) + + +def dupl_preset( presetL, keyLabel, labelsL ): + """ Create a new preset list formed by duplicating the preset + identified by 'keyLabel' for each label in 'labelsL' + """ + psL = label_to_psL(presetL,keyLabel); + newL = [] + + for label in labelsL: + newL.append( { label:copy.deepcopy(psL) } ) + + return newL + +def mod_range( presetL, var, val00, val01, val10, val11 ): + + N = len(presetL) + v0L = [] + v1L = [] + for i in range(0,N): + v0L.append( val00 + (i*(val01-val00)/(N-1)) ) + v1L.append( val10 + (i*(val11-val10)/(N-1)) ) + + + for i,preset in enumerate(presetL): + label = preset.keys()[0] + psL = preset[label] + + #print "%i %s %f %f" % (i,label,v0L[i],v1L[i]) + + psL[0][var] = v0L[i] + psL[1][var] = v1L[i] + + + +def print_preset( presetL ): + + for x in presetL: + label = x.keys()[0] + psL = x[label] + print "%s %i" % (label,len(psL)) + + for i,psD in enumerate(psL): + for var,val in psD.items(): + print "%s%i:%f" % (var,i,val) + + + + +if __name__ == "__main__": + + #print_preset( presetL ) + + fn = sys.argv[1] + + + # + seq0L = [ + ( 961, "g_1_d"), # (loc preset_label) + ( 967, "wnd", 0, 3 ), # (loc var channel value) + ( 967, "f_3"), # (loc preset_label) + (1023, None) # (loc preset_label = seq_label) + ] + + seq1L =[ + (301, None) # meas 33 + #(480, None) # meas 41 + ] + + + # make all presets identical to preset 'a'. + presetL = dupl_preset( dfltPresetL, "f_4", dfltLabelsL) + + # assign a sequential range of thresholds to each preset + mod_range( presetL, "thr", 50.0, 90.0, 55.0, 95.0 ) + mod_range( presetL, "cigain", 6.0, 12.0, 6.0, 12.0 ) + mod_range( presetL, "upr", 2.5, -5.0, 2.3, -5.2) + mod_range( presetL, "lwr", 0.5, 2.0, 0.5, 2.0) + + #mod_range( presetL, "thr", 50.0, 90.0, 55.0, 95.0 ) + #mod_range( presetL, "cigain", 6.0, 12.0, 6.0, 12.0 ) + #mod_range( presetL, "upr", 2.5, -8.0, 2.3, -8.2) + #mod_range( presetL, "lwr", 0.5, 3.0, 0.5, 3.0) + + + with open(fn,"wt") as f: + f.write("{\n") + + write_seqs(f,dfltLabelsL,seq1L) # assign seq0L to each sequence + #write_seqs(f,'a',scoreSeqL); # the only sequence will be 'a' + + f.write("%s\n" % initPresetStr) + + write_presets(f,presetL) + + f.write("}\n") +