Esempio n. 1
0
File: file.py Progetto: msg/g2ools
  def parse(self, patch, data):
    bitstream = BitStream(data)
    read_bits = bitstream.read_bits

    nvariations, nmorphs, _, _ = bitstream.read_bitsa([8, 4, 10, 10])

    # variations seem to be 9 bytes with first nibble variation # from 0 ~ 8
    # number of morph parameters starts at byte 7-bit 0 for 5-bits
    morphs = patch.settings.morphs
    morphmaps = patch.settings.morphmaps

    for i in xrange(nvariations):
      variation = read_bits(4)
      bitstream.seek_bit(4 + (6*8) + 4, 1) # zeros

      nmorphs = read_bits(8)
      for j in xrange(nmorphs):
        morph_map       = MorphMap()
        area, index, param, morph = bitstream.read_bitsa([2, 8, 7, 4])
        morph_map.range = read_bits(8, 1)

        module = get_patch_area(patch, area).find_module(index)
        morph_map.param     = module.params[param]
        morph_map.variation = variation
        morph_map.morph     = morphs[morph-1]
        morph_map.morph.maps[variation].append(morph_map)
        morphmaps[variation].append(morph_map)

      reserved = read_bits(4) # always 0
Esempio n. 2
0
File: file.py Progetto: msg/g2ools
  def parse(self):
    morphs = self.patch.morphs
    morphmod = None
    for i, moduledefs in enumerate(self.moduledefs):
      if moduledefs[1].type == MORPH_TYPE:
        morphdmod = moduledefs[1]
    if morphmod:
      for i, morph in enumerate(morphs):
        morph.dial = getattr(morphmod, 'p%d' % i)
    define = self.defines.get('Morphs', None)
    if define == None:
      return

    modules = getv2params(define, 'm') # module to connect to
    params = getv2params(define, 'p')  # parameters to connecto to
    dials = getv2params(define, 'd')   # morph dial of parameter
    groups = getv2params(define, 'g')  # morph groups
    area = self.patch.voice
    for i, module in enumerate(modules):
      morph, index = module
      morph, param  = params[i]
      morph, dial   = dials[i]
      morph, group  = groups[i]
      if not (0 <= morph <= 25): ### HACK
        #raise NM1Error('MorphMapDump: invalid morph index %d' % morph)
        continue
      morphmap = MorphMap()
      morphmap.range = dial
      mod = area.find_module(index)
      if param > len(mod.params) - 1:
        param = 0
      morphmap.param = mod.params[param]
      morphmap.param.morph = morphs[group]
      morphs[group].maps.append(morphmap)
Esempio n. 3
0
    def parse(self):
        morphs = self.patch.morphs
        morphmod = None
        for i, moduledefs in enumerate(self.moduledefs):
            if moduledefs[1].type == MORPH_TYPE:
                morphdmod = moduledefs[1]
        if morphmod:
            for i, morph in enumerate(morphs):
                morph.dial = getattr(morphmod, 'p%d' % i)
        define = self.defines.get('Morphs', None)
        if define == None:
            return

        modules = getv2params(define, 'm')  # module to connect to
        params = getv2params(define, 'p')  # parameters to connecto to
        dials = getv2params(define, 'd')  # morph dial of parameter
        groups = getv2params(define, 'g')  # morph groups
        area = self.patch.voice
        for i, module in enumerate(modules):
            morph, index = module
            morph, param = params[i]
            morph, dial = dials[i]
            morph, group = groups[i]
            if not (0 <= morph <= 25):  ### HACK
                #raise NM1Error('MorphMapDump: invalid morph index %d' % morph)
                continue
            morphmap = MorphMap()
            morphmap.range = dial
            mod = area.find_module(index)
            if param > len(mod.params) - 1:
                param = 0
            morphmap.param = mod.params[param]
            morphmap.param.morph = morphs[group]
            morphs[group].maps.append(morphmap)
Esempio n. 4
0
    def parse(self, patch, data):
        bitstream = BitStream(data)
        read_bits = bitstream.read_bits

        nvariations, nmorphs, _, _ = bitstream.read_bitsa([8, 4, 10, 10])

        # variations seem to be 9 bytes with first nibble variation # from 0 ~ 8
        # number of morph parameters starts at byte 7-bit 0 for 5-bits
        morphs = patch.settings.morphs
        morphmaps = patch.settings.morphmaps

        for i in xrange(nvariations):
            variation = read_bits(4)
            bitstream.seek_bit(4 + (6 * 8) + 4, 1)  # zeros

            nmorphs = read_bits(8)
            for j in xrange(nmorphs):
                morph_map = MorphMap()
                area, index, param, morph = bitstream.read_bitsa([2, 8, 7, 4])
                morph_map.range = read_bits(8, 1)

                module = get_patch_area(patch, area).find_module(index)
                morph_map.param = module.params[param]
                morph_map.variation = variation
                morph_map.morph = morphs[morph - 1]
                morph_map.morph.maps[variation].append(morph_map)
                morphmaps[variation].append(morph_map)

            reserved = read_bits(4)  # always 0
Esempio n. 5
0
    def domorphs(self):
        # handle Morphs
        #  morphs[x].ctrl.midicc
        #    1: Wheel -> Wheel (morph 0)
        #    7: Volume -> ?
        #    4: Foot -> Ctrl.Pd (morph 5)
        #  morphs[x].keyassign
        #    0: None -> ignored
        #    1: Velocity -> Vel (morph 1)
        #    2: Note -> Keyb (morph 2)
        #  morphs[x].knob.knob
        #    19: Pedal -> Sust Pd. (morph 4)
        #    20: After Touch -> Aft. Tch. (morph 3)
        #    22: On/Off -> P.Stick (morph 6) set to knob
        #
        #  Priority:
        #    keyassign (highest)
        #    ctrl
        #    knob (lowest)
        #    This means if keyassign is found it's will ignore the other two
        #
        # build a morphmap[x] that maps x to g2 morph
        g2patch, nmpatch = self.g2patch, self.nmpatch
        self.log.info('morphs:')
        nmmorphs = nmpatch.morphs
        g2morphs = g2patch.settings.morphs
        unused = g2morphs[:]
        morphmap = [None] * 4
        for morph in range(len(nmmorphs)):
            if nmmorphs[morph].ctrl:
                self.log.debug(' nm morph%d: midicc=%d' %
                               (morph, nmmorphs[morph].ctrl.midicc))
                # ignore Volume cannot be assigned anyways
                if nmmorphs[morph].ctrl.midicc == 1:
                    morphmap[morph] = g2morphs[0]
                    unused[0] = None
                    continue
                elif nmmorphs[morph].ctrl.midicc == 4:
                    morphmap[morph] = g2morphs[5]
                    unused[5] = None
                    continue
            if nmmorphs[morph].keyassign:
                self.log.debug(' nm morph%d: keyassign=%d' %
                               (morph, nmmorphs[morph].keyassign))
                g2morph = g2morphs[nmmorphs[morph].keyassign]
                unused[morph] = None
                morphmap[morph] = g2morph
                continue
            if nmmorphs[morph].knob:
                knob = nmmorphs[morph].knob
                self.log.debug(' nm morph%d: knob=%d' % (morph, knob.knob))
                if knob.knob > 18:  #  v: 0 unused
                    g2morph = g2morphs[[4, 3, 0, 6][knob.knob - 19]]
                    if hasattr(knob, 'dial'):
                        setv(g2morph.dial, knob.dial)
                    morphmap[morph] = g2morph
                    unused[morph] = None

        def find_unused():
            for i, morph in enumerate(unused):
                if morph:
                    unused[i] = None
                    return morph
            return None

        # if morphmap[morph] empty assign unused morph and set it to knob
        for morph in range(len(morphmap) - 1, -1, -1):
            if not morphmap[morph]:
                morphmap[morph] = find_unused()
                setv(morphmap[morph].mode, 0)
            else:
                setv(morphmap[morph].mode, 1)
            self.log.debug(' nm morph%d -> g2 morph%d' % \
                (morph, morphmap[morph].index))

        for morph in range(len(morphmap)):
            g2morph = morphmap[morph]
            self.log.debug(
                ' Morph%d: dial=%d g2morph%d' %
                (morph + 1, nmmorphs[morph].dial, g2morph.dial.index))
            setv(g2morph.dial, nmmorphs[morph].dial)
            for nmap in nmmorphs[morph].maps:
                s = '  %s:%s range=%d' % (nmap.param.module.name,
                                          nmap.param.type.name, nmap.range)
                conv = nmap.param.module.conv
                gmap = MorphMap()
                gmap.range = conv.domorphrange(nmap.param.index, nmap.range)
                index = nmap.param.index
                if nmap.range == 0:  # ignore junk morphs (0 range)
                    continue
                if index < len(conv.params) and conv.params[index]:
                    gmap.param = conv.params[index]
                    gmap.morph = g2morph
                    morphmap[morph].maps[0].append(gmap)
                    self.log.debug(s)
                else:
                    self.log.warning(s + ' -- Parameter missing')
            for variation in range(1, 9):
                g2morph.maps[variation] = g2morph.maps[0][:]
        self.morphmap = morphmap
Esempio n. 6
0
File: nm2g2.py Progetto: msg/g2ools
  def domorphs(self):
    # handle Morphs
    #  morphs[x].ctrl.midicc
    #    1: Wheel -> Wheel (morph 0)
    #    7: Volume -> ?
    #    4: Foot -> Ctrl.Pd (morph 5)
    #  morphs[x].keyassign
    #    0: None -> ignored
    #    1: Velocity -> Vel (morph 1)
    #    2: Note -> Keyb (morph 2)
    #  morphs[x].knob.knob
    #    19: Pedal -> Sust Pd. (morph 4)
    #    20: After Touch -> Aft. Tch. (morph 3)
    #    22: On/Off -> P.Stick (morph 6) set to knob
    #
    #  Priority:
    #    keyassign (highest)
    #    ctrl
    #    knob (lowest)
    #    This means if keyassign is found it's will ignore the other two
    #
    # build a morphmap[x] that maps x to g2 morph
    g2patch, nmpatch = self.g2patch, self.nmpatch
    self.log.info('morphs:')
    nmmorphs = nmpatch.morphs
    g2morphs = g2patch.settings.morphs
    unused = g2morphs[:]
    morphmap = [None] * 4
    for morph in range(len(nmmorphs)):
      if nmmorphs[morph].ctrl:
        self.log.debug(' nm morph%d: midicc=%d' %
            (morph, nmmorphs[morph].ctrl.midicc))
        # ignore Volume cannot be assigned anyways
        if nmmorphs[morph].ctrl.midicc == 1:
          morphmap[morph] = g2morphs[0]
          unused[0] = None
          continue
        elif nmmorphs[morph].ctrl.midicc == 4:
          morphmap[morph] = g2morphs[5]
          unused[5] = None
          continue
      if nmmorphs[morph].keyassign:
        self.log.debug(' nm morph%d: keyassign=%d' %
            (morph, nmmorphs[morph].keyassign))
        g2morph = g2morphs[nmmorphs[morph].keyassign]
        unused[morph] = None
        morphmap[morph] = g2morph
        continue
      if nmmorphs[morph].knob:
        knob = nmmorphs[morph].knob
        self.log.debug(' nm morph%d: knob=%d' % (morph, knob.knob))
        if knob.knob > 18:                  #  v: 0 unused
          g2morph = g2morphs[[4, 3, 0, 6][knob.knob-19]]
          if hasattr(knob, 'dial'):
            setv(g2morph.dial, knob.dial)
          morphmap[morph] = g2morph
          unused[morph] = None

    def find_unused():
      for i, morph in enumerate(unused):
        if morph:
          unused[i] = None
          return morph
      return None
    # if morphmap[morph] empty assign unused morph and set it to knob
    for morph in range(len(morphmap)-1, -1, -1):
      if not morphmap[morph]:
        morphmap[morph] = find_unused()
        setv(morphmap[morph].mode, 0)
      else:
        setv(morphmap[morph].mode, 1)
      self.log.debug(' nm morph%d -> g2 morph%d' % \
          (morph, morphmap[morph].index))

    for morph in range(len(morphmap)):
      g2morph = morphmap[morph]
      self.log.debug(' Morph%d: dial=%d g2morph%d' % (morph+1,
              nmmorphs[morph].dial, g2morph.dial.index))
      setv(g2morph.dial, nmmorphs[morph].dial)
      for nmap in nmmorphs[morph].maps:
        s = '  %s:%s range=%d' % (nmap.param.module.name, nmap.param.type.name,
            nmap.range)
        conv = nmap.param.module.conv
        gmap = MorphMap()
        gmap.range = conv.domorphrange(nmap.param.index, nmap.range)
        index = nmap.param.index
        if nmap.range == 0: # ignore junk morphs (0 range)
          continue
        if index < len(conv.params) and conv.params[index]:
          gmap.param = conv.params[index]
          gmap.morph = g2morph
          morphmap[morph].maps[0].append(gmap)
          self.log.debug(s)
        else:
          self.log.warning(s + ' -- Parameter missing')
      for variation in range(1, 9):
        g2morph.maps[variation] = g2morph.maps[0][:]
    self.morphmap = morphmap