From 4659cf7cdbd103bedae80c206544b558e63a58bc Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Tue, 4 Oct 2022 15:42:36 +0100 Subject: [PATCH] util: in comp, consider level value clean if below -60.0 vbancmd: pass tuple expansion into string format in version method. ldirty and _get_levels logic now moved into rt packet class --- vban_cmd/util.py | 6 ++++-- vban_cmd/vbancmd.py | 17 ++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/vban_cmd/util.py b/vban_cmd/util.py index a67793a..227298b 100644 --- a/vban_cmd/util.py +++ b/vban_cmd/util.py @@ -61,10 +61,12 @@ def comp(t0: tuple, t1: tuple) -> Iterator[bool]: Evaluates equality of each member in both tuples. """ + for a, b in zip(t0, t1): - if b <= 9500: + if ((1 << 16) - 1) - b <= 6000: yield a == b - yield True + else: + yield True Socket = IntEnum("Socket", "register request response", start=0) diff --git a/vban_cmd/vbancmd.py b/vban_cmd/vbancmd.py index 0a5d4ad..883fc8f 100644 --- a/vban_cmd/vbancmd.py +++ b/vban_cmd/vbancmd.py @@ -7,7 +7,7 @@ from typing import Iterable, Optional, Union from .event import Event from .packet import RequestHeader from .subject import Subject -from .util import Socket, comp, script +from .util import Socket, script from .worker import Subscriber, Updater @@ -37,7 +37,7 @@ class VbanCmd(metaclass=ABCMeta): socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for _ in Socket ) self.subject = Subject() - self.cache = dict() + self.cache = {} self.event = Event(self.subs) @abstractmethod @@ -95,8 +95,7 @@ class VbanCmd(metaclass=ABCMeta): @property def version(self) -> str: """Returns Voicemeeter's version as a string""" - v1, v2, v3, v4 = self.public_packet.voicemeeterversion - return f"{v1}.{v2}.{v3}.{v4}" + return "{0}.{1}.{2}.{3}".format(*self.public_packet.voicemeeterversion) @property def pdirty(self): @@ -106,11 +105,7 @@ class VbanCmd(metaclass=ABCMeta): @property def ldirty(self): """True iff a level value has changed.""" - self._strip_comp, self._bus_comp = ( - tuple(not x for x in comp(self.cache["strip_level"], self._strip_buf)), - tuple(not x for x in comp(self.cache["bus_level"], self._bus_buf)), - ) - return any(any(l) for l in (self._strip_comp, self._bus_comp)) + return self._ldirty @property def public_packet(self): @@ -127,8 +122,8 @@ class VbanCmd(metaclass=ABCMeta): strip levels in PREFADER mode. """ return ( - tuple(((1 << 16) - 1) - val for val in packet.inputlevels), - tuple(((1 << 16) - 1) - val for val in packet.outputlevels), + packet.inputlevels, + packet.outputlevels, ) def apply(self, data: dict):