mpsync improvements.
authorFredrik Tolf <fredrik@dolda2000.com>
Fri, 15 Apr 2016 23:46:04 +0000 (01:46 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Fri, 15 Apr 2016 23:46:04 +0000 (01:46 +0200)
mpsync

diff --git a/mpsync b/mpsync
index 8783e28..62008f0 100755 (executable)
--- a/mpsync
+++ b/mpsync
@@ -135,8 +135,8 @@ class target(object):
                 continue
             return resp
 
-    def runcmd(self, cmd):
-        self.send(json.dumps(cmd).encode("utf-8") + b"\n")
+    def runcmd(self, *cmd):
+        self.send(json.dumps({"command": cmd}).encode("utf-8") + b"\n")
         resp = self.getresp()
         if "error" not in resp:
             sys.stderr.write("mpsync: strange response from %s: %r\n" % (self.path, resp))
@@ -145,10 +145,10 @@ class target(object):
         return resp
 
     def getprop(self, pname):
-        return self.runcmd({"command": ["get_property", pname]})["data"]
+        return self.runcmd("get_property", pname)["data"]
 
     def setprop(self, pname, val):
-        self.runcmd({"command": ["set_property", pname, val]})
+        self.runcmd("set_property", pname, val)
 
 def usage(out):
     out.write("usage: mpsync [-h] SOCKET...\n")
@@ -172,9 +172,8 @@ for path in args:
     targets.append(target(path))
 
 def runcmd(*cmd):
-    cmd = {"command": cmd}
     for tgt in targets:
-        tgt.runcmd(cmd)
+        tgt.runcmd(*cmd)
 
 def simulcmd(*cmd):
     cmd = json.dumps({"command": cmd}).encode("utf-8") + b"\n"
@@ -200,8 +199,9 @@ def getoffsets():
     return ret
 
 def main(tty):
-    paused = targets[0].getprop("pause")
     runcmd("set_property", "hr-seek", "yes")
+    paused = targets[0].getprop("pause")
+    mutemode = 0
     offsets = [0.0] * len(targets)
     while True:
         c, mods = tty.readkey()
@@ -229,9 +229,24 @@ def main(tty):
             relseek(5, offsets)
         elif c == rawtty.K_DOWN and mods == {rawtty.MOD_SHIFT}:
             relseek(-5, offsets)
+        elif c == 's':
+            relseek(0, offsets)
+        elif c == 'm':
+            mutemode = (mutemode + 1) % 3
+            if mutemode == 0:
+                for tgt in targets:
+                    tgt.setprop("mute", False)
+            elif mutemode == 1:
+                for i, tgt in enumerate(targets):
+                    tgt.setprop("mute", i != 0)
+            elif mutemode == 2:
+                for tgt in targets:
+                    tgt.setprop("mute", True)
+            targets[0].runcmd("show_text", "Audio mode: %s" % ["All", "One", "None"][mutemode])
         elif c == 'S':
             offsets = getoffsets()
-            print(offsets)
+            for tgt, off in zip(targets, offsets):
+                tgt.runcmd("show_text", "Offset: %f" % off)
         elif c == '.':
             runcmd("frame_step")
             paused = True