From f26de42b89eeea61d348b7c24bbcbb8a443c7871 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 3 Jan 2025 10:19:06 +0000 Subject: [PATCH] add headamp class --- CHANGELOG.md | 2 +- examples/headamp/__main__.py | 18 +++++++++++++ pyproject.toml | 2 +- xair_api/adapter.py | 7 ++++++ xair_api/headamp.py | 49 ++++++++++++++++++++++++++++++++++++ xair_api/kinds.py | 1 + xair_api/xair.py | 3 +++ 7 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 examples/headamp/__main__.py create mode 100644 xair_api/headamp.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 4aa7937..b0dbb8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass ## [Unreleased] -- [ ] +- [x] Add preamp class to all kinds for enabling phantom power and setting preamp gain. ## [2.3.2] - 2024-02-16 diff --git a/examples/headamp/__main__.py b/examples/headamp/__main__.py new file mode 100644 index 0000000..ad1018a --- /dev/null +++ b/examples/headamp/__main__.py @@ -0,0 +1,18 @@ +import logging + +import xair_api + +logging.basicConfig(level=logging.DEBUG) + + +def main(): + with xair_api.connect("XR18", ip="mixer.local") as mixer: + mixer.headamp[8].phantom = True + for i in range(-12, -6): + mixer.headamp[8].gain = i + print(mixer.headamp[8].gain) + input("Press Enter to continue...") + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml index 6d454b6..c5b92a2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "xair-api" -version = "2.3.2" +version = "2.3.3a0" description = "Remote control Behringer X-Air | Midas MR mixers through OSC" authors = ["onyx-and-iris "] license = "MIT" diff --git a/xair_api/adapter.py b/xair_api/adapter.py index 0424c82..c7422fe 100644 --- a/xair_api/adapter.py +++ b/xair_api/adapter.py @@ -1,4 +1,5 @@ from .bus import Bus as IBus +from .headamp import HeadAmp as IHeadAmp from .lr import LR as ILR from .rtn import AuxRtn as IAuxRtn from .rtn import FxRtn as IFxRtn @@ -38,3 +39,9 @@ class Matrix(ILR): @property def address(self) -> str: return f"/mtx/{str(self.index).zfill(2)}" + + +class HeadAmp(IHeadAmp): + @property + def address(self): + return f"/headamp/{str(self.index).zfill(3)}" diff --git a/xair_api/headamp.py b/xair_api/headamp.py new file mode 100644 index 0000000..221af03 --- /dev/null +++ b/xair_api/headamp.py @@ -0,0 +1,49 @@ +import abc +import logging + +from . import util + +logger = logging.getLogger(__name__) + + +class IHeadAmp(abc.ABC): + """Abstract Base Class for headamps""" + + def __init__(self, remote, index: int): + self._remote = remote + self.index = index + 1 + self.logger = logger.getChild(self.__class__.__name__) + + def getter(self, param: str): + return self._remote.query(f"{self.address}/{param}") + + def setter(self, param: str, val: int): + self._remote.send(f"{self.address}/{param}", val) + + @abc.abstractmethod + def address(self): + pass + + +class HeadAmp(IHeadAmp): + """Concrete class for headamps""" + + @property + def address(self): + return f"/headamp/{str(self.index).zfill(2)}" + + @property + def gain(self): + return round(util.lin_get(-12, 60, self.getter("gain")[0]), 1) + + @gain.setter + def gain(self, val): + self.setter("gain", util.lin_set(-12, 60, val)) + + @property + def phantom(self): + return self.getter("phantom")[0] == 1 + + @phantom.setter + def phantom(self, val): + self.setter("phantom", 1 if val else 0) diff --git a/xair_api/kinds.py b/xair_api/kinds.py index 6bc305f..dc00991 100644 --- a/xair_api/kinds.py +++ b/xair_api/kinds.py @@ -16,6 +16,7 @@ class X32KindMap(KindMap): num_fx: int = 8 num_auxrtn: int = 8 num_matrix: int = 6 + num_headamp: int = 127 @dataclass diff --git a/xair_api/xair.py b/xair_api/xair.py index ec73896..ac34069 100644 --- a/xair_api/xair.py +++ b/xair_api/xair.py @@ -20,6 +20,7 @@ from .config import Config from .dca import DCA from .errors import XAirRemoteConnectionTimeoutError, XAirRemoteError from .fx import FX, FXSend +from .headamp import HeadAmp from .kinds import KindMap from .lr import LR from .rtn import AuxRtn, FxRtn @@ -134,6 +135,7 @@ def _make_remote(kind: KindMap) -> XAirRemote: self.fxreturn = tuple(adapter.FxRtn.make(self, i) for i in range(kind.num_fx)) self.auxin = tuple(adapter.AuxRtn.make(self, i) for i in range(kind.num_auxrtn)) self.config = Config.make(self) + self.headamp = tuple(adapter.HeadAmp(self, i) for i in range(kind.num_headamp)) def init_xair(self, *args, **kwargs): defaultkwargs = { @@ -154,6 +156,7 @@ def _make_remote(kind: KindMap) -> XAirRemote: self.fxreturn = tuple(FxRtn.make(self, i) for i in range(kind.num_fx)) self.auxreturn = AuxRtn.make(self) self.config = Config.make(self) + self.headamp = tuple(HeadAmp(self, i) for i in range(kind.num_strip)) if kind.id_ == "X32": return type(