From d455d410e0cb02843178e339d9cfecf5068fc97c Mon Sep 17 00:00:00 2001
From: David Trattnig <david.trattnig@o94.at>
Date: Wed, 27 May 2020 16:26:33 +0200
Subject: [PATCH] Server function to de-/activate channel.

---
 modules/liquidsoap/serverfunctions.liq | 36 +++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/modules/liquidsoap/serverfunctions.liq b/modules/liquidsoap/serverfunctions.liq
index e328e82f..e618edd8 100644
--- a/modules/liquidsoap/serverfunctions.liq
+++ b/modules/liquidsoap/serverfunctions.liq
@@ -272,4 +272,38 @@ server.register(namespace = "mixer",
 )
 
 ignore(fade_in_time)
-ignore(fade_out_time)
\ No newline at end of file
+ignore(fade_out_time)
+
+
+# Activate a source by selecting it and setting the volume to 100 (or vice versa)
+
+def activate(p) =
+    params=string.split(separator=" ", p) 
+    if list.length(params) < 2 then
+        print(p)
+        "Usage: mixer.activate <source nb> <true|false>"
+    else
+        source_number = list.nth(default="0", params, 0)
+        source_enable = list.nth(default="false", params, 1)
+
+        if source_enable == "true" then
+            r = server.execute("mixer.select #{source_number} true")
+            print(r)
+            r = server.execute("mixer.volume #{source_number} 100")
+            print(r)
+        else
+            r = server.execute("mixer.volume #{source_number} 0")
+            print(r)
+            r = server.execute("mixer.select #{source_number} false")
+            print(r)
+        end
+        "Done!"
+    end
+end
+
+server.register(namespace = "mixer",
+    description = "is selecting a source and setting the volume to 100",
+    usage = "activate <source nb> <true|false>",
+    "activate",
+    activate
+)
-- 
GitLab