# Path: nord/utils.py
# def setv(g2param, val):
#   '''setv(g2param, val) - set all variations to val.'''
#   g2param.variations = [ val ] * 9
# 
# def getv(nmparam, variation=0):
#   '''getv(nmparam) - get variations[variation].'''
#   return nmparam.variations[variation]
# 
# Path: nord/g2/colors.py

# 
# Path: nord/nm1/colors.py

# 
# Path: nord/units.py
# def nm2g2val(nm1midival, nm1vals, g2vals):
#   nm1val = nm1vals[nm1midival]
#   g2min = 1000000 # nothing here will never be that big
#   g2midival = 0
#   for midival in xrange(128):
#     g2val = g2vals[midival]
#     if abs(g2val-nm1val) < g2min:
#       g2min = abs(g2val-nm1val)
#       g2midival = midival
#   return g2midival
# 
# Path: nord/utils.py
# def toascii(s):
#   # conversion strings for 192-255
#   s161 = '!cL#Y|S"Ca<^-R-o+23\'uP.10>%%%?' \
#          'AAAAAAACEEEEIIIIDNOOOOOOXOUUUUYpBaaaaaaaceeeeeiiiienooooo/ouuuuypy'
#   def conv(c):
#     o = ord(c)
#     if o < 128:
#       return c
#     elif o < 161:
#       return chr(c-64)
#     else:
#       return s161[o-161]
#     return ''
#   return ''.join([ conv(c) for c in s ])
# 
# Path: nord/convert/table.py



from nord.utils import setv, getv
from nord.g2.colors import g2cablecolors
from nord.nm1.colors import nm1conncolors
from nord.units import nm2g2val
from nord.utils import toascii
from nord.convert.table import kbttable
      if module.horiz >= column:
        module.horiz += 1

def handlekbt(conv, input, kbt100, addalways=False):
  '''handlekbt(conv, input, kbt100, addalways=False) -> input
  '''
  nmm, g2m = conv.nmmodule, conv.g2module
  nmmp, g2mp = nmm.params, g2m.params

  kbt = getv(nmmp.Kbt)
  if addalways:
    pass
  elif kbt == 0:
    setv(conv.kbt, kbt)
    return None
  elif kbt == 64:
    setv(conv.kbt, kbt100)
    return None

  if not g2m.area.keyboard:
    g2m.area.keyboard = conv.add_module('Keyboard')
  keyboard = g2m.area.keyboard

  setv(conv.kbt, 0)
  mix21b = conv.add_module('Mix2-1B', name='Kbt')
  conv.connect(keyboard.outputs.Note, mix21b.inputs.In1)
  conv.connect(mix21b.inputs.In1, mix21b.inputs.In2)
  conv.connect(mix21b.outputs.Out, input)
  setv(mix21b.params.ExpLin, 1) # Lin
  setv(mix21b.params.Lev1, kbttable[kbt][0])

# Path: nord/utils.py
# def setv(g2param, val):
#   '''setv(g2param, val) - set all variations to val.'''
#   g2param.variations = [ val ] * 9
# 
# def getv(nmparam, variation=0):
#   '''getv(nmparam) - get variations[variation].'''
#   return nmparam.variations[variation]
# 
# Path: nord/g2/colors.py

# 
# Path: nord/nm1/colors.py

# 
# Path: nord/units.py
# def nm2g2val(nm1midival, nm1vals, g2vals):
#   nm1val = nm1vals[nm1midival]
#   g2min = 1000000 # nothing here will never be that big
#   g2midival = 0
#   for midival in xrange(128):
#     g2val = g2vals[midival]
#     if abs(g2val-nm1val) < g2min:
#       g2min = abs(g2val-nm1val)
#       g2midival = midival
#   return g2midival
# 
# Path: nord/utils.py
# def toascii(s):
#   # conversion strings for 192-255
#   s161 = '!cL#Y|S"Ca<^-R-o+23\'uP.10>%%%?' \
#          'AAAAAAACEEEEIIIIDNOOOOOOXOUUUUYpBaaaaaaaceeeeeiiiienooooo/ouuuuypy'
#   def conv(c):
#     o = ord(c)
#     if o < 128:
#       return c
#     elif o < 161:
#       return chr(c-64)
#     else:
#       return s161[o-161]
#     return ''
#   return ''.join([ conv(c) for c in s ])
# 
# Path: nord/convert/table.py



# Path: nord/convert/convert.py
from nord.utils import setv, getv
from nord.g2.colors import g2cablecolors
from nord.nm1.colors import nm1conncolors
from nord.units import nm2g2val
from nord.utils import toascii
from nord.convert.table import kbttable

      if module.horiz >= column:
        module.horiz += 1

def handlekbt(conv, input, kbt100, addalways=False):
  '''handlekbt(conv, input, kbt100, addalways=False) -> input
  '''
  nmm, g2m = conv.nmmodule, conv.g2module
  nmmp, g2mp = nmm.params, g2m.params

  kbt = getv(nmmp.Kbt)
  if addalways:
    pass
  elif kbt == 0:
    setv(conv.kbt, kbt)
    return None
  elif kbt == 64:
    setv(conv.kbt, kbt100)
    return None

  if not g2m.area.keyboard:
    g2m.area.keyboard = conv.add_module('Keyboard')
  keyboard = g2m.area.keyboard

  setv(conv.kbt, 0)
  mix21b = conv.add_module('Mix2-1B', name='Kbt')
  conv.connect(keyboard.outputs.Note, mix21b.inputs.In1)
  conv.connect(mix21b.inputs.In1, mix21b.inputs.In2)
  conv.connect(mix21b.outputs.Out, input)
  setv(mix21b.params.ExpLin, 1) # Lin
  setv(mix21b.params.Lev1, kbttable[kbt][0])

  setv(mix21b.params.Lev2, kbttable[kbt][1])