voicemeeter-api-python/voicemeeterlib/recorder.py

76 lines
1.9 KiB
Python
Raw Normal View History

2022-06-16 14:07:12 +01:00
from .error import VMError
from .iremote import IRemote
from .kinds import kinds_all
from .meta import action_prop, bool_prop
class Recorder(IRemote):
"""
Implements the common interface
Defines concrete implementation for recorder
"""
@classmethod
def make(cls, remote):
"""
Factory function for recorder.
Returns a Recorder class of a kind.
"""
2022-06-18 11:12:33 +01:00
CHANNELOUTMIXIN_cls = _make_channelout_mixins[remote.kind.name]
2022-06-16 14:07:12 +01:00
REC_cls = type(
f"Recorder{remote.kind}",
2022-06-18 11:12:33 +01:00
(cls, CHANNELOUTMIXIN_cls),
2022-06-16 14:07:12 +01:00
{
**{
param: action_prop(param)
for param in [
"play",
"stop",
"pause",
"replay",
"record",
"ff",
2022-06-25 15:13:00 +01:00
"rew",
2022-06-16 14:07:12 +01:00
]
},
},
)
return REC_cls(remote)
def __str__(self):
return f"{type(self).__name__}"
@property
def identifier(self) -> str:
return "recorder"
def load(self, file: str):
try:
self.setter("load", file)
except UnicodeError:
raise VMError("File full directory must be a raw string")
def set_loop(self, val: bool):
self.setter("mode.loop", 1 if val else 0)
loop = property(fset=set_loop)
2022-06-18 11:12:33 +01:00
def _make_channelout_mixin(kind):
2022-06-16 14:07:12 +01:00
"""Creates a channel out property mixin"""
return type(
2022-06-18 11:12:33 +01:00
f"ChannelOutMixin{kind}",
2022-06-16 14:07:12 +01:00
(),
{
2022-06-18 11:12:33 +01:00
**{f"A{i}": bool_prop(f"A{i}") for i in range(1, kind.phys_out + 1)},
**{f"B{i}": bool_prop(f"B{i}") for i in range(1, kind.virt_out + 1)},
2022-06-16 14:07:12 +01:00
},
)
2022-06-18 11:12:33 +01:00
_make_channelout_mixins = {
kind.name: _make_channelout_mixin(kind) for kind in kinds_all
}