2023-06-30 19:00:27 +01:00
|
|
|
import re
|
|
|
|
|
2022-06-16 14:07:12 +01:00
|
|
|
from .error import VMError
|
|
|
|
from .iremote import IRemote
|
|
|
|
from .kinds import kinds_all
|
2023-06-23 03:39:07 +01:00
|
|
|
from .meta import action_fn, bool_prop
|
2022-06-16 14:07:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
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]
|
2023-07-01 18:09:31 +01:00
|
|
|
ARMCHANNELMIXIN_cls = _make_armchannel_mixins(remote)[remote.kind.name]
|
2022-06-16 14:07:12 +01:00
|
|
|
REC_cls = type(
|
|
|
|
f"Recorder{remote.kind}",
|
2023-07-01 18:09:31 +01:00
|
|
|
(cls, CHANNELOUTMIXIN_cls, ARMCHANNELMIXIN_cls),
|
2022-06-16 14:07:12 +01:00
|
|
|
{
|
|
|
|
**{
|
2023-06-23 03:39:07 +01:00
|
|
|
param: action_fn(param)
|
2022-06-16 14:07:12 +01:00
|
|
|
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
|
|
|
]
|
|
|
|
},
|
2023-06-30 01:22:30 +01:00
|
|
|
"mode": RecorderMode(remote),
|
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"
|
|
|
|
|
2023-06-30 19:00:27 +01:00
|
|
|
@property
|
|
|
|
def samplerate(self) -> int:
|
|
|
|
return int(self.getter("samplerate"))
|
2022-06-16 14:07:12 +01:00
|
|
|
|
2023-06-30 19:00:27 +01:00
|
|
|
@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)
|
2022-06-16 14:07:12 +01:00
|
|
|
|
2023-06-30 01:22:30 +01:00
|
|
|
@property
|
|
|
|
def bitresolution(self) -> int:
|
2023-06-30 19:00:27 +01:00
|
|
|
return int(self.getter("bitresolution"))
|
2023-06-30 01:22:30 +01:00
|
|
|
|
|
|
|
@bitresolution.setter
|
|
|
|
def bitresolution(self, val: int):
|
2023-06-30 19:00:27 +01:00
|
|
|
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)
|
2023-06-30 01:22:30 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def channel(self) -> int:
|
2023-06-30 19:00:27 +01:00
|
|
|
return int(self.getter("channel"))
|
2023-06-30 01:22:30 +01:00
|
|
|
|
|
|
|
@channel.setter
|
|
|
|
def channel(self, val: int):
|
2023-06-30 23:51:20 +01:00
|
|
|
if not 1 <= val <= 8:
|
|
|
|
self.logger.warning(f"channel got: {val} but expected a value from 1 to 8")
|
|
|
|
self.setter("channel", val)
|
2023-06-30 19:00:27 +01:00
|
|
|
|
|
|
|
@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)
|
2023-06-30 01:22:30 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def gain(self) -> float:
|
|
|
|
return round(self.getter("gain"), 1)
|
|
|
|
|
|
|
|
@gain.setter
|
|
|
|
def gain(self, val: float):
|
|
|
|
self.setter("gain", val)
|
|
|
|
|
2023-06-30 19:00:27 +01:00
|
|
|
def load(self, file: str):
|
|
|
|
try:
|
|
|
|
self.setter("load", file)
|
|
|
|
except UnicodeError:
|
|
|
|
raise VMError("File full directory must be a raw string")
|
|
|
|
|
2023-06-30 23:51:20 +01:00
|
|
|
# loop forwarder methods, for backwards compatibility
|
|
|
|
@property
|
|
|
|
def loop(self):
|
|
|
|
return self.mode.loop
|
2023-06-30 19:00:27 +01:00
|
|
|
|
2023-06-30 23:51:20 +01:00
|
|
|
@loop.setter
|
|
|
|
def loop(self, val: bool):
|
|
|
|
self.mode.loop = val
|
2023-06-30 19:00:27 +01:00
|
|
|
|
|
|
|
def goto(self, time_str):
|
|
|
|
def get_sec():
|
|
|
|
"""Get seconds from time string"""
|
|
|
|
h, m, s = time_str.split(":")
|
|
|
|
return int(h) * 3600 + int(m) * 60 + int(s)
|
|
|
|
|
|
|
|
time_str = str(time_str) # coerce the type
|
|
|
|
if (
|
|
|
|
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'"
|
|
|
|
)
|
|
|
|
|
|
|
|
def filetype(self, val: str):
|
|
|
|
opts = {"wav": 1, "aiff": 2, "bwf": 3, "mp3": 100}
|
|
|
|
try:
|
2023-06-30 23:51:20 +01:00
|
|
|
self.setter("filetype", opts[val.lower()])
|
2023-06-30 19:00:27 +01:00
|
|
|
except KeyError:
|
|
|
|
self.logger.warning(
|
|
|
|
f"filetype got: {val} but expected a value in {list(opts.keys())}"
|
|
|
|
)
|
|
|
|
|
2023-06-30 01:22:30 +01:00
|
|
|
|
|
|
|
class RecorderMode(IRemote):
|
2023-06-30 23:51:20 +01:00
|
|
|
@property
|
2023-06-30 01:22:30 +01:00
|
|
|
def identifier(self):
|
|
|
|
return "recorder.mode"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def recbus(self) -> bool:
|
2023-06-30 19:00:27 +01:00
|
|
|
return self.getter("recbus") == 1
|
2023-06-30 01:22:30 +01:00
|
|
|
|
|
|
|
@recbus.setter
|
|
|
|
def recbus(self, val: bool):
|
|
|
|
self.setter("recbus", 1 if val else 0)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def playonload(self) -> bool:
|
2023-06-30 19:00:27 +01:00
|
|
|
return self.getter("playonload") == 1
|
2023-06-30 01:22:30 +01:00
|
|
|
|
|
|
|
@playonload.setter
|
|
|
|
def playonload(self, val: bool):
|
|
|
|
self.setter("playonload", 1 if val else 0)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def loop(self) -> bool:
|
2023-06-30 19:00:27 +01:00
|
|
|
return self.getter("loop") == 1
|
2023-06-30 01:22:30 +01:00
|
|
|
|
|
|
|
@loop.setter
|
|
|
|
def loop(self, val: bool):
|
2023-06-30 19:00:27 +01:00
|
|
|
self.setter("loop", 1 if val else 0)
|
2023-06-30 01:22:30 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def multitrack(self) -> bool:
|
2023-06-30 19:00:27 +01:00
|
|
|
return self.getter("multitrack") == 1
|
2023-06-30 01:22:30 +01:00
|
|
|
|
|
|
|
@multitrack.setter
|
|
|
|
def multitrack(self, val: bool):
|
2023-06-30 19:00:27 +01:00
|
|
|
self.setter("multitrack", 1 if val else 0)
|
2023-06-30 01:22:30 +01:00
|
|
|
|
|
|
|
|
2023-06-30 23:51:20 +01:00
|
|
|
class RecorderArmChannel(IRemote):
|
2023-06-30 01:22:30 +01:00
|
|
|
def __init__(self, remote, i):
|
|
|
|
super().__init__(remote)
|
|
|
|
self._i = i
|
|
|
|
|
|
|
|
def set(self, val: bool):
|
|
|
|
self.setter("", 1 if val else 0)
|
|
|
|
|
|
|
|
|
2023-06-30 23:51:20 +01:00
|
|
|
class RecorderArmStrip(RecorderArmChannel):
|
|
|
|
@property
|
|
|
|
def identifier(self):
|
|
|
|
return f"recorder.armstrip[{self._i}]"
|
2023-06-30 01:22:30 +01:00
|
|
|
|
2023-06-30 23:51:20 +01:00
|
|
|
|
|
|
|
class RecorderArmBus(RecorderArmChannel):
|
2023-06-30 01:22:30 +01:00
|
|
|
@property
|
|
|
|
def identifier(self):
|
|
|
|
return f"recorder.armbus[{self._i}]"
|
|
|
|
|
|
|
|
|
2023-06-30 19:00:27 +01:00
|
|
|
def _make_armchannel_mixin(remote, kind):
|
|
|
|
"""Creates an armchannel out mixin"""
|
2023-06-30 01:22:30 +01:00
|
|
|
return type(
|
2023-06-30 19:00:27 +01:00
|
|
|
f"ArmChannelMixin{kind}",
|
2023-06-30 01:22:30 +01:00
|
|
|
(),
|
|
|
|
{
|
|
|
|
"armstrip": tuple(
|
|
|
|
RecorderArmStrip(remote, i) for i in range(kind.num_strip)
|
|
|
|
),
|
|
|
|
"armbus": tuple(RecorderArmBus(remote, i) for i in range(kind.num_bus)),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-06-30 19:00:27 +01:00
|
|
|
def _make_armchannel_mixins(remote):
|
|
|
|
return {kind.name: _make_armchannel_mixin(remote, kind) for kind in kinds_all}
|
2023-06-30 01:22:30 +01:00
|
|
|
|
2022-06-16 14:07:12 +01:00
|
|
|
|
2022-06-18 11:12:33 +01:00
|
|
|
def _make_channelout_mixin(kind):
|
2023-06-30 19:00:27 +01:00
|
|
|
"""Creates a channel out mixin"""
|
2022-06-16 14:07:12 +01:00
|
|
|
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
|
|
|
|
}
|