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(): def main():
with vban_cmd.connect('potato', ip='ws.local') as vban: with vban_cmd.connect('potato', ip='ws.local') as vban:
for i in range(100): for i in range(100):
print(vban.strip[5].A1) print(vban.bus[3].levels.all)
print(vban.strip[5].A2)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

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

View File

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

View File

@ -60,9 +60,6 @@ class Channel(abc.ABC):
self.index = index self.index = index
self._modes = Modes() self._modes = Modes()
def getter(self):
""" Returns an RT data packet. """
return self._remote.public_packet
def setter(self, param, val): def setter(self, param, val):
""" Sends a string request RT packet. """ """ Sends a string request RT packet. """
self._remote.set_rt(f'{self.identifier}', param, val) self._remote.set_rt(f'{self.identifier}', param, val)
@ -70,3 +67,8 @@ class Channel(abc.ABC):
@abc.abstractmethod @abc.abstractmethod
def identifier(self): def identifier(self):
pass 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 @property
def voicemeeterversion(self) -> tuple: def voicemeeterversion(self) -> tuple:
""" returns voicemeeter version as a string """ """ 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 @property
def samplerate(self) -> int: def samplerate(self) -> int:
""" returns samplerate as an int """ """ returns samplerate as an int """

View File

@ -3,21 +3,10 @@ from .errors import VMCMDErrors
def strip_output_prop(param): def strip_output_prop(param):
""" A strip output prop. """ """ A strip output prop. """
def fget(self): 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 return not int.from_bytes(data.stripstate[self.index], 'little') & getattr(self._modes, f'_bus{param.lower()}') == 0
def fset(self, val): def fset(self, val):
if not isinstance(val, bool) and val not in (0, 1): if not isinstance(val, bool) and val not in (0, 1):
raise VMCMDErrors(f'{param} is a boolean parameter') raise VMCMDErrors(f'{param} is a boolean parameter')
self.setter(param, 1 if val else 0) self.setter(param, 1 if val else 0)
return property(fget, fset) 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] PhysStrip, VirtStrip = _strip_pairs[remote.kind.id]
InputStrip = PhysStrip if is_physical else VirtStrip 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), 'levels': StripLevel(remote, index),
}) })
return IS_cls(remote, index, **kwargs) return IS_cls(remote, index, **kwargs)
@ -25,8 +26,7 @@ class InputStrip(Channel):
@property @property
def mono(self) -> bool: def mono(self) -> bool:
data = self.getter() return not int.from_bytes(self.public_packet.stripstate[self.index], 'little') & self._modes._mono == 0
return not int.from_bytes(data.stripstate[self.index], 'little') & self._modes._mono == 0
@mono.setter @mono.setter
def mono(self, val: bool): def mono(self, val: bool):
@ -36,8 +36,7 @@ class InputStrip(Channel):
@property @property
def solo(self) -> bool: def solo(self) -> bool:
data = self.getter() return not int.from_bytes(self.public_packet.stripstate[self.index], 'little') & self._modes._solo == 0
return not int.from_bytes(data.stripstate[self.index], 'little') & self._modes._solo == 0
@solo.setter @solo.setter
def solo(self, val: bool): def solo(self, val: bool):
@ -47,8 +46,7 @@ class InputStrip(Channel):
@property @property
def mute(self) -> bool: def mute(self) -> bool:
data = self.getter() return not int.from_bytes(self.public_packet.stripstate[self.index], 'little') & self._modes._mute == 0
return not int.from_bytes(data.stripstate[self.index], 'little') & self._modes._mute == 0
@mute.setter @mute.setter
def mute(self, val: bool): def mute(self, val: bool):
@ -58,7 +56,6 @@ class InputStrip(Channel):
@property @property
def limit(self) -> int: def limit(self) -> int:
data = self.getter()
return return
@limit.setter @limit.setter
@ -69,8 +66,7 @@ class InputStrip(Channel):
@property @property
def label(self) -> str: def label(self) -> str:
data = self.getter() return self.public_packet.striplabels[self.index]
return data.striplabels[self.index]
@label.setter @label.setter
def label(self, val: str): def label(self, val: str):
@ -82,7 +78,6 @@ class InputStrip(Channel):
class PhysicalInputStrip(InputStrip): class PhysicalInputStrip(InputStrip):
@property @property
def comp(self) -> float: def comp(self) -> float:
data = self.getter()
return return
@comp.setter @comp.setter
@ -91,7 +86,6 @@ class PhysicalInputStrip(InputStrip):
@property @property
def gate(self) -> float: def gate(self) -> float:
data = self.getter()
return return
@gate.setter @gate.setter
@ -100,19 +94,16 @@ class PhysicalInputStrip(InputStrip):
@property @property
def device(self): def device(self):
data = self.getter()
return return
@property @property
def sr(self): def sr(self):
data = self.getter()
return return
class VirtualInputStrip(InputStrip): class VirtualInputStrip(InputStrip):
@property @property
def mc(self) -> bool: def mc(self) -> bool:
data = self.getter()
return return
@mc.setter @mc.setter
@ -124,7 +115,6 @@ class VirtualInputStrip(InputStrip):
@property @property
def k(self) -> int: def k(self) -> int:
data = self.getter()
return return
@k.setter @k.setter
@ -140,12 +130,12 @@ class StripLevel(InputStrip):
self.level_map = _strip_maps[remote.kind.id] self.level_map = _strip_maps[remote.kind.id]
def getter_level(self, mode=None): def getter_level(self, mode=None):
def fget(data, i): def fget(i, data):
return data.inputlevels[i] return data.inputlevels[i]
range_ = self.level_map[self.index] range_ = self.level_map[self.index]
data = self._remote.get_rt() data = self.public_packet
levels = tuple(fget(data, i) for i in range(*range_)) levels = tuple(fget(i, data) for i in range(*range_))
return levels return levels
@property @property
@ -161,6 +151,26 @@ class StripLevel(InputStrip):
return 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): def _make_strip_mixin(kind):
""" Creates a mixin with the kind's strip layout set as class variables. """ """ Creates a mixin with the kind's strip layout set as class variables. """
num_A, num_B = kind.outs num_A, num_B = kind.outs

View File

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