2023-06-25 13:52:39 +01:00
|
|
|
import logging
|
2022-06-16 16:10:06 +01:00
|
|
|
import time
|
|
|
|
from abc import ABCMeta, abstractmethod
|
2022-03-04 14:22:29 +00:00
|
|
|
from dataclasses import dataclass
|
|
|
|
|
2023-06-25 13:52:39 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
@dataclass
|
|
|
|
class Modes:
|
2022-03-26 23:00:09 +00:00
|
|
|
"""Channel Modes"""
|
|
|
|
|
|
|
|
_mute: hex = 0x00000001
|
|
|
|
_solo: hex = 0x00000002
|
|
|
|
_mono: hex = 0x00000004
|
2022-04-29 02:57:47 +01:00
|
|
|
_mc: hex = 0x00000008
|
2022-03-26 23:00:09 +00:00
|
|
|
|
|
|
|
_amix: hex = 0x00000010
|
|
|
|
_repeat: hex = 0x00000020
|
|
|
|
_bmix: hex = 0x00000030
|
|
|
|
_composite: hex = 0x00000040
|
|
|
|
_tvmix: hex = 0x00000050
|
|
|
|
_upmix21: hex = 0x00000060
|
|
|
|
_upmix41: hex = 0x00000070
|
|
|
|
_upmix61: hex = 0x00000080
|
|
|
|
_centeronly: hex = 0x00000090
|
|
|
|
_lfeonly: hex = 0x000000A0
|
|
|
|
_rearonly: hex = 0x000000B0
|
|
|
|
|
|
|
|
_mask: hex = 0x000000F0
|
|
|
|
|
2023-06-25 13:52:39 +01:00
|
|
|
_on: hex = 0x00000100 # eq.on
|
2022-03-26 23:00:09 +00:00
|
|
|
_cross: hex = 0x00000200
|
2023-06-25 13:52:39 +01:00
|
|
|
_ab: hex = 0x00000800 # eq.ab
|
2022-03-26 23:00:09 +00:00
|
|
|
|
|
|
|
_busa: hex = 0x00001000
|
|
|
|
_busa1: hex = 0x00001000
|
|
|
|
_busa2: hex = 0x00002000
|
|
|
|
_busa3: hex = 0x00004000
|
|
|
|
_busa4: hex = 0x00008000
|
|
|
|
_busa5: hex = 0x00080000
|
|
|
|
|
|
|
|
_busb: hex = 0x00010000
|
|
|
|
_busb1: hex = 0x00010000
|
|
|
|
_busb2: hex = 0x00020000
|
|
|
|
_busb3: hex = 0x00040000
|
|
|
|
|
|
|
|
_pan0: hex = 0x00000000
|
|
|
|
_pancolor: hex = 0x00100000
|
|
|
|
_panmod: hex = 0x00200000
|
|
|
|
_panmask: hex = 0x00F00000
|
|
|
|
|
|
|
|
_postfx_r: hex = 0x01000000
|
|
|
|
_postfx_d: hex = 0x02000000
|
|
|
|
_postfx1: hex = 0x04000000
|
|
|
|
_postfx2: hex = 0x08000000
|
|
|
|
|
|
|
|
_sel: hex = 0x10000000
|
|
|
|
_monitor: hex = 0x20000000
|
2022-03-04 14:22:29 +00:00
|
|
|
|
2022-03-19 09:51:48 +00:00
|
|
|
@property
|
|
|
|
def modevals(self):
|
2022-03-26 23:00:09 +00:00
|
|
|
return (
|
|
|
|
val
|
|
|
|
for val in [
|
|
|
|
self._amix,
|
|
|
|
self._repeat,
|
|
|
|
self._bmix,
|
|
|
|
self._composite,
|
|
|
|
self._tvmix,
|
|
|
|
self._upmix21,
|
|
|
|
self._upmix41,
|
|
|
|
self._upmix61,
|
|
|
|
self._centeronly,
|
|
|
|
self._lfeonly,
|
|
|
|
self._rearonly,
|
|
|
|
]
|
|
|
|
)
|
2022-03-19 09:51:48 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
|
2022-06-16 16:10:06 +01:00
|
|
|
class IRemote(metaclass=ABCMeta):
|
|
|
|
"""
|
|
|
|
Common interface between base class and extended (higher) classes
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-06-16 16:10:06 +01:00
|
|
|
Provides some default implementation
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, remote, index=None):
|
2022-03-04 14:22:29 +00:00
|
|
|
self._remote = remote
|
|
|
|
self.index = index
|
2023-06-25 13:52:39 +01:00
|
|
|
self.logger = logger.getChild(self.__class__.__name__)
|
2022-03-04 14:22:29 +00:00
|
|
|
self._modes = Modes()
|
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
def getter(self, param):
|
2023-06-25 13:52:39 +01:00
|
|
|
cmd = self._cmd(param)
|
|
|
|
self.logger.debug(f"getter: {cmd}")
|
2022-04-26 21:03:02 +01:00
|
|
|
if cmd in self._remote.cache:
|
2022-04-29 02:57:47 +01:00
|
|
|
return self._remote.cache.pop(cmd)
|
2022-10-19 14:20:23 +01:00
|
|
|
if self._remote.sync:
|
|
|
|
self._remote.clear_dirty()
|
2022-03-20 12:25:50 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
def setter(self, param, val):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""Sends a string request RT packet."""
|
2023-06-25 13:52:39 +01:00
|
|
|
self.logger.debug(f"setter: {self._cmd(param)}={val}")
|
2023-07-05 19:20:57 +01:00
|
|
|
self._remote._set_rt(self._cmd(param), val)
|
2023-06-25 13:52:39 +01:00
|
|
|
|
|
|
|
def _cmd(self, param):
|
|
|
|
cmd = (self.identifier,)
|
|
|
|
if param:
|
|
|
|
cmd += (f".{param}",)
|
|
|
|
return "".join(cmd)
|
2022-03-04 14:22:29 +00:00
|
|
|
|
2023-07-25 16:22:47 +01:00
|
|
|
@property
|
2022-06-16 16:10:06 +01:00
|
|
|
@abstractmethod
|
2022-03-04 14:22:29 +00:00
|
|
|
def identifier(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@property
|
|
|
|
def public_packet(self):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""Returns an RT data packet."""
|
2022-03-04 14:22:29 +00:00
|
|
|
return self._remote.public_packet
|
2022-03-11 19:21:26 +00:00
|
|
|
|
2022-06-16 16:10:06 +01:00
|
|
|
def apply(self, data):
|
2022-04-29 22:07:44 +01:00
|
|
|
"""Sets all parameters of a dict for the channel."""
|
2022-07-16 21:50:50 +01:00
|
|
|
|
|
|
|
def fget(attr, val):
|
|
|
|
if attr == "mode":
|
|
|
|
return (f"mode.{val}", 1)
|
2023-06-25 13:52:39 +01:00
|
|
|
elif attr == "knob":
|
|
|
|
return ("", val)
|
2022-07-16 21:50:50 +01:00
|
|
|
return (attr, val)
|
|
|
|
|
2022-06-16 16:10:06 +01:00
|
|
|
for attr, val in data.items():
|
2023-06-25 13:52:39 +01:00
|
|
|
if not isinstance(val, dict):
|
|
|
|
if attr in dir(self): # avoid calling getattr (with hasattr)
|
|
|
|
attr, val = fget(attr, val)
|
|
|
|
if isinstance(val, bool):
|
|
|
|
val = 1 if val else 0
|
|
|
|
|
|
|
|
self._remote.cache[self._cmd(attr)] = val
|
|
|
|
self._remote._script += f"{self._cmd(attr)}={val};"
|
|
|
|
else:
|
|
|
|
target = getattr(self, attr)
|
|
|
|
target.apply(val)
|
2023-07-05 19:20:57 +01:00
|
|
|
|
|
|
|
self._remote.sendtext(self._remote._script)
|
2022-06-16 16:10:06 +01:00
|
|
|
return self
|
|
|
|
|
|
|
|
def then_wait(self):
|
2023-06-25 13:52:39 +01:00
|
|
|
self._remote._script = str()
|
2022-06-16 16:10:06 +01:00
|
|
|
time.sleep(self._remote.DELAY)
|