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.
This commit is contained in:
onyx-and-iris 2022-07-16 21:50:50 +01:00
parent a1d6cf1042
commit a86a25ca8f
5 changed files with 78 additions and 26 deletions

View File

@ -16,13 +16,10 @@ limit = -15
[strip-3] [strip-3]
label = "VirtStrip0" label = "VirtStrip0"
bass = -3.2 limit = -12
mid = 1.5
treble = 2.1
[strip-4] [strip-4]
label = "VirtStrip1" label = "VirtStrip1"
limit = -12
[bus-0] [bus-0]
label = "PhysBus0" label = "PhysBus0"
@ -35,10 +32,12 @@ mono = true
[bus-2] [bus-2]
label = "PhysBus2" label = "PhysBus2"
eq = true eq = true
mode = "composite"
[bus-3] [bus-3]
label = "VirtBus0" label = "VirtBus0"
eq_ab = true eq_ab = true
mode = "upmix61"
[bus-4] [bus-4]
label = "VirtBus1" label = "VirtBus1"

View File

@ -10,14 +10,13 @@ audibility = 3.2
[strip-2] [strip-2]
label = "VirtStrip0" label = "VirtStrip0"
bass = -3.2
mid = 1.5
treble = 2.1
[bus-0] [bus-0]
label = "PhysBus0" label = "PhysBus0"
mute = true mute = true
mode = "composite"
[bus-1] [bus-1]
label = "PhysBus1" label = "VirtBus0"
mono = true mono = true
mode = "amix"

29
tests/test_configs.py Normal file
View File

@ -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"

View File

@ -1,9 +1,18 @@
import time
from abc import abstractmethod from abc import abstractmethod
from enum import IntEnum
from typing import Union from typing import Union
from .error import VMCMDErrors
from .iremote import IRemote from .iremote import IRemote
from .meta import bus_mode_prop, channel_bool_prop, channel_label_prop 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): class Bus(IRemote):
""" """
@ -95,28 +104,34 @@ def _make_bus_mode_mixin():
def identifier(self) -> str: def identifier(self) -> str:
return f"Bus[{self.index}].mode" 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( return type(
"BusModeMixin", "BusModeMixin",
(IRemote,), (IRemote,),
{ {
"identifier": property(identifier), "identifier": property(identifier),
**{ **{mode.name: bus_mode_prop(mode.name) for mode in BusModes},
mode: bus_mode_prop(mode) "get": get,
for mode in [
"normal",
"amix",
"bmix",
"repeat",
"composite",
"tvmix",
"upmix21",
"upmix41",
"upmix61",
"centeronly",
"lfeonly",
"rearonly",
]
},
}, },
) )

View File

@ -107,9 +107,19 @@ class IRemote(metaclass=ABCMeta):
def apply(self, data): def apply(self, data):
"""Sets all parameters of a dict for the channel.""" """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(): for attr, val in data.items():
if hasattr(self, attr): 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 self._remote.cache[f"{self.identifier}[{self.index}].{attr}"] = val
script += f"{self.identifier}[{self.index}].{attr}={val};" script += f"{self.identifier}[{self.index}].{attr}={val};"