From f4fc58cea047902f66a825ccce5b1522ac165535 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Tue, 11 Oct 2022 12:53:08 +0100 Subject: [PATCH] added strip/bus device mixins. device_prop added to meta README, CHANGELOG updated to reflect changes. minor version bump fixes #3 --- CHANGELOG.md | 22 ++++++++++++++++ README.md | 25 +++++++++++++++--- pyproject.toml | 2 +- voicemeeterlib/bus.py | 57 +++++++++++++++++++++++++++++++++-------- voicemeeterlib/meta.py | 9 +++++++ voicemeeterlib/strip.py | 52 ++++++++++++++++++++++++++++++++----- 6 files changed, 145 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5df3e6c..3b9346e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,28 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass - [x] +## [0.9.0] - 2022-10-11 + +### Added + +- StripDevice and BusDevice mixins. +- README updated to reflect changes. +- Minor version bump + +### Removed + +- device, sr properties for physical strip, bus moved into mixin classes + +### Changed + +- Event class property setters added. +- Event add/remove methods now accept multiple events. +- bus levels now printed in observer example. + +### Fixed + +- initialize channel comps in updater thread. Fixes bug when switching to a kind before any level updates have occurred. + ## [0.8.0] - 2022-09-29 ### Added diff --git a/README.md b/README.md index 3b468f2..3cf3179 100644 --- a/README.md +++ b/README.md @@ -114,8 +114,6 @@ The following properties are available. - `limit`: int, from -40 to 12 - `A1 - A5`, `B1 - B3`: boolean - `label`: string -- `device`: string -- `sr`: int - `mc`: boolean - `k`: int, from 0 to 4 - `bass`: float, from -12.0 to 12.0 @@ -199,8 +197,6 @@ The following properties are available. - `sel`: boolean - `gain`: float, from -60.0 to 12.0 - `label`: string -- `device`: string -- `sr`: int - `returnreverb`: float, from 0.0 to 10.0 - `returndelay`: float, from 0.0 to 10.0 - `returnfx1`: float, from 0.0 to 10.0 @@ -274,6 +270,27 @@ vm.strip[0].fadeto(-10.3, 1000) vm.bus[3].fadeby(-5.6, 500) ``` +#### Strip.Device | Bus.Device + +The following properties are available + +- `name`: str +- `sr`: int +- `wdm`: str +- `ks`: str +- `mme`: str +- `asio`: str + +example: + +```python +print(vm.strip[0].device.name) +vm.bus[0].device.asio = "Audient USB Audio ASIO Driver" +``` + +strip|bus device parameters are defined for physical channels only. +name, sr are read only. wdm, ks, mme, asio are write only. + ### Macrobuttons The following properties are available. diff --git a/pyproject.toml b/pyproject.toml index d24480b..4c37f9b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "voicemeeter-api" -version = "0.8.4" +version = "0.9.0" description = "A Python wrapper for the Voiceemeter API" authors = ["onyx-and-iris "] license = "MIT" diff --git a/voicemeeterlib/bus.py b/voicemeeterlib/bus.py index 14b2891..3730fed 100644 --- a/voicemeeterlib/bus.py +++ b/voicemeeterlib/bus.py @@ -4,10 +4,9 @@ from enum import IntEnum from math import log from typing import Union -from .error import VMError from .iremote import IRemote from .kinds import kinds_all -from .meta import bool_prop, bus_mode_prop, float_prop +from .meta import bus_mode_prop, device_prop, float_prop BusModes = IntEnum( "BusModes", @@ -106,7 +105,7 @@ class Bus(IRemote): class PhysicalBus(Bus): @classmethod - def make(cls, kind): + def make(cls, remote, i, kind): """ Factory method for PhysicalBus. @@ -116,18 +115,54 @@ class PhysicalBus(Bus): if kind.name == "potato": EFFECTS_cls = _make_effects_mixin() kls += (EFFECTS_cls,) - return type("PhysicalBus", kls, {}) + return type( + "PhysicalBus", + kls, + { + "device": BusDevice.make(remote, i), + }, + ) def __str__(self): return f"{type(self).__name__}{self.index}" - @property - def device(self) -> str: - return self.getter("device.name", is_string=True) + +class BusDevice(IRemote): + @classmethod + def make(cls, remote, i): + """ + Factory function for bus.device. + + Returns a BusDevice class of a kind. + """ + DEVICE_cls = type( + f"BusDevice{remote.kind}", + (cls,), + { + **{ + param: device_prop(param) + for param in [ + "wdm", + "ks", + "mme", + "asio", + ] + }, + }, + ) + return DEVICE_cls(remote, i) @property - def sr(self) -> int: - return int(self.getter("device.sr")) + def identifier(self) -> str: + return f"Bus[{self.index}].device" + + @property + def name(self): + return self.getter("name", is_string=True) + + @property + def sr(self): + return int(self.getter("sr")) class VirtualBus(Bus): @@ -263,7 +298,9 @@ def bus_factory(is_phys_bus, remote, i) -> Union[PhysicalBus, VirtualBus]: Returns a physical or virtual bus subclass """ BUS_cls = ( - PhysicalBus.make(remote.kind) if is_phys_bus else VirtualBus.make(remote.kind) + PhysicalBus.make(remote, i, remote.kind) + if is_phys_bus + else VirtualBus.make(remote.kind) ) BUSMODEMIXIN_cls = _make_bus_mode_mixin() return type( diff --git a/voicemeeterlib/meta.py b/voicemeeterlib/meta.py index 89e5b33..e4c9129 100644 --- a/voicemeeterlib/meta.py +++ b/voicemeeterlib/meta.py @@ -42,3 +42,12 @@ def bus_mode_prop(param): self.setter(param, 1 if val else 0) return property(fget, fset) + + +def device_prop(param): + """meta function for strip device parameters""" + + def fset(self, val: str): + self.setter(param, val) + + return property(fset=fset) diff --git a/voicemeeterlib/strip.py b/voicemeeterlib/strip.py index 689a966..b4ebb00 100644 --- a/voicemeeterlib/strip.py +++ b/voicemeeterlib/strip.py @@ -5,7 +5,7 @@ from typing import Union from .iremote import IRemote from .kinds import kinds_all -from .meta import bool_prop, float_prop +from .meta import bool_prop, device_prop, float_prop class Strip(IRemote): @@ -82,14 +82,20 @@ class Strip(IRemote): class PhysicalStrip(Strip): @classmethod - def make(cls, kind): + def make(cls, remote, i, kind): """ Factory method for PhysicalStrip. Returns a PhysicalStrip class. """ EFFECTS_cls = _make_effects_mixins[kind.name] - return type(f"PhysicalStrip", (cls, EFFECTS_cls), {}) + return type( + f"PhysicalStrip", + (cls, EFFECTS_cls), + { + "device": StripDevice.make(remote, i), + }, + ) def __str__(self): return f"{type(self).__name__}{self.index}" @@ -118,13 +124,43 @@ class PhysicalStrip(Strip): def audibility(self, val: float): self.setter("audibility", val) + +class StripDevice(IRemote): + @classmethod + def make(cls, remote, i): + """ + Factory function for strip.device. + + Returns a StripDevice class of a kind. + """ + DEVICE_cls = type( + f"StripDevice{remote.kind}", + (cls,), + { + **{ + param: device_prop(param) + for param in [ + "wdm", + "ks", + "mme", + "asio", + ] + }, + }, + ) + return DEVICE_cls(remote, i) + @property - def device(self): - return self.getter("device.name", is_string=True) + def identifier(self) -> str: + return f"Strip[{self.index}].device" + + @property + def name(self): + return self.getter("name", is_string=True) @property def sr(self): - return int(self.getter("device.sr")) + return int(self.getter("sr")) class VirtualStrip(Strip): @@ -358,7 +394,9 @@ def strip_factory(is_phys_strip, remote, i) -> Union[PhysicalStrip, VirtualStrip Returns a physical or virtual strip subclass """ - STRIP_cls = PhysicalStrip.make(remote.kind) if is_phys_strip else VirtualStrip + STRIP_cls = ( + PhysicalStrip.make(remote, i, remote.kind) if is_phys_strip else VirtualStrip + ) CHANNELOUTMIXIN_cls = _make_channelout_mixins[remote.kind.name] _kls = (STRIP_cls, CHANNELOUTMIXIN_cls)