2022-03-04 14:22:29 +00:00
|
|
|
from .errors import VMCMDErrors
|
|
|
|
from . import channel
|
|
|
|
from .channel import Channel
|
|
|
|
from . import kinds
|
2022-03-20 12:25:50 +00:00
|
|
|
from .meta import bus_mode_prop, bus_bool_prop
|
2022-03-04 14:22:29 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
class OutputBus(Channel):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""Base class for output buses."""
|
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
@classmethod
|
|
|
|
def make(cls, is_physical, remote, index, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Factory function for output busses.
|
|
|
|
Returns a physical/virtual bus of a kind.
|
|
|
|
"""
|
2022-03-17 14:08:49 +00:00
|
|
|
BusModeMixin = _make_bus_mode_mixin(cls)
|
2022-03-04 14:22:29 +00:00
|
|
|
OutputBus = PhysicalOutputBus if is_physical else VirtualOutputBus
|
2022-03-26 23:00:09 +00:00
|
|
|
OB_cls = type(
|
|
|
|
f"Bus{remote.kind.name}",
|
|
|
|
(OutputBus,),
|
|
|
|
{
|
|
|
|
"levels": BusLevel(remote, index),
|
|
|
|
"mode": BusModeMixin(remote, index),
|
|
|
|
},
|
|
|
|
)
|
2022-03-04 14:22:29 +00:00
|
|
|
return OB_cls(remote, index, *args, **kwargs)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def identifier(self):
|
2022-03-26 23:00:09 +00:00
|
|
|
return f"Bus[{self.index}]"
|
2022-03-04 14:22:29 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
mute = bus_bool_prop("mute")
|
2022-03-04 14:22:29 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
mono = bus_bool_prop("mono")
|
2022-03-04 14:22:29 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
eq = bus_bool_prop("eq.On")
|
2022-03-04 14:22:29 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
eq_ab = bus_bool_prop("eq.ab")
|
2022-03-04 14:22:29 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def label(self) -> str:
|
2022-03-26 23:00:09 +00:00
|
|
|
val = self.getter("label")
|
2022-03-20 12:25:50 +00:00
|
|
|
if val is None:
|
|
|
|
val = self.public_packet.buslabels[self.index]
|
2022-03-26 23:00:09 +00:00
|
|
|
self._remote.cache[f"{self.identifier}.label"] = [val, False]
|
2022-03-20 12:25:50 +00:00
|
|
|
return val
|
2022-03-04 14:22:29 +00:00
|
|
|
|
|
|
|
@label.setter
|
|
|
|
def label(self, val: str):
|
|
|
|
if not isinstance(val, str):
|
2022-03-26 23:00:09 +00:00
|
|
|
raise VMCMDErrors("label is a string parameter")
|
|
|
|
self.setter("label", val)
|
2022-03-04 14:22:29 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def gain(self) -> float:
|
|
|
|
def fget():
|
|
|
|
val = self.public_packet.busgain[self.index]
|
|
|
|
if val < 10000:
|
|
|
|
return -val
|
|
|
|
elif val == ((1 << 16) - 1):
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
return ((1 << 16) - 1) - val
|
2022-03-26 23:00:09 +00:00
|
|
|
|
|
|
|
val = self.getter("gain")
|
2022-03-20 12:25:50 +00:00
|
|
|
if val is None:
|
|
|
|
val = round((fget() * 0.01), 1)
|
2022-03-26 23:00:09 +00:00
|
|
|
self._remote.cache[f"{self.identifier}.gain"] = [val, False]
|
2022-03-20 12:25:50 +00:00
|
|
|
return round(val, 1)
|
2022-03-04 14:22:29 +00:00
|
|
|
|
|
|
|
@gain.setter
|
|
|
|
def gain(self, val: float):
|
2022-03-26 23:00:09 +00:00
|
|
|
self.setter("gain", val)
|
2022-03-04 14:22:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PhysicalOutputBus(OutputBus):
|
|
|
|
@property
|
|
|
|
def device(self) -> str:
|
|
|
|
return
|
|
|
|
|
|
|
|
@property
|
|
|
|
def sr(self) -> int:
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
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(i, data):
|
|
|
|
val = data.outputlevels[i]
|
|
|
|
return -val * 0.01
|
|
|
|
|
|
|
|
range_ = self.level_map[self.index]
|
|
|
|
data = self.public_packet
|
|
|
|
levels = tuple(round(fget(i, data), 1) for i in range(*range_))
|
|
|
|
return levels
|
|
|
|
|
|
|
|
@property
|
|
|
|
def all(self) -> tuple:
|
|
|
|
return self.getter_level()
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
def _make_bus_level_map(kind):
|
|
|
|
phys_out, virt_out = kind.outs
|
2022-03-26 23:00:09 +00:00
|
|
|
return tuple((i, i + 8) for i in range(0, (phys_out + virt_out) * 8, 8))
|
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
|
|
|
|
_bus_maps = {kind.id: _make_bus_level_map(kind) for kind in kinds.all}
|
2022-03-17 14:08:49 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-17 14:08:49 +00:00
|
|
|
def _make_bus_mode_mixin(cls):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""Creates a mixin of Bus Modes."""
|
|
|
|
return type(
|
|
|
|
"BusModeMixin",
|
|
|
|
(cls,),
|
|
|
|
{
|
|
|
|
**{
|
|
|
|
f"{mode.lower()}": bus_mode_prop(mode)
|
|
|
|
for mode in [
|
|
|
|
"normal",
|
|
|
|
"Amix",
|
|
|
|
"Bmix",
|
|
|
|
"Repeat",
|
|
|
|
"Composite",
|
|
|
|
"TVMix",
|
|
|
|
"UpMix21",
|
|
|
|
"UpMix41",
|
|
|
|
"UpMix61",
|
|
|
|
"CenterOnly",
|
|
|
|
"LFEOnly",
|
|
|
|
"RearOnly",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|