From 08a20d02065db4c55d9dfa57225b2329a3d9225e Mon Sep 17 00:00:00 2001 From: Sophie Schiller Date: Mon, 1 May 2023 13:47:22 +0200 Subject: rename inputs on startup --- .gitignore | 4 ++++ config.toml | 21 ++++++++++++--------- switcher.py | 10 +++++++--- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index f7275bb..39882e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ +*.swp +*.swo +__pycache__/ venv/ +env/ diff --git a/config.toml b/config.toml index 4e3f0ea..31289ab 100644 --- a/config.toml +++ b/config.toml @@ -1,15 +1,18 @@ [atem] -ip = '10.73.96.40' -video_mode = '1080p50' +ip = "10.73.4.40" +video_mode = "1080p25" -[atem.settings] +[atem.settings.inputs] +hdmi1 = "Laptop" +hdmi2 = "Kamera" +hdmi3 = "VGA" +hdmi4 = "Infobeamer" +[gtk-settings] +gtk-application-prefer-dark-theme = true +gtk-theme-name = "Adwaita" [logging] -# see https://docs.python.org/3/library/logging.html#levels -level = 10 -format = '%(name)25s [%(levelname)-8s] %(message)s' +format = "%(name)25s [%(levelname)-8s] %(message)s" +level = "DEBUG" -[gtk-settings] -gtk-theme-name = "Adwaita" -gtk-application-prefer-dark-theme = true diff --git a/switcher.py b/switcher.py index c025ce7..6454850 100644 --- a/switcher.py +++ b/switcher.py @@ -63,9 +63,6 @@ class PyATEMSwitcher: def _push_config(self): conf = self.config.get('settings', {}) - - # TODO setInputLongName - # TODO setInputShortName # TODO media upload to MP1 if 'video_mode' in self.config: @@ -75,6 +72,13 @@ class PyATEMSwitcher: ) if self.atem.videoMode.format != video_mode: self.atem.setVideoModeFormat(video_mode) + + if conf.get('inputs', None): + for i in range(1,5): + input_name = conf['inputs'][f'hdmi{i}'] + self.log.debug(f"setting input {i} to name '{input_name}'") + self.atem.setInputLongName(i, input_name) + self.atem.setInputShortName(i, input_name[0:3]) def _validate_config(self): if 'ip' not in self.config: -- cgit v1.2.3 From eddde71c3969888195c5758cced40a6afa007069 Mon Sep 17 00:00:00 2001 From: Sophie Schiller Date: Mon, 1 May 2023 14:26:46 +0200 Subject: allow renaming an arbitrary count of inputs --- config.toml | 19 +++++++++++++++---- switcher.py | 13 +++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/config.toml b/config.toml index 31289ab..8256646 100644 --- a/config.toml +++ b/config.toml @@ -3,10 +3,21 @@ ip = "10.73.4.40" video_mode = "1080p25" [atem.settings.inputs] -hdmi1 = "Laptop" -hdmi2 = "Kamera" -hdmi3 = "VGA" -hdmi4 = "Infobeamer" +1 = "Laptop" +2 = "Kamera" +3 = "VGA" +4 = "Infobeamer" +# 5 ... 40 further HDMI/SDI Inputs +# 1000 = 'colorBars' +# 2001 = 'color1' +# 2002 = 'color2' +# 3010 = 'mediaPlayer1' +# 3011 = 'mediaPlayer1Key' +# 3020 .. 3040 further media players +# 3021 .. 3041 further media plaer keys +# 4010 = 'key1Mask' +# ... and a gazillion more inputs + [gtk-settings] gtk-application-prefer-dark-theme = true diff --git a/switcher.py b/switcher.py index 6454850..31b5933 100644 --- a/switcher.py +++ b/switcher.py @@ -2,7 +2,7 @@ import logging import PyATEMMax from PyATEMMax.ATEMProtocolEnums import ATEMVideoModeFormats, ATEMTransitionStyles - +from rich import inspect VIDEO_FORMATS = { f[1:] for f in dir(ATEMVideoModeFormats) @@ -74,11 +74,12 @@ class PyATEMSwitcher: self.atem.setVideoModeFormat(video_mode) if conf.get('inputs', None): - for i in range(1,5): - input_name = conf['inputs'][f'hdmi{i}'] - self.log.debug(f"setting input {i} to name '{input_name}'") - self.atem.setInputLongName(i, input_name) - self.atem.setInputShortName(i, input_name[0:3]) + for inp in self.atem.atem.videoSources: + if conf['inputs'].get(inp.value, None): + new_name = conf['inputs'][inp.value] + self.log.debug(f"setting input {inp.value} to name '{new_name}'") + self.atem.setInputLongName(inp.value, new_name) + self.atem.setInputShortName(inp.value, new_name[0:3]) def _validate_config(self): if 'ip' not in self.config: -- cgit v1.2.3 From f317e0ee068fd8f018868a1eaa6e8c1b6f604cd9 Mon Sep 17 00:00:00 2001 From: Sophie Schiller Date: Mon, 1 May 2023 14:44:11 +0200 Subject: rename inputs on startup --- config.toml | 19 ++++--------------- switcher.py | 13 ++++++------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/config.toml b/config.toml index 8256646..7d5bfea 100644 --- a/config.toml +++ b/config.toml @@ -3,21 +3,10 @@ ip = "10.73.4.40" video_mode = "1080p25" [atem.settings.inputs] -1 = "Laptop" -2 = "Kamera" -3 = "VGA" -4 = "Infobeamer" -# 5 ... 40 further HDMI/SDI Inputs -# 1000 = 'colorBars' -# 2001 = 'color1' -# 2002 = 'color2' -# 3010 = 'mediaPlayer1' -# 3011 = 'mediaPlayer1Key' -# 3020 .. 3040 further media players -# 3021 .. 3041 further media plaer keys -# 4010 = 'key1Mask' -# ... and a gazillion more inputs - +input1 = "Laptop" +input3 = "Kamera" +input2 = "VGA" +input4 = "Infobeamer" [gtk-settings] gtk-application-prefer-dark-theme = true diff --git a/switcher.py b/switcher.py index 31b5933..4262846 100644 --- a/switcher.py +++ b/switcher.py @@ -2,7 +2,7 @@ import logging import PyATEMMax from PyATEMMax.ATEMProtocolEnums import ATEMVideoModeFormats, ATEMTransitionStyles -from rich import inspect + VIDEO_FORMATS = { f[1:] for f in dir(ATEMVideoModeFormats) @@ -74,12 +74,11 @@ class PyATEMSwitcher: self.atem.setVideoModeFormat(video_mode) if conf.get('inputs', None): - for inp in self.atem.atem.videoSources: - if conf['inputs'].get(inp.value, None): - new_name = conf['inputs'][inp.value] - self.log.debug(f"setting input {inp.value} to name '{new_name}'") - self.atem.setInputLongName(inp.value, new_name) - self.atem.setInputShortName(inp.value, new_name[0:3]) + for key, name in conf['inputs'].items(): + input_number = getattr(self.atem.atem.videoSources, key) + self.log.debug(f"setting input {input_number} to name '{name}'") + self.atem.setInputLongName(input_number, name) + self.atem.setInputShortName(input_number, name[0:3]) def _validate_config(self): if 'ip' not in self.config: -- cgit v1.2.3 From dc775c9113ad65b5e5773dfd5ebe8a61d29c1711 Mon Sep 17 00:00:00 2001 From: Sophie Schiller Date: Mon, 1 May 2023 14:46:05 +0200 Subject: black and isort --- switcher.py | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/switcher.py b/switcher.py index 4262846..595962a 100644 --- a/switcher.py +++ b/switcher.py @@ -1,20 +1,17 @@ import logging import PyATEMMax -from PyATEMMax.ATEMProtocolEnums import ATEMVideoModeFormats, ATEMTransitionStyles +from PyATEMMax.ATEMProtocolEnums import (ATEMTransitionStyles, + ATEMVideoModeFormats) -VIDEO_FORMATS = { - f[1:] - for f in dir(ATEMVideoModeFormats) - if f.startswith('f') -} +VIDEO_FORMATS = {f[1:] for f in dir(ATEMVideoModeFormats) if f.startswith("f")} class PyATEMSwitcher: def __init__(self, config): self.atem = PyATEMMax.ATEMMax() - self.config = config.get('atem', {}) - self.log = logging.getLogger('Switcher') + self.config = config.get("atem", {}) + self.log = logging.getLogger("Switcher") self._connect_subscribers = [] self._connect_attempt_subscribers = [] @@ -41,61 +38,61 @@ class PyATEMSwitcher: ) def _on_connect(self, params): - self.log.debug(f'_on_connect({repr(params)})') + self.log.debug(f"_on_connect({repr(params)})") self._push_config() for callback in self._connect_subscribers: callback(params) def _on_connect_attempt(self, params): - self.log.debug(f'_on_connect_attempt({repr(params)})') + self.log.debug(f"_on_connect_attempt({repr(params)})") for callback in self._connect_attempt_subscribers: callback(params) def _on_disconnect(self, params): - self.log.debug(f'_on_disconnect({repr(params)})') + self.log.debug(f"_on_disconnect({repr(params)})") for callback in self._disconnect_subscribers: callback(params) def _on_receive(self, params): - self.log.debug(f'_on_receive({repr(params)})') + self.log.debug(f"_on_receive({repr(params)})") for callback in self._receive_subscribers: callback(params) def _push_config(self): - conf = self.config.get('settings', {}) + conf = self.config.get("settings", {}) # TODO media upload to MP1 - if 'video_mode' in self.config: + if "video_mode" in self.config: video_mode = getattr( ATEMVideoModeFormats, - 'f'+self.config['video_mode'], + "f" + self.config["video_mode"], ) if self.atem.videoMode.format != video_mode: self.atem.setVideoModeFormat(video_mode) - - if conf.get('inputs', None): - for key, name in conf['inputs'].items(): + + if conf.get("inputs", None): + for key, name in conf["inputs"].items(): input_number = getattr(self.atem.atem.videoSources, key) self.log.debug(f"setting input {input_number} to name '{name}'") self.atem.setInputLongName(input_number, name) self.atem.setInputShortName(input_number, name[0:3]) def _validate_config(self): - if 'ip' not in self.config: - raise KeyError('Please set ATEM IP in config!') + if "ip" not in self.config: + raise KeyError("Please set ATEM IP in config!") if ( - 'video_mode' in self.config - and self.config['video_mode'] not in VIDEO_FORMATS + "video_mode" in self.config + and self.config["video_mode"] not in VIDEO_FORMATS ): raise ValueError( f'ATEM video_mode {self.config["video_mode"]} ' - 'is not a valid video mode, must be one of: ' + "is not a valid video mode, must be one of: " f'{", ".join(sorted(VIDEO_FORMATS))}' ) def connect(self): - self.log.info('Initiating connection to switcher') - self.atem.connect(self.config['ip']) + self.log.info("Initiating connection to switcher") + self.atem.connect(self.config["ip"]) def disconnect(self): self.atem.disconnect() @@ -113,7 +110,7 @@ class PyATEMSwitcher: self._receive_subscribers.append(callback) def trans(self, input): - self.log.debug(f'hehehehe trans({repr(input)})') + self.log.debug(f"hehehehe trans({repr(input)})") self.atem.setPreviewInputVideoSource( ATEMTransitionStyles.mix, input, -- cgit v1.2.3 From 968194e89f4efb3c0bb96267b498f05ec5d0ee2c Mon Sep 17 00:00:00 2001 From: Sophie Schiller Date: Mon, 1 May 2023 15:28:42 +0200 Subject: error handling --- switcher.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/switcher.py b/switcher.py index 595962a..e4387a2 100644 --- a/switcher.py +++ b/switcher.py @@ -71,11 +71,15 @@ class PyATEMSwitcher: self.atem.setVideoModeFormat(video_mode) if conf.get("inputs", None): - for key, name in conf["inputs"].items(): - input_number = getattr(self.atem.atem.videoSources, key) - self.log.debug(f"setting input {input_number} to name '{name}'") - self.atem.setInputLongName(input_number, name) - self.atem.setInputShortName(input_number, name[0:3]) + try: + for key, name in conf["inputs"].items(): + input_number = getattr(self.atem.atem.videoSources, key) + self.log.debug(f"setting input {input_number} to name '{name}'") + self.atem.setInputLongName(input_number, name) + self.atem.setInputShortName(input_number, name[0:4].upper()) + except Exception as e: + self.log.error("An error occurred while trying to adjust input names") + self.log.exception(e) def _validate_config(self): if "ip" not in self.config: -- cgit v1.2.3