2022-07-16 21:50:50 +01:00
|
|
|
import time
|
2022-06-16 16:10:06 +01:00
|
|
|
from abc import abstractmethod
|
2022-07-16 21:50:50 +01:00
|
|
|
from enum import IntEnum
|
2022-06-16 16:10:06 +01:00
|
|
|
from typing import Union
|
|
|
|
|
|
|
|
from .iremote import IRemote
|
|
|
|
from .meta import bus_mode_prop, channel_bool_prop, channel_label_prop
|
|
|
|
|
2022-07-16 21:50:50 +01:00
|
|
|
BusModes = IntEnum(
|
|
|
|
"BusModes",
|
|
|
|
"normal amix bmix repeat composite tvmix upmix21 upmix41 upmix61 centeronly lfeonly rearonly",
|
|
|
|
start=0,
|
|
|
|
)
|
|
|
|
|
2022-06-16 16:10:06 +01:00
|
|
|
|
|
|
|
class Bus(IRemote):
|
|
|
|
"""
|
|
|
|
Implements the common interface
|
|
|
|
|
|
|
|
Defines concrete implementation for bus
|
|
|
|
"""
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def __str__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@property
|
|
|
|
def identifier(self) -> str:
|
2023-08-07 17:38:51 +01:00
|
|
|
return f"bus[{self.index}]"
|
2022-06-16 16:10:06 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def gain(self) -> float:
|
|
|
|
def fget():
|
|
|
|
val = self.public_packet.busgain[self.index]
|
2022-09-28 18:07:10 +01:00
|
|
|
if 0 <= val <= 1200:
|
|
|
|
return val * 0.01
|
|
|
|
return (((1 << 16) - 1) - val) * -0.01
|
2022-06-16 16:10:06 +01:00
|
|
|
|
|
|
|
val = self.getter("gain")
|
2022-09-28 18:07:10 +01:00
|
|
|
return round(val if val else fget(), 1)
|
2022-06-16 16:10:06 +01:00
|
|
|
|
|
|
|
@gain.setter
|
|
|
|
def gain(self, val: float):
|
|
|
|
self.setter("gain", val)
|
|
|
|
|
2022-10-06 20:28:26 +01:00
|
|
|
def fadeto(self, target: float, time_: int):
|
|
|
|
self.setter("FadeTo", f"({target}, {time_})")
|
|
|
|
time.sleep(self._remote.DELAY)
|
|
|
|
|
|
|
|
def fadeby(self, change: float, time_: int):
|
|
|
|
self.setter("FadeBy", f"({change}, {time_})")
|
|
|
|
time.sleep(self._remote.DELAY)
|
|
|
|
|
2022-06-16 16:10:06 +01:00
|
|
|
|
2023-06-25 01:47:05 +01:00
|
|
|
class BusEQ(IRemote):
|
|
|
|
@classmethod
|
|
|
|
def make(cls, remote, index):
|
|
|
|
BUSEQ_cls = type(
|
|
|
|
f"BusEQ{remote.kind}",
|
|
|
|
(cls,),
|
|
|
|
{
|
|
|
|
**{param: channel_bool_prop(param) for param in ["on", "ab"]},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
return BUSEQ_cls(remote, index)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def identifier(self) -> str:
|
2023-08-07 17:38:51 +01:00
|
|
|
return f"bus[{self.index}].eq"
|
2023-06-25 01:47:05 +01:00
|
|
|
|
|
|
|
|
2022-06-16 16:10:06 +01:00
|
|
|
class PhysicalBus(Bus):
|
|
|
|
def __str__(self):
|
|
|
|
return f"{type(self).__name__}{self.index}"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device(self) -> str:
|
|
|
|
return
|
|
|
|
|
|
|
|
@property
|
|
|
|
def sr(self) -> int:
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
class VirtualBus(Bus):
|
|
|
|
def __str__(self):
|
|
|
|
return f"{type(self).__name__}{self.index}"
|
|
|
|
|
|
|
|
|
|
|
|
class BusLevel(IRemote):
|
|
|
|
def __init__(self, remote, index):
|
|
|
|
super().__init__(remote, index)
|
|
|
|
self.level_map = tuple(
|
|
|
|
(i, i + 8)
|
|
|
|
for i in range(0, (remote.kind.phys_out + remote.kind.virt_out) * 8, 8)
|
|
|
|
)
|
2022-07-06 13:40:46 +01:00
|
|
|
self.range = self.level_map[self.index]
|
2022-06-16 16:10:06 +01:00
|
|
|
|
|
|
|
def getter(self):
|
|
|
|
"""Returns a tuple of level values for the channel."""
|
|
|
|
|
2022-10-04 15:40:32 +01:00
|
|
|
def fget(i):
|
|
|
|
return round((((1 << 16) - 1) - i) * -0.01, 1)
|
|
|
|
|
2023-08-04 23:13:58 +01:00
|
|
|
if not self._remote.stopped() and self._remote.event.ldirty:
|
2022-09-28 18:07:10 +01:00
|
|
|
return tuple(
|
2022-10-04 15:40:32 +01:00
|
|
|
fget(i)
|
2022-09-28 18:07:10 +01:00
|
|
|
for i in self._remote.cache["bus_level"][self.range[0] : self.range[-1]]
|
|
|
|
)
|
2022-06-16 16:10:06 +01:00
|
|
|
return tuple(
|
2022-10-04 15:40:32 +01:00
|
|
|
fget(i)
|
2022-09-28 18:07:10 +01:00
|
|
|
for i in self._remote._get_levels(self.public_packet)[1][
|
|
|
|
self.range[0] : self.range[-1]
|
|
|
|
]
|
2022-06-16 16:10:06 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def identifier(self) -> str:
|
2023-08-07 17:38:51 +01:00
|
|
|
return f"bus[{self.index}]"
|
2022-06-16 16:10:06 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def all(self) -> tuple:
|
|
|
|
return self.getter()
|
|
|
|
|
|
|
|
@property
|
2022-08-02 09:31:08 +01:00
|
|
|
def isdirty(self) -> bool:
|
|
|
|
"""
|
|
|
|
Returns dirty status for this specific channel.
|
|
|
|
|
|
|
|
Expected to be used in a callback only.
|
|
|
|
"""
|
2022-07-06 13:40:46 +01:00
|
|
|
return any(self._remote._bus_comp[self.range[0] : self.range[-1]])
|
2022-06-16 16:10:06 +01:00
|
|
|
|
2022-08-02 09:31:08 +01:00
|
|
|
is_updated = isdirty
|
|
|
|
|
2022-06-16 16:10:06 +01:00
|
|
|
|
|
|
|
def _make_bus_mode_mixin():
|
|
|
|
"""Creates a mixin of Bus Modes."""
|
|
|
|
|
2024-07-05 17:43:28 +01:00
|
|
|
modestates = {
|
|
|
|
"normal": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
"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],
|
|
|
|
}
|
|
|
|
|
2022-06-16 16:10:06 +01:00
|
|
|
def identifier(self) -> str:
|
2023-08-07 17:38:51 +01:00
|
|
|
return f"bus[{self.index}].mode"
|
2022-06-16 16:10:06 +01:00
|
|
|
|
2022-07-16 21:50:50 +01:00
|
|
|
def get(self):
|
2024-07-05 17:43:28 +01:00
|
|
|
states = [
|
|
|
|
(int.from_bytes(self.public_packet.busstate[self.index], "little") & val)
|
|
|
|
>> 4
|
|
|
|
for val in self._modes.modevals
|
|
|
|
]
|
|
|
|
for k, v in modestates.items():
|
|
|
|
if states == v:
|
|
|
|
return k
|
2022-07-16 21:50:50 +01:00
|
|
|
|
2022-06-16 16:10:06 +01:00
|
|
|
return type(
|
|
|
|
"BusModeMixin",
|
|
|
|
(IRemote,),
|
|
|
|
{
|
|
|
|
"identifier": property(identifier),
|
2024-07-05 17:43:28 +01:00
|
|
|
"modestates": modestates,
|
2022-07-16 21:50:50 +01:00
|
|
|
**{mode.name: bus_mode_prop(mode.name) for mode in BusModes},
|
|
|
|
"get": get,
|
2022-06-16 16:10:06 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def bus_factory(phys_bus, remote, i) -> Union[PhysicalBus, VirtualBus]:
|
|
|
|
"""
|
|
|
|
Factory method for buses
|
|
|
|
|
|
|
|
Returns a physical or virtual bus subclass
|
|
|
|
"""
|
|
|
|
BUS_cls = PhysicalBus if phys_bus else VirtualBus
|
|
|
|
BUSMODEMIXIN_cls = _make_bus_mode_mixin()
|
|
|
|
return type(
|
|
|
|
f"{BUS_cls.__name__}{remote.kind}",
|
|
|
|
(BUS_cls,),
|
|
|
|
{
|
2023-06-25 01:47:05 +01:00
|
|
|
"eq": BusEQ.make(remote, i),
|
2022-06-16 16:10:06 +01:00
|
|
|
"levels": BusLevel(remote, i),
|
|
|
|
"mode": BUSMODEMIXIN_cls(remote, i),
|
|
|
|
**{param: channel_bool_prop(param) for param in ["mute", "mono"]},
|
|
|
|
"label": channel_label_prop(),
|
|
|
|
},
|
|
|
|
)(remote, i)
|
|
|
|
|
|
|
|
|
|
|
|
def request_bus_obj(phys_bus, remote, i) -> Bus:
|
|
|
|
"""
|
|
|
|
Bus entry point. Wraps factory method.
|
|
|
|
|
|
|
|
Returns a reference to a bus subclass of a kind
|
|
|
|
"""
|
|
|
|
return bus_factory(phys_bus, remote, i)
|