def __init__(self, stageaddress, midiportindex): Subscriber.__init__(self) self.setThreading(True) self.publisher = LivePublisher() self.midiRouter = Showtime_Live.MidiRouter.MidiRouter(midiportindex) if not self.midiRouter.midiActive(): print("--- No midi loopback port available, incoming messages to Ableton will be considerably slower") print("--- Is loopMidi running?\n") if not stageaddress: print("Creating internal stage at tcp://127.0.0.1:6000") self.stageNode = ZstNode("ShowtimeStage") port = 6000 address = "tcp://*:" + str(port) self.stageNode.reply.socket.bind(address) self.stageNode.start() stageaddress = "127.0.0.1:" + str(port) # Create showtime node self.node = ZstNode("LiveNode", stageaddress) self.node.start() self.node.request_register_node() self.register_methods() self.subscribeMatch('[^' + PyroPrefixes.DELIMITER + ']*') self.registrar = RegistrationThread(self.node) self.registrar.daemon = True self.registrar.start()
def __init__(self, stageName="stage", port=6000): ZstNode.__init__(self, stageName) self.zeroconf = Zeroconf() address = "tcp://*:" + str(port) self.reply.socket.bind(address) desc = {'name': self.name} addr = socket.gethostbyname(socket.gethostname()) servicename = "ShowtimeStage" self.stageServiceInfo = ServiceInfo("_zeromq._tcp.local.", servicename + "._zeromq._tcp.local.", socket.inet_aton(addr), port, 0, 0, desc) self.zeroconf.register_service(self.stageServiceInfo) print("Stage active on address " + str(self.reply.socket.getsockopt(zmq.LAST_ENDPOINT)))
def __init__(self, stageaddress): threading.Thread.__init__(self) self.name = "LiveRouter" Log.set_log_network(True) self.exitFlag = 0 self.daemon = True self.serverID = str(uuid.uuid4())[:8] if not stageaddress: print("Creating internal stage at tcp://127.0.0.1:6000") port = 6000 self.stageNode = ZstStage("ShowtimeStage", port) self.stageNode.start() stageaddress = "127.0.0.1:" + str(port) # Create showtime node self.node = ZstNode("LiveNode", stageaddress) self.node.start() self.node.request_register_node() # Create registration thread self.registrar = RegistrationThread(self.node) self.registrar.daemon = True self.registrar.start() # Create sockets self.tcpEndpoint = TCPEndpoint(6003, 6004, True, True) self.udpEndpoint = UDPEndpoint(6001, 6002, True, self.serverID) self.tcpEndpoint.add_event_callback(self.event) self.udpEndpoint.add_event_callback(self.event) self.tcpEndpoint.add_ready_callback(self.endpoint_ready) self.udpEndpoint.add_ready_callback(self.endpoint_ready) self.inputSockets = {self.tcpEndpoint.socket: self.tcpEndpoint, self.udpEndpoint.socket: self.udpEndpoint} self.outputSockets = {} self.client = None self.clientConnected = False self.clientConnectedCallback = None self.set_client_connection_status(False)
def close(self): self.zeroconf.unregister_service(self.stageServiceInfo) self.zeroconf.close() ZstNode.close(self)
class LiveRouter(threading.Thread): def __init__(self, stageaddress): threading.Thread.__init__(self) self.name = "LiveRouter" Log.set_log_network(True) self.exitFlag = 0 self.daemon = True self.serverID = str(uuid.uuid4())[:8] if not stageaddress: print("Creating internal stage at tcp://127.0.0.1:6000") port = 6000 self.stageNode = ZstStage("ShowtimeStage", port) self.stageNode.start() stageaddress = "127.0.0.1:" + str(port) # Create showtime node self.node = ZstNode("LiveNode", stageaddress) self.node.start() self.node.request_register_node() # Create registration thread self.registrar = RegistrationThread(self.node) self.registrar.daemon = True self.registrar.start() # Create sockets self.tcpEndpoint = TCPEndpoint(6003, 6004, True, True) self.udpEndpoint = UDPEndpoint(6001, 6002, True, self.serverID) self.tcpEndpoint.add_event_callback(self.event) self.udpEndpoint.add_event_callback(self.event) self.tcpEndpoint.add_ready_callback(self.endpoint_ready) self.udpEndpoint.add_ready_callback(self.endpoint_ready) self.inputSockets = {self.tcpEndpoint.socket: self.tcpEndpoint, self.udpEndpoint.socket: self.udpEndpoint} self.outputSockets = {} self.client = None self.clientConnected = False self.clientConnectedCallback = None self.set_client_connection_status(False) def run(self): while not self.exitFlag: inputready = [] outputready = [] exceptready = [] try: inputready, outputready, exceptready = select.select(self.inputSockets.keys(), self.outputSockets.keys(), [], 1) except socket.error, e: if e[0] == NetworkErrors.EBADF: Log.error("Bad file descriptor! Probably a dead socket passed to select") Log.debug(self.inputSockets.keys()) Log.debug(self.outputSockets.keys()) for s in inputready: if s == self.tcpEndpoint.socket: if self.client: Log.error("Live instance already connected. Only one instance can be connected at a time!") return client, address = self.tcpEndpoint.socket.accept() Log.network("New client connecting. Socket is %s" % client) endpoint = TCPEndpoint(-1, -1, True, False, client) endpoint.add_event_callback(self.event) endpoint.add_client_handshake_callback(self.incoming_client_handshake) endpoint.connectionStatus = NetworkEndpoint.PIPE_CONNECTED # endpoint.add_ready_callback(self.endpoint_ready) self.inputSockets[client] = endpoint self.outputSockets[client] = endpoint self.client = endpoint self.set_client_connection_status(True) elif s == self.udpEndpoint.socket: try: self.udpEndpoint.recv_msg() except ReadError: pass # Log.network("Read failed. UDP probably closed. %s" % e) except RuntimeError, e: Log.network("Receive failed. Reason: %s" % e) else: endpoint = self.inputSockets[s] try: endpoint.recv_msg() except (ReadError, RuntimeError): Log.network("Client socket closed") endpoint.close() self.set_client_connection_status(False) self.client = None try: del self.inputSockets[endpoint.socket] del self.outputSockets[endpoint.socket] try: outputready.remove(endpoint.socket) except ValueError: pass except KeyError: Log.network("Socket missing. In hangup") for s in outputready: try: endpoint = self.outputSockets[s] except KeyError: continue try: while 1: msg = endpoint.outgoingMailbox.get_nowait() endpoint.send(msg) except Queue.Empty: pass if endpoint.enteringImmediate: try: del self.outputSockets[endpoint.socket] except KeyError: pass endpoint.enteringImmediate = False endpoint.immediate = True for s in exceptready: Log.error("Socket %s in select() except list!. Check for errors." % s)
class LiveRouter(Subscriber): def __init__(self, stageaddress, midiportindex): Subscriber.__init__(self) self.setThreading(True) self.publisher = LivePublisher() self.midiRouter = Showtime_Live.MidiRouter.MidiRouter(midiportindex) if not self.midiRouter.midiActive(): print("--- No midi loopback port available, incoming messages to Ableton will be considerably slower") print("--- Is loopMidi running?\n") if not stageaddress: print("Creating internal stage at tcp://127.0.0.1:6000") self.stageNode = ZstNode("ShowtimeStage") port = 6000 address = "tcp://*:" + str(port) self.stageNode.reply.socket.bind(address) self.stageNode.start() stageaddress = "127.0.0.1:" + str(port) # Create showtime node self.node = ZstNode("LiveNode", stageaddress) self.node.start() self.node.request_register_node() self.register_methods() self.subscribeMatch('[^' + PyroPrefixes.DELIMITER + ']*') self.registrar = RegistrationThread(self.node) self.registrar.daemon = True self.registrar.start() def close(self): self.registrar.stop() self.node.close() if(hasattr(self, "stageNode")): self.stageNode.close() self.getDaemon().shutdown(True) self.midiRouter.close() def register_methods(self): if(self.midiRouter.midiActive()): self.node.request_register_method( "play_note", ZstMethod.WRITE, { "trackindex": None, "note": None, "state": None, "velocity": None }, self.midiRouter.play_midi_note) def event(self, event): methodName = event.subject[2:] pyroType = event.subject[:1] if pyroType == PyroPrefixes.REGISTRATION: self.registrar.add_registration_request(methodName, event.msg["methodaccess"], event.msg["args"], self.incoming) elif pyroType == PyroPrefixes.OUTGOING or pyroType == PyroPrefixes.RESPONDER: print "Live-->ST: " + str(event.subject) + '=' + str(event.msg) if methodName in self.node.methods: self.node.update_local_method_by_name(methodName, event.msg) else: print "Outgoing method not registered!" def incoming(self, message): print "ST-->Live: " + str(message.name) args = message.args if message.args else {} self.publisher.send_to_live(message.name, args)