def _receive_announce(self, src_addr, version, server_status, options, session_root, is_net_free): self._announce_timer.stop() if version.split('.')[:2] != ray.VERSION.split('.')[:2]: # works only if the two firsts digits are the same (ex: 0.6) self.signaler.daemon_url_request.emit(ErrDaemon.WRONG_VERSION, self.url) self.disannounce(src_addr) return if (CommandLineArgs.net_session_root and session_root != CommandLineArgs.net_session_root): self.signaler.daemon_url_request.emit(ErrDaemon.WRONG_ROOT, self.url) self.disannounce(src_addr) return if not is_net_free: self.signaler.daemon_url_request.emit(ErrDaemon.FORBIDDEN_ROOT, self.url) self.disannounce(src_addr) return if (CommandLineArgs.out_daemon and server_status != ray.ServerStatus.OFF): self.signaler.daemon_url_request.emit(ErrDaemon.NOT_OFF, self.url) self.disannounce(src_addr) return self._is_announced = True self.address = src_addr self._port = src_addr.port self.url = src_addr.url self.session_root = session_root CommandLineArgs.change_session_root(self.session_root) self._is_nsm_locked = options & ray.Option.NSM_LOCKED if self._is_nsm_locked: if self.main_win is not None: self.main_win.set_nsm_locked(True) elif CommandLineArgs.under_nsm: server = GuiServerThread.instance() server.to_daemon('/ray/server/set_nsm_locked') if self.main_win is not None and self.main_win.waiting_for_patchbay: self.main_win.waiting_for_patchbay = False server = GuiServerThread.instance() server.to_daemon('/ray/server/ask_for_patchbay') self.signaler.daemon_announce_ok.emit() self.session.set_daemon_options(options)
def to_daemon(cls, *args): server = GuiServerThread.instance() if server: server.to_daemon(*args) else: sys.stderr.write('Error No GUI OSC Server, can not send %s.\n' % args)
def remove_favorite(self, template_name: str, factory: bool): for favorite in self.favorite_list: if favorite.name == template_name and favorite.factory == factory: break server = GuiServerThread.instance() if server: server.to_daemon('/ray/favorites/remove', template_name, int(factory))
def stop(self): if self.launched_before: self.disannounce() QTimer.singleShot(10, QApplication.quit) return server = GuiServerThread.instance() server.to_daemon('/ray/server/quit') QTimer.singleShot(50, QApplication.quit)
def _save(self): if self.session.main_win: self.session.main_win.save_window_settings() self.wait_for_save = True server = GuiServerThread.instance() if server: server.save_session()
def _open(self, project_path: str, session_name: str, jack_client_name: str): self.wait_for_open = True self.project_path = project_path server = GuiServerThread.instance() if server: server.open_session(project_path, 0) self.send_gui_state(self.session.main_win.isVisible())
def send_properties_to_daemon(self): server = GuiServerThread.instance() if not server: sys.stderr.write( 'Server not found. Client %s can not send its properties\n' % self.client_id) return server.to_daemon('/ray/client/update_properties', *ray.ClientData.spread_client(self))
def send_ray_hack(self): if self.protocol != ray.Protocol.RAY_HACK: return server = GuiServerThread.instance() if not server: return server.to_daemon('/ray/client/update_ray_hack_properties', self.client_id, *self.ray_hack.spread())
def _open(self, project_path: str, session_name: str, jack_client_name: str): self.wait_for_open = True #Here project_path is used for template if needed template_name = jack_client_name server = GuiServerThread.instance() if server: server.open_session(project_path, 0, template_name) self.send_gui_state(self.session.main_win.isVisible())
def __init__(self): self.client_list = [] self.trashed_clients = [] self.favorite_list = [] self.recent_sessions = [] self.name = '' self.path = '' self.notes = '' self.server_status = ray.ServerStatus.OFF self.is_renameable = True self.signaler = Signaler() self.patchbay_manager = PatchbayManager(self) server = GuiServerThread.instance() server.start() self.daemon_manager = DaemonManager(self) if CommandLineArgs.daemon_url: self.daemon_manager.set_osc_address(CommandLineArgs.daemon_url) elif CommandLineArgs.daemon_port: self.daemon_manager.set_osc_address(CommandLineArgs.daemon_port) elif not CommandLineArgs.out_daemon: self.daemon_manager.set_new_osc_address() # build nsm_child if NSM_URL in env self.nsm_child = None if CommandLineArgs.under_nsm: if CommandLineArgs.out_daemon: self.nsm_child = NsmChildOutside(self) self.daemon_manager.set_external() else: self.nsm_child = NsmChild(self) # build and show Main UI self.main_win = MainWindow(self) self.daemon_manager.finish_init() self.patchbay_manager.finish_init() server.finish_init(self) self.main_win.show() # display donations dialog under conditions if not RS.is_hidden(RS.HD_Donations): coreff_counter = RS.settings.value('coreff_counter', 0, type=int) coreff_counter += 1 RS.settings.setValue('coreff_counter', coreff_counter) if coreff_counter % 44 == 29: self.main_win.donate(True)
def disannounce(self, address=None): if not address: address = self.address if address: server = GuiServerThread.instance() server.disannounce(address) self._port = None self.url = '' del self.address self.address = None self._is_announced = False
def dropEvent(self, event): QListWidget.dropEvent(self, event) client_ids_list = [] for i in range(self.count()): item = self.item(i) #widget = self.itemWidget(item) client_id = item.get_client_id() client_ids_list.append(client_id) server = GuiServerThread.instance() if server: server.to_daemon('/ray/session/reorder_clients', *client_ids_list)
def _call_daemon(self): if not self.address: # I don't know really why, but it works only with a timer QTimer.singleShot(5, self._show_daemon_url_window) return self._announce_timer.start() server = GuiServerThread.instance() if not server: sys.stderr.write( 'GUI can not call daemon, GUI OSC server is missing.\n') return server.announce()
def signal_handler(sig, frame): if sig in (signal.SIGINT, signal.SIGTERM): if session.daemon_manager.launched_before: if (CommandLineArgs.under_nsm and session.server_status != ray.ServerStatus.OFF): session.main_win.terminate_request = True l_server = GuiServerThread.instance() if l_server: l_server.abort_session() else: session.daemon_manager.stop() return session.main_win.terminate_request = True session.daemon_manager.stop()
def add_favorite(self, template_name: str, icon_name: str, factory: bool): server = GuiServerThread.instance() if server: server.to_daemon('/ray/favorites/add', template_name, icon_name, int(factory))
def to_daemon(cls, *args): server = GuiServerThread.instance() if server: server.to_daemon(*args)
parser = ArgParser() init_gui_tools() # Add raysession/src/bin to $PATH # to can use raysession after make, whitout install ray.add_self_bin_to_path() #connect signals signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) #needed for signals SIGINT, SIGTERM timer = QTimer() timer.start(200) timer.timeout.connect(lambda: None) #build session server = GuiServerThread() session = SignaledSession() app.exec() # TODO find something better, sometimes program never ends without. #time.sleep(0.002) server.stop() session.quit() del session del app
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)