From a86a25ca8f183fcfe2545316acc6d60105913518 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Sat, 16 Jul 2022 21:50:50 +0100 Subject: [PATCH] BusModes IntEnum added to bus get() added to bus mode mixin, returns the current bus mode. added support for setting bus mode by dict fixed bug in apply where bool parameters weren't being applied. bus modes added to all 3 example configs. test_config added to unit tests. --- configs/banana/example.toml | 7 +++--- configs/basic/example.toml | 7 +++--- tests/test_configs.py | 29 ++++++++++++++++++++++ vban_cmd/bus.py | 49 ++++++++++++++++++++++++------------- vban_cmd/iremote.py | 12 ++++++++- 5 files changed, 78 insertions(+), 26 deletions(-) create mode 100644 tests/test_configs.py diff --git a/configs/banana/example.toml b/configs/banana/example.toml index 9f3d62e..5576cca 100644 --- a/configs/banana/example.toml +++ b/configs/banana/example.toml @@ -16,13 +16,10 @@ limit = -15 [strip-3] label = "VirtStrip0" -bass = -3.2 -mid = 1.5 -treble = 2.1 +limit = -12 [strip-4] label = "VirtStrip1" -limit = -12 [bus-0] label = "PhysBus0" @@ -35,10 +32,12 @@ mono = true [bus-2] label = "PhysBus2" eq = true +mode = "composite" [bus-3] label = "VirtBus0" eq_ab = true +mode = "upmix61" [bus-4] label = "VirtBus1" diff --git a/configs/basic/example.toml b/configs/basic/example.toml index edd2cf6..39db844 100644 --- a/configs/basic/example.toml +++ b/configs/basic/example.toml @@ -10,14 +10,13 @@ audibility = 3.2 [strip-2] label = "VirtStrip0" -bass = -3.2 -mid = 1.5 -treble = 2.1 [bus-0] label = "PhysBus0" mute = true +mode = "composite" [bus-1] -label = "PhysBus1" +label = "VirtBus0" mono = true +mode = "amix" diff --git a/tests/test_configs.py b/tests/test_configs.py new file mode 100644 index 0000000..d29315e --- /dev/null +++ b/tests/test_configs.py @@ -0,0 +1,29 @@ +import time + +import pytest + +from tests import data, tests + + +class TestSetAndGetBoolHigher: + __test__ = True + + """example config tests""" + + @classmethod + def setup_class(cls): + tests.apply_config("example") + + def test_it_tests_config_string(self): + assert "PhysStrip" in tests.strip[data.phys_in].label + assert "VirtStrip" in tests.strip[data.virt_in].label + + def test_it_tests_config_bool(self): + assert tests.strip[0].A1 == True + + @pytest.mark.skipif( + "not config.getoption('--run-slow')", + reason="Only run when --run-slow is given", + ) + def test_it_tests_config_busmode(self): + assert tests.bus[data.phys_out].mode.get() == "composite" diff --git a/vban_cmd/bus.py b/vban_cmd/bus.py index 1b0fca9..917db2c 100644 --- a/vban_cmd/bus.py +++ b/vban_cmd/bus.py @@ -1,9 +1,18 @@ +import time from abc import abstractmethod +from enum import IntEnum from typing import Union +from .error import VMCMDErrors from .iremote import IRemote from .meta import bus_mode_prop, channel_bool_prop, channel_label_prop +BusModes = IntEnum( + "BusModes", + "normal amix bmix repeat composite tvmix upmix21 upmix41 upmix61 centeronly lfeonly rearonly", + start=0, +) + class Bus(IRemote): """ @@ -95,28 +104,34 @@ def _make_bus_mode_mixin(): def identifier(self) -> str: return f"Bus[{self.index}].mode" + def get(self): + time.sleep(0.01) + for i, val in enumerate( + [ + self.amix, + self.bmix, + self.repeat, + self.composite, + self.tvmix, + self.upmix21, + self.upmix41, + self.upmix61, + self.centeronly, + self.lfeonly, + self.rearonly, + ] + ): + if val: + return BusModes(i + 1).name + return "normal" + return type( "BusModeMixin", (IRemote,), { "identifier": property(identifier), - **{ - mode: bus_mode_prop(mode) - for mode in [ - "normal", - "amix", - "bmix", - "repeat", - "composite", - "tvmix", - "upmix21", - "upmix41", - "upmix61", - "centeronly", - "lfeonly", - "rearonly", - ] - }, + **{mode.name: bus_mode_prop(mode.name) for mode in BusModes}, + "get": get, }, ) diff --git a/vban_cmd/iremote.py b/vban_cmd/iremote.py index 6de79f6..22e8af2 100644 --- a/vban_cmd/iremote.py +++ b/vban_cmd/iremote.py @@ -107,9 +107,19 @@ class IRemote(metaclass=ABCMeta): def apply(self, data): """Sets all parameters of a dict for the channel.""" - script = "" + + def fget(attr, val): + if attr == "mode": + return (f"mode.{val}", 1) + return (attr, val) + + script = str() for attr, val in data.items(): if hasattr(self, attr): + attr, val = fget(attr, val) + if isinstance(val, bool): + val = 1 if val else 0 + self._remote.cache[f"{self.identifier}[{self.index}].{attr}"] = val script += f"{self.identifier}[{self.index}].{attr}={val};"