From b6695fbc4dffdd52b9137786aa06ab4b3ba7b9c7 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Wed, 4 May 2022 18:33:04 +0100 Subject: [PATCH] rename Channel to IChannel to signify it as the common interface. bus mode mixin now subclasses IChannel bus mode properties lowercased in array. --- vbancmd/bus.py | 45 +++++++++++++++++++++++++++------------------ vbancmd/channel.py | 2 +- vbancmd/meta.py | 6 +++--- vbancmd/strip.py | 4 ++-- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/vbancmd/bus.py b/vbancmd/bus.py index c1f82ba..ed4f9c3 100644 --- a/vbancmd/bus.py +++ b/vbancmd/bus.py @@ -1,10 +1,10 @@ from .errors import VMCMDErrors -from .channel import Channel +from .channel import IChannel from . import kinds from .meta import bus_mode_prop, channel_bool_prop, channel_label_prop -class OutputBus(Channel): +class OutputBus(IChannel): """Base class for output buses.""" @classmethod @@ -13,7 +13,7 @@ class OutputBus(Channel): Factory function for output busses. Returns a physical/virtual bus of a kind. """ - BusModeMixin = _make_bus_mode_mixin(cls) + BusModeMixin = _make_bus_mode_mixin(IChannel) OutputBus = PhysicalOutputBus if is_physical else VirtualOutputBus OB_cls = type( f"Bus{remote.kind.name}", @@ -68,11 +68,15 @@ class VirtualOutputBus(OutputBus): pass -class BusLevel(OutputBus): +class BusLevel(IChannel): def __init__(self, remote, index): super().__init__(remote, index) self.level_map = _bus_maps[remote.kind.id] + @property + def identifier(self) -> str: + return f"Bus[{self.index}]" + def getter_level(self, mode=None): def fget(i, data): val = data.outputlevels[i] @@ -96,27 +100,32 @@ def _make_bus_level_map(kind): _bus_maps = {kind.id: _make_bus_level_map(kind) for kind in kinds.all} -def _make_bus_mode_mixin(cls): +def _make_bus_mode_mixin(kls): """Creates a mixin of Bus Modes.""" + + def identifier(self) -> str: + return f"Bus[{self.index}].mode" + return type( "BusModeMixin", - (cls,), + (kls,), { + "identifier": property(identifier), **{ - f"{mode.lower()}": bus_mode_prop(mode.lower()) + mode: bus_mode_prop(mode) for mode in [ "normal", - "Amix", - "Bmix", - "Repeat", - "Composite", - "TVMix", - "UpMix21", - "UpMix41", - "UpMix61", - "CenterOnly", - "LFEOnly", - "RearOnly", + "amix", + "bmix", + "repeat", + "composite", + "tvmix", + "upmix21", + "upmix41", + "upmix61", + "centeronly", + "lfeonly", + "rearonly", ] }, }, diff --git a/vbancmd/channel.py b/vbancmd/channel.py index 3880fb6..d4cb008 100644 --- a/vbancmd/channel.py +++ b/vbancmd/channel.py @@ -76,7 +76,7 @@ class Modes: ) -class Channel(abc.ABC): +class IChannel(abc.ABC): """Base class for InputStrip and OutputBus.""" def __init__(self, remote, index): diff --git a/vbancmd/meta.py b/vbancmd/meta.py index d84bc03..4830e3e 100644 --- a/vbancmd/meta.py +++ b/vbancmd/meta.py @@ -63,7 +63,7 @@ def strip_output_prop(param): def bus_mode_prop(param): """A bus mode prop.""" - @partial(cache_bool, param=f"mode.{param}") + @partial(cache_bool, param=param) def fget(self): modelist = { "amix": (1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1), @@ -88,8 +88,8 @@ def bus_mode_prop(param): def fset(self, val): if not isinstance(val, bool) and val not in (0, 1): - raise VMCMDErrors(f"mode.{param} is a boolean parameter") - self.setter(f"mode.{param}", 1 if val else 0) + raise VMCMDErrors(f"{param} is a boolean parameter") + self.setter(param, 1 if val else 0) return property(fget, fset) diff --git a/vbancmd/strip.py b/vbancmd/strip.py index 7d651d5..9849e30 100644 --- a/vbancmd/strip.py +++ b/vbancmd/strip.py @@ -1,10 +1,10 @@ from .errors import VMCMDErrors -from .channel import Channel +from .channel import IChannel from . import kinds from .meta import strip_output_prop, channel_bool_prop, channel_label_prop -class InputStrip(Channel): +class InputStrip(IChannel): """Base class for input strips.""" @classmethod