2022-03-04 14:22:29 +00:00
|
|
|
from .errors import VMCMDErrors
|
2022-05-04 18:33:04 +01:00
|
|
|
from .channel import IChannel
|
2022-03-04 14:22:29 +00:00
|
|
|
from . import kinds
|
2022-04-29 02:57:47 +01:00
|
|
|
from .meta import strip_output_prop, channel_bool_prop, channel_label_prop
|
2022-03-04 14:22:29 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-05-04 18:33:04 +01:00
|
|
|
class InputStrip(IChannel):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""Base class for input strips."""
|
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
@classmethod
|
|
|
|
def make(cls, is_physical, remote, index, **kwargs):
|
|
|
|
"""
|
|
|
|
Factory function for input strips.
|
|
|
|
Returns a physical/virtual strip of a kind.
|
|
|
|
"""
|
|
|
|
PhysStrip, VirtStrip = _strip_pairs[remote.kind.id]
|
|
|
|
InputStrip = PhysStrip if is_physical else VirtStrip
|
|
|
|
GainLayerMixin = _make_gainlayer_mixin(remote, index)
|
2022-03-26 23:00:09 +00:00
|
|
|
IS_cls = type(
|
|
|
|
f"Strip{remote.kind.name}",
|
|
|
|
(InputStrip, GainLayerMixin),
|
|
|
|
{
|
|
|
|
"levels": StripLevel(remote, index),
|
2022-04-29 02:57:47 +01:00
|
|
|
**{
|
|
|
|
param: channel_bool_prop(param)
|
|
|
|
for param in ["mono", "solo", "mute"]
|
|
|
|
},
|
2022-04-29 21:53:44 +01:00
|
|
|
"label": channel_label_prop(),
|
2022-03-26 23:00:09 +00:00
|
|
|
},
|
|
|
|
)
|
2022-03-04 14:22:29 +00:00
|
|
|
return IS_cls(remote, index, **kwargs)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def identifier(self):
|
2022-04-29 02:57:47 +01:00
|
|
|
return "strip"
|
2022-03-04 14:22:29 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def limit(self) -> int:
|
|
|
|
return
|
|
|
|
|
|
|
|
@limit.setter
|
|
|
|
def limit(self, val: int):
|
2022-03-26 23:00:09 +00:00
|
|
|
self.setter("limit", val)
|
2022-03-04 14:22:29 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def gain(self) -> float:
|
2022-04-29 03:24:32 +01:00
|
|
|
val = self.getter("gain")
|
2022-03-20 12:25:50 +00:00
|
|
|
if val is None:
|
|
|
|
val = self.gainlayer[0].gain
|
2022-04-29 03:24:32 +01: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 PhysicalInputStrip(InputStrip):
|
|
|
|
@property
|
|
|
|
def comp(self) -> float:
|
|
|
|
return
|
|
|
|
|
|
|
|
@comp.setter
|
|
|
|
def comp(self, val: float):
|
2022-03-26 23:00:09 +00:00
|
|
|
self.setter("Comp", val)
|
2022-03-04 14:22:29 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def gate(self) -> float:
|
|
|
|
return
|
|
|
|
|
|
|
|
@gate.setter
|
|
|
|
def gate(self, val: float):
|
2022-03-26 23:00:09 +00:00
|
|
|
self.setter("gate", val)
|
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
@property
|
|
|
|
def device(self):
|
|
|
|
return
|
|
|
|
|
|
|
|
@property
|
|
|
|
def sr(self):
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
class VirtualInputStrip(InputStrip):
|
2022-04-29 02:57:47 +01:00
|
|
|
mc = channel_bool_prop("mc")
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
mono = mc
|
|
|
|
|
|
|
|
@property
|
|
|
|
def k(self) -> int:
|
|
|
|
return
|
|
|
|
|
|
|
|
@k.setter
|
|
|
|
def k(self, val: int):
|
2022-03-26 23:00:09 +00:00
|
|
|
self.setter("karaoke", val)
|
2022-03-04 14:22:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
class StripLevel(InputStrip):
|
|
|
|
def __init__(self, remote, index):
|
|
|
|
super().__init__(remote, index)
|
|
|
|
self.level_map = _strip_maps[remote.kind.id]
|
|
|
|
|
|
|
|
def getter_level(self, mode=None):
|
|
|
|
def fget(i, data):
|
|
|
|
val = data.inputlevels[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 prefader(self) -> tuple:
|
|
|
|
return self.getter_level()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def postfader(self) -> tuple:
|
|
|
|
return
|
|
|
|
|
|
|
|
@property
|
|
|
|
def postmute(self) -> tuple:
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
class GainLayer(InputStrip):
|
|
|
|
def __init__(self, remote, index, i):
|
|
|
|
super().__init__(remote, index)
|
|
|
|
self._i = i
|
|
|
|
|
|
|
|
@property
|
|
|
|
def gain(self) -> float:
|
|
|
|
def fget():
|
2022-03-26 23:00:09 +00:00
|
|
|
val = getattr(self.public_packet, f"stripgainlayer{self._i+1}")[self.index]
|
2022-03-04 14:22:29 +00:00
|
|
|
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
|
|
|
|
2022-04-29 03:24:32 +01:00
|
|
|
val = self.getter(f"GainLayer[{self._i}]")
|
2022-03-20 12:25:50 +00:00
|
|
|
if val is None:
|
2022-04-29 03:24:32 +01:00
|
|
|
val = fget() * 0.01
|
|
|
|
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(f"GainLayer[{self._i}]", val)
|
2022-03-04 14:22:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _make_gainlayer_mixin(remote, index):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""Creates a GainLayer mixin"""
|
|
|
|
return type(
|
|
|
|
f"GainlayerMixin",
|
|
|
|
(),
|
|
|
|
{"gainlayer": tuple(GainLayer(remote, index, i) for i in range(8))},
|
|
|
|
)
|
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
|
|
|
|
def _make_strip_mixin(kind):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""Creates a mixin with the kind's strip layout set as class variables."""
|
2022-03-04 14:22:29 +00:00
|
|
|
num_A, num_B = kind.outs
|
2022-03-26 23:00:09 +00:00
|
|
|
return type(
|
|
|
|
f"StripMixin{kind.name}",
|
|
|
|
(),
|
|
|
|
{
|
|
|
|
**{f"A{i}": strip_output_prop(f"A{i}") for i in range(1, num_A + 1)},
|
|
|
|
**{f"B{i}": strip_output_prop(f"B{i}") for i in range(1, num_B + 1)},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
|
|
|
|
_strip_mixins = {kind.id: _make_strip_mixin(kind) for kind in kinds.all}
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
def _make_strip_pair(kind):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""Creates a PhysicalInputStrip and a VirtualInputStrip of a kind."""
|
2022-03-04 14:22:29 +00:00
|
|
|
StripMixin = _strip_mixins[kind.id]
|
2022-03-26 23:00:09 +00:00
|
|
|
PhysStrip = type(
|
|
|
|
f"PhysicalInputStrip{kind.name}", (PhysicalInputStrip, StripMixin), {}
|
|
|
|
)
|
|
|
|
VirtStrip = type(
|
|
|
|
f"VirtualInputStrip{kind.name}", (VirtualInputStrip, StripMixin), {}
|
|
|
|
)
|
2022-03-04 14:22:29 +00:00
|
|
|
return (PhysStrip, VirtStrip)
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
_strip_pairs = {kind.id: _make_strip_pair(kind) for kind in kinds.all}
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
def _make_strip_level_map(kind):
|
|
|
|
phys_in, virt_in = kind.ins
|
2022-03-26 23:00:09 +00:00
|
|
|
phys_map = tuple((i, i + 2) for i in range(0, phys_in * 2, 2))
|
|
|
|
virt_map = tuple(
|
|
|
|
(i, i + 8) for i in range(phys_in * 2, phys_in * 2 + virt_in * 8, 8)
|
|
|
|
)
|
|
|
|
return phys_map + virt_map
|
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
_strip_maps = {kind.id: _make_strip_level_map(kind) for kind in kinds.all}
|