summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranziska Kunsmann <hi@kunsmann.eu>2023-05-01 15:29:25 +0200
committerGitHub <noreply@github.com>2023-05-01 15:29:25 +0200
commite7b773148b86676414419d76a4b40c4201b18d87 (patch)
treef01b76bcfbe4a3ee57042b2927c2ddac477b90a0
parent96328d2790dd1ac2ebd4ea86efc27c00dce337e5 (diff)
parent968194e89f4efb3c0bb96267b498f05ec5d0ee2c (diff)
Merge pull request #1 from sophieschi/input-renamin-on-startup
rename inputs on startup
-rw-r--r--.gitignore4
-rw-r--r--config.toml21
-rw-r--r--switcher.py57
3 files changed, 47 insertions, 35 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..7d5bfea 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]
+input1 = "Laptop"
+input3 = "Kamera"
+input2 = "VGA"
+input4 = "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..e4387a2 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,57 +38,65 @@ 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', {})
-
- # TODO setInputLongName
- # TODO setInputShortName
+ 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):
+ 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:
- 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()
@@ -109,7 +114,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,