Beispiel #1
0
    def __init__(self,
                 value=None,
                 change=None,
                 rtransient=False,
                 transient=False,
                 creator=None,
                 wrecker=None,
                 extension=None,
                 dynlist=False):
        self.__children = None
        self.__creator = utils.weaken(creator
                                      or getattr(self, 'dynamic_create', None))
        self.__wrecker = utils.weaken(wrecker or self.dynamic_destroy)
        self.__extension = extension

        flags = 0

        if self.__creator is not None or dynlist:
            flags = flags | const.server_list

        if rtransient:
            flags = flags | const.server_rtransient

        if transient:
            flags = flags | const.server_transient

        piw.server.__init__(self, flags)
        self.set_change_handler(change)
        self.set_data(value or piw.data())
Beispiel #2
0
 def upgrade_2_0_to_3_0(self, tools, address):
     root = tools.root(address)
     root.ensure_node(255, 17)
     p = root.ensure_node(255, 6)
     oc = p.get_data()
     if not oc.is_bool(): oc = piw.makebool(False, 0)
     p.set_data(piw.data())
     p.ensure_node(1).set_data(oc)
     p.ensure_node(2).set_data(piw.makebool(False, 0))
     return True
Beispiel #3
0
    def test_numeric(self):
        f = 1.1
        i = 10
        f2 = -1.1
        i2 = -10
        b = True
        n = None

        df = piw.makefloat(f,0L)
        di = piw.makelong(i,0L)
        df2 = piw.makefloat(f2,0L)
        di2 = piw.makelong(i2,0L)
        db = piw.makebool(b,0L)
        dn = piw.data()

        self.check_domain('bint(1,10)',i,di)
        self.check_domain('bint(-10,-1)',i2,di2)
        self.check_domain('bfloat(1.1,10.1)',f,df)
        self.check_domain('bfloat(-10.1,-1.1)',f2,df2)
        self.check_domain('bool()',b,db)
        self.check_domain('null()',n,dn)
Beispiel #4
0
    def phase2_1_0_1(self,tools,address):
        print 'upgrading plugin host',address
        root = tools.get_root(address)
        freq_input = root.ensure_node(6,2)
        scaler_conn = freq_input.get_master()
        if not scaler_conn: return
        scaler_addr = paths.id2server(scaler_conn[0])
        scaler_root = tools.get_root(scaler_addr)
        if not scaler_root: return
        scaler_type = scaler_root.get_meta_string('plugin')
        if scaler_type != 'scaler': return
        print 'scaler is',scaler_addr
        scaler_pressure_input = scaler_root.get_node(4,2)
        recorder_conn = scaler_pressure_input.get_master()
        if not recorder_conn: return
        recorder_addr = paths.id2server(recorder_conn[0])
        recorder_root = tools.get_root(recorder_addr)
        if not recorder_root: return
        recorder_type = recorder_root.get_meta_string('plugin')
        if recorder_type != 'recorder': return
        print 'recorder is',recorder_addr

        canonical_names = {}
        available_sources = {}
        blocked_sources = []

        available_sources['pressure'] = paths.makeid_list(scaler_addr,1,2)
        available_sources['roll'] = paths.makeid_list(scaler_addr,1,3)
        available_sources['yaw'] = paths.makeid_list(scaler_addr,1,4)

        for (k,v) in available_sources.items():
            canonical_names[v] = k

        for i in range(5,15):
            recorder_input = recorder_root.get_node(1,i)
            if recorder_input:
                input_name = recorder_input.get_name()
                input_conn = recorder_input.get_master()
                output_id = paths.makeid_list(recorder_addr,2,i)
                if not input_conn:
                    blocked_sources.append(output_id)
                    print 'unavailable input',output_id
                    continue
                upstream_addr,upstream_path = paths.breakid_list(input_conn[0])
                upstream_root = tools.get_root(upstream_addr)
                if not upstream_root: continue
                upstream = upstream_root.get_node(*upstream_path)
                if not upstream: continue
                upstream_name = upstream.get_name().split()
                if 'output' in upstream_name: upstream_name.remove('output')
                upstream_name = ' '.join(upstream_name)
                if upstream_name == 'controller': continue
                print 'recorder output',i,'at',output_id,'called',input_name,'connected to',upstream_name
                available_sources[upstream_name] = output_id
                canonical_names[output_id] = upstream_name

        for n,id in available_sources.items():
            print 'source',n,'at',id

        current_parms = {}
        unused_parms = range(1,16)
        existing_names = []

        for k in range(1,16):
            parm_node = root.get_node(4,k)
            parm_name = parm_node.get_name()
            if not parm_node: continue
            parm_conn = parm_node.get_master()
            if not parm_conn: continue
            parm_master = parm_conn[0]

            if parm_master in canonical_names:
                parm_name = canonical_names[parm_master]
            else:
                split_name = parm_name.split()
                kstr = str(k)
                if split_name and split_name[-1]==kstr:
                    parm_name = ' '.join(split_name[:-1])

            if parm_master not in current_parms:
                current_parms[parm_master] = (k,parm_name)
                existing_names.append(parm_name)
                print 'existing source',k,'called',parm_name,'connected to',parm_master
                unused_parms.remove(k)

        for pname,pmaster in available_sources.items():
            if pmaster not in current_parms and pname not in existing_names:
                if unused_parms:
                    k = unused_parms[0]
                    unused_parms = unused_parms[1:]
                    current_parms[pmaster] = (k,pname)
                    print 'adding available source',k,pname,'from',pmaster


        print 'parameter map:'
        for pmaster,(k,pname) in current_parms.items():
            print 'parameter',k,'called',pname,'connected to',pmaster

        for k in range(1,17):
            parm_node = root.ensure_node(4,k)
            parm_node.set_meta('master',piw.data())
            parm_node.set_name('parameter %d' % k)
            
        for pmaster,(k,pname) in current_parms.items():
            if pmaster in blocked_sources:
                continue
            conn = logic.make_term('conn',None,None,pmaster,None)
            conn_txt = logic.render_term(conn)
            parm_node = root.ensure_node(4,k)
            parm_node.set_meta_string('master',conn_txt)
            parm_node.set_name(pname)
            print 'connected',parm_node.id(),'to',conn_txt,'called',pname,'parameter',k

        conn = logic.make_term('conn',None,None,paths.makeid_list(scaler_addr,1,2),None)
        conn_txt = logic.render_term(conn)
        parm_node = root.ensure_node(4,16)
        parm_node.set_meta_string('master',conn_txt)
        parm_node.set_name('key position')

        local_map = {}

        self.check_midi_controller(root,(6,4),7,current_parms,local_map) # volume
        self.check_midi_controller(root,(6,5),1,current_parms,local_map) # modwheel
        self.check_midi_controller(root,(6,6),10,current_parms,local_map) # pan
        self.check_midi_controller(root,(6,7),4,current_parms,local_map) # foot pedal
        self.check_midi_controller(root,(6,8),11,current_parms,local_map) # expression
        self.check_midi_controller(root,(6,9),130,current_parms,local_map) # channel pressure
        self.check_midi_controller(root,(6,10),128,current_parms,local_map) # poly pressure
        self.check_midi_controller(root,(6,11),131,current_parms,local_map) # pitch bend
        self.check_midi_controller(root,(6,12),64,current_parms,local_map) # sustain pedal

        print 'local map',local_map

        map_node = root.ensure_node(255,5)
        map_data = map_node.get_data()
        map_list = []

        if map_data.is_string() and map_data.as_string() and map_data.as_string() != '[]':
            print 'map data',map_data.as_string()
            map_term = logic.parse_term(map_data.as_string())
            map_list = map_term.args

        bits_14 = set([0x07,0x01,0x0a,0x04,0x0b])

        for cc,p in local_map.items():
            ccl = (cc+32) if cc<32 else -1
            res = const.resolution_bits_7 if cc not in bits_14 else const.resolution_bits_14
            map_list=list(map_list)
            map_list.append(logic.make_term('c',p,cc,1.0,0,0,1.0,True,const.scope_pernote,res,ccl))

        map_term = logic.make_term('mapping',*map_list)
        map_node.set_data(piw.makestring(logic.render_term(map_term),0))
Beispiel #5
0
 def value2data(self, v, t=0L):
     return piw.data()
Beispiel #6
0
    def phase2_1_0_2(self, tools, address):
        print 'upgrading converter', address
        root = tools.get_root(address)
        freq_input = root.ensure_node(2, 2)
        scaler_conn = freq_input.get_master()
        if not scaler_conn: return
        scaler_addr = paths.id2server(scaler_conn[0])
        scaler_root = tools.get_root(scaler_addr)
        if not scaler_root: return
        scaler_type = scaler_root.get_meta_string('plugin')
        if scaler_type != 'scaler': return
        print 'scaler is', scaler_addr
        scaler_pressure_input = scaler_root.get_node(4, 2)
        recorder_conn = scaler_pressure_input.get_master()
        if not recorder_conn: return
        recorder_addr = paths.id2server(recorder_conn[0])
        recorder_root = tools.get_root(recorder_addr)
        if not recorder_root: return
        recorder_type = recorder_root.get_meta_string('plugin')
        if recorder_type != 'recorder': return
        print 'recorder is', recorder_addr

        available_sources = {}
        available_sources['pressure'] = paths.makeid_list(scaler_addr, 1, 2)
        available_sources['roll'] = paths.makeid_list(scaler_addr, 1, 3)
        available_sources['yaw'] = paths.makeid_list(scaler_addr, 1, 4)
        available_sources['key position'] = paths.makeid_list(
            scaler_addr, 1, 2)

        for i in range(5, 15):
            recorder_input = recorder_root.get_node(1, i)
            if recorder_input:
                input_name = recorder_input.get_name()
                input_conn = recorder_input.get_master()
                if not input_conn: continue
                upstream_addr, upstream_path = paths.breakid_list(
                    input_conn[0])
                upstream_root = tools.get_root(upstream_addr)
                if not upstream_root: continue
                upstream = upstream_root.get_node(*upstream_path)
                if not upstream: continue
                upstream_name = upstream.get_name().split()
                if 'output' in upstream_name: upstream_name.remove('output')
                upstream_name = ' '.join(upstream_name)
                if upstream_name == 'controller': continue
                output_id = paths.makeid_list(recorder_addr, 2, i)
                print 'recorder output', i, 'at', output_id, 'called', input_name, 'connected to', upstream_name
                available_sources[upstream_name] = output_id

        for n, id in available_sources.items():
            print 'source', n, 'at', id

        desired_sources = {
            'pressure': 1,
            'roll': 2,
            'yaw': 3,
            'breath': 4,
            'strip position 1': 5,
            'absolute strip 1': 6,
            'strip position 2': 7,
            'absolute strip 2': 8,
            'pedal 1': 9,
            'pedal 2': 10,
            'pedal 3': 11,
            'pedal 4': 12,
            'key position': 16,
        }

        active_sources = {}

        for k in range(1, 17):
            parm_node = root.ensure_node(12, k)
            parm_node.set_meta('master', piw.data())
            parm_node.set_name('parameter %d' % k)

        for k, v in desired_sources.items():
            if k in available_sources:
                conn = logic.make_term('conn', None, None,
                                       available_sources[k], None)
                conn_txt = logic.render_term(conn)
                parm_node = root.ensure_node(12, v)
                parm_node.set_meta_string('master', conn_txt)
                parm_node.set_name(k)
                if v < 16:  # dont map anything to key position
                    active_sources[available_sources[k]] = v
                print 'connected', parm_node.id(), 'to', conn_txt, 'called', k

        print 'checking for midi output', active_sources

        my_controller = None

        all_agents = tools.get_agents()
        for agent in all_agents:
            agent_root = tools.get_root(agent)
            if not agent_root: continue
            agent_type = agent_root.get_meta_string('plugin')
            if agent_type != 'midi_output': continue
            agent_midi_input = agent_root.get_node(2)
            if not agent_midi_input: continue
            agent_conn = [
                paths.id2server(i) for i in agent_midi_input.get_master()
            ]
            print agent, 'is midi output', agent_conn, root.id()
            if root.id() not in agent_conn: continue
            print 'my midi output', agent
            for i in agent_conn:
                controller_root = tools.get_root(i)
                controller_type = controller_root.get_meta_string('plugin')
                if controller_type != 'midi_controller': continue
                my_controller = controller_root
                break
            if my_controller: break

        if not my_controller: return

        cc1 = self.get_midi_cc(my_controller, 1)
        cc2 = self.get_midi_cc(my_controller, 2)
        cc3 = self.get_midi_cc(my_controller, 3)
        cc4 = self.get_midi_cc(my_controller, 4)

        print 'midi controller', my_controller.id(), cc1, cc2, cc3, cc4

        global_map = {}

        self.check_midi_controller(my_controller, (2, 1), 7, active_sources,
                                   global_map)  # volume
        self.check_midi_controller(my_controller, (2, 2), 1, active_sources,
                                   global_map)  # modwheel
        self.check_midi_controller(my_controller, (2, 3), 10, active_sources,
                                   global_map)  # pan
        self.check_midi_controller(my_controller, (2, 4), 4, active_sources,
                                   global_map)  # foot pedal
        self.check_midi_controller(my_controller, (2, 5), 11, active_sources,
                                   global_map)  # EXPRESSION
        self.check_midi_controller(my_controller, (2, 6), 130, active_sources,
                                   global_map)  # channel pressure
        self.check_midi_controller(my_controller, (2, 7), 131, active_sources,
                                   global_map)  # pitch bend
        self.check_midi_controller(my_controller, (2, 8), 64, active_sources,
                                   global_map)  # sustain pedal
        self.check_midi_controller(my_controller, (2, 9), cc1, active_sources,
                                   global_map)
        self.check_midi_controller(my_controller, (2, 10), cc2, active_sources,
                                   global_map)
        self.check_midi_controller(my_controller, (2, 11), cc3, active_sources,
                                   global_map)
        self.check_midi_controller(my_controller, (2, 12), cc4, active_sources,
                                   global_map)

        local_map = {}

        self.check_midi_controller(root, (2, 4), 7, active_sources,
                                   local_map)  # volume
        self.check_midi_controller(root, (2, 5), 1, active_sources,
                                   local_map)  # modwheel
        self.check_midi_controller(root, (2, 6), 10, active_sources,
                                   local_map)  # pan
        self.check_midi_controller(root, (2, 7), 4, active_sources,
                                   local_map)  # foot pedal
        self.check_midi_controller(root, (2, 8), 11, active_sources,
                                   local_map)  # expression
        self.check_midi_controller(root, (2, 9), 130, active_sources,
                                   local_map)  # channel pressure
        self.check_midi_controller(root, (2, 10), 128, active_sources,
                                   local_map)  # poly pressure
        self.check_midi_controller(root, (2, 11), 131, active_sources,
                                   local_map)  # pitch bend
        self.check_midi_controller(root, (2, 12), 64, active_sources,
                                   local_map)  # sustain pedal

        print 'per key mappings', local_map
        print 'global mappings', global_map

        map_node = root.ensure_node(255, 1)
        map_data = map_node.get_data()
        map_list = []

        if map_data.is_string() and map_data.as_string(
        ) and map_data.as_string() != '[]':
            print 'map data', map_data.as_string()
            map_term = logic.parse_term(map_data.as_string())
            map_list = map_term.args

        bits_14 = set([0x07, 0x01, 0x0a, 0x04, 0x0b])

        for cc, p in local_map.items():
            ccl = (cc + 32) if cc < 32 else -1
            res = const.resolution_bits_7 if cc not in bits_14 else const.resolution_bits_14
            map_list = list(map_list)
            map_list.append(
                logic.make_term('c', p, cc, 1.0, 0, 0, 1.0, True,
                                const.scope_pernote, ccl, ccl))

        for cc, p in global_map.items():
            ccl = (cc + 32) if cc < 32 else -1
            res = const.resolution_bits_7 if cc not in bits_14 else const.resolution_bits_14
            map_list.append(
                logic.make_term('c', p, cc, 1.0, 0, 0, 1.0, True,
                                const.scope_global, ccl, ccl))

        map_term = logic.make_term('mapping', *map_list)
        map_node.set_data(piw.makestring(logic.render_term(map_term), 0))
Beispiel #7
0
    def __init__(self, agent, controller, index):
        collection.Collection.__init__(
            self,
            creator=self.__create,
            wrecker=self.__wreck,
            ordinal=index,
            names='key',
            protocols='hidden-connection remove explicit')
        self.__event = piw.fasttrigger(const.light_unknown)
        self.__event.attach_to(controller, index)
        self.__handler = piw.change2_nb(self.__event.trigger(),
                                        utils.changify(self.event_triggered))

        self.key_mapper = piw.function1(
            True, 2, 2, piw.data(),
            agent.light_aggregator.get_output(index + 1))
        self.key_mapper.set_functor(
            piw.d2d_const(utils.maketuple_longs((0, 0), 0)))
        self.key_aggregator = piw.aggregator(self.key_mapper.cookie(),
                                             agent.domain)

        self.agent = agent
        self.index = index

        self.set_private(node.Server(
            rtransient=True))  # kept in there for backwards compatibility
        self.set_internal(
            250,
            atom.Atom(domain=domain.Trigger(),
                      init=False,
                      names='activate',
                      policy=policy.TriggerPolicy(self.__handler),
                      transient=True))

        self.set_internal(
            247,
            atom.Atom(domain=domain.BoundedInt(0, 3),
                      names='default colour',
                      init=3,
                      policy=atom.default_policy(self.set_color)))
        self.set_internal(
            248,
            atom.Atom(domain=domain.BoundedInt(-32767, 32767),
                      names='key column',
                      init=0,
                      policy=atom.default_policy(self.__change_key_column)))
        self.set_internal(
            249,
            atom.Atom(domain=domain.BoundedInt(-32767, 32767),
                      names='key row',
                      init=0,
                      policy=atom.default_policy(self.__change_key_row)))
        self.set_internal(
            245,
            atom.Atom(domain=domain.Bool(),
                      names='key column end relative',
                      init=False,
                      policy=atom.default_policy(
                          self.__change_key_column_endrel)))
        self.set_internal(
            246,
            atom.Atom(domain=domain.Bool(),
                      names='key row end relative',
                      init=False,
                      policy=atom.default_policy(
                          self.__change_key_row_endrel)))

        self.agent.light_convertor.set_status_handler(
            self.index, self.__make_key_coordinate(),
            piw.slowchange(utils.changify(self.set_status)))