mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2026-04-09 08:43:29 +00:00
added strip/bus device mixins.
device_prop added to meta README, CHANGELOG updated to reflect changes. minor version bump fixes #3
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user