add gainlayers, levels, public_packet property object

add gainlayers, levels

_get_rt now private method.

public_packet now property object
This commit is contained in:
onyx-and-iris 2022-02-26 23:57:19 +00:00
parent 416550fa95
commit 0f18116cd1
8 changed files with 55 additions and 65 deletions

View File

@ -4,8 +4,7 @@ from time import sleep
def main():
with vban_cmd.connect('potato', ip='ws.local') as vban:
for i in range(100):
print(vban.strip[5].A1)
print(vban.strip[5].A2)
print(vban.bus[3].levels.all)
if __name__ == '__main__':
main()

View File

@ -15,7 +15,7 @@ class TestSetAndGetParamsLower(unittest.TestCase):
])
def test_it_sets_and_gets_strip_bool_params(self, index, param):
tests.set_rt(f'Strip[{index}]', param, self.val)
retval = tests.get_rt()
retval = tests._get_rt()
retval = not int.from_bytes(retval.stripstate[index], 'little') & tests._modes._mute == 0
assert_equal(retval, self.val)
@ -24,6 +24,6 @@ class TestSetAndGetParamsLower(unittest.TestCase):
])
def test_it_sets_and_gets_strip_bool_params(self, index, param):
tests.set_rt(f'Strip[{index}]', param, self.val)
retval = tests.get_rt()
retval = tests._get_rt()
retval = not int.from_bytes(retval.stripstate[index], 'little') & tests._modes._mono == 0
assert_equal(retval, self.val)

View File

@ -2,7 +2,6 @@ from .errors import VMCMDErrors
from . import channel
from .channel import Channel
from . import kinds
from .meta import bus_output_prop
class OutputBus(Channel):
""" Base class for output buses. """
@ -24,8 +23,7 @@ class OutputBus(Channel):
@property
def mute(self) -> bool:
data = self.getter()
return not int.from_bytes(data.busstate[self.index], 'little') & self._modes._mute == 0
return not int.from_bytes(self.public_packet.busstate[self.index], 'little') & self._modes._mute == 0
@mute.setter
def mute(self, val: bool):
@ -35,8 +33,7 @@ class OutputBus(Channel):
@property
def mono(self) -> bool:
data = self.getter()
return not int.from_bytes(data.busstate[self.index], 'little') & self._modes._mono == 0
return not int.from_bytes(self.public_packet.busstate[self.index], 'little') & self._modes._mono == 0
@mono.setter
def mono(self, val: bool):
@ -46,8 +43,7 @@ class OutputBus(Channel):
@property
def eq(self) -> bool:
data = self.getter()
return not int.from_bytes(data.busstate[self.index], 'little') & self._modes._eq == 0
return not int.from_bytes(self.public_packet.busstate[self.index], 'little') & self._modes._eq == 0
@eq.setter
def eq(self, val: bool):
@ -57,8 +53,7 @@ class OutputBus(Channel):
@property
def eq_ab(self) -> bool:
data = self.getter()
return not int.from_bytes(data.busstate[self.index], 'little') & self._modes._eqb == 0
return not int.from_bytes(self.public_packet.busstate[self.index], 'little') & self._modes._eqb == 0
@eq_ab.setter
def eq_ab(self, val: bool):
@ -68,8 +63,7 @@ class OutputBus(Channel):
@property
def label(self) -> str:
data = self.getter()
return data.buslabels[self.index]
return self.public_packet.buslabels[self.index]
@label.setter
def label(self, val: str):
@ -77,16 +71,17 @@ class OutputBus(Channel):
raise VMCMDErrors('label is a string parameter')
self.setter('Label', val)
def gain(self):
return self.public_packet.busgain[self.index]
class PhysicalOutputBus(OutputBus):
@property
def device(self) -> str:
data = self.getter()
return
@property
def sr(self) -> int:
data = self.getter()
return
@ -100,12 +95,12 @@ class BusLevel(OutputBus):
self.level_map = _bus_maps[remote.kind.id]
def getter_level(self, mode=None):
def fget(data, i):
def fget(i, data):
return data.outputlevels[i]
range_ = self.level_map[self.index]
data = self._remote.get_rt()
levels = tuple(fget(data, i) for i in range(*range_))
data = self.public_packet
levels = tuple(fget(i, data) for i in range(*range_))
return levels
@property

View File

@ -60,9 +60,6 @@ class Channel(abc.ABC):
self.index = index
self._modes = Modes()
def getter(self):
""" Returns an RT data packet. """
return self._remote.public_packet
def setter(self, param, val):
""" Sends a string request RT packet. """
self._remote.set_rt(f'{self.identifier}', param, val)
@ -70,3 +67,8 @@ class Channel(abc.ABC):
@abc.abstractmethod
def identifier(self):
pass
@property
def public_packet(self):
""" Returns an RT data packet. """
return self._remote.public_packet

View File

@ -39,7 +39,7 @@ class VBAN_VMRT_Packet_Data:
@property
def voicemeeterversion(self) -> tuple:
""" returns voicemeeter version as a string """
return tuple(reversed(tuple(int.from_bytes(self._voicemeeterVersion[i:i+1], 'little') for i in range(0, 4))))
return tuple(reversed(tuple(int.from_bytes(self._voicemeeterVersion[i:i+1], 'little') for i in range(4))))
@property
def samplerate(self) -> int:
""" returns samplerate as an int """

View File

@ -3,21 +3,10 @@ from .errors import VMCMDErrors
def strip_output_prop(param):
""" A strip output prop. """
def fget(self):
data = self.getter()
data = self._remote.public_packet
return not int.from_bytes(data.stripstate[self.index], 'little') & getattr(self._modes, f'_bus{param.lower()}') == 0
def fset(self, val):
if not isinstance(val, bool) and val not in (0, 1):
raise VMCMDErrors(f'{param} is a boolean parameter')
self.setter(param, 1 if val else 0)
return property(fget, fset)
def bus_output_prop(param):
""" A bus output prop. """
def fget(self):
data = self.getter()
return not int.from_bytes(data.busstate[self.index], 'little') & getattr(self._modes, f'_bus{param.lower()}') == 0
def fset(self, val):
if not isinstance(val, bool) and val not in (0, 1):
raise VMCMDErrors(f'{param} is a boolean parameter')
self.setter(param, 1 if val else 0)
return property(fget, fset)

View File

@ -14,7 +14,8 @@ class InputStrip(Channel):
"""
PhysStrip, VirtStrip = _strip_pairs[remote.kind.id]
InputStrip = PhysStrip if is_physical else VirtStrip
IS_cls = type(f'Strip{remote.kind.name}', (InputStrip,), {
GainLayerMixin = _make_gainlayer_mixin(remote, index)
IS_cls = type(f'Strip{remote.kind.name}', (InputStrip, GainLayerMixin), {
'levels': StripLevel(remote, index),
})
return IS_cls(remote, index, **kwargs)
@ -25,8 +26,7 @@ class InputStrip(Channel):
@property
def mono(self) -> bool:
data = self.getter()
return not int.from_bytes(data.stripstate[self.index], 'little') & self._modes._mono == 0
return not int.from_bytes(self.public_packet.stripstate[self.index], 'little') & self._modes._mono == 0
@mono.setter
def mono(self, val: bool):
@ -36,8 +36,7 @@ class InputStrip(Channel):
@property
def solo(self) -> bool:
data = self.getter()
return not int.from_bytes(data.stripstate[self.index], 'little') & self._modes._solo == 0
return not int.from_bytes(self.public_packet.stripstate[self.index], 'little') & self._modes._solo == 0
@solo.setter
def solo(self, val: bool):
@ -47,8 +46,7 @@ class InputStrip(Channel):
@property
def mute(self) -> bool:
data = self.getter()
return not int.from_bytes(data.stripstate[self.index], 'little') & self._modes._mute == 0
return not int.from_bytes(self.public_packet.stripstate[self.index], 'little') & self._modes._mute == 0
@mute.setter
def mute(self, val: bool):
@ -58,7 +56,6 @@ class InputStrip(Channel):
@property
def limit(self) -> int:
data = self.getter()
return
@limit.setter
@ -69,8 +66,7 @@ class InputStrip(Channel):
@property
def label(self) -> str:
data = self.getter()
return data.striplabels[self.index]
return self.public_packet.striplabels[self.index]
@label.setter
def label(self, val: str):
@ -82,7 +78,6 @@ class InputStrip(Channel):
class PhysicalInputStrip(InputStrip):
@property
def comp(self) -> float:
data = self.getter()
return
@comp.setter
@ -91,7 +86,6 @@ class PhysicalInputStrip(InputStrip):
@property
def gate(self) -> float:
data = self.getter()
return
@gate.setter
@ -100,19 +94,16 @@ class PhysicalInputStrip(InputStrip):
@property
def device(self):
data = self.getter()
return
@property
def sr(self):
data = self.getter()
return
class VirtualInputStrip(InputStrip):
@property
def mc(self) -> bool:
data = self.getter()
return
@mc.setter
@ -124,7 +115,6 @@ class VirtualInputStrip(InputStrip):
@property
def k(self) -> int:
data = self.getter()
return
@k.setter
@ -140,12 +130,12 @@ class StripLevel(InputStrip):
self.level_map = _strip_maps[remote.kind.id]
def getter_level(self, mode=None):
def fget(data, i):
def fget(i, data):
return data.inputlevels[i]
range_ = self.level_map[self.index]
data = self._remote.get_rt()
levels = tuple(fget(data, i) for i in range(*range_))
data = self.public_packet
levels = tuple(fget(i, data) for i in range(*range_))
return levels
@property
@ -161,6 +151,26 @@ class StripLevel(InputStrip):
return
class GainLayer(InputStrip):
def __init__(self, remote, index, i):
super().__init__(remote, index)
self._i = i
@property
def gain(self):
return getattr(self.public_packet, f'stripgainlayer{self._i+1}')[self.index]
@gain.setter
def gain(self, val):
self.setter(f'GainLayer[{self._i}]', val)
def _make_gainlayer_mixin(remote, index):
""" Creates a GainLayer mixin """
return type(f'GainlayerMixin', (), {
'gainlayer': tuple(GainLayer(remote, index, i) for i in range(8))
})
def _make_strip_mixin(kind):
""" Creates a mixin with the kind's strip layout set as class variables. """
num_A, num_B = kind.outs

View File

@ -97,19 +97,17 @@ class VbanCmd(abc.ABC):
@property
def public_packet(self):
self.buff = self.get_rt()
self.buff = self._get_rt()
return self.buff
def get_rt(self):
def _get_rt(self):
def fget():
data = False
while not data:
data = self._fetch_rt_packet()
return data
private_packet = fget()
if private_packet.__eq__(self.buff):
private_packet = fget()
return private_packet
return private_packet if private_packet.__eq__(self.buff) else fget()
def set_rt(self, id_, param, val):
cmd = f'{id_}.{param}={val}'
@ -119,17 +117,14 @@ class VbanCmd(abc.ABC):
)
count = int.from_bytes(self._text_header.framecounter, 'little') + 1
self._text_header.framecounter = count.to_bytes(4, 'little')
sleep(self._delay)
@property
def type(self):
data = self.get_rt()
return data.voicemeetertype
return self.public_packet.voicemeetertype
@property
def version(self):
data = self.get_rt()
return data.voicemeeterversion
return self.public_packet.voicemeeterversion
def show(self) -> NoReturn:
""" Shows Voicemeeter if it's hidden. """