voicemeeter-api-python/voicemeeterlib/macrobutton.py

58 lines
1.4 KiB
Python
Raw Normal View History

from enum import IntEnum
2022-06-16 14:07:12 +01:00
from .iremote import IRemote
ButtonModes = IntEnum(
"ButtonModes",
"state stateonly trigger",
start=1,
)
2022-06-16 14:07:12 +01:00
class Adapter(IRemote):
"""Adapter to the common interface."""
def identifier(self):
pass
2022-06-21 23:21:55 +01:00
def getter(self, mode):
self.logger.debug(f"getter: button[{self.index}].{ButtonModes(mode).name}")
2022-06-21 23:21:55 +01:00
return self._remote.get_buttonstatus(self.index, mode)
2022-06-16 14:07:12 +01:00
def setter(self, mode, val):
self.logger.debug(
f"setter: button[{self.index}].{ButtonModes(mode).name}={val}"
)
2022-06-21 23:21:55 +01:00
self._remote.set_buttonstatus(self.index, val, mode)
2022-06-16 14:07:12 +01:00
class MacroButton(Adapter):
"""Defines concrete implementation for macrobutton"""
def __str__(self):
return f"{type(self).__name__}{self._remote.kind}{self.index}"
@property
def state(self) -> bool:
return self.getter(ButtonModes.state) == 1
2022-06-16 14:07:12 +01:00
@state.setter
2023-07-20 11:11:34 +01:00
def state(self, val: bool):
self.setter(ButtonModes.state, 1 if val else 0)
2022-06-16 14:07:12 +01:00
@property
def stateonly(self) -> bool:
return self.getter(ButtonModes.stateonly) == 1
2022-06-16 14:07:12 +01:00
@stateonly.setter
2023-07-20 11:11:34 +01:00
def stateonly(self, val: bool):
self.setter(ButtonModes.stateonly, 1 if val else 0)
2022-06-16 14:07:12 +01:00
@property
def trigger(self) -> bool:
return self.getter(ButtonModes.trigger) == 1
2022-06-16 14:07:12 +01:00
@trigger.setter
2023-07-20 11:11:34 +01:00
def trigger(self, val: bool):
self.setter(ButtonModes.trigger, 1 if val else 0)