diff --git a/vbancmd/bus.py b/vbancmd/bus.py index 31fa02d..414f2c7 100644 --- a/vbancmd/bus.py +++ b/vbancmd/bus.py @@ -2,6 +2,7 @@ from .errors import VMCMDErrors from . import channel from .channel import Channel from . import kinds +from .meta import bus_mode_prop class OutputBus(Channel): """ Base class for output buses. """ @@ -11,9 +12,11 @@ class OutputBus(Channel): Factory function for output busses. Returns a physical/virtual bus of a kind. """ + BusModeMixin = _make_bus_mode_mixin(cls) OutputBus = PhysicalOutputBus if is_physical else VirtualOutputBus OB_cls = type(f'Bus{remote.kind.name}', (OutputBus,), { 'levels': BusLevel(remote, index), + 'mode': BusModeMixin(remote, index), }) return OB_cls(remote, index, *args, **kwargs) @@ -126,3 +129,11 @@ def _make_bus_level_map(kind): return tuple((i, i+8) for i in range(0, (phys_out+virt_out)*8, 8)) _bus_maps = {kind.id: _make_bus_level_map(kind) for kind in kinds.all} + +def _make_bus_mode_mixin(cls): + """ Creates a mixin of Bus Modes. """ + return type('BusModeMixin', (cls,), { + **{f'{mode.lower()}': bus_mode_prop(f'mode.{mode}') for mode in + ['normal', 'Amix', 'Bmix', 'Repeat', 'Composite', 'TVMix', 'UpMix21', + 'UpMix41', 'UpMix61', 'CenterOnly', 'LFEOnly', 'RearOnly']}, + }) diff --git a/vbancmd/channel.py b/vbancmd/channel.py index 12230ac..42ca7dc 100644 --- a/vbancmd/channel.py +++ b/vbancmd/channel.py @@ -10,17 +10,17 @@ class Modes: _mono: hex=0x00000004 _mutec: hex=0x00000008 - _mixdown: hex=0x00000010 + _amix: hex=0x00000010 _repeat: hex=0x00000020 - _mixdownb: hex=0x00000030 + _bmix: hex=0x00000030 _composite: hex=0x00000040 - _upmixtv: hex=0x00000050 - _updmix2: hex=0x00000060 - _upmix4: hex=0x00000070 - _upmix6: hex=0x00000080 - _center: hex=0x00000090 - _lfe: hex=0x000000A0 - _rear: hex=0x000000B0 + _tvmix: hex=0x00000050 + _upmix21: hex=0x00000060 + _upmix41: hex=0x00000070 + _upmix61: hex=0x00000080 + _centeronly: hex=0x00000090 + _lfeonly: hex=0x000000A0 + _rearonly: hex=0x000000B0 _mask: hex=0x000000F0 diff --git a/vbancmd/meta.py b/vbancmd/meta.py index af36ec2..ac7e7fe 100644 --- a/vbancmd/meta.py +++ b/vbancmd/meta.py @@ -10,3 +10,22 @@ def strip_output_prop(param): raise VMCMDErrors(f'{param} is a boolean parameter') self.setter(param, 1 if val else 0) return property(fget, fset) + +def bus_mode_prop(param): + """ A strip output prop. """ + def fget(self): + data = self._remote.public_packet + if param == 'mode.normal': + vals = [ + not int.from_bytes(data.busstate[self.index], 'little') & getattr(self._modes, f'_{param.lower()}') == 0 + for param in ['Amix', 'Bmix', 'Repeat', 'Composite', 'TVMix', 'UpMix21', + 'UpMix41', 'UpMix61', 'CenterOnly', 'LFEOnly', 'RearOnly'] + ] + return not True in vals + return not int.from_bytes(data.busstate[self.index], 'little') & getattr(self._modes, f'_{param.lower().split(".")[1]}') == 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) +