From 6432eae3b4ddcd9178dc6c471010cd29d6bd1ae9 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Fri, 25 Feb 2022 18:06:24 +0000 Subject: [PATCH] add levels add levels to strip and bus class. strip level values defined as: pre fader input peak level in dB * 100 bus level values defined as: bus output peak level in dB * 100 --- __main__.py | 3 ++- vban_cmd/bus.py | 26 ++++++++++++++++++++++++++ vban_cmd/strip.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/__main__.py b/__main__.py index 81d714e..7e89b95 100644 --- a/__main__.py +++ b/__main__.py @@ -3,7 +3,8 @@ from time import sleep def main(): with vban_cmd.connect('potato', ip='ws.local') as vban: - pass + for i in range(8): + print(vban.bus[i].levels.all) if __name__ == '__main__': main() diff --git a/vban_cmd/bus.py b/vban_cmd/bus.py index 916fa7f..4beb6c4 100644 --- a/vban_cmd/bus.py +++ b/vban_cmd/bus.py @@ -14,6 +14,7 @@ class OutputBus(Channel): """ OutputBus = PhysicalOutputBus if is_physical else VirtualOutputBus OB_cls = type(f'Bus{remote.kind.name}', (OutputBus,), { + 'levels': BusLevel(remote, index), }) return OB_cls(remote, index, *args, **kwargs) @@ -91,3 +92,28 @@ class PhysicalOutputBus(OutputBus): class VirtualOutputBus(OutputBus): pass + + +class BusLevel(OutputBus): + def __init__(self, remote, index): + super().__init__(remote, index) + self.level_map = _bus_maps[remote.kind.id] + + def getter_level(self, mode=None): + def fget(data, i): + return data.outputlevels[i] + + range_ = self.level_map[self.index] + data = self._remote.get_rt() + levels = tuple(fget(data, i) for i in range(*range_)) + return levels + + @property + def all(self) -> tuple: + return self.getter_level() + +def _make_bus_level_map(kind): + phys_out, virt_out = kind.outs + return tuple((i, i+8) for i in range(0, (phys_out+virt_out)*8, 8)) + +_bus_maps = {kind.id: _make_bus_level_map(kind) for kind in kinds.all} diff --git a/vban_cmd/strip.py b/vban_cmd/strip.py index 558cb34..583215b 100644 --- a/vban_cmd/strip.py +++ b/vban_cmd/strip.py @@ -15,6 +15,7 @@ class InputStrip(Channel): PhysStrip, VirtStrip = _strip_pairs[remote.kind.id] InputStrip = PhysStrip if is_physical else VirtStrip IS_cls = type(f'Strip{remote.kind.name}', (InputStrip,), { + 'levels': StripLevel(remote, index), }) return IS_cls(remote, index, **kwargs) @@ -133,6 +134,33 @@ class VirtualInputStrip(InputStrip): self.setter('karaoke', val) +class StripLevel(InputStrip): + def __init__(self, remote, index): + super().__init__(remote, index) + self.level_map = _strip_maps[remote.kind.id] + + def getter_level(self, mode=None): + def fget(data, i): + return data.inputlevels[i] + + range_ = self.level_map[self.index] + data = self._remote.get_rt() + levels = tuple(fget(data, i) for i in range(*range_)) + return levels + + @property + def prefader(self) -> tuple: + return self.getter_level() + + @property + def postfader(self) -> tuple: + return + + @property + def postmute(self) -> tuple: + return + + def _make_strip_mixin(kind): """ Creates a mixin with the kind's strip layout set as class variables. """ num_A, num_B = kind.outs @@ -151,3 +179,11 @@ def _make_strip_pair(kind): return (PhysStrip, VirtStrip) _strip_pairs = {kind.id: _make_strip_pair(kind) for kind in kinds.all} + +def _make_strip_level_map(kind): + phys_in, virt_in = kind.ins + phys_map = tuple((i, i+2) for i in range(0, phys_in*2, 2)) + virt_map = tuple((i, i+8) for i in range(phys_in*2, phys_in*2+virt_in*8, 8)) + return phys_map+virt_map + +_strip_maps = {kind.id: _make_strip_level_map(kind) for kind in kinds.all}