From 2bc9fa9d57e4c0198ed3705b9bdc12de3c793f86 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Tue, 26 Apr 2022 07:35:41 +0100 Subject: [PATCH] change to bus_mode_prop meta function. change to bus_mode_prop meta function. save gain to cache as gain. remove kwarg ratelimiter (used for test units) --- vbancmd/bus.py | 2 +- vbancmd/channel.py | 2 -- vbancmd/meta.py | 67 ++++++++++++++-------------------------------- vbancmd/strip.py | 4 +-- vbancmd/vbancmd.py | 13 +++++---- 5 files changed, 31 insertions(+), 57 deletions(-) diff --git a/vbancmd/bus.py b/vbancmd/bus.py index 69ad5e5..ba275d4 100644 --- a/vbancmd/bus.py +++ b/vbancmd/bus.py @@ -123,7 +123,7 @@ def _make_bus_mode_mixin(cls): (cls,), { **{ - f"{mode.lower()}": bus_mode_prop(mode) + f"{mode.lower()}": bus_mode_prop(mode.lower()) for mode in [ "normal", "Amix", diff --git a/vbancmd/channel.py b/vbancmd/channel.py index b4b2b7e..f6a2003 100644 --- a/vbancmd/channel.py +++ b/vbancmd/channel.py @@ -13,7 +13,6 @@ class Modes: _mono: hex = 0x00000004 _mutec: hex = 0x00000008 - _normal: hex = 0x00000000 _amix: hex = 0x00000010 _repeat: hex = 0x00000020 _bmix: hex = 0x00000030 @@ -62,7 +61,6 @@ class Modes: return ( val for val in [ - self._normal, self._amix, self._repeat, self._bmix, diff --git a/vbancmd/meta.py b/vbancmd/meta.py index 6228429..569d9db 100644 --- a/vbancmd/meta.py +++ b/vbancmd/meta.py @@ -73,62 +73,35 @@ def strip_output_prop(param): def bus_mode_prop(param): """A bus mode prop.""" - # fmt: off + def fget(self): - data = self.public_packet - modes = { - "normal": ( - False, False, False, False, False, False, False, False, False, False, False, False, - ), - "amix": ( - False, True, False, True, False, True, False, True, False, True, False, True, - ), - "repeat": ( - False, False, True, True, False, False, True, True, False, False, True, True, - ), - "bmix": ( - False, True, True, True, False, True, True, True, False, True, True, True, - ), - "composite": ( - False, False, False, False, True, True, True, True, False, False, False, False, - ), - "tvmix": ( - False, True, False, True, True, True, True, True, False, True, False, True, - ), - "upmix21": ( - False, False, True, True, True, True, True, True, False, False, True, True, - ), - "upmix41": ( - False, True, True, True, True, True, True, True, False, True, True, True, - ), - "upmix61": ( - False, False, False, False, False, False, False, False, True, True, True, True, - ), - "centeronly": ( - False, True, False, True, False, True, False, True, True, True, True, True, - ), - "lfeonly": ( - False, False, True, True, False, False, True, True, True, True, True, True, - ), - "rearonly": ( - False, True, True, True, False, True, True, True, True, True, True, True, - ), - } - vals = tuple( - not int.from_bytes(data.busstate[self.index], "little") & val == 0 - for val in self._modes.modevals - ) val = self.getter(f"mode.{param}") if val is None: - val = vals == modes[param.lower()] + if param == "normal": + return not any( + not int.from_bytes( + self.public_packet.busstate[self.index], "little" + ) + & val + == 0 + for val in self._modes.modevals + ) + else: + val = ( + not int.from_bytes( + self.public_packet.busstate[self.index], "little" + ) + & getattr(self._modes, f"_{param}") + == 0 + ) self._remote.cache[f"{self.identifier}.mode.{param}"] = [val, False] return val return val == 1 - # fmt: on + def fset(self, val): if not isinstance(val, bool) and val not in (0, 1): raise VMCMDErrors(f"mode.{param} is a boolean parameter") - self.setter(f"mode.{param}", 1 if val else 0) + self.setter(f"mode.{param}", 1) return property(fget, fset) diff --git a/vbancmd/strip.py b/vbancmd/strip.py index de7349f..6000ed8 100644 --- a/vbancmd/strip.py +++ b/vbancmd/strip.py @@ -60,10 +60,10 @@ class InputStrip(Channel): @property def gain(self) -> float: - val = self.getter("GainLayer[0]") + val = self.getter("gain") if val is None: val = self.gainlayer[0].gain - self._remote.cache[f"{self.identifier}.GainLayer[0]"] = [val, False] + self._remote.cache[f"{self.identifier}.gain"] = [val, False] return round(val, 1) @gain.setter diff --git a/vbancmd/vbancmd.py b/vbancmd/vbancmd.py index 72486b4..6bf4da4 100644 --- a/vbancmd/vbancmd.py +++ b/vbancmd/vbancmd.py @@ -28,7 +28,6 @@ class VbanCmd(abc.ABC): self._bps = kwargs["bps"] self._channel = kwargs["channel"] self._delay = kwargs["delay"] - self._ratelimiter = kwargs["ratelimiter"] self._sync = kwargs["sync"] # fmt: off self._bps_opts = [ @@ -89,6 +88,7 @@ class VbanCmd(abc.ABC): self._public_packet = self._get_rt() worker2 = Thread(target=self._keepupdated, daemon=True) worker2.start() + self._clear_dirty() def _send_register_rt(self): """ @@ -150,6 +150,10 @@ class VbanCmd(abc.ABC): def public_packet(self): return self._public_packet + def _clear_dirty(self): + while self.pdirty: + pass + @public_packet.setter def public_packet(self, val): self._public_packet = val @@ -198,7 +202,7 @@ class VbanCmd(abc.ABC): self._text_header.framecounter = count.to_bytes(4, "little") self.cache[f"{id_}.{param}"] = [val, True] if self._sync: - sleep(self._ratelimiter) + sleep(self._delay) def sendtext(self, cmd): """Sends a multiple parameter string over a network.""" @@ -243,9 +247,10 @@ class VbanCmd(abc.ABC): else: raise ValueError(obj) target.apply(submapping) + if not self._sync: + sleep(self._ratelimiter) def apply_profile(self, name: str): - self._sync = True try: profile = self.profiles[name] if "extends" in profile: @@ -260,7 +265,6 @@ class VbanCmd(abc.ABC): self.apply(profile) except KeyError: raise VMCMDErrors(f"Unknown profile: {self.kind.id}/{name}") - self._sync = False def reset(self) -> NoReturn: self.apply_profile("base") @@ -309,7 +313,6 @@ def _make_remote(kind: NamedTuple) -> VbanCmd: "bps": 0, "channel": 0, "delay": 0.001, - "ratelimiter": 0.018, "sync": False, } kwargs = defaultkwargs | kwargs