2022-04-29 02:57:47 +01:00
|
|
|
from .util import cache_bool, cache_string
|
2022-03-04 14:22:29 +00:00
|
|
|
from .errors import VMCMDErrors
|
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
from functools import partial
|
2022-03-26 23:00:09 +00:00
|
|
|
|
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
def channel_bool_prop(param):
|
|
|
|
"""A channel bool prop. (strip|bus)"""
|
|
|
|
|
|
|
|
@partial(cache_bool, param=param)
|
2022-03-20 12:25:50 +00:00
|
|
|
def fget(self):
|
2022-04-29 02:57:47 +01:00
|
|
|
return (
|
|
|
|
not int.from_bytes(
|
|
|
|
getattr(self.public_packet, f"{self.identifier}state")[self.index],
|
|
|
|
"little",
|
2022-03-26 23:00:09 +00:00
|
|
|
)
|
2022-04-29 20:52:03 +01:00
|
|
|
& getattr(self._modes, f'_{param.replace(".", "_").lower()}')
|
2022-04-29 02:57:47 +01:00
|
|
|
== 0
|
|
|
|
)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
def fset(self, val):
|
2022-03-26 23:00:09 +00:00
|
|
|
if not isinstance(val, bool) and val not in (0, 1):
|
|
|
|
raise VMCMDErrors(f"{param} is a boolean parameter")
|
2022-03-20 12:25:50 +00:00
|
|
|
self.setter(param, 1 if val else 0)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
return property(fget, fset)
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
def channel_label_prop():
|
|
|
|
"""A channel label prop. (strip|bus)"""
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
@partial(cache_string, param="label")
|
|
|
|
def fget(self) -> str:
|
|
|
|
return getattr(self.public_packet, f"{self.identifier}labels")[self.index]
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
def fset(self, val: str):
|
|
|
|
if not isinstance(val, str):
|
|
|
|
raise VMCMDErrors("label is a string parameter")
|
|
|
|
self.setter("label", val)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
return property(fget, fset)
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
def strip_output_prop(param):
|
2022-04-29 02:57:47 +01:00
|
|
|
"""A strip output prop. (A1-A5, B1-B3)"""
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
@partial(cache_bool, param=param)
|
2022-03-04 14:22:29 +00:00
|
|
|
def fget(self):
|
2022-04-29 02:57:47 +01:00
|
|
|
return (
|
|
|
|
not int.from_bytes(self.public_packet.stripstate[self.index], "little")
|
|
|
|
& getattr(self._modes, f"_bus{param.lower()}")
|
|
|
|
== 0
|
|
|
|
)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
def fset(self, val):
|
|
|
|
if not isinstance(val, bool) and val not in (0, 1):
|
2022-03-26 23:00:09 +00:00
|
|
|
raise VMCMDErrors(f"{param} is a boolean parameter")
|
2022-03-04 14:22:29 +00:00
|
|
|
self.setter(param, 1 if val else 0)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
return property(fget, fset)
|
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 bus_mode_prop(param):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""A bus mode prop."""
|
2022-04-26 07:35:41 +01:00
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
@partial(cache_bool, param=f"mode.{param}")
|
2022-03-17 14:08:49 +00:00
|
|
|
def fget(self):
|
2022-04-29 02:57:47 +01:00
|
|
|
modelist = {
|
|
|
|
"amix": (1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1),
|
|
|
|
"repeat": (0, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2),
|
|
|
|
"bmix": (1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3),
|
|
|
|
"composite": (0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0),
|
|
|
|
"tvmix": (1, 0, 1, 4, 5, 4, 5, 0, 1, 0, 1),
|
|
|
|
"upmix21": (0, 2, 2, 4, 4, 6, 6, 0, 0, 2, 2),
|
|
|
|
"upmix41": (1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3),
|
|
|
|
"upmix61": (0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8),
|
|
|
|
"centeronly": (1, 0, 1, 0, 1, 0, 1, 8, 9, 8, 9),
|
|
|
|
"lfeonly": (0, 2, 2, 0, 0, 2, 2, 8, 8, 10, 10),
|
|
|
|
"rearonly": (1, 2, 3, 0, 1, 2, 3, 8, 9, 10, 11),
|
|
|
|
}
|
|
|
|
vals = (
|
|
|
|
int.from_bytes(self.public_packet.busstate[self.index], "little") & val
|
|
|
|
for val in self._modes.modevals
|
|
|
|
)
|
|
|
|
if param == "normal":
|
|
|
|
return not any(vals)
|
|
|
|
return tuple(round(val / 16) for val in vals) == modelist[param]
|
2022-04-26 07:35:41 +01:00
|
|
|
|
2022-03-17 14:08:49 +00:00
|
|
|
def fset(self, val):
|
|
|
|
if not isinstance(val, bool) and val not in (0, 1):
|
2022-03-26 23:00:09 +00:00
|
|
|
raise VMCMDErrors(f"mode.{param} is a boolean parameter")
|
2022-04-26 21:03:02 +01:00
|
|
|
self.setter(f"mode.{param}", 1 if val else 0)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-17 14:08:49 +00:00
|
|
|
return property(fget, fset)
|
2022-03-21 11:20:53 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-21 11:20:53 +00:00
|
|
|
def action_prop(param, val=1):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""A param that performs an action"""
|
|
|
|
|
2022-03-21 11:20:53 +00:00
|
|
|
def fdo(self):
|
|
|
|
self.setter(param, val)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-21 11:20:53 +00:00
|
|
|
return fdo
|