def areOnSameMachine(url1, url2): if url1 == url2: return True try: address1 = Address(url1) address2 = Address(url2) except BaseException: return False if address1.hostname == address2.hostname: return True try: if ((socket.gethostbyname(address1.hostname) in ('127.0.0.1', '127.0.1.1')) and ( socket.gethostbyname(address2.hostname) in ('127.0.0.1', '127.0.1.1'))): return True if socket.gethostbyaddr( address1.hostname) == socket.gethostbyaddr( address2.hostname): return True except BaseException: try: ips = subprocess.check_output(['hostname', '-I']).decode() ip = ips.split(' ')[0] if ip.count('.') != 3: return False if ip not in (address1.hostname, address2.hostname): return False try: if socket.gethostbyname( address1.hostname) in ( '127.0.0.1', '127.0.1.1'): if address2.hostname == ip: return True except BaseException: if socket.gethostbyname( address2.hostname) in ( '127.0.0.1', '127.0.1.1'): if address1.hostname == ip: return True except BaseException: return False return False return False
def are_on_same_machine(url1, url2): if url1 == url2: return True try: address1 = Address(url1) address2 = Address(url2) except BaseException: return False if address1.hostname == address2.hostname: return True try: if (socket.gethostbyname(address1.hostname) in ('127.0.0.1', '127.0.1.1') and socket.gethostbyname( address2.hostname) in ('127.0.0.1', '127.0.1.1')): return True if socket.gethostbyaddr(address1.hostname) == socket.gethostbyaddr( address2.hostname): return True ip = Machine192.get() if ip not in (address1.hostname, address2.hostname): return False if (ip == socket.gethostbyname(address1.hostname) == socket.gethostbyname(address2.hostname)): # on some systems (as fedora), # socket.gethostbyname returns a 192.168.. url return True if (socket.gethostbyname(address1.hostname) in ('127.0.0.1', '127.0.1.1')): if address2.hostname == ip: return True if (socket.gethostbyname(address2.hostname) in ('127.0.0.1', '127.0.1.1')): if address1.hostname == ip: return True except BaseException: return False return False
def connectToAddr(self, addr): global lo_target, lo_targetName self.lo_address = addr lo_target = Address(self.lo_address) lo_targetName = self.lo_address.rsplit("/", 1)[-1] print("Connecting to \"%s\" as '%s'..." % (self.lo_address, lo_targetName)) try: self.lo_server = ControlServer( self, LO_UDP if self.lo_address.startswith("osc.udp") else LO_TCP) except: # ServerError, err: print("Connecting error!") #print str(err) QMessageBox.critical( self, self.tr("Error"), self.tr("Failed to connect, operation failed.")) return if self.lo_server: self.lo_server.start() self.ui.act_file_refresh.setEnabled(True) lo_send(lo_target, "/register", self.lo_server.getFullURL()) self.fIdleTimerFast = self.startTimer(60) self.fIdleTimerSlow = self.startTimer(60 * 2)
def __init__(self, incoming, outgoing, sparseOutput=None, config={}, device_source='Muse', software_source='muselsl', debug_outputs=True, verbose=False): self.incoming = incoming self.outgoing = outgoing self.eeg_chunk_length = 12 self.threshold = 30 self.conc_level = 50 self.inc = 2 self._osc_server = ServerThread(incoming['port']) print('OSC server initialized at port {}.'.format(incoming['port'])) if not isinstance(self.outgoing, tuple): self.outgoing = [self.outgoing] self._output_threads = [] for out in self.outgoing: self._output_threads.append(Address(out['address'], out['port'])) print('OSC client initialized at {}:{}.'.format( out['address'], out['port'])) self._init_processing(config) self.incremented_value = 50
def areSameOscPort(url1, url2): if url1 == url2: return True try: address1 = Address(url1) address2 = Address(url2) except BaseException: return False if address1.port != address2.port: return False if areOnSameMachine(url1, url2): return True return False
def connectOsc(self, addr=None): global lo_target, lo_target_name if addr is not None: self.fOscAddress = addr lo_target = Address(self.fOscAddress) lo_target_name = self.fOscAddress.rsplit("/", 1)[-1] print("Connecting to \"%s\" as '%s'..." % (self.fOscAddress, lo_target_name)) try: self.fOscServer = CarlaControlServer( self.host, LO_UDP if self.fOscAddress.startswith("osc.udp") else LO_TCP) except: # ServerError as err: QMessageBox.critical( self, self.tr("Error"), self.tr("Failed to connect, operation failed.")) return self.fIdleTimer = self.startTimer(20) lo_send(lo_target, "/register", self.fOscServer.getFullURL()) self.startTimers() self.ui.act_file_refresh.setEnabled(True)
def are_same_osc_port(url1, url2): if url1 == url2: return True try: address1 = Address(url1) address2 = Address(url2) except BaseException: return False if address1.port != address2.port: return False if are_on_same_machine(url1, url2): return True return False
def areOnSameMachine(url1, url2): if url1 == url2: return True try: address1 = Address(url1) address2 = Address(url2) except BaseException: return False if address1.hostname == address2.hostname: return True try: if (socket.gethostbyname(address1.hostname) in ('127.0.0.1', '127.0.1.1') and socket.gethostbyname( address2.hostname) in ('127.0.0.1', '127.0.1.1')): return True if socket.gethostbyaddr(address1.hostname) == socket.gethostbyaddr( address2.hostname): return True except BaseException: try: ip = Machine192.get() if ip not in (address1.hostname, address2.hostname): return False try: if socket.gethostbyname(address1.hostname) in ('127.0.0.1', '127.0.1.1'): if address2.hostname == ip: return True except BaseException: if socket.gethostbyname(address2.hostname) in ('127.0.0.1', '127.0.1.1'): if address1.hostname == ip: return True except BaseException: return False return False return False
def getMachine192ByUrl(url): try: addr = Address(url) except BaseException: return '' hostname = addr.hostname del addr return getMachine192(hostname)
def __init__(self): QObject.__init__(self) self.sl_process = QProcess() self.sl_process.setProcessChannelMode(QProcess.ForwardedChannels) self.sl_process.finished.connect(self.slProcessFinished) self.sl_port = ray.getFreeOscPort(9951) self.sl_url = Address(self.sl_port) self.sl_process.start('sooperlooper', ['-p', str(self.sl_port)]) self.gui_process = QProcess() self.gui_process.setProcessChannelMode(QProcess.ForwardedChannels) self.gui_process.started.connect(self.guiProcessStarted) self.gui_process.finished.connect(self.guiProcessFinished) self.project_path = '' self.session_path = '' self.session_name = '' self.full_client_id = '' self.session_file = '' self.session_bak = '' self.midi_bindings_file = '' self.file_timer = QTimer() self.file_timer.setInterval(100) self.file_timer.timeout.connect(self.checkFile) self.n_file_timer = 0 signaler.server_sends_open.connect(self.initialize) signaler.server_sends_save.connect(self.saveSlSession) signaler.show_optional_gui.connect(self.showOptionalGui) signaler.hide_optional_gui.connect(self.hideOptionalGui) self.sl_ready.connect(self.loadSession) self.leaving = False self.wait_for_load = False self.showOptionalGui() self.ping_timer = QTimer() self.ping_timer.setInterval(100) self.ping_timer.timeout.connect(self.pingSL) self.ping_timer.start() self.transport_timer = QTimer() self.transport_timer.setInterval(2) self.transport_timer.timeout.connect(self.checkTransport) self.transport_playing = False self.will_trig = False
def send_server_lose(self): self.send_gui('/ray/gui/patchbay/server_lose') # In the case server is not responding # and gui has not yet been added to gui_list # but gui url stocked in self._tmp_gui_url if not self.gui_list and self._tmp_gui_url: try: addr = Address(self._tmp_gui_url) except: return self.send(addr, '/ray/gui/patchbay/server_lose')
def start(self): if self.launched_before: self.callDaemon() return ray_control_process = QProcess() ray_control_process.start("ray_control", ['get_port_gui_free']) ray_control_process.waitForFinished(2000) if ray_control_process.exitCode() == 0: port_str_lines = ray_control_process.readAllStandardOutput().data( ).decode('utf-8') port_str = port_str_lines.partition('\n')[0] if port_str and port_str.isdigit(): self.address = Address(int(port_str)) self.port = self.address.port self.url = self.address.url self.launched_before = True self.is_local = True self.callDaemon() return server = GUIServerThread.instance() if not server: sys.stderr.write( "impossible for GUI to launch daemon. server missing.\n") # start process arguments = [ '--gui-url', str(server.url), '--osc-port', str(self.port), '--session-root', CommandLineArgs.session_root ] if CommandLineArgs.session: arguments.append('--session') arguments.append(CommandLineArgs.session) if CommandLineArgs.debug_only: arguments.append('--debug-only') elif CommandLineArgs.debug: arguments.append('--debug') elif CommandLineArgs.no_client_messages: arguments.append('--no-client-messages') if CommandLineArgs.config_dir: arguments.append('--config-dir') arguments.append(CommandLineArgs.config_dir) self.process.startDetached('ray-daemon', arguments)
def add_gui(self, gui_url): gui_addr = Address(gui_url) if gui_addr is None: return self.send(gui_addr, '/ray/gui/patchbay/announce', int(self.main_object.jack_running), self.main_object.samplerate, self.main_object.buffer_size) self.send(gui_addr, '/ray/gui/patchbay/dsp_load', self.main_object.last_sent_dsp_load) if areOnSameMachine(gui_url, self.url): self.send_local_data([gui_addr]) else: self.send_distant_data([gui_addr]) self.gui_list.append(gui_addr)
def start(self): if self.launched_before: self._call_daemon() return if not CommandLineArgs.force_new_daemon: ray_control_process = QProcess() ray_control_process.start( "ray_control", ['get_port_gui_free', CommandLineArgs.session_root]) ray_control_process.waitForFinished(2000) if ray_control_process.exitCode() == 0: port_str_lines = \ ray_control_process.readAllStandardOutput().data().decode('utf-8') port_str = port_str_lines.partition('\n')[0] if port_str and port_str.isdigit(): self.address = Address(int(port_str)) self._port = self.address.port self.url = self.address.url self.launched_before = True self.is_local = True self._call_daemon() sys.stderr.write("\033[92m%s\033[0m\n" % (_translate( 'GUI_daemon', "Connecting GUI to existing ray-daemon port %i") % self._port)) if CommandLineArgs.start_session: server = GuiServerThread.instance() if server: server.send(self.address, '/ray/server/open_session', CommandLineArgs.start_session) return server = GuiServerThread.instance() if not server: sys.stderr.write( "impossible for GUI to launch daemon. server missing.\n") # start process arguments = [ '--gui-url', str(server.url), '--gui-pid', str(os.getpid()), '--osc-port', str(self._port), '--session-root', CommandLineArgs.session_root ] if CommandLineArgs.start_session: arguments.append('--session') arguments.append(CommandLineArgs.start_session) if CommandLineArgs.debug_only: arguments.append('--debug-only') elif CommandLineArgs.debug: arguments.append('--debug') elif CommandLineArgs.no_client_messages: arguments.append('--no-client-messages') if CommandLineArgs.config_dir: arguments.append('--config-dir') arguments.append(CommandLineArgs.config_dir) self._process.startDetached('ray-daemon', arguments)
def __init__(self, incoming, outgoing, sparseOutput=None, config={}, device_source='Muse', software_source='muselsl', debug_outputs=True, verbose=False): self.incoming = incoming self.outgoing = outgoing self.sparseOutput = sparseOutput self.device_source = device_source self.software_source = software_source self.debug_outputs = debug_outputs self.verbose = verbose self.eeg_chunk_length = 12 # 1. Initialize inlet if isinstance(self.incoming, str): # LSL inlet print('Looking for the {} stream...'.format(incoming)) self._stream = resolve_byprop('type', incoming, timeout=2) if len(self._stream) == 0: raise (RuntimeError('Can\'t find {} stream.'.format(incoming))) print('Aquiring data from the \'{}\' stream...'.format(incoming)) self._inlet = StreamInlet(self._stream[0], max_chunklen=self.eeg_chunk_length) self._info_in = self._inlet.info() else: # OSC port if USE_LIBLO: self._osc_server = ServerThread(incoming['port']) print('OSC server initialized at port {}.'.format( incoming['port'])) else: self._dispatcher = dispatcher.Dispatcher() print('python-osc dispatcher initialized.') # 2. Initialize outlets if not isinstance(self.outgoing, tuple): self.outgoing = [self.outgoing] self._output_threads = [] for out in self.outgoing: if isinstance(out, str): # LSL outlet raise NotImplementedError elif isinstance(out, dict): # OSC port if USE_LIBLO: self._output_threads.append( Address(out['address'], out['port'])) else: raise NotImplementedError # self._client = udp_client.SimpleUDPClient( # outgoing['address'], outgoing['port']) print('OSC client initialized at {}:{}.'.format( out['address'], out['port'])) if (self.sparseOutput != None): if not isinstance(self.sparseOutput, tuple): self.sparseOutput = [self.sparseOutput] self._sparseOutput_threads = [] for out in self.sparseOutput: if isinstance(out, str): # LSL outlet raise NotImplementedError elif isinstance(out, dict): # OSC port if USE_LIBLO: self._sparseOutput_threads.append( Address(out['address'], out['port'])) else: raise NotImplementedError print('OSC sparse output client initialized at {}:{}.'. format(out['address'], out['port'])) # 3. Initialize internal buffers and variables self._init_processing(config)
def connectOsc(self, addrTCP=None, addrUDP=None, rhost=None): if self.fCustomOscAddress is not None: addrTCP = self.fCustomOscAddress.replace("osc.udp://", "osc.tcp://") addrUDP = self.fCustomOscAddress.replace("osc.tcp://", "osc.udp://") else: if addrTCP is not None: self.fOscAddressTCP = addrTCP if addrUDP is not None: self.fOscAddressUDP = addrUDP if rhost is not None: self.fOscReportedHost = rhost lo_target_tcp_name = addrTCP.rsplit("/", 1)[-1] lo_target_udp_name = addrUDP.rsplit("/", 1)[-1] err = None try: lo_target_tcp = Address(addrTCP) lo_server_tcp = CarlaControlServerTCP(self.host, rhost) lo_send(lo_target_tcp, "/register", lo_server_tcp.getFullURL()) lo_target_udp = Address(addrUDP) lo_server_udp = CarlaControlServerUDP(self.host, rhost) lo_send(lo_target_udp, "/register", lo_server_udp.getFullURL()) except AddressError as e: err = e except OSError as e: err = e except: err = Exception() if err is not None: fullError = self.tr("Failed to connect to the Carla instance.") if len(err.args) > 0: fullError += " %s\n%s\n" % (self.tr("Error was:"), err.args[0]) fullError += "\n" fullError += self.tr( "Make sure the remote Carla is running and the URL and Port are correct." ) + "\n" fullError += self.tr( "If it still does not work, check your current device and the remote's firewall." ) CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Connection failed"), fullError, QMessageBox.Ok, QMessageBox.Ok) return self.host.lo_server_tcp = lo_server_tcp self.host.lo_target_tcp = lo_target_tcp self.host.lo_target_tcp_name = lo_target_tcp_name self.host.lo_server_udp = lo_server_udp self.host.lo_target_udp = lo_target_udp self.host.lo_target_udp_name = lo_target_udp_name self.ui.act_file_refresh.setEnabled(True) self.startTimers()
def setNewOscAddress(self): if not (self.address or self.port): self.port = ray.getFreeOscPort() self.address = Address(self.port)
def set_new_osc_address(self): if not (self.address or self._port): self._port = ray.get_free_osc_port() self.address = Address(self._port)
""" Audition audio reconstruction from Supercollider, since I do not want to write granular synthesis in python. """ from liblo import send, Address ADDRESS = Address('localhost', 57120) def file(filename): send(ADDRESS, '/file', filename) def note(start_time, gain, rate, **kwargs): ns = list(start_time.ravel()) + list(gain.ravel()) + list(rate.ravel()) floats = [float(f) for f in ns] send(ADDRESS, '/note', *floats)