def get_connections(self): if self.__connections is not None: return self.__connections connections = {} for i in range(0,self.__snap.agent_count()): agent = self.__snap.get_agent_index(i) address = agent.get_address() root = agent.get_root() signature = root.get_data() if agent.get_type()>1 or not signature.is_dict(): continue node = Node(root,address,(),self) for a in node.iter_tree(): tgt = a.id() for src in a.get_master(): src_server,src_path = paths.breakid_list(src) connections.setdefault(src_server,{}).setdefault(tuple(src_path),set()).add(tgt) self.__connections = connections return connections
def __getfullname(snap, cache, address): (id, path) = paths.breakid_list(address) if id in cache: return paths.makeid_list(cache[id], *path) agent = snap.get_agent_address(0, id, False) if not agent.isvalid(): agent = snap.get_agent_address(1, id, False) if not agent.isvalid(): cache[id] = id return paths.makeid_list(id, *path) root = agent.get_root() sig = root.get_data().as_string().split(':') parent_name = None if guid.isguid(address) and len(sig) > 3: parent = __findroot(snap, guid.split(address)[0]) parent_name = __getfullname(snap, cache, parent) node = Node(root, id, ()) name = node.getname() if parent_name: name = parent_name + ' ' + name cache[id] = name return paths.makeid_list(name, *path)
def mimic_connections(self,fr,to,name,argstocopy=(0,1,3)): from_input = self.get_node(*fr) if from_input: input_name = from_input.get_name() input_connections = from_input.get_meta('master') if input_connections and input_connections.is_string() and input_connections.as_string(): input_connections_parsed = logic.parse_termlist(input_connections.as_string()) output_connections = [] if input_connections_parsed: for input_conn in input_connections_parsed: upstream_addr,upstream_path = paths.breakid_list(input_conn.args[2]) upstream_root = self.tools.get_root(upstream_addr) if upstream_root: upstream_node = upstream_root for n in upstream_path[:-1]: c = upstream_node.get_node(n) if c: upstream_node = c for c in upstream_node.iter(): if name == c.get_name(): conn = logic.make_term('conn',input_conn.args[0] if 0 in argstocopy else None,input_conn.args[1] if 1 in argstocopy else None,c.id(),input_conn.args[3] if 3 in argstocopy else None) output_connections.append(conn) if len(output_connections): conn_txt = logic.render_termlist(output_connections) c = self.ensure_node(*to) c.set_meta_string('master', conn_txt) print 'connected',name,'for',c.id(),'from',conn_txt
def move_connections(self,old_id,new_id): connections = self.get_connections() old_server,old_path = paths.breakid_list(old_id) old_path = tuple(old_path) old_path_len = len(old_path) old_connections = connections.get(old_server,{}) new_server,new_path = paths.breakid_list(new_id) new_path = tuple(new_path) for src_path,tgt_id_set in old_connections.items(): if src_path[:old_path_len] == old_path: old_src_id = paths.makeid_list(old_server,*src_path) new_src_id = paths.makeid_list(new_server,*(new_path+src_path[old_path_len:])) for tgt_id in tgt_id_set: tgt_server,tgt_path = paths.breakid_list(tgt_id) tgt_node = self.get_root(tgt_server).get_node(*tgt_path) if tgt_node: tgt_node.move_connection(old_src_id,new_src_id)
def dump_agent(db, snap, address): (name, path) = paths.breakid_list(address) agents = snap.agent_count() for i in range(0, agents): agent = snap.get_agent_index(i) if agent.get_address() == name: dump_node(db, snap, address, agent, path) return print 'No agent', name
def __getportname(snap, address): (id, path) = paths.breakid_list(address) agent = snap.get_agent_address(0, id, False) if not agent.isvalid(): agent = snap.get_agent_address(1, id, False) if not agent.isvalid(): return id, '.'.join([str(p) for p in path]) agent_node = Node(agent.get_root(), id, ()) port_node = agent_node.get_node(*path) port_name = port_node.get_node(255, 8) if not port_name: return id, '.'.join([str(p) for p in path]) return id, port_name.get_data().as_string()
def __getname(snap, cache, address): (id, path) = paths.breakid_list(address) if id in cache: return paths.makeid_list(cache[id], *path) agent = snap.get_agent_address(0, id, False) if not agent.isvalid(): agent = snap.get_agent_address(1, id, False) if not agent.isvalid(): cache[id] = id return paths.makeid_list(id, *path) root = agent.get_root() node = Node(root, id, ()) name = node.getname() cache[id] = name return paths.makeid_list(name, *path)
def __substitute_connection(self, tgt, old_id, new_id): (s, p) = paths.breakid_list(tgt) root = self.root(s) atom = root.get_node(*p) if atom is None: return conn = atom.get_node(255, 2) if conn is None: return old_conn = logic.parse_clauselist(conn.get_string_default('')) new_conn = [] for c in old_conn: if c.args[2] == old_id: new_conn.append( logic.make_term(c.pred, c.args[0], c.args[1], new_id, c.args[3])) else: new_conn.append(c) conn.set_string(logic.render_termlist(new_conn))
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))