From 5ad5622612db796dbd8578fbdebc68a99be6abc2 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Wed, 26 Oct 2022 14:24:13 +0100 Subject: [PATCH] pan_x, pan_y added to virtual strips pan_x, pan_y virt tests added to higher. patch bump --- pyproject.toml | 2 +- tests/test_higher.py | 2 ++ voicemeeterlib/strip.py | 64 ++++++++++++++++++++++++++++------------- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4c37f9b..0516a73 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "voicemeeter-api" -version = "0.9.0" +version = "0.9.1" description = "A Python wrapper for the Voiceemeter API" authors = ["onyx-and-iris "] license = "MIT" diff --git a/tests/test_higher.py b/tests/test_higher.py index 9e3c9e2..64c97ec 100644 --- a/tests/test_higher.py +++ b/tests/test_higher.py @@ -381,6 +381,8 @@ class TestSetAndGetFloatHigher: @pytest.mark.parametrize( "index, param, value", [ + (data.virt_in, "pan_x", -0.6), + (data.virt_in, "pan_x", 0.6), (data.virt_in, "treble", -1.6), (data.virt_in, "mid", 5.8), (data.virt_in, "bass", -8.1), diff --git a/voicemeeterlib/strip.py b/voicemeeterlib/strip.py index 6a1b0df..d246579 100644 --- a/voicemeeterlib/strip.py +++ b/voicemeeterlib/strip.py @@ -82,13 +82,13 @@ class Strip(IRemote): class PhysicalStrip(Strip): @classmethod - def make(cls, remote, i, kind): + def make(cls, remote, i, is_phys): """ Factory method for PhysicalStrip. Returns a PhysicalStrip class. """ - EFFECTS_cls = _make_effects_mixins[kind.name] + EFFECTS_cls = _make_effects_mixins(is_phys)[remote.kind.name] return type( f"PhysicalStrip", (cls, EFFECTS_cls), @@ -164,6 +164,20 @@ class StripDevice(IRemote): class VirtualStrip(Strip): + @classmethod + def make(cls, remote, i, is_phys): + """ + Factory method for PhysicalStrip. + + Returns a PhysicalStrip class. + """ + EFFECTS_cls = _make_effects_mixins(is_phys)[remote.kind.name] + return type( + f"VirtualStrip", + (cls, EFFECTS_cls), + {}, + ) + def __str__(self): return f"{type(self).__name__}{self.index}" @@ -340,23 +354,30 @@ _make_channelout_mixins = { } -def _make_effects_mixin(kind): +def _make_effects_mixin(kind, is_phys): """creates an effects mixin for a kind""" - XY_cls = type( - "XY", - (), - { - param: float_prop(param) - for param in [ - "pan_x", - "pan_y", - "color_x", - "color_y", - "fx_x", - "fx_y", - ] - }, - ) + + def _make_xy_cls(): + pan = {param: float_prop(param) for param in ["pan_x", "pan_y"]} + color = {param: float_prop(param) for param in ["color_x", "color_y"]} + fx = {param: float_prop(param) for param in ["fx_x", "fx_y"]} + if is_phys: + return type( + "XYPhys", + (), + { + **pan, + **color, + **fx, + }, + ) + return type( + "XYVirt", + (), + {**pan}, + ) + + XY_cls = _make_xy_cls() FX_cls = type( "FX", @@ -383,7 +404,8 @@ def _make_effects_mixin(kind): return type(f"Effects{kind}", (XY_cls,), {}) -_make_effects_mixins = {kind.name: _make_effects_mixin(kind) for kind in kinds_all} +def _make_effects_mixins(is_phys): + return {kind.name: _make_effects_mixin(kind, is_phys) for kind in kinds_all} def strip_factory(is_phys_strip, remote, i) -> Union[PhysicalStrip, VirtualStrip]: @@ -395,7 +417,9 @@ def strip_factory(is_phys_strip, remote, i) -> Union[PhysicalStrip, VirtualStrip Returns a physical or virtual strip subclass """ STRIP_cls = ( - PhysicalStrip.make(remote, i, remote.kind) if is_phys_strip else VirtualStrip + PhysicalStrip.make(remote, i, is_phys_strip) + if is_phys_strip + else VirtualStrip.make(remote, i, is_phys_strip) ) CHANNELOUTMIXIN_cls = _make_channelout_mixins[remote.kind.name]