def check_func_available(self): self.current = SocketCom("server").call_func("get", "eq_current") eqid, desc, is_playing, eq_profile, is_dyn = (self.current) if eqid == -1: # Dialog equalizer not installed xbmcgui.Dialog().ok(tr(32004), tr(32035)) return False, eqid, desc, is_playing, eq_profile, is_dyn if is_playing and eq_profile == 'off' and is_dyn: # Dialog switch on? if not xbmcgui.Dialog().yesno(tr(32000), tr(32003)): return False, eqid, desc, is_playing, eq_profile, is_dyn else: SocketCom("server").call_func("switch", "eq_on") count = 10 while count > 0: count = count - 1 self.current = SocketCom("server").call_func( "get", "eq_current") eqid, desc, is_playing, eq_profile, is_dyn = (self.current) if eqid is not None: return True, eqid, desc, is_playing, eq_profile, is_dyn sleep(0.1) # Dialog problem switch on xbmcgui.Dialog().ok(tr(32004), tr(32005)) return False, eqid, desc, is_playing, eq_profile, is_dyn # all ok return True, eqid, desc, is_playing, eq_profile, is_dyn
def __init__( self, *args, **_kwargs ): self.cwd = args[1] self.skin = args[2] self.sock = SocketCom("server") result = self.sock.call_func("get","eq_channel") if result is None: return self.eqid, self.name, channel = (result) self.channel_id = channel ch_index = [] for ch_name in channel: try: index = chan_num.index(ch_name) ch_index.append(index) except Exception as e: opthandle(e) self.channel = ch_index self.profiles = [tr(32413)] + self.sock.call_func("get","eq_profiles") self.save_profile = self.sock.call_func("get","eq_base_profile") self.sock.call_func("unload","eq_profile",[self.eqid]) self.corrections =[tr(32411)] + self.sock.call_func("get","room_corrections") self.save_correction = self.sock.call_func("get","room_correction") self.sock.call_func("unset","room_correction" , [self.eqid])
def __init__(self, *args, **kwargs): self.sock = SocketCom("server") self.path = os.path.join(args[1], "resources/skins/" + args[2] + "/media") self.progress1 = None self.updown = kwargs["updown"] try: step = (float(get_user_setting("sysvolstep", 0)) + 1) / 100 except Exception: step = float(0.01) if step <= 0: step = float(0.01) self.dyn_step = DynStep(step, 0.05, 0.01, 3) self.key_up = None self.key_down = None self.updating = False self.vol = self.sock.call_func("get", "volume") if self.updown == "up": self.vol_up() elif self.updown == "down": self.vol_down() self.last = time.time() if self.updown != "none": threading.Thread(target=self.check_close).start()
def __init__( self ): #strat process xbmc.Monitor.__init__( self ) xbmc.log("eq: start PulesEqualizer service",xbmc.LOGDEBUG) self.server_sock = SocketCom("kodi") if not self.server_sock.is_server_running(): self.server_sock.start_func_server(self) else: self.server_sock = None launcher = Launcher("menu") launcher.start() self.sock = SocketCom("server") ps = PulseService() ps.start() self.sock.call_func("set","device",[self.get_device()]) while not self.abortRequested(): if self.waitForAbort( 10 ): break launcher.stop() ps.stop() if self.server_sock: self.server_sock.stop_server()
def sel_profile(self): func_available, eqid, _, is_playing, _, is_dyn = self.check_func_available( ) if not func_available: return self.eqid = eqid include_switch_off = is_dyn and is_playing profiles = SocketCom("server").call_func("get", "eq_profiles") profile = SocketCom("server").call_func("get", "eq_base_profile") if include_switch_off: profiles = [tr(32011)] + profiles funcs = [(tr(32014), self.sel_new_profile), (tr(32015), self.sel_delete_profile), (tr(32016), self.sel_load_defaults)] sel = contextMenu(items=profiles, default=profile, funcs=funcs) if sel is None: return if include_switch_off and sel == 0: SocketCom("server").call_func("switch", "eq_off") else: SocketCom("server").call_func("load", "eq_profile", [eqid, profiles[sel]])
def on_pulse_connect(self): log("pact: start pulse control") self.pc.start() self.padb.on_pa_connect() self.pamm.on_pa_connect() SocketCom("kodi").call_func("up", "service", []) SocketCom("kodi").call_func("get", "player", [])
def sel_new_profile(self): # Name for new Profile profile = xbmcgui.Dialog().input(tr(32017)) if profile != '': SocketCom("server").call_func("save", "eq_profile", [profile]) SocketCom("server").call_func("load", "eq_profile", [self.eqid, profile]) self.sel_profile()
def __init__(self, *args, **kwargs): self.sock = SocketCom("server") self.cwd = args[1] self.sock = SocketCom("server") self.eqid = kwargs["eqid"] self.desc = kwargs["desc"] self.tmp_fn = self.sock.path + "graph_%s.png" self.cnt = 0
def __init__(self, *_args, **kwargs): self.sock = SocketCom("server") self.rec = SocketCom("sweep") self.channel = kwargs["channel"] self.count = kwargs["count"] result = self.sock.call_func("get", "eq_channel") if result is None: return self.eqid, self.name, _ = (result) self.rec.start_func_server(self)
def sel_delete_correction(self): corrections = SocketCom("server").call_func("get", "room_corrections") if not corrections: return nr = contextMenu(items=corrections) if nr is None: return del_correction = corrections[nr] # sure to delete if xbmcgui.Dialog().yesno( tr(32030) % del_correction, tr(32031) % del_correction) is True: SocketCom("server").call_func("remove", "room_correction", [del_correction]) self.sel_correction()
def sel_delete_profile(self): profiles = SocketCom("server").call_func("get", "eq_profiles") if not profiles: return nr = contextMenu(items=profiles) if nr is None: return # sure to delete del_profile = profiles[nr] if xbmcgui.Dialog().yesno( tr(32018) % del_profile, tr(32019) % del_profile) is True: SocketCom("server").call_func("remove", "eq_profile", [del_profile]) self.sel_profile()
def __init__(self, gid=0): self.service_owner = False self.running = False self.pulseloop = False self.gid = gid self.sock = SocketCom("server") self.q = Queue() self.mc = MessageCentral() #allow only one instance of the server if not self.sock.is_server_running(): self.start_event_loop() self.service_owner = True else: log("pase: server alreay running, don't start")
def on_message(self, target, func, arg, conn): try: # filter messages if self.padb.on_message(target, func, arg): return # other messages are just forwarded cmd = "on_" + target + "_" + func methods = [] for cl in [self.padb, self, self.pamm, self.eq, self.sg]: try: methods.append(getattr(cl, cmd)) except AttributeError: pass except Exception as e: opthandle(e) if len(methods) == 0: SocketCom.respond(conn, None) return for method in methods: ret = method(*arg) SocketCom.respond(conn, ret) except PulseError as e: handle(e) logerror("pact: in {},{},{}".format(target, func, str(arg))) logerror("pact: try to recover") try: self.pc.stop() self.on_pulse_connect() except Exception as e: handle(e) logerror("pact: recover failed") except Exception as e: logerror("pact: in {},{},{}".format(target, func, str(arg))) handle(e)
class LatencyGui(xbmcgui.WindowXMLDialog): def __init__(self, *_args, **_kwargs): self.sock = SocketCom("server") self.latency_info = self.sock.call_func("get", "latency") self.save = self.latency_info.copy() def onInit(self): self.header = self.getControl(100) self.header.setLabel(tr(32022)) self.slider = self.getControl(1900) self.label = self.getControl(2000) self.setFocus(self.slider) latency = int(self.latency_info["latency"] / 1000) self.slider.setInt(latency, 0, 25, 2000) self.label.setLabel("{:d} ms".format(latency)) def setLatency(self): latency = int(self.slider.getInt()) self.label.setLabel("{:d} ms".format(latency)) self.latency_info["latency"] = latency * 1000 self.sock.call_func("set", "latency", [self.latency_info]) def onAction(self, action): aid = action.getId() #log("%s %s"%(aid,self.getFocusId())) #OK pressed if aid == 7: self.close() #Cancel if aid in [92, 10]: self.sock.call_func("set", "latency", [self.save]) self.close() #up/down/left/right if aid in [1, 2, 3, 4, 106]: fid = self.getFocusId() if fid == 0: self.setFocusId(1900) self.setLatency()
def on_pa_connect(self): log("pamm: start paModuleManager") try: self.load_dyn_equalizer() self.eq_fatal = False except Exception as e: self.eq_fatal = True handle(e) logerror("cannot load pulseaudio-equalizer, maybe not installed?") logerror("run: sudo apt install pulseaudio-equalizer") return None self.config.load_config() self.load_required_module("module-dbus-protocol") self.eq.on_pa_connect() sock = SocketCom("kodi") player = sock.call_func("get", "player") if player and len(player) > 0: self.on_player_play() else: self.on_player_stop()
def sel_correction(self): func_available, eqid, _, _, _, _ = self.check_func_available() if not func_available: return corrections = SocketCom("server").call_func("get", "room_corrections") correction = SocketCom("server").call_func("get", "room_correction") if correction is None: correction = tr(32411) corrections = [tr(32411)] + corrections funcs = [(tr(32033), self.sel_import_correction), (tr(32028), self.sel_delete_correction), (tr(32032), self.sel_playsweep)] sel = contextMenu(items=corrections, default=correction, funcs=funcs) if sel is None: return if sel == 0: SocketCom("server").call_func("unset", "room_correction", [eqid]) return SocketCom("server").call_func("set", "room_correction", [eqid, corrections[sel]])
def __init__(self, *args, **kwargs): self.build_dialog(**kwargs) self.index = None self.updating = False self.controlId = 2000 self.cwd = args[1] self.sock = SocketCom("server") self.eqid = kwargs["eqid"] self.desc = kwargs["desc"] try: step = int(get_user_setting("equalstep", 0)) + 1 except Exception: step = int(1) self.dyn_step = DynStep(step, 5, 1, 3) self.sock.call_func("set", "eq_frequencies", [self.freqs]) self.profile = self.sock.call_func("get", "eq_base_profile") self.preamp, self.coef = self.sock.call_func("get", "eq_filter") self.is_changed = False
def sel_device(): response = xbmc.executeJSONRPC( '{"jsonrpc":"2.0", "method":"Settings.GetSettings", "params":{ "filter": {"section":"system", "category":"audio"}}, "id":1}' ) r_dict = json.loads(response) settings = r_dict["result"]["settings"] for s in settings: if s["id"] == "audiooutput.audiodevice": value = s["value"] options = s["options"] sel_lables = [] sel_values = [] preselect = 0 index = 0 for o in options: if "eq-auto-load" in o["value"]: continue if o["value"] == value: preselect = index sel_values.append(o["value"]) sel_lables.append(o["label"].replace("(PULSEAUDIO)", '')) index = index + 1 # device selection Dialog sel = contextMenu(items=sel_lables, default=sel_lables[preselect], width=1000) if sel is None: return response = xbmc.executeJSONRPC( '{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice", "value":"%s"}, "id":1}' % (sel_values[sel])) SocketCom("server").call_func("set", "device", [sel_values[sel]])
class SweepGui(xbmcgui.WindowXMLDialog): def __init__(self, *_args, **kwargs): self.sock = SocketCom("server") self.rec = SocketCom("sweep") self.channel = kwargs["channel"] self.count = kwargs["count"] result = self.sock.call_func("get", "eq_channel") if result is None: return self.eqid, self.name, _ = (result) self.rec.start_func_server(self) def onInit(self): self.prog1 = self.getControl(1900) self.prog2 = self.getControl(1901) self.prog1.setPercent(0.1) self.prog2.setPercent(0.1) #self.getControl(101).setLabel("%s - %s" % (self.name, tr(32410))) self.sock.call_func("play", "sweep", [self.count, self.channel]) @staticmethod def on_sound_play(nr): log("on_sound_play %s" % nr) def on_sound_stop(self): log("on_sound_stop") self.rec.stop_server() self.close() def on_chunk_play(self, c_nr, c_size, c_cnt, c_total): self.prog1.setPercent(c_cnt * 100 / (c_total - 1)) self.prog2.setPercent(c_nr * 100 / (c_size - 1)) def end_gui(self): self.sock.call_func("stop", "tone") self.sock.call_func("stop", "pulseplayer") self.rec.stop_server() self.close() def onAction(self, action): #OK pressed if action.getId() in [7, 100]: self.end_gui() #Cancel if action.getId() in [92, 10]: self.end_gui()
def proc_device(self): self.output_sink = None sock = SocketCom("kodi") device = sock.call_func("get", "device") if device: self.proc_device_set(device)
def __init__(self, *_args, **_kwargs): self.sock = SocketCom("server") self.latency_info = self.sock.call_func("get", "latency") self.save = self.latency_info.copy()
class PaMonitor( xbmc.Monitor ): def __init__( self ): #strat process xbmc.Monitor.__init__( self ) xbmc.log("eq: start PulesEqualizer service",xbmc.LOGDEBUG) self.server_sock = SocketCom("kodi") if not self.server_sock.is_server_running(): self.server_sock.start_func_server(self) else: self.server_sock = None launcher = Launcher("menu") launcher.start() self.sock = SocketCom("server") ps = PulseService() ps.start() self.sock.call_func("set","device",[self.get_device()]) while not self.abortRequested(): if self.waitForAbort( 10 ): break launcher.stop() ps.stop() if self.server_sock: self.server_sock.stop_server() @staticmethod def get_device(): device = "" r_dict = json.loads(xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.GetSettings", "params":{ "filter": {"section":"system", "category":"audio"}}, "id":1}')) for s in r_dict["result"]["settings"]: if s["id"] == "audiooutput.audiodevice": device = s["value"] break return device def on_device_get(self): result = self.get_device() xbmc.log("eq: kodi service: on_device_get %s" % result,xbmc.LOGDEBUG) return result @staticmethod def on_player_get(): r_dict = json.loads(xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":0}')) try: return r_dict["result"] except Exception: return None @staticmethod def on_log_write(message, level): xbmc.log(message, level) def on_service_up(self): self.sock.call_func("set","device",[self.get_device()]) def onNotification( self, _sender, method, _data ): target,func = method.lower().replace("on","").split(".") if target in ["system", "player"]: self.sock.call_func(func, target)
class PulseInterfaceService(): def __init__(self, gid=0): self.service_owner = False self.running = False self.pulseloop = False self.gid = gid self.sock = SocketCom("server") self.q = Queue() self.mc = MessageCentral() #allow only one instance of the server if not self.sock.is_server_running(): self.start_event_loop() self.service_owner = True else: log("pase: server alreay running, don't start") #start all message loops def start_event_loop(self): self.running = True Thread(target=self.message_forward).start() Thread(target=self.start_pulse_loop).start() self.sock.start_server(self.on_socket_message) #stop all message loops def stop_event_loop(self): if self.running: self.running = False self.pulseloop = True self.q.put(('exit', '', '', None)) self.sock.stop_server() self.send_message_to_central('message', 'exit') self.pulse_event.close() # # support functions # def send_message_to_central(self, target, func, param='', conn=None): # create a new thread per message. So message_forward thread will not crash in case of message handling crash th = Thread(target=self.mc.on_message, args=(target, func, param, conn)) th.start() th.join() if conn: conn.close() # # message loops # def on_socket_message(self, conn, msg): try: func, target, args = json.loads(msg) log("pase: receive from socket: %s" % repr([func, target, args])) if target == "service" and func == "stop" and args[0] == self.gid: log("pase: stop_service received - stopping service") conn.close() self.stop_event_loop() self.q.put((target, func, args, conn)) except Exception as e: handle(e) #messages from pulse audio def pulse_event_receive(self, event): if event.facility._value in ["server", "source", "source_output"]: return self.q.put( (event.facility._value, event.t._value, [event.index], None)) #start message loop for pulse audio def start_pulse_loop(self): log("pase: start pulse loop") cnt = 1 while True: try: self.pulse_event = pulsectl.Pulse('Event Manager') log("pase: connected to pulse") cnt = 1 self.pulse_event.event_mask_set('all') self.pulse_event.event_callback_set(self.pulse_event_receive) self.send_message_to_central('pulse', 'connect') self.pulse_event.event_listen() except pulsectl.PulseDisconnected: log("pase: pulse disconnected") if not self.running: self.pulseloop = False log("pase: stop pulse loop") return except Exception as e: if cnt > 0: handle(e) logerror("pase: in event manager") cnt = cnt - 1 if not self.running: return time.sleep(0.5) # # message forward # # message from pulse may arrive to late/ quick for our message handling. # therefore collect them and process them 100ms after the last message. def message_forward(self): log("pase: start message_dispatch") timeout = None while True: try: try: target, func, param, conn = self.q.get(timeout=timeout) except Empty: # we did not receive any message since 100 ms. Send this info to # message collector. Message collector will then process the previouse # collected messages t = time.time() self.send_message_to_central('pa', 'update') timeout = None log("pase: pa_updated: time needed {:2f} ms".format( (time.time() - t) * 1000)) continue except Exception as e: handle(e) if target == "exit": break if conn is None: timeout = 0.1 self.send_message_to_central(target, func, param, conn) self.q.task_done() except Exception as e: handle(e) log("pase: stop message_dispatch")
class EqGui(xbmcgui.WindowXMLDialog): ''' Equalizer Dialog The equalizer dialog is build up dynamically ''' def __init__(self, *args, **kwargs): self.build_dialog(**kwargs) self.index = None self.updating = False self.controlId = 2000 self.cwd = args[1] self.sock = SocketCom("server") self.eqid = kwargs["eqid"] self.desc = kwargs["desc"] try: step = int(get_user_setting("equalstep", 0)) + 1 except Exception: step = int(1) self.dyn_step = DynStep(step, 5, 1, 3) self.sock.call_func("set", "eq_frequencies", [self.freqs]) self.profile = self.sock.call_func("get", "eq_base_profile") self.preamp, self.coef = self.sock.call_func("get", "eq_filter") self.is_changed = False def build_dialog(self, **kwargs): self.freqs = get_frequencies() color = kwargs["color"] file_s = kwargs["file_s"] header_t, itemgap_t, templ_t, end_t = get_template( file_s, [ "<!-- item gap -->", "<!-- element begin -->", "<!-- element end -->" ]) itemgap = int(read_next_tag("itemgap", itemgap_t, 0)) num_freq = len(self.freqs) if num_freq >= 15: itemgap = 0 itemgap_t = itemgap_t.format(itemgap=itemgap) width = int(read_next_tag("width", templ_t, 0)) slider_width = (width + itemgap) * num_freq if slider_width > 1700: slider_width = 1700 total_width = slider_width + 100 xpos = (1920 - total_width) / 2 items = "" i = 0 max_id = 1999 + num_freq for freq in self.freqs: item_r = self.set_replace_item(2000 + i, freq, max_id) items = items + templ_t.format(**item_r, **color) i += 1 glob = { "slider_width": slider_width, "total_width": total_width, "xpos": xpos } write_dialog( file_s, localize( header_t.format(**glob, **color) + itemgap_t + items + end_t)) @staticmethod def set_replace_item(item_id, freq, max_id): item_r = {"sid": item_id, "lid": item_id + 100, "onleft": item_id - 1} if item_id < max_id: item_r["onright"] = item_id + 1 else: item_r["onright"] = "" if freq < 1000: item_r["labelid"] = '$NUMBER[{}]'.format(int(freq)) else: item_r["labelid"] = format_float(freq) return item_r @staticmethod def str(nr): if nr < 1000: return str(nr) fnr = float(nr) / 1000 if round(fnr) == fnr: return "{:d}k".format(int(fnr)) else: return "{:.1f}k".format(fnr) @staticmethod def slider2coef(val): #slider 0-100 into dB [-20db .. 20db] = [0.1 ... 10] return 10.0**((val - 50.0) / 50.0) @staticmethod def coef2slider(val): return int(math.log10(val) * 50 + 50.0) def onInit(self): self.setFocusId(2000) #set slider names self.getControl(3500).setLabel(self.profile) self.getControl(3501).setLabel(self.desc) self.getControl(3502).setLabel("0 dB ") #set slider i = 0 for coef in self.coef[1:]: self.getControl(2000 + i).setInt(self.coef2slider(coef), 0, 0, 100) i = i + 1 # set preamp slider self.getControl(1999).setInt(self.coef2slider(self.preamp), 0, 0, 100) def onFocus(self, controlId): if controlId >= 1999 and controlId < 2100: self.controlId = controlId val = 2 * (self.getControl(self.controlId).getFloat() - 50) / 5 self.getControl(3502).setLabel("{:.1f} dB ".format(val)) def set_filter(self): self.coef[0] = self.coef[1] self.sock.call_func("set", "eq_filter", [self.eqid, self.preamp, self.coef]) def load_profile(self): self.sock.call_func("load", "eq_profile", [self.eqid, self.profile]) def save_profile(self): self.sock.call_func("save", "eq_profile", [self.profile]) def update(self): sleep(0.3) self.set_filter() self.updating = False self.is_changed = True def setFilter(self): val = 2 * (self.getControl(self.controlId).getFloat() - 50) / 5 self.getControl(3502).setLabel("{:.1f} dB ".format(val)) change = False for i in range(1, len(self.coef) - 2): c = self.slider2coef(self.getControl(1999 + i).getFloat()) if c != self.coef[i]: self.coef[i] = c change = True c = self.slider2coef(self.getControl(1999).getFloat()) if c != self.preamp: self.preamp = c change = True if not change: return if not self.updating: self.updating = True Thread(target=self.update).start() def _close(self): self.close() def sel_cancel(self): self.load_profile() self._close() def sel_save(self): self.save_profile() self._close() def onAction(self, action): t = time.time() aid = action.getId() fid = self.getFocusId() buc = action.getButtonCode() & 255 #log("eqdialog: key: %s fid: %s"%(aid,fid)) #OK pressed if aid in [7]: self.save_profile() self._close() if aid in [100]: if fid == 1800: #self.save_profile() self.load_profile() self._close() #Cancel if aid in [92, 10]: if self.is_changed: contextMenu(funcs=[(tr(32622), self.sel_cancel), (tr(32623), self.sel_save)]) else: self.close() self.dyn_step.dynamic_step(buc) if aid in [3, 104]: ctl = self.getControl(self.controlId) new = ctl.getInt() + self.dyn_step.dynstep if ctl.getInt() < 50 and new > 50: new = 50 pos = new if pos > 100: pos = 100 ctl.setInt(pos, 0, 0, 100) if aid in [4, 105]: ctl = self.getControl(self.controlId) new = ctl.getInt() - self.dyn_step.dynstep if ctl.getInt() > 50 and new < 50: new = 50 pos = new if pos < 0: pos = 0 ctl.setInt(pos, 0, 0, 100) if aid in [3, 4, 104, 105, 106]: self.setFocusId(self.controlId) self.setFilter() self.last_key = t
class SweepGenGui( xbmcgui.WindowXMLDialog ): name = None eqid = None channel_id = [] channel = [] channel_sel = 0 profiles= [] save_profile = None sel_profile = 0 corrections=[] save_correction=None sel_correction=0 repeats = 0 def __init__( self, *args, **_kwargs ): self.cwd = args[1] self.skin = args[2] self.sock = SocketCom("server") result = self.sock.call_func("get","eq_channel") if result is None: return self.eqid, self.name, channel = (result) self.channel_id = channel ch_index = [] for ch_name in channel: try: index = chan_num.index(ch_name) ch_index.append(index) except Exception as e: opthandle(e) self.channel = ch_index self.profiles = [tr(32413)] + self.sock.call_func("get","eq_profiles") self.save_profile = self.sock.call_func("get","eq_base_profile") self.sock.call_func("unload","eq_profile",[self.eqid]) self.corrections =[tr(32411)] + self.sock.call_func("get","room_corrections") self.save_correction = self.sock.call_func("get","room_correction") self.sock.call_func("unset","room_correction" , [self.eqid]) def onInit( self ): if self.name is None: self.close() self.getControl(300).setLabel(self.profiles[self.sel_profile]) self.getControl(301).setLabel(self.corrections[self.sel_correction]) def on_sel_profile(self): nsel = contextMenu(items = self.profiles, default = self.profiles[self.sel_profile]) if nsel is None: return if nsel == 0: self.sock.call_func("unload","eq_profile",[self.eqid]) else: self.sock.call_func("load","eq_profile" , [self.eqid, self.profiles[nsel]]) self.sel_profile = nsel self.getControl(300).setLabel(self.profiles[self.sel_profile]) def on_sel_correction(self): nsel = contextMenu(items = self.corrections, default = self.corrections[self.sel_correction]) if nsel is None: return if nsel == 0: self.sock.call_func("unset","room_correction", [self.eqid]) else: self.sock.call_func("set","room_correction" , [self.eqid, self.corrections[nsel]]) self.sel_correction = nsel self.getControl(301).setLabel(self.corrections[nsel]) def on_sel_channel(self): sel_list = [tr(32412) + " (0)"] + [tr(32500 + i)+ " (%s)"%(i+1) for i in self.channel] nsel = contextMenu(items = sel_list, default = sel_list[self.channel_sel]) if nsel is None: return self.channel_sel=nsel self.getControl(302).setLabel(sel_list[nsel]) def on_sel_repeats(self): numbers = ["- %s -" % str(i+1) for i in range(10)] nsel = contextMenu(items = numbers, default = numbers[self.repeats]) if nsel is None: return self.repeats = nsel self.getControl(303).setLabel(str(nsel+1)) def on_sel_play(self): channel = None if self.channel_sel == 0 else self.channel_id[self.channel_sel-1] runDialog(SweepGui,"Sweep",channel=channel , count = self.repeats + 1) def handleOK(self): fid = self.getFocusId() if fid == 3000: self.on_sel_profile() elif fid == 3001: self.on_sel_correction() elif fid == 3002: self.on_sel_channel() elif fid == 3003: self.on_sel_repeats() elif fid == 3004: self.on_sel_play() def end_gui(self): if self.save_profile: self.sock.call_func("load","eq_profile",[self.eqid, self.save_profile]) if self.save_correction: self.sock.call_func("set","room_correction" , [self.eqid, self.save_correction]) self.close() def onAction( self, action ): #OK pressed if action.getId() in [7, 100]: self.handleOK() #Cancel if action.getId() in [92,10]: self.end_gui()
class VolumeGui(xbmcgui.WindowXMLDialog): def __init__(self, *args, **kwargs): self.sock = SocketCom("server") self.path = os.path.join(args[1], "resources/skins/" + args[2] + "/media") self.progress1 = None self.updown = kwargs["updown"] try: step = (float(get_user_setting("sysvolstep", 0)) + 1) / 100 except Exception: step = float(0.01) if step <= 0: step = float(0.01) self.dyn_step = DynStep(step, 0.05, 0.01, 3) self.key_up = None self.key_down = None self.updating = False self.vol = self.sock.call_func("get", "volume") if self.updown == "up": self.vol_up() elif self.updown == "down": self.vol_down() self.last = time.time() if self.updown != "none": threading.Thread(target=self.check_close).start() def check_close(self): while True: if time.time() - self.last > 2: break time.sleep(0.5) self.close() def onInit(self): self.progress1 = self.getControl(1900) self.label = self.getControl(1901) self.set_vol_gui() # slow down messages to server def update_to_pulse(self): time.sleep(0.3) self.sock.call_func("set", "volume", [self.vol]) self.updating = False def update(self): if not self.updating: self.updating = True threading.Thread(target=self.update_to_pulse).start() def vol_up(self): if self.vol is None: return vol_new = self.vol + self.dyn_step.dynstep if self.vol < float(1) and vol_new > float(1): vol_new = float(1) self.vol = vol_new if self.vol > float(1.5): self.vol = float(1.5) self.update() def vol_down(self): if self.vol is None: return vol_new = self.vol - self.dyn_step.dynstep if self.vol > float(1) and vol_new < float(1): vol_new = float(1) self.vol = vol_new if self.vol < 0: self.vol = float(0) self.update() def set_vol_gui(self): self.last = time.time() if self.progress1 is None: return if self.vol is None: return v = (self.vol / 1.5) * 100 if v > 100: v = 100 self.progress1.setPercent(v if v > 0 else 0.1) self.label.setLabel("{:d} %".format(int(self.vol * 100))) def onAction(self, action): aid = action.getId() buc = action.getButtonCode() & 255 #log("volumegui: key: {} button code: {} time: {:.2f}".format(aid, buc, t - self.last_key)) #OK pressed if aid == 7: self.close() #Cancel if aid in [92, 10]: self.close() self.dyn_step.dynamic_step(buc) if buc == self.key_up or aid in [2, 3, 104]: self.vol_up() self.set_vol_gui() #log("key up") elif buc == self.key_down or aid in [1, 4, 105]: self.vol_down() self.set_vol_gui() #log("key down") else: if self.updown == "up": if self.key_up is None: self.key_up = buc self.vol_up() elif self.key_down is None: self.key_down = buc self.vol_down() elif self.updown == "down": if self.key_down is None: self.key_down = buc self.vol_down() elif self.key_up is None: self.key_up = buc self.vol_up() self.set_vol_gui() self.last = time.time()
def sel_load_defaults(self): # load predefined SocketCom("server").call_func("set", "eq_defaults") self.sel_profile()
# Copyright (C) 2021 wastis https://github.com/wastis/PulseEqualizerGui # # PulseEqualizerGui is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation; either version 3 of the License, # or (at your option) any later version. import sys sys.path.append('./resources/lib/') sys.path.append('./fakekodi') from helper import SocketCom #sc = SocketCom("sound") sc = SocketCom("server") if not sc.is_server_running(): print("server is not running") sys.exit(0) try: func = sys.argv[1] if func == "exit": sc.stop_server() sys.exit(0) target = sys.argv[2] try: args = [] for arg in sys.argv[3:]:
def sweep_play_loop(self, count, channel, vol): if not self.player_proc: if not self.on_pulseplayer_start(channel): return False self.playing = True self.stop = False log("soge: sweep start") socket = SocketCom("sweep") sock_up = socket.is_server_running() if sock_up: log("soge: sweep server is up") sampleRate = float(self.cur_eq.sample_spec["rate"]) chunk = int(sampleRate / 4) chunk_duration = float(0.25) # # prepare Sound # total_chunk = 20 * count cur_chunk = 0 chunk_list = [] pos = 0 for c in range(20): base = c * chunk samples = array('f', []) for f in range(chunk): step = float((base + f)) / (sampleRate * 10) samples.append(float(sin(2 * pos * pi) * vol)) pos = pos + step chunk_list.append(samples) cur_chunk = 0 # # play Sound # for cnt in range(count): if sock_up: socket.send("play", "sound", [count - cnt]) c = 0 for samples in chunk_list: if sock_up: socket.send("play", "chunk", [c, 20, cur_chunk, total_chunk]) self.player_proc.stdin.write(samples) if self.stop: break cur_chunk = cur_chunk + 1 c = c + 1 if cur_chunk > 2: sleep(chunk_duration) if self.stop: break sleep(4 * chunk_duration) log("soge: sweep has finished") self.stop = False self.playing = False if sock_up: socket.send("stop", "sound") self.on_pulseplayer_stop()