Compare commits

..

No commits in common. "5640f54e657db0ed63019f8a2996499465dd44aa" and "32527e37bd5aea2cf9875898f3b3455f21757e5c" have entirely different histories.

6 changed files with 15 additions and 57 deletions

@ -11,20 +11,6 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
- [x]
## [2.2.0] - 2023-07-10
### Added
- CAPIError class now stores fn_name, error code and message as class attributes.
### Changed
- macrobutton capi calls now use error code -9 on AttributeError (using an old version of the API).
### Fixed
- call to `self.vm_get_midi_message` now wrapped by {CBindings}.call.
## [2.1.1] - 2023-07-01
### Added

@ -18,7 +18,6 @@ class App:
def __enter__(self):
self.vm.init_thread()
return self
def __exit__(self, exc_type, exc_value, traceback):
self.vm.end_thread()

@ -1,13 +1,15 @@
[tool.poetry]
name = "voicemeeter-api"
version = "2.2.1"
version = "2.1.3"
description = "A Python wrapper for the Voiceemeter API"
authors = ["onyx-and-iris <code@onyxandiris.online>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/onyx-and-iris/voicemeeter-api-python"
packages = [{ include = "voicemeeterlib" }]
packages = [
{ include = "voicemeeterlib" },
]
[tool.poetry.dependencies]
python = "^3.10"

@ -16,7 +16,7 @@ class CBindings(metaclass=ABCMeta):
Maps expected ctype argument and res types for each binding.
"""
logger_cbindings = logger.getChild("CBindings")
logger_cbindings = logger.getChild("Cbindings")
vm_login = libc.VBVMR_Login
vm_login.restype = LONG
@ -116,10 +116,10 @@ class CBindings(metaclass=ABCMeta):
res = func(*args)
if ok_exp is None:
if res not in ok:
raise CAPIError(func.__name__, res)
elif not ok_exp(res) and res not in ok:
raise CAPIError(func.__name__, res)
raise CAPIError(f"{func.__name__} returned {res}")
elif not ok_exp(res):
raise CAPIError(f"{func.__name__} returned {res}")
return res
except CAPIError as e:
self.logger_cbindings.exception(str(e))
self.logger_cbindings.exception(f"{type(e).__name__}: {e}")
raise

@ -5,15 +5,6 @@ class InstallError(Exception):
class CAPIError(Exception):
"""Exception raised when the C-API returns error values"""
def __init__(self, fn_name, code, msg=None):
self.fn_name = fn_name
self.code = code
self.message = msg if msg else f"{fn_name} returned {code}"
super().__init__(self.message)
def __str__(self):
return f"{type(self).__name__}: {self.message}"
class VMError(Exception):
"""Exception raised when general errors occur"""

@ -116,12 +116,8 @@ class Remote(CBindings):
return self.call(self.vm_mdirty, ok=(0, 1)) == 1
except AttributeError as e:
self.logger.exception(f"{type(e).__name__}: {e}")
ERR_MSG = (
"no bind for VBVMR_MacroButton_IsDirty.",
"are you using an old version of the API?",
)
raise CAPIError(
"VBVMR_MacroButton_IsDirty", -9, msg=" ".join(ERR_MSG)
"no bind for VBVMR_MacroButton_IsDirty. are you using an old version of the API?"
) from e
@property
@ -137,10 +133,8 @@ class Remote(CBindings):
try:
while self.pdirty or self.mdirty:
pass
except CAPIError as e:
if not (e.fn_name == "VBVMR_MacroButton_IsDirty" and e.code == -9):
raise
self.logger.error(f"{e} clearing pdirty only.")
except CAPIError:
self.logger.error("no bind for mdirty, clearing pdirty only")
while self.pdirty:
pass
@ -180,12 +174,8 @@ class Remote(CBindings):
)
except AttributeError as e:
self.logger.exception(f"{type(e).__name__}: {e}")
ERR_MSG = (
"no bind for VBVMR_MacroButton_GetStatus.",
"are you using an old version of the API?",
)
raise CAPIError(
"VBVMR_MacroButton_GetStatus", -9, msg=" ".join(ERR_MSG)
"no bind for VBVMR_MacroButton_GetStatus. are you using an old version of the API?"
) from e
return int(state.value)
@ -196,12 +186,8 @@ class Remote(CBindings):
self.call(self.vm_set_buttonstatus, ct.c_long(id), c_state, ct.c_long(mode))
except AttributeError as e:
self.logger.exception(f"{type(e).__name__}: {e}")
ERR_MSG = (
"no bind for VBVMR_MacroButton_SetStatus.",
"are you using an old version of the API?",
)
raise CAPIError(
"VBVMR_MacroButton_SetStatus", -9, msg=" ".join(ERR_MSG)
"no bind for VBVMR_MacroButton_SetStatus. are you using an old version of the API?"
) from e
self.cache[f"mb_{id}_{mode}"] = int(c_state.value)
@ -254,13 +240,7 @@ class Remote(CBindings):
def get_midi_message(self):
n = ct.c_long(1024)
buf = ct.create_string_buffer(1024)
res = self.call(
self.vm_get_midi_message,
ct.byref(buf),
n,
ok=(-5, -6), # no data received from midi device
ok_exp=lambda r: r >= 0,
)
res = self.vm_get_midi_message(ct.byref(buf), n, ok_exp=lambda r: r >= 0)
if res > 0:
vals = tuple(
grouper(3, (int.from_bytes(buf[i], "little") for i in range(res)))