示例#1
0
    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)
示例#2
0
    def sel_menu(self, command="None"):
        if command == "None": self.sel_main_menu()
        else:
            func = 'sel_' + command
            try:
                method = getattr(self, func)
            except Exception:
                method = None
                logerror("unkonwn command: '%s'" % (func))

            if method: method()
示例#3
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
示例#4
0
def get_template(file_s, delimiter):
    with open(file_s["template"]) as f:
        content = f.read()

    result = []
    follow_pos = 0
    for deli in delimiter:
        pos = content.find(deli, follow_pos)
        if pos < 0:
            logerror("template not correct, did not find {}".format(deli))
            return []

        result.append(content[follow_pos:pos])
        follow_pos = pos + len(deli)

    result.append(content[follow_pos:])

    return result
示例#5
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()
示例#6
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)
示例#7
0
#	or (at your option) any later version.
#
#

import sys
import math

from basic import logerror
from basic import opthandle

if sys.version_info[0] > 2:
    try:
        from PIL import Image
        from PIL import ImageDraw
    except ModuleNotFoundError:
        logerror("please install python3-pil")
else:
    try:
        from PIL import Image
        from PIL import ImageDraw
    except ImportError:
        logerror("please install python-pil")


def createGraph2(fn, spec=None, width=1700, height=700):
    with Image.new("RGBA", (width, height), (0, 0, 0, 0)) as im:
        h = height
        w = width
        zero_x = 0
        scale = h / 40
        zero_y = scale * 4
示例#8
0
#  dbus wraper for Python 2.x
#

from . import interface as IF
import sys
import os

from basic import log
from basic import logerror

from .pulseerror import PulseDBusError

try:
    import dbus
except ImportError:
    logerror("please install python-dbus")


class PulseDBus:
    def __init__(self, *_args, **_kwargs):
        destination = 'org.PulseAudio1'
        object_path = '/org/pulseaudio/server_lookup1'
        interface_name = 'org.PulseAudio.ServerLookup1'

        try:
            if 'PULSE_DBUS_SERVER' in os.environ:
                address = os.environ['PULSE_DBUS_SERVER']
                log("got dbus address from environment: %s" % address)

            else:
                bus = dbus.SessionBus()