From efdcfce3870a946b948e0d5350a10a05996d5401 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 17 Jan 2026 13:19:43 +0000 Subject: [PATCH] refactor gainlayers and bus gains --- vban_cmd/bus.py | 11 +++---- vban_cmd/packet.py | 73 +++++++++++++--------------------------------- vban_cmd/strip.py | 12 ++++---- 3 files changed, 29 insertions(+), 67 deletions(-) diff --git a/vban_cmd/bus.py b/vban_cmd/bus.py index 1b4d1bb..d767037 100644 --- a/vban_cmd/bus.py +++ b/vban_cmd/bus.py @@ -24,14 +24,11 @@ class Bus(IRemote): @property def gain(self) -> float: - def fget(): - val = self.public_packets[NBS.zero].busgain[self.index] - if 0 <= val <= 1200: - return val * 0.01 - return (((1 << 16) - 1) - val) * -0.01 - val = self.getter('gain') - return round(val if val else fget(), 1) + if val: + return round(val, 2) + else: + return self.public_packets[NBS.zero].busgain[self.index] @gain.setter def gain(self, val: float): diff --git a/vban_cmd/packet.py b/vban_cmd/packet.py index c930f15..afd29fe 100644 --- a/vban_cmd/packet.py +++ b/vban_cmd/packet.py @@ -169,66 +169,33 @@ class VbanRtPacketNBS0(VbanRtPacket): """ @property - def stripgainlayer1(self) -> tuple: + def gainlayers(self) -> tuple: + """returns tuple of all strip gain layers as tuples""" return tuple( - int.from_bytes(self._stripGaindB100Layer1[i : i + 2], 'little') - for i in range(0, 16, 2) - ) - - @property - def stripgainlayer2(self) -> tuple: - return tuple( - int.from_bytes(self._stripGaindB100Layer2[i : i + 2], 'little') - for i in range(0, 16, 2) - ) - - @property - def stripgainlayer3(self) -> tuple: - return tuple( - int.from_bytes(self._stripGaindB100Layer3[i : i + 2], 'little') - for i in range(0, 16, 2) - ) - - @property - def stripgainlayer4(self) -> tuple: - return tuple( - int.from_bytes(self._stripGaindB100Layer4[i : i + 2], 'little') - for i in range(0, 16, 2) - ) - - @property - def stripgainlayer5(self) -> tuple: - return tuple( - int.from_bytes(self._stripGaindB100Layer5[i : i + 2], 'little') - for i in range(0, 16, 2) - ) - - @property - def stripgainlayer6(self) -> tuple: - return tuple( - int.from_bytes(self._stripGaindB100Layer6[i : i + 2], 'little') - for i in range(0, 16, 2) - ) - - @property - def stripgainlayer7(self) -> tuple: - return tuple( - int.from_bytes(self._stripGaindB100Layer7[i : i + 2], 'little') - for i in range(0, 16, 2) - ) - - @property - def stripgainlayer8(self) -> tuple: - return tuple( - int.from_bytes(self._stripGaindB100Layer8[i : i + 2], 'little') - for i in range(0, 16, 2) + tuple( + round( + int.from_bytes( + getattr(self, f'_stripGaindB100Layer{layer}')[i : i + 2], + 'little', + signed=True, + ) + * 0.01, + 2, + ) + for i in range(0, 16, 2) + ) + for layer in range(1, 9) ) @property def busgain(self) -> tuple: """returns tuple of bus gains""" return tuple( - int.from_bytes(self._busGaindB100[i : i + 2], 'little') + round( + int.from_bytes(self._busGaindB100[i : i + 2], 'little', signed=True) + * 0.01, + 2, + ) for i in range(0, 16, 2) ) diff --git a/vban_cmd/strip.py b/vban_cmd/strip.py index dc9b804..1d062f3 100644 --- a/vban_cmd/strip.py +++ b/vban_cmd/strip.py @@ -408,15 +408,13 @@ class GainLayer(IRemote): @property def gain(self) -> float: def fget(): - val = getattr( - self.public_packets[NBS.zero], f'stripgainlayer{self._i + 1}' - )[self.index] - if 0 <= val <= 1200: - return val * 0.01 - return (((1 << 16) - 1) - val) * -0.01 + return self.public_packets[NBS.zero].gainlayers[self._i][self.index] val = self.getter(f'GainLayer[{self._i}]') - return round(val if val else fget(), 1) + if val: + return round(val, 2) + else: + return self.public_packets[NBS.zero].gainlayers[self._i][self.index] @gain.setter def gain(self, val: float):