From 55725a8a034f588789c6d497c8c3163d5abe56dc Mon Sep 17 00:00:00 2001
From: David Trattnig <david.trattnig@o94.at>
Date: Fri, 23 Oct 2020 14:59:07 +0200
Subject: [PATCH] More flexible Liquidsoap mixer handling. #44

---
 modules/core/liquidsoap/client.py       | 10 ++--
 modules/core/liquidsoap/playerclient.py | 62 +++++++++++--------------
 2 files changed, 32 insertions(+), 40 deletions(-)

diff --git a/modules/core/liquidsoap/client.py b/modules/core/liquidsoap/client.py
index 87d2e2fb..c49b89a9 100644
--- a/modules/core/liquidsoap/client.py
+++ b/modules/core/liquidsoap/client.py
@@ -27,13 +27,15 @@ from multiprocessing import Lock
 from modules.base.exceptions import LQConnectionError
 from modules.base.utils import TerminalColors
 
-""" 
-    LiquidSoapClient Class 
-    Connects to a LiquidSoap instance over a socket and sends commands to it
-"""
+
 
 
 class LiquidSoapClient:
+    """ 
+    LiquidSoapClient Class
+    
+    Connects to a LiquidSoap instance over a socket and sends commands to it
+    """
     mutex = None
     logger = None
     debug = False
diff --git a/modules/core/liquidsoap/playerclient.py b/modules/core/liquidsoap/playerclient.py
index e2f5325b..7604c67c 100644
--- a/modules/core/liquidsoap/playerclient.py
+++ b/modules/core/liquidsoap/playerclient.py
@@ -17,8 +17,6 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-# FIXME Refactor to avoid use of Channel Class here
-from modules.core.channels import Channel
 from modules.core.liquidsoap.client import LiquidSoapClient
 
 
@@ -28,37 +26,37 @@ class LiquidSoapPlayerClient(LiquidSoapClient):
     # Mixer
     #
 
-    def mixer(self, command, *args):
-        if command == "status":
-            return self.mixerstatus(*args)
+    # def mixer(self, mixer_id, command, *args):
+    #     if command == "status":
+    #         return self.mixer_status(mixer_id, *args)
 
-        if command == "inputs":
-            return self.mixerinputs()
+    #     if command == "inputs":
+    #         return self.mixer_inputs(mixer_id)
 
-        if command == "volume":
-            return self.mixer_volume(*args)
+    #     if command == "volume":
+    #         return self.mixer_volume(mixer_id, *args)
 
-        if command == "select":
-            if len(args) == 2:
-                return self.mixer_select(args[0], args[1])
+    #     if command == "select":
+    #         if len(args) == 2:
+    #             return self.mixer_select(mixer_id, args[0], args[1])
 
-        if command == "activate":
-            if len(args) == 2:
-                return self.mixer_activate(args[0], args[1])
+    #     if command == "activate":
+    #         if len(args) == 2:
+    #             return self.mixer_activate(mixer_id, args[0], args[1])
 
-        return "LiquidSoapPlayerClient does not understand mixer."+command+str(args)
+    #     return "LiquidSoapPlayerClient does not understand mixer."+command+str(args)
 
 
     # ------------------------------------------------------------------------------------------ #
-    def mixerinputs(self):
+    def mixer_inputs(self, mixer_id):
         # send command
-        self.command("mixer", "inputs")
+        self.command(mixer_id, "inputs")
 
         # convert to list and return it
         return self.message.strip().split(' ')
 
     # ------------------------------------------------------------------------------------------ #
-    def mixerstatus(self, pos=""):
+    def mixer_status(self, mixer_id, pos=""):
         """
         Get state of a source in the mixer
         @type    pos:       string
@@ -66,11 +64,11 @@ class LiquidSoapPlayerClient(LiquidSoapClient):
         @rtype:  string
         @return: Response from LiquidSoap
         """
-        self.command("mixer", "status", str(pos))
+        self.command(mixer_id, "status", str(pos))
         return self.message
 
 
-    def mixer_volume(self, pos, volume):
+    def mixer_volume(self, mixer_id, pos, volume):
         """
         Sets some mixer channel to the given volume
 
@@ -81,11 +79,11 @@ class LiquidSoapPlayerClient(LiquidSoapClient):
         Returns:
             (String):   Liquidsoap server response
         """
-        self.command("mixer", "volume", str(pos) + " " + str(volume))
+        self.command(mixer_id, "volume", str(pos) + " " + str(volume))
         return self.message
 
 
-    def mixer_select(self, pos, select):
+    def mixer_select(self, mixer_id, pos, select):
         """
         Selects some mixer channel or vice versa.
 
@@ -96,11 +94,11 @@ class LiquidSoapPlayerClient(LiquidSoapClient):
         Returns:
             (String):   Liquidsoap server response
         """
-        self.command("mixer", "select", str(pos) + " " + str(select).lower())
+        self.command(mixer_id, "select", str(pos) + " " + str(select).lower())
         return self.message
 
 
-    def mixer_activate(self, pos, activate):
+    def mixer_activate(self, mixer_id, pos, activate):
         """
         Selects some mixer channel and increases the volume to 100 or vice versa.
 
@@ -111,7 +109,7 @@ class LiquidSoapPlayerClient(LiquidSoapClient):
         Returns:
             (String):   Liquidsoap server response
         """
-        self.command("mixer", "activate", str(pos) + " " + str(activate).lower())
+        self.command(mixer_id, "activate", str(pos) + " " + str(activate).lower())
         return self.message
 
 
@@ -176,11 +174,7 @@ class LiquidSoapPlayerClient(LiquidSoapClient):
         Returns:
             Liquidsoap server response
         """
-        if channel == Channel.SCHEDULED_FALLBACK.value:
-            self.command(channel, 'uri', uri)            
-        else:
-            return "Invalid filesystem channel '%s'" % channel
-
+        self.command(channel, 'uri', uri)            
         return self.message
 
 
@@ -195,11 +189,7 @@ class LiquidSoapPlayerClient(LiquidSoapClient):
         Returns:
             Liquidsoap server response
         """
-        if channel == Channel.SCHEDULED_FALLBACK.value:
-            self.command(channel, 'clear')            
-        else:
-            return "Invalid filesystem channel '%s'" % channel
-
+        self.command(channel, 'clear')            
         return self.message
 
 
-- 
GitLab