rename Channel to IChannel to signify it as the common interface.

bus mode mixin now subclasses IChannel

bus mode properties lowercased in array.
This commit is contained in:
onyx-and-iris 2022-05-04 18:33:04 +01:00
parent b3762de5be
commit b6695fbc4d
4 changed files with 33 additions and 24 deletions

View File

@ -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",
]
},
},

View File

@ -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):

View File

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

View File

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