mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2024-11-22 11:00:47 +00:00
adds more properties and methods to Recorder class
rename _make_armstrip_mixin to _make_armchannel_mixin
This commit is contained in:
parent
f92bb1e457
commit
ee3fa0a372
@ -1,3 +1,5 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
from .error import VMError
|
from .error import VMError
|
||||||
from .iremote import IRemote
|
from .iremote import IRemote
|
||||||
from .kinds import kinds_all
|
from .kinds import kinds_all
|
||||||
@ -19,7 +21,7 @@ class Recorder(IRemote):
|
|||||||
Returns a Recorder class of a kind.
|
Returns a Recorder class of a kind.
|
||||||
"""
|
"""
|
||||||
CHANNELOUTMIXIN_cls = _make_channelout_mixins[remote.kind.name]
|
CHANNELOUTMIXIN_cls = _make_channelout_mixins[remote.kind.name]
|
||||||
ARMSTRIPMIXIN_cls = _make_armstrip_mixins(remote)[remote.kind.name]
|
ARMSTRIPMIXIN_cls = _make_armchannel_mixins(remote)[remote.kind.name]
|
||||||
REC_cls = type(
|
REC_cls = type(
|
||||||
f"Recorder{remote.kind}",
|
f"Recorder{remote.kind}",
|
||||||
(cls, CHANNELOUTMIXIN_cls, ARMSTRIPMIXIN_cls),
|
(cls, CHANNELOUTMIXIN_cls, ARMSTRIPMIXIN_cls),
|
||||||
@ -48,6 +50,57 @@ class Recorder(IRemote):
|
|||||||
def identifier(self) -> str:
|
def identifier(self) -> str:
|
||||||
return "recorder"
|
return "recorder"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def samplerate(self) -> int:
|
||||||
|
return int(self.getter("samplerate"))
|
||||||
|
|
||||||
|
@samplerate.setter
|
||||||
|
def samplerate(self, val: int):
|
||||||
|
opts = (22050, 24000, 32000, 44100, 48000, 88200, 96000, 176400, 192000)
|
||||||
|
if val not in opts:
|
||||||
|
self.logger.warning(f"samplerate got: {val} but expected a value in {opts}")
|
||||||
|
self.setter("samplerate", val)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bitresolution(self) -> int:
|
||||||
|
return int(self.getter("bitresolution"))
|
||||||
|
|
||||||
|
@bitresolution.setter
|
||||||
|
def bitresolution(self, val: int):
|
||||||
|
opts = (8, 16, 24, 32)
|
||||||
|
if val not in opts:
|
||||||
|
self.logger.warning(
|
||||||
|
f"bitresolution got: {val} but expected a value in {opts}"
|
||||||
|
)
|
||||||
|
self.setter("bitresolution", val)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def channel(self) -> int:
|
||||||
|
return int(self.getter("channel"))
|
||||||
|
|
||||||
|
@channel.setter
|
||||||
|
def channel(self, val: int):
|
||||||
|
self.getter("channel", val)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def kbps(self):
|
||||||
|
return int(self.getter("kbps"))
|
||||||
|
|
||||||
|
@kbps.setter
|
||||||
|
def kbps(self, val: int):
|
||||||
|
opts = (32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320)
|
||||||
|
if val not in opts:
|
||||||
|
self.logger.warning(f"kbps got: {val} but expected a value in {opts}")
|
||||||
|
self.setter("kbps", val)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def gain(self) -> float:
|
||||||
|
return round(self.getter("gain"), 1)
|
||||||
|
|
||||||
|
@gain.setter
|
||||||
|
def gain(self, val: float):
|
||||||
|
self.setter("gain", val)
|
||||||
|
|
||||||
def load(self, file: str):
|
def load(self, file: str):
|
||||||
try:
|
try:
|
||||||
self.setter("load", file)
|
self.setter("load", file)
|
||||||
@ -59,29 +112,34 @@ class Recorder(IRemote):
|
|||||||
|
|
||||||
loop = property(fset=set_loop)
|
loop = property(fset=set_loop)
|
||||||
|
|
||||||
@property
|
def goto(self, time_str):
|
||||||
def bitresolution(self) -> int:
|
def get_sec():
|
||||||
set.getter("bitresolution")
|
"""Get seconds from time string"""
|
||||||
|
h, m, s = time_str.split(":")
|
||||||
|
return int(h) * 3600 + int(m) * 60 + int(s)
|
||||||
|
|
||||||
@bitresolution.setter
|
time_str = str(time_str) # coerce the type
|
||||||
def bitresolution(self, val: int):
|
if (
|
||||||
set.getter("bitresolution", val)
|
match := re.match(
|
||||||
|
r"^(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)$",
|
||||||
|
time_str,
|
||||||
|
)
|
||||||
|
is not None
|
||||||
|
):
|
||||||
|
self.setter("goto", get_sec())
|
||||||
|
else:
|
||||||
|
self.logger.warning(
|
||||||
|
f"goto expects a string that matches the format 'hh:mm:ss'"
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
def filetype(self, val: str):
|
||||||
def channel(self) -> int:
|
opts = {"wav": 1, "aiff": 2, "bwf": 3, "mp3": 100}
|
||||||
set.getter("channel")
|
try:
|
||||||
|
self.setter("filetype", opts[val])
|
||||||
@channel.setter
|
except KeyError:
|
||||||
def channel(self, val: int):
|
self.logger.warning(
|
||||||
set.getter("channel", val)
|
f"filetype got: {val} but expected a value in {list(opts.keys())}"
|
||||||
|
)
|
||||||
@property
|
|
||||||
def gain(self) -> float:
|
|
||||||
return round(self.getter("gain"), 1)
|
|
||||||
|
|
||||||
@gain.setter
|
|
||||||
def gain(self, val: float):
|
|
||||||
self.setter("gain", val)
|
|
||||||
|
|
||||||
|
|
||||||
class RecorderMode(IRemote):
|
class RecorderMode(IRemote):
|
||||||
@ -90,7 +148,7 @@ class RecorderMode(IRemote):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def recbus(self) -> bool:
|
def recbus(self) -> bool:
|
||||||
self.getter("recbus")
|
return self.getter("recbus") == 1
|
||||||
|
|
||||||
@recbus.setter
|
@recbus.setter
|
||||||
def recbus(self, val: bool):
|
def recbus(self, val: bool):
|
||||||
@ -98,7 +156,7 @@ class RecorderMode(IRemote):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def playonload(self) -> bool:
|
def playonload(self) -> bool:
|
||||||
self.getter("playonload")
|
return self.getter("playonload") == 1
|
||||||
|
|
||||||
@playonload.setter
|
@playonload.setter
|
||||||
def playonload(self, val: bool):
|
def playonload(self, val: bool):
|
||||||
@ -106,19 +164,19 @@ class RecorderMode(IRemote):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def loop(self) -> bool:
|
def loop(self) -> bool:
|
||||||
self.getter("loop")
|
return self.getter("loop") == 1
|
||||||
|
|
||||||
@loop.setter
|
@loop.setter
|
||||||
def loop(self, val: bool):
|
def loop(self, val: bool):
|
||||||
self.setter("recbus", 1 if val else 0)
|
self.setter("loop", 1 if val else 0)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def multitrack(self) -> bool:
|
def multitrack(self) -> bool:
|
||||||
self.getter("recbus")
|
return self.getter("multitrack") == 1
|
||||||
|
|
||||||
@multitrack.setter
|
@multitrack.setter
|
||||||
def multitrack(self, val: bool):
|
def multitrack(self, val: bool):
|
||||||
self.setter("recbus", 1 if val else 0)
|
self.setter("multitrack", 1 if val else 0)
|
||||||
|
|
||||||
|
|
||||||
class RecorderArmStrip(IRemote):
|
class RecorderArmStrip(IRemote):
|
||||||
@ -147,9 +205,10 @@ class RecorderArmBus(IRemote):
|
|||||||
self.setter("", 1 if val else 0)
|
self.setter("", 1 if val else 0)
|
||||||
|
|
||||||
|
|
||||||
def _make_armstrip_mixin(remote, kind):
|
def _make_armchannel_mixin(remote, kind):
|
||||||
|
"""Creates an armchannel out mixin"""
|
||||||
return type(
|
return type(
|
||||||
f"ArmStripMixin",
|
f"ArmChannelMixin{kind}",
|
||||||
(),
|
(),
|
||||||
{
|
{
|
||||||
"armstrip": tuple(
|
"armstrip": tuple(
|
||||||
@ -160,12 +219,12 @@ def _make_armstrip_mixin(remote, kind):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _make_armstrip_mixins(remote):
|
def _make_armchannel_mixins(remote):
|
||||||
return {kind.name: _make_armstrip_mixin(remote, kind) for kind in kinds_all}
|
return {kind.name: _make_armchannel_mixin(remote, kind) for kind in kinds_all}
|
||||||
|
|
||||||
|
|
||||||
def _make_channelout_mixin(kind):
|
def _make_channelout_mixin(kind):
|
||||||
"""Creates a channel out property mixin"""
|
"""Creates a channel out mixin"""
|
||||||
return type(
|
return type(
|
||||||
f"ChannelOutMixin{kind}",
|
f"ChannelOutMixin{kind}",
|
||||||
(),
|
(),
|
||||||
|
Loading…
Reference in New Issue
Block a user