mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2024-11-25 20:30:46 +00:00
rename bindings to match CAPI functions
use prefix bind_
This commit is contained in:
parent
160a6f89f9
commit
bdf8dc489a
@ -18,98 +18,98 @@ class CBindings(metaclass=ABCMeta):
|
||||
|
||||
logger_cbindings = logger.getChild("CBindings")
|
||||
|
||||
vm_login = libc.VBVMR_Login
|
||||
vm_login.restype = LONG
|
||||
vm_login.argtypes = None
|
||||
bind_login = libc.VBVMR_Login
|
||||
bind_login.restype = LONG
|
||||
bind_login.argtypes = None
|
||||
|
||||
vm_logout = libc.VBVMR_Logout
|
||||
vm_logout.restype = LONG
|
||||
vm_logout.argtypes = None
|
||||
bind_logout = libc.VBVMR_Logout
|
||||
bind_logout.restype = LONG
|
||||
bind_logout.argtypes = None
|
||||
|
||||
vm_runvm = libc.VBVMR_RunVoicemeeter
|
||||
vm_runvm.restype = LONG
|
||||
vm_runvm.argtypes = [LONG]
|
||||
bind_run_voicemeeter = libc.VBVMR_RunVoicemeeter
|
||||
bind_run_voicemeeter.restype = LONG
|
||||
bind_run_voicemeeter.argtypes = [LONG]
|
||||
|
||||
vm_get_type = libc.VBVMR_GetVoicemeeterType
|
||||
vm_get_type.restype = LONG
|
||||
vm_get_type.argtypes = [ct.POINTER(LONG)]
|
||||
bind_get_voicemeeter_type = libc.VBVMR_GetVoicemeeterType
|
||||
bind_get_voicemeeter_type.restype = LONG
|
||||
bind_get_voicemeeter_type.argtypes = [ct.POINTER(LONG)]
|
||||
|
||||
vm_get_version = libc.VBVMR_GetVoicemeeterVersion
|
||||
vm_get_version.restype = LONG
|
||||
vm_get_version.argtypes = [ct.POINTER(LONG)]
|
||||
bind_get_voicemeeter_version = libc.VBVMR_GetVoicemeeterVersion
|
||||
bind_get_voicemeeter_version.restype = LONG
|
||||
bind_get_voicemeeter_version.argtypes = [ct.POINTER(LONG)]
|
||||
|
||||
if hasattr(libc, "VBVMR_MacroButton_IsDirty"):
|
||||
vm_mdirty = libc.VBVMR_MacroButton_IsDirty
|
||||
vm_mdirty.restype = LONG
|
||||
vm_mdirty.argtypes = None
|
||||
bind_macro_button_is_dirty = libc.VBVMR_MacroButton_IsDirty
|
||||
bind_macro_button_is_dirty.restype = LONG
|
||||
bind_macro_button_is_dirty.argtypes = None
|
||||
|
||||
if hasattr(libc, "VBVMR_MacroButton_GetStatus"):
|
||||
vm_get_buttonstatus = libc.VBVMR_MacroButton_GetStatus
|
||||
vm_get_buttonstatus.restype = LONG
|
||||
vm_get_buttonstatus.argtypes = [LONG, ct.POINTER(FLOAT), LONG]
|
||||
bind_macro_button_get_status = libc.VBVMR_MacroButton_GetStatus
|
||||
bind_macro_button_get_status.restype = LONG
|
||||
bind_macro_button_get_status.argtypes = [LONG, ct.POINTER(FLOAT), LONG]
|
||||
|
||||
if hasattr(libc, "VBVMR_MacroButton_SetStatus"):
|
||||
vm_set_buttonstatus = libc.VBVMR_MacroButton_SetStatus
|
||||
vm_set_buttonstatus.restype = LONG
|
||||
vm_set_buttonstatus.argtypes = [LONG, FLOAT, LONG]
|
||||
bind_macro_button_set_status = libc.VBVMR_MacroButton_SetStatus
|
||||
bind_macro_button_set_status.restype = LONG
|
||||
bind_macro_button_set_status.argtypes = [LONG, FLOAT, LONG]
|
||||
|
||||
vm_pdirty = libc.VBVMR_IsParametersDirty
|
||||
vm_pdirty.restype = LONG
|
||||
vm_pdirty.argtypes = None
|
||||
bind_is_parameters_dirty = libc.VBVMR_IsParametersDirty
|
||||
bind_is_parameters_dirty.restype = LONG
|
||||
bind_is_parameters_dirty.argtypes = None
|
||||
|
||||
vm_get_parameter_float = libc.VBVMR_GetParameterFloat
|
||||
vm_get_parameter_float.restype = LONG
|
||||
vm_get_parameter_float.argtypes = [ct.POINTER(CHAR), ct.POINTER(FLOAT)]
|
||||
bind_get_parameter_float = libc.VBVMR_GetParameterFloat
|
||||
bind_get_parameter_float.restype = LONG
|
||||
bind_get_parameter_float.argtypes = [ct.POINTER(CHAR), ct.POINTER(FLOAT)]
|
||||
|
||||
vm_set_parameter_float = libc.VBVMR_SetParameterFloat
|
||||
vm_set_parameter_float.restype = LONG
|
||||
vm_set_parameter_float.argtypes = [ct.POINTER(CHAR), FLOAT]
|
||||
bind_set_parameter_float = libc.VBVMR_SetParameterFloat
|
||||
bind_set_parameter_float.restype = LONG
|
||||
bind_set_parameter_float.argtypes = [ct.POINTER(CHAR), FLOAT]
|
||||
|
||||
vm_get_parameter_string = libc.VBVMR_GetParameterStringW
|
||||
vm_get_parameter_string.restype = LONG
|
||||
vm_get_parameter_string.argtypes = [ct.POINTER(CHAR), ct.POINTER(WCHAR * 512)]
|
||||
bind_get_parameter_string_w = libc.VBVMR_GetParameterStringW
|
||||
bind_get_parameter_string_w.restype = LONG
|
||||
bind_get_parameter_string_w.argtypes = [ct.POINTER(CHAR), ct.POINTER(WCHAR * 512)]
|
||||
|
||||
vm_set_parameter_string = libc.VBVMR_SetParameterStringW
|
||||
vm_set_parameter_string.restype = LONG
|
||||
vm_set_parameter_string.argtypes = [ct.POINTER(CHAR), ct.POINTER(WCHAR)]
|
||||
bind_set_parameter_string_w = libc.VBVMR_SetParameterStringW
|
||||
bind_set_parameter_string_w.restype = LONG
|
||||
bind_set_parameter_string_w.argtypes = [ct.POINTER(CHAR), ct.POINTER(WCHAR)]
|
||||
|
||||
vm_set_parameter_multi = libc.VBVMR_SetParameters
|
||||
vm_set_parameter_multi.restype = LONG
|
||||
vm_set_parameter_multi.argtypes = [ct.POINTER(CHAR)]
|
||||
bind_set_parameters = libc.VBVMR_SetParameters
|
||||
bind_set_parameters.restype = LONG
|
||||
bind_set_parameters.argtypes = [ct.POINTER(CHAR)]
|
||||
|
||||
vm_get_level = libc.VBVMR_GetLevel
|
||||
vm_get_level.restype = LONG
|
||||
vm_get_level.argtypes = [LONG, LONG, ct.POINTER(FLOAT)]
|
||||
bind_get_level = libc.VBVMR_GetLevel
|
||||
bind_get_level.restype = LONG
|
||||
bind_get_level.argtypes = [LONG, LONG, ct.POINTER(FLOAT)]
|
||||
|
||||
vm_get_num_indevices = libc.VBVMR_Input_GetDeviceNumber
|
||||
vm_get_num_indevices.restype = LONG
|
||||
vm_get_num_indevices.argtypes = None
|
||||
bind_input_get_device_number = libc.VBVMR_Input_GetDeviceNumber
|
||||
bind_input_get_device_number.restype = LONG
|
||||
bind_input_get_device_number.argtypes = None
|
||||
|
||||
vm_get_desc_indevices = libc.VBVMR_Input_GetDeviceDescW
|
||||
vm_get_desc_indevices.restype = LONG
|
||||
vm_get_desc_indevices.argtypes = [
|
||||
bind_input_get_device_desc_w = libc.VBVMR_Input_GetDeviceDescW
|
||||
bind_input_get_device_desc_w.restype = LONG
|
||||
bind_input_get_device_desc_w.argtypes = [
|
||||
LONG,
|
||||
ct.POINTER(LONG),
|
||||
ct.POINTER(WCHAR * 256),
|
||||
ct.POINTER(WCHAR * 256),
|
||||
]
|
||||
|
||||
vm_get_num_outdevices = libc.VBVMR_Output_GetDeviceNumber
|
||||
vm_get_num_outdevices.restype = LONG
|
||||
vm_get_num_outdevices.argtypes = None
|
||||
bind_output_get_device_number = libc.VBVMR_Output_GetDeviceNumber
|
||||
bind_output_get_device_number.restype = LONG
|
||||
bind_output_get_device_number.argtypes = None
|
||||
|
||||
vm_get_desc_outdevices = libc.VBVMR_Output_GetDeviceDescW
|
||||
vm_get_desc_outdevices.restype = LONG
|
||||
vm_get_desc_outdevices.argtypes = [
|
||||
bind_output_get_device_desc_w = libc.VBVMR_Output_GetDeviceDescW
|
||||
bind_output_get_device_desc_w.restype = LONG
|
||||
bind_output_get_device_desc_w.argtypes = [
|
||||
LONG,
|
||||
ct.POINTER(LONG),
|
||||
ct.POINTER(WCHAR * 256),
|
||||
ct.POINTER(WCHAR * 256),
|
||||
]
|
||||
|
||||
vm_get_midi_message = libc.VBVMR_GetMidiMessage
|
||||
vm_get_midi_message.restype = LONG
|
||||
vm_get_midi_message.argtypes = [ct.POINTER(CHAR * 1024), LONG]
|
||||
bind_get_midi_message = libc.VBVMR_GetMidiMessage
|
||||
bind_get_midi_message.restype = LONG
|
||||
bind_get_midi_message.argtypes = [ct.POINTER(CHAR * 1024), LONG]
|
||||
|
||||
def call(self, func, *args, ok=(0,), ok_exp=None):
|
||||
try:
|
||||
|
@ -64,7 +64,7 @@ class Remote(CBindings):
|
||||
|
||||
def login(self) -> NoReturn:
|
||||
"""Login to the API, initialize dirty parameters"""
|
||||
self.gui.launched = self.call(self.vm_login, ok=(0, 1)) == 0
|
||||
self.gui.launched = self.call(self.bind_login, ok=(0, 1)) == 0
|
||||
if not self.gui.launched:
|
||||
self.logger.info(
|
||||
"Voicemeeter engine running but GUI not launched. Launching the GUI now."
|
||||
@ -82,21 +82,21 @@ class Remote(CBindings):
|
||||
value = KindId[kind_id.upper()].value + 3
|
||||
else:
|
||||
value = KindId[kind_id.upper()].value
|
||||
self.call(self.vm_runvm, value)
|
||||
self.call(self.bind_run_voicemeeter, value)
|
||||
time.sleep(1)
|
||||
|
||||
@property
|
||||
def type(self) -> str:
|
||||
"""Returns the type of Voicemeeter installation (basic, banana, potato)."""
|
||||
type_ = ct.c_long()
|
||||
self.call(self.vm_get_type, ct.byref(type_))
|
||||
self.call(self.bind_get_voicemeeter_type, ct.byref(type_))
|
||||
return KindId(type_.value).name.lower()
|
||||
|
||||
@property
|
||||
def version(self) -> str:
|
||||
"""Returns Voicemeeter's version as a string"""
|
||||
ver = ct.c_long()
|
||||
self.call(self.vm_get_version, ct.byref(ver))
|
||||
self.call(self.bind_get_voicemeeter_version, ct.byref(ver))
|
||||
return "{}.{}.{}.{}".format(
|
||||
(ver.value & 0xFF000000) >> 24,
|
||||
(ver.value & 0x00FF0000) >> 16,
|
||||
@ -107,13 +107,13 @@ class Remote(CBindings):
|
||||
@property
|
||||
def pdirty(self) -> bool:
|
||||
"""True iff UI parameters have been updated."""
|
||||
return self.call(self.vm_pdirty, ok=(0, 1)) == 1
|
||||
return self.call(self.bind_is_parameters_dirty, ok=(0, 1)) == 1
|
||||
|
||||
@property
|
||||
def mdirty(self) -> bool:
|
||||
"""True iff MB parameters have been updated."""
|
||||
try:
|
||||
return self.call(self.vm_mdirty, ok=(0, 1)) == 1
|
||||
return self.call(self.bind_macro_button_is_dirty, ok=(0, 1)) == 1
|
||||
except AttributeError as e:
|
||||
self.logger.exception(f"{type(e).__name__}: {e}")
|
||||
ERR_MSG = (
|
||||
@ -149,10 +149,10 @@ class Remote(CBindings):
|
||||
"""Gets a string or float parameter"""
|
||||
if is_string:
|
||||
buf = ct.create_unicode_buffer(512)
|
||||
self.call(self.vm_get_parameter_string, param.encode(), ct.byref(buf))
|
||||
self.call(self.bind_get_parameter_string_w, param.encode(), ct.byref(buf))
|
||||
else:
|
||||
buf = ct.c_float()
|
||||
self.call(self.vm_get_parameter_float, param.encode(), ct.byref(buf))
|
||||
self.call(self.bind_get_parameter_float, param.encode(), ct.byref(buf))
|
||||
return buf.value
|
||||
|
||||
def set(self, param: str, val: Union[str, float]) -> NoReturn:
|
||||
@ -160,22 +160,24 @@ class Remote(CBindings):
|
||||
if isinstance(val, str):
|
||||
if len(val) >= 512:
|
||||
raise VMError("String is too long")
|
||||
self.call(self.vm_set_parameter_string, param.encode(), ct.c_wchar_p(val))
|
||||
self.call(
|
||||
self.bind_set_parameter_string_w, param.encode(), ct.c_wchar_p(val)
|
||||
)
|
||||
else:
|
||||
self.call(
|
||||
self.vm_set_parameter_float, param.encode(), ct.c_float(float(val))
|
||||
self.bind_set_parameter_float, param.encode(), ct.c_float(float(val))
|
||||
)
|
||||
self.cache[param] = val
|
||||
|
||||
@polling
|
||||
def get_buttonstatus(self, id: int, mode: int) -> int:
|
||||
def get_buttonstatus(self, id_: int, mode: int) -> int:
|
||||
"""Gets a macrobutton parameter"""
|
||||
state = ct.c_float()
|
||||
c_state = ct.c_float()
|
||||
try:
|
||||
self.call(
|
||||
self.vm_get_buttonstatus,
|
||||
ct.c_long(id),
|
||||
ct.byref(state),
|
||||
self.bind_macro_button_get_status,
|
||||
ct.c_long(id_),
|
||||
ct.byref(c_state),
|
||||
ct.c_long(mode),
|
||||
)
|
||||
except AttributeError as e:
|
||||
@ -187,13 +189,18 @@ class Remote(CBindings):
|
||||
raise CAPIError(
|
||||
"VBVMR_MacroButton_GetStatus", -9, msg=" ".join(ERR_MSG)
|
||||
) from e
|
||||
return int(state.value)
|
||||
return int(c_state.value)
|
||||
|
||||
def set_buttonstatus(self, id: int, state: int, mode: int) -> NoReturn:
|
||||
def set_buttonstatus(self, id_: int, val: int, mode: int) -> NoReturn:
|
||||
"""Sets a macrobutton parameter. Caches value"""
|
||||
c_state = ct.c_float(float(state))
|
||||
c_state = ct.c_float(float(val))
|
||||
try:
|
||||
self.call(self.vm_set_buttonstatus, ct.c_long(id), c_state, ct.c_long(mode))
|
||||
self.call(
|
||||
self.bind_macro_button_set_status,
|
||||
ct.c_long(id_),
|
||||
c_state,
|
||||
ct.c_long(mode),
|
||||
)
|
||||
except AttributeError as e:
|
||||
self.logger.exception(f"{type(e).__name__}: {e}")
|
||||
ERR_MSG = (
|
||||
@ -203,7 +210,7 @@ class Remote(CBindings):
|
||||
raise CAPIError(
|
||||
"VBVMR_MacroButton_SetStatus", -9, msg=" ".join(ERR_MSG)
|
||||
) from e
|
||||
self.cache[f"mb_{id}_{mode}"] = int(c_state.value)
|
||||
self.cache[f"mb_{id_}_{mode}"] = int(c_state.value)
|
||||
|
||||
def get_num_devices(self, direction: str = None) -> int:
|
||||
"""Retrieves number of physical devices connected"""
|
||||
@ -220,7 +227,7 @@ class Remote(CBindings):
|
||||
type_ = ct.c_long()
|
||||
name = ct.create_unicode_buffer(256)
|
||||
hwid = ct.create_unicode_buffer(256)
|
||||
func = getattr(self, f"vm_get_desc_{direction}devices")
|
||||
func = getattr(self, f"bind_{direction}put_get_device_desc_w")
|
||||
self.call(
|
||||
func,
|
||||
ct.c_long(index),
|
||||
@ -233,7 +240,9 @@ class Remote(CBindings):
|
||||
def get_level(self, type_: int, index: int) -> float:
|
||||
"""Retrieves a single level value"""
|
||||
val = ct.c_float()
|
||||
self.call(self.vm_get_level, ct.c_long(type_), ct.c_long(index), ct.byref(val))
|
||||
self.call(
|
||||
self.bind_get_level, ct.c_long(type_), ct.c_long(index), ct.byref(val)
|
||||
)
|
||||
return val.value
|
||||
|
||||
def _get_levels(self) -> Iterable:
|
||||
@ -252,7 +261,7 @@ class Remote(CBindings):
|
||||
n = ct.c_long(1024)
|
||||
buf = ct.create_string_buffer(1024)
|
||||
res = self.call(
|
||||
self.vm_get_midi_message,
|
||||
self.bind_get_midi_message,
|
||||
ct.byref(buf),
|
||||
n,
|
||||
ok=(-5, -6), # no data received from midi device
|
||||
@ -275,7 +284,7 @@ class Remote(CBindings):
|
||||
"""Sets many parameters from a script"""
|
||||
if len(script) > 48000:
|
||||
raise ValueError("Script too large, max size 48kB")
|
||||
self.call(self.vm_set_parameter_multi, script.encode())
|
||||
self.call(self.bind_set_parameters, script.encode())
|
||||
time.sleep(self.DELAY * 5)
|
||||
|
||||
def apply(self, data: dict):
|
||||
@ -328,7 +337,7 @@ class Remote(CBindings):
|
||||
def logout(self) -> NoReturn:
|
||||
"""Logout of the API"""
|
||||
time.sleep(0.1)
|
||||
self.call(self.vm_logout)
|
||||
self.call(self.bind_logout)
|
||||
self.logger.info(f"{type(self).__name__}: Successfully logged out of {self}")
|
||||
|
||||
def __exit__(self, exc_type, exc_value, exc_traceback) -> NoReturn:
|
||||
|
Loading…
Reference in New Issue
Block a user