コード例 #1
0
    def get_list(self, obj):
        if not obj in ["sink", "sink_input", "client", "module", "card"]:
            return

        result = None
        func = obj + '_list'

        try:
            method = getattr(self.pulse, func)
        except Exception as e:
            handle(e)
            return

        self.lock.acquire()
        try:
            result = method()
        except Exception as e:
            handle(e)
        finally:
            self.lock.release()
            for ele in result:
                try:
                    sample_spec = {
                        "format": self.sformats[ele.sample_spec.format],
                        "rate": ele.sample_spec.rate,
                        "channels": ele.sample_spec.channels
                    }
                    ele.sample_spec = sample_spec
                except AttributeError:
                    pass
                except Exception as e:
                    opthandle(e)

        return result
コード例 #2
0
ファイル: paservice.py プロジェクト: wastis/PulseEqualizerGui
    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)
コード例 #3
0
ファイル: __init__.py プロジェクト: wastis/PulseEqualizerGui
def get_skin_colors(skin):
    try:
        with open(path_addon + "resources/skins/Default/skincolors.json") as f:
            colors = json.loads(f.read())

        defcol = colors["default"]
        try:
            skicol = colors[skin]
            log("skin: {} defined".format(skin))
        except KeyError:
            log("skin: {} not defined".format(skin))
            skicol = {}

        for key, val in list(skicol.items()):
            defcol[key] = val

        defcol["button_tags"] = "".join(defcol["button_tags"]).format(**defcol)
        defcol["button_textcolor"] = "".join(
            defcol["button_textcolor"]).format(**defcol)
        defcol["button_radio"] = "".join(
            defcol["button_radio"]).format(**defcol)
        defcol["progress_bar"] = "".join(
            defcol["progress_bar"]).format(**defcol)
        defcol["background_img"] = "".join(
            defcol["background_img"]).format(**defcol)

        return defcol

    except Exception as e:
        handle(e)

    return {}
コード例 #4
0
ファイル: padb.py プロジェクト: wastis/PulseEqualizerGui
    def do_update(self):
        self.update_objects()
        self.update_kodi_info()
        msg_list = self.mc.get_messages_and_clear()

        for cmd, arg in msg_list:
            #log("padb: co: %s %s" % (cmd,*arg))
            try:
                method = None
                try:
                    method = getattr(self, cmd)
                except AttributeError:
                    pass
                except Exception as e:
                    opthandle(e)

                if method: method(*arg)
            except Exception as e:
                handle(e)

        msg_list = self.update_attr() + msg_list
        msg_list = self.update_output_sink() + msg_list

        #log("padb: {}".format(str(self)))

        return msg_list
コード例 #5
0
    def get_info(self, obj, index):
        if not obj in ["sink", "sink_input", "client", "module", "card"]:
            return

        result = None
        func = obj + '_info'

        try:
            method = getattr(self.pulse, func)
        except Exception:
            return

        self.lock.acquire()
        try:
            result = method(index)
        except PulseIndexError:
            return None
        except Exception as e:
            handle(e)
        finally:
            self.lock.release()
            try:
                sample_spec = {
                    "format": self.sformats[result.sample_spec.format],
                    "rate": result.sample_spec.rate,
                    "channels": result.sample_spec.channels
                }
                result.sample_spec = sample_spec
            except AttributeError:
                pass
            except Exception as e:
                opthandle(e)
        return result
コード例 #6
0
    def load(self, filename):
        path, fn = os.path.split(filename)
        name, ext = os.path.splitext(fn)
        name, nr = os.path.splitext(name)

        self.name = name

        cnt = 0

        try:
            nr = int(nr[1:])

            for i in range(1, 10):
                fn = "%s/%s.%s%s" % (path, name, i, ext)
                if not os.path.exists(fn): continue
                log("load %s" % fn)

                self.speclist[i] = Spectrum().load(fn)
                self.filenames[i] = "%s.%s%s" % (name, i, ext)
                cnt = cnt + 1
        except ValueError:
            pass
        except Exception as e:
            handle(e)

        if not cnt:
            if os.path.exists(filename):
                self.speclist[0] = Spectrum().load(filename)
                self.filenames[0] = fn
                cnt = 1

        self.count = cnt
        return self
コード例 #7
0
    def update_minmax(self):
        minval = None
        maxval = None
        try:
            it = iter(self.freq_db)

            f, v = next(it)
            maxval = v

            while f < 200:
                f, v = next(it)
                if v > maxval: maxval = v

            minval = v
            while f < 8000:
                f, v = next(it)
                if v > maxval: maxval = v
                if v < minval: minval = v

            while True:
                f, v = next(it)
                if v > maxval: maxval = v

        except StopIteration:
            pass
        except Exception as e:
            handle(e)

        self.maxval = maxval
        self.minval = minval

        return self
コード例 #8
0
ファイル: menus.py プロジェクト: wastis/PulseEqualizerGui
    def sel_equalizer(self):
        try:
            func_available, eqid, desc, is_playing, _, _ = self.check_func_available(
            )
            if not func_available: return

            eqDialog(eqid=eqid, desc=desc, is_playing=is_playing)
        except Exception as e:
            handle(e)
コード例 #9
0
	def save(self):
		try:
			xml = self.create_xml()
			if xml != "":
				with open(self.file_name, "w") as f: f.write(xml)
			else:
				os.remove(self.file_name)
		except OSError: pass
		except Exception as e: handle(e)
コード例 #10
0
	def profile_load(self, name):
		if not self.profiles: self.profile_file_load()
		try:
			self.profile = EqProfile([name] + self.profiles[name])
		except KeyError:
			log("cannot find %s, load default profile" % name)
			self.profile = EqProfile()
		except Exception as e: handle(e)
		self.filter_freq = None
コード例 #11
0
    def on_volume_set(self, volume):
        vol = float(volume)
        log("pamm: on_volume_set %f" % vol)
        if self.padb.output_sink is None: return None

        try:
            self.pc.set_sink_volume(self.padb.output_sink.index, vol)
        except Exception as e:
            handle(e)
コード例 #12
0
ファイル: launcher.py プロジェクト: wastis/PulseEqualizerGui
 def wait_user_action(self):
     try:
         log("launcher: wait for user action")
         with open(self.ppath) as f:
             result = f.read()
         return result
     except OSError as e:
         handle(e)
         return self.exit_str
コード例 #13
0
def run_on_service(cmd):
    try:
        pname = "{}menu.{}".format(path_pipe, os.getppid())
        cmd = "{}".format(cmd)
        with open(pname, "w") as f:
            f.write(cmd)

    except Exception as e:
        from resources.lib.basic import handle
        handle(e)
コード例 #14
0
ファイル: config.py プロジェクト: wastis/PulseEqualizerGui
 def load_config(self):
     log("conf: load_config %s" % self.file_name)
     try:
         with open(self.file_name, 'r') as f:
             self.config = json.loads(f.read())
     except IOError:
         log("conf: cannot open config.json, settings is empty")
         self.config = {}
     except Exception as e:
         handle(e)
         self.config = {}
コード例 #15
0
def run_direct(cmd):
    from menus import Menu

    try:
        log("addon: start script.pulseequalizer.gui addon")

        m = Menu()
        m.sel_menu(cmd)

        log("addon: end script.pulseequalizer.gui addon")

    except Exception as e:
        handle(e)
コード例 #16
0
ファイル: paservice.py プロジェクト: wastis/PulseEqualizerGui
    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)
コード例 #17
0
ファイル: __init__.py プロジェクト: wastis/PulseEqualizerGui
def get_valid_skin():
    try:
        skin = get_current_skin()
        skincol = skin
        if not os.path.exists(path_addon + path_skin.format(skin=skin) +
                              "EqualizerDialog.xml"):
            skin = "Default"
    except Exception as e:
        handle(e)
        skin = "Default"
        skincol = skin

    color = get_skin_colors(skincol)

    return skin, color
コード例 #18
0
	def onAction( self, action ):
		try:
			aid = action.getId()
			fid = self.getFocusId()
			but = action.getButtonCode()

			log("action id {} button {:x}".format(aid,but))

			if aid == 0 and not self.success:
				self.keycount -= 1
				if self.keycount == 0:
					# no direction keyes pressed, maybe not supported device
					xbmcgui.Dialog().notification(tr(32753),tr(32754))
					self.end_gui_cancel()
					return

			if but == 0:
				if aid in [107,203]:
					return
				#mouse click
				if aid == 100 and self.check_end(self.index[fid]):
					return True

				xbmcgui.Dialog().notification(tr(32753),tr(32754))
				self.end_gui_cancel()
				return

			keycode = translate_keycode(but)

			if self.kmf.is_mapped(but):
				xbmcgui.Dialog().notification(tr(32755),self.format_key(but,keycode), time=700)

			log("translated keycode {}".format(str(keycode)))

			if keycode and keycode["mods"]==[]:
				self.kmf.unlock()

				if self.navigate(keycode["keyname"]["name"],fid):
					return
			try:
				if self.index[fid] not in ["CANCEL","SAVE"]:
					self.set_key(fid, but, self.format_key(but,keycode))

			except KeyError: pass
		except Exception as e:
			handle(e)
			self.end_gui_cancel()
コード例 #19
0
    def on_pulseplayer_start(self, channel):
        try:
            sink = self.padb.chaineq_sink if self.padb.chaineq_sink is not None else self.padb.autoeq_sink
            if sink is None:
                log("soge: on_pulseplayer_start: no equalizer sink found")
                self.cur_eq_index = None
                return False

            try:
                self.cur_eq = sink
                self.cur_eq_index = sink.index
                self.cur_eq_stream = self.padb.stream_by_module[
                    sink.owner_module].index
                self.cur_rate = sink.sample_spec["rate"]
            except Exception:
                self.cur_eq_index = None
                return False

            if self.player_proc: self.on_pulseplayer_stop()
            if channel is None: ch = []
            else: ch = ["--channel-map=%s" % channel]
            log("soge: start parec: rate=%s, channel=%s" %
                (self.cur_rate, repr(channel)))

            self.player_proc = subprocess.Popen([
                "parec", "-p",
                "--rate=%d" % self.cur_rate, "--format=float32le",
                "--volume=65535", "--latency-msec=250", "--channels=1"
            ] + ch,
                                                stdin=subprocess.PIPE,
                                                stdout=subprocess.PIPE)
            self.pid = self.player_proc.pid
            return True

        except Exception as e:
            if e.__class__.__name__ == "FileNotFoundError":
                logerror(
                    "soge: cannot find 'parec', please install 'pulseaudio-utils'"
                )
            elif e.__class__.__name__ == "OSError" and e[0] == 2:
                logerror(
                    "soge: cannot find 'parec', please install 'pulseaudio-utils'"
                )
            else:
                handle(e)
            return False
コード例 #20
0
    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()
コード例 #21
0
	def dispatch(self, conn, msg):
		try:
			try:
				func,target,args = json.loads(msg)
				cmd = "on_%s_%s" % (target,func)
			except Exception:
				#log(repr(msg))
				try:conn.close()
				except Exception as e: opthandle(e)
				return

			try: method = getattr(self.rec_class,cmd)
			except Exception: method = None

			result = method(*args) if method else None

			self.respond(conn,result)

			try:conn.close()
			except Exception as e: opthandle(e)

		except Exception as e: handle(e)
コード例 #22
0
ファイル: launcher.py プロジェクト: wastis/PulseEqualizerGui
    def loop(self):
        log("launcher: start {}".format(self.ppath))
        try:
            os.makedirs(path_pipe)
        except OSError:
            pass

        try:
            os.mkfifo(self.ppath)
        except OSError:
            pass

        lock = path_pipe + "lock"

        while True:
            try:
                result = self.wait_user_action()
                if result == self.exit_str: break

                log("launcher: start menu {}".format(result))

                self.menu.sel_menu(result)

            except Exception as e:
                handle(e)

            try:
                os.remove(lock)
            except OSError:
                pass

        try:
            os.remove(self.ppath)
        except OSError:
            pass

        log("launcher: stop")
コード例 #23
0
ファイル: paservice.py プロジェクト: wastis/PulseEqualizerGui
    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")
コード例 #24
0
    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)
コード例 #25
0
ファイル: config.py プロジェクト: wastis/PulseEqualizerGui
 def save_config(self):
     try:
         with open(self.file_name, 'w') as f:
             f.write(json.dumps(self.config))
     except Exception as e:
         handle(e)
コード例 #26
0
from basic import handle

from pulseinterface import PulseControl

pc = PulseControl()
pc.start()

try:
    si = pc.get_server_info()
    for key in vars(si):
        print(key, getattr(si, key))

    print(sys.argv)
    cmd = sys.argv[1]
    result = pc.get_list(cmd)

    for obj in result:
        print(obj.index, obj.name)
        for key, val in list(vars(obj).items()):
            if key == "proplist":
                print("\tproplist:")
                for k, v in list(val.items()):
                    print("\t\t%s=%s" % (k, v))
            else:
                print("\t%s=%s" % (key, val))
        print("***************************************************")

except Exception as e:
    handle(e)
コード例 #27
0
 def start(self):
     log("pctl: start")
     try:
         self.pulse = pulsectl.Pulse(self.name)
     except Exception as e:
         handle(e)