diff --git a/vban_cmd/enums.py b/vban_cmd/enums.py index fd00350..9c5c35b 100644 --- a/vban_cmd/enums.py +++ b/vban_cmd/enums.py @@ -1,4 +1,11 @@ -from enum import IntEnum +from enum import Enum, IntEnum, unique + + +@unique +class KindId(Enum): + BASIC = 1 + BANANA = 2 + POTATO = 3 class NBS(IntEnum): @@ -11,5 +18,3 @@ BusModes = IntEnum( 'normal amix bmix repeat composite tvmix upmix21 upmix41 upmix61 centeronly lfeonly rearonly', start=0, ) - -EQGains = IntEnum('EQGains', 'bass mid treble', start=0) diff --git a/vban_cmd/kinds.py b/vban_cmd/kinds.py index edb692f..9f79950 100644 --- a/vban_cmd/kinds.py +++ b/vban_cmd/kinds.py @@ -1,16 +1,9 @@ from dataclasses import dataclass -from enum import Enum, unique +from .enums import KindId from .error import VBANCMDError -@unique -class KindId(Enum): - BASIC = 1 - BANANA = 2 - POTATO = 3 - - class SingletonType(type): """ensure only a single instance of a kind map object""" diff --git a/vban_cmd/meta.py b/vban_cmd/meta.py index e020355..4d4aa64 100644 --- a/vban_cmd/meta.py +++ b/vban_cmd/meta.py @@ -106,13 +106,23 @@ def xy_prop(param): def fget(self): cmd = self._cmd(param) self.logger.debug(f'getter: {cmd}') - _type, axis = param.split('_') if self.public_packets[NBS.one] is None: return 0.0 - x, y = getattr( - self.public_packets[NBS.one].strips[self.index], f'position_{_type.lower()}' - ) - return x if axis == 'x' else y + + positions = self.public_packets[NBS.one].strips[self.index].positions + match param: + case 'pan_x': + return positions.pan_x + case 'pan_y': + return positions.pan_y + case 'color_x': + return positions.color_x + case 'color_y': + return positions.color_y + case 'fx1': + return positions.fx1 + case 'fx2': + return positions.fx2 def fset(self, val): self.setter(param, val) @@ -129,12 +139,17 @@ def send_prop(param): self.logger.debug(f'getter: {cmd}') if self.public_packets[NBS.one] is None: return 0.0 - val = getattr(self.public_packets[NBS.one].strips[self.index], f'send_{param}') + + sends = self.public_packets[NBS.one].strips[self.index].sends match param: - case 'reverb' | 'fx1': - return val[0] - case 'delay' | 'fx2': - return val[1] + case 'reverb': + return sends.reverb + case 'delay': + return sends.delay + case 'fx1': + return sends.fx1 + case 'fx2': + return sends.fx2 def fset(self, val): self.setter(param, val) diff --git a/vban_cmd/packet.py b/vban_cmd/packet.py index ad78729..05ce74d 100644 --- a/vban_cmd/packet.py +++ b/vban_cmd/packet.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +from typing import NamedTuple from .enums import NBS from .kinds import KindMapClass @@ -30,6 +31,28 @@ class VbanRtPacket: _samplerate: bytes # data[40:44] +class EqGains(NamedTuple): + bass: float + mid: float + treble: float + + +class Positions(NamedTuple): + pan_x: float + pan_y: float + color_x: float + color_y: float + fx1: float + fx2: float + + +class Sends(NamedTuple): + reverb: float + delay: float + fx1: float + fx2: float + + @dataclass class VbanRtPacketNBS0(VbanRtPacket): """Represents the body of a VBAN RT data packet with NBS 0""" @@ -333,55 +356,38 @@ class VbanVMParamStrip: return int.from_bytes(self._mode, 'little') @property - def position_pan(self) -> tuple[int, int]: - return ( + def eqgains(self) -> EqGains: + return EqGains( + *[ + round( + int.from_bytes(getattr(self, f'_EQgain{i}'), 'little', signed=True) + * 0.01, + 2, + ) + for i in range(1, 4) + ] + ) + + @property + def positions(self) -> Positions: + return Positions( round(int.from_bytes(self._pos3D_x, 'little', signed=True) * 0.01, 2), round(int.from_bytes(self._pos3D_y, 'little', signed=True) * 0.01, 2), - ) - - @property - def position_color(self) -> tuple[int, int]: - return ( round(int.from_bytes(self._posColor_x, 'little', signed=True) * 0.01, 2), round(int.from_bytes(self._posColor_y, 'little', signed=True) * 0.01, 2), - ) - - @property - def position_fx(self) -> tuple[int, int]: - return ( round(int.from_bytes(self._posMod_x, 'little', signed=True) * 0.01, 2), round(int.from_bytes(self._posMod_y, 'little', signed=True) * 0.01, 2), ) @property - def send_reverb(self) -> tuple[float, float]: - return ( + def sends(self) -> Sends: + return Sends( round(int.from_bytes(self._send_reverb, 'little', signed=True) * 0.01, 2), round(int.from_bytes(self._send_delay, 'little', signed=True) * 0.01, 2), - ) - - send_delay = send_reverb - - @property - def send_fx1(self) -> tuple[float, float]: - return ( round(int.from_bytes(self._send_fx1, 'little', signed=True) * 0.01, 2), round(int.from_bytes(self._send_fx2, 'little', signed=True) * 0.01, 2), ) - send_fx2 = send_fx1 - - @property - def eqgains(self) -> tuple[float, float, float]: - return tuple( - round( - int.from_bytes(getattr(self, f'_EQgain{i}'), 'little', signed=True) - * 0.01, - 2, - ) - for i in range(1, 4) - ) - @property def karaoke(self) -> int: return int.from_bytes(self._nKaraoke, 'little') diff --git a/vban_cmd/strip.py b/vban_cmd/strip.py index 3d2164e..98c9875 100644 --- a/vban_cmd/strip.py +++ b/vban_cmd/strip.py @@ -3,7 +3,7 @@ from abc import abstractmethod from typing import Union from . import kinds -from .enums import NBS, EQGains +from .enums import NBS from .iremote import IRemote from .meta import ( channel_bool_prop, @@ -296,7 +296,7 @@ class VirtualStrip(Strip): def bass(self) -> float: if self.public_packets[NBS.one] is None: return 0.0 - return self.public_packets[NBS.one].strips[self.index].eqgains[EQGains.bass] + return self.public_packets[NBS.one].strips[self.index].eqgains.bass @bass.setter def bass(self, val: float): @@ -306,7 +306,7 @@ class VirtualStrip(Strip): def mid(self) -> float: if self.public_packets[NBS.one] is None: return 0.0 - return self.public_packets[NBS.one].strips[self.index].eqgains[EQGains.mid] + return self.public_packets[NBS.one].strips[self.index].eqgains.mid @mid.setter def mid(self, val: float): @@ -318,7 +318,7 @@ class VirtualStrip(Strip): def treble(self) -> float: if self.public_packets[NBS.one] is None: return 0.0 - return self.public_packets[NBS.one].strips[self.index].eqgains[EQGains.treble] + return self.public_packets[NBS.one].strips[self.index].eqgains.treble @treble.setter def treble(self, val: float):