# 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 },  // lwr has a hardcoded min. of 0.3
   {                 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 mod_discrete_range( presetL, var, v0L, v1L ):

    assert( len(v0L) == len(v1L) )
    
    N   = min(len(v0L),len(presetL))


    for i in range(N):
        preset = presetL[i]
        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]
        
    return N

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 =[
        (1, None)   # meas 1
        #(301, None) # meas 33
        #(480, None) # meas 41
        ]
    

    presetL = []

    # assign a sequential range of thresholds to each preset
    if 0: # 12/28/16
        
        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)

    if 0: # 12/28/16

        # make all presets identical to preset 'a'.
        presetL = dupl_preset( dfltPresetL, "g_1_d", dfltLabelsL)
        
        #mod_range( presetL, "thr", 30.0, 90.0, 35.0, 95.0 )
        #mod_range( presetL, "cigain", 10.0, 16.0, 10.0, 16.0 )
        mod_range( presetL, "thr", 65.0, 65.0, 65.0, 65.0 )
        #mod_range( presetL, "upr", -0.05, 4.5, -0.05, 4.5)  # upr slope min: -0.05
        mod_range( presetL, "upr", -0.05, -0.05, -0.05, -0.05) 
        #mod_range( presetL, "lwr", 1.1, 8.0, 1.1, 8.0 )     # 1.5 is good
        #mod_range( presetL, "lwr", 8.0, 8.0, 8.0, 8.0 )
        mod_range( presetL, "lwr", 1.5, 1.5, 1.5, 1.5 )
        mod_range( presetL, "off", 0.0, 99.9, 0.0, 99.9)
        #mod_range( presetL, "upr",  2.5, -5.0, 2.3, -5.2)
        #mod_range( presetL, "lwr",  0.5,  2.0, 0.5,  2.0)

    if 0: # 1/14/17

        seq1L =[
            (778, None)   # meas 50
            ]

        if 0:
            presetL = dupl_preset( dfltPresetL, "f_3", dfltLabelsL)

            # thr: (40 ok) - (71 0k) upr:-3.0 lwr:1.0 cigain:6.0 vetted trajectory for measure 50 
        
            mod_range( presetL, "thr",   40.0, 71.0, 40.0, 71.0 )
            #mod_range( presetL, "thr",   68.0, 68.0, 68.0, 68.0 )
            #mod_range( presetL, "upr",  -4.0,  0.0,  -4.0,  0.0)
            mod_range( presetL, "upr",  -3.0,  -3.0,  -3.0,  -3.0) 
            mod_range( presetL, "lwr",    1.0,  1.0,  1.0,  1.0 )
            mod_range( presetL, "cigain", 6.0,  6.0,  6.0,  6.0 )

        else:  # 3/6/17

            presetL = dupl_preset( dfltPresetL, "g_1_a", dfltLabelsL)

            mod_range( presetL, "thr",   20.0, 50.0, 20.0, 50.0 )  # offs:65 thr:20-50
            mod_range( presetL, "off",   10.0, 80.0, 10.0, 80.0)
            mod_range( presetL, "upr",  -0.7, -0.2, -0.7, -0.2 )
            mod_range( presetL, "lwr",   2.0, 2.0,   8.0, 4.0 )
        
            mod_range( presetL, "cigain", 10.0,  14.0,  10.0,  14.0 )


    if 0: # 1/14/17 and 1/28/17
    
        seq1L =[
            (917, None)   # meas 53
            #(1, None)   # meas 1
            ]

        # 2/4/17 vetted for both meas 53 and meas 1
        
        # make all presets identical to preset 'a'.
        presetL = dupl_preset( dfltPresetL, "g_1_d", dfltLabelsL)
        
        mod_range( presetL, "thr",   20.0, 50.0, 20.0, 50.0 )  # offs:65 thr:20-50
        #mod_range( presetL, "off",   10.0, 80.0, 10.0, 80.0)
        #mod_range( presetL, "off",   65.0, 65.0, 65.0, 65.0)      # thr 34, offset should be > 50
        #mod_range( presetL, "off",   50.0, 80.0, 50.0, 80.0)
        mod_range( presetL, "off",   10.0, 80.0, 10.0, 80.0)
        mod_range( presetL, "cigain", 14.0,  14.0,  14.0,  14.0 )

    if 0: #  1/28/17

        seq1L =[
            (917, None)   # meas 53
            ]
        
        # make all presets identical to preset 'a'.
        presetL = dupl_preset( dfltPresetL, "f_3", dfltLabelsL)
        
        mod_range( presetL, "thr",   40.0, 90.0, 40.0, 90.0 ) 
        mod_range( presetL, "upr",   0.0, 0.0, 0.0, 0.0 )
        mod_range( presetL, "lwr",   4.0, 4.0, 4.0, 4.0)       # vocal artifacts come in with lwr < 4
        mod_range( presetL, "cigain", 3.0,  8.0,  3.0,  8.0 )


    if 0: # 2/4/17
        
        seq1L =[
            (378, None),   # meas 36
        ]

        presetL = dupl_preset( dfltPresetL, "g_1_a", dfltLabelsL)

        mod_range( presetL, "thr",   20.0, 50.0, 20.0, 50.0 )  # offs:65 thr:20-50
        mod_range( presetL, "off",   10.0, 80.0, 10.0, 80.0)
        mod_range( presetL, "upr",  -0.7, -0.2, -0.7, -0.2 )
        mod_range( presetL, "lwr",   2.0, 2.0,   8.0, 4.0 )
        
        mod_range( presetL, "cigain", 10.0,  14.0,  10.0,  14.0 )


        
    if 0: # 2/4/17
        
        seq1L =[
            (378, "g_1_a"),  # meas 36
            (384, None),  
        ]

        presetL = dupl_preset( dfltPresetL, "f_4", dfltLabelsL)

        mod_range( presetL, "thr",  70.0, 75.0, 70.0, 75.0 ) 
        mod_range( presetL, "upr",  -8.0, -4.0, -8.0, -4.0 )
        mod_range( presetL, "lwr",   8.0,  1.0, 8.0, 1.0)    
        mod_range( presetL, "cigain", 10.0,  14.0,  10.0,  14.0 )


    if 0:

        seq1L =[
            (1, None)   # meas 1
        ]

        # 2/4/17 vetted for both meas 53 and meas 1
        
        # make all presets identical to preset 'a'.
        presetL = dupl_preset( dfltPresetL, "g_1_d", dfltLabelsL)

        print "preset len:",len(presetL)
        
        w0L = [ 512,  512,  512,  512,  1024, 1024, 1024, 2048, 2048, 4096 ]
        w1L = [ 512, 1024, 2048, 4096,  1024, 2048, 4096, 2048, 4096, 4096 ]


        
        N = mod_discrete_range( presetL, "win", w0L, w1L )

        presetL = presetL[0:N]
        
        mod_range( presetL, "thr",   40.0, 40.0, 40.0, 40.0 )  # offs:65 thr:20-50
        mod_range( presetL, "off",   55.0, 55.0, 55.0, 55.0)
        mod_range( presetL, "cigain", 14.0,  14.0,  14.0,  14.0 )


    if 0: # 3/6/17

        seq1L =[
            (1, None)   # meas 1
        ]

        presetL = dupl_preset( dfltPresetL, "g_1_d", dfltLabelsL)

        mod_range( presetL, "thr",   20.0, 50.0, 20.0, 50.0 )  # offs:65 thr:20-50
        mod_range( presetL, "off",   10.0, 80.0, 10.0, 80.0)
        mod_range( presetL, "cigain", 14.0,  14.0,  14.0,  14.0 )


    if 0: # 3/6/17

        seq1L =[
            (1, None)   # meas 1
        ]


        presetL = dupl_preset( dfltPresetL, "a", dfltLabelsL)
        mod_range( presetL, "thr",   55.0, 65.0, 55.0, 65.0 )
        mod_range( presetL, "upr", -1.0,  -5.0,  -1.0,  -5.0 )
        mod_range( presetL, "lwr",  2.0,   1.0,   2.0,   1.0 )
        mod_range( presetL, "cigain", 6.0,  8.0,  6.0,  8.0 )
        

    if 0: # 3/6/17

        seq1L =[
            #(1, None)   # meas 38
            (476, None)
        ]

        presetL = dupl_preset( dfltPresetL, "f_4", dfltLabelsL)

        """
        w0L = [ 512,  512,  512,  512,  1024, 1024, 1024, 2048, 2048, 4096 ]
        w1L = [ 512, 1024, 2048, 4096,  1024, 2048, 4096, 2048, 4096, 4096 ]
        
        N = mod_discrete_range( presetL, "win", w0L, w1L )

        presetL = presetL[0:N]
        """
        if 1:
            mod_range( presetL, "thr",   55.0, 65.0, 55.0, 65.0 )
            mod_range( presetL, "upr", -1.0,  -5.0,  -1.0,  -5.0 )
            mod_range( presetL, "lwr",  2.0,   1.0,   2.0,   1.0 )
            mod_range( presetL, "cigain", 6.0,  8.0,  6.0,  8.0 )
        else:
            mod_range( presetL, "thr",  55.0, 75.0, 55.0, 75.0 ) 
            mod_range( presetL, "upr",  -8.0, -4.0, -8.0, -4.0 )
            mod_range( presetL, "lwr",   8.0,  1.0, 8.0, 1.0)    
            mod_range( presetL, "cigain", 10.0,  14.0,  10.0,  14.0 )
        
    if 1: # 3/11/17

        seq1L =[
            (1015, None)  # meas 57 (just before section 29)
            #(1068, None)  # meas 58 (just before section 29)
        ]

        
        presetL = dupl_preset( dfltPresetL, "g_1_d", dfltLabelsL)

        # this is a good parameter space - notice that it can
        # generate 4 lines connecting the diagnals of a cube

        mod_range( presetL, "thr",    10.0, 80.0, 10.0, 80.0 )  # line 1
        mod_range( presetL, "off",    10.0, 99.0, 10.0, 99.0)

        #mod_range( presetL, "thr",    10.0, 80.0, 10.0, 80.0 )  #  line 2
        #mod_range( presetL, "off",    99.0, 10.0, 99.0, 10.0)
        
        #mod_range( presetL, "upr",  5.0,  -1.5,  5.0,  -1.5 )    
        mod_range( presetL, "upr", -1.5,  5.0,  -1.5, 5.0 )
        
        #mod_range( presetL, "lwr", 0.9,  30.0,  0.9,  30.0 )
        
        mod_range( presetL, "cigain", 14.0, 14.0, 14.0, 14.0 )

        
            
        
    # thr    upr  lwr   offs
    # 65   -0.05  1.5   0.0
    #                  99.9
    # 65   -0.05 10.0   0.0
    #                  99.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")
        
