From 83a85fd7c59cd345e34d8a6f71383e9bcdebc170 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 4 Jul 2024 09:14:14 +0100 Subject: [PATCH] add new typedef struct *PT_VMR use it to pass around references to the iVMR instance --- include/VoicemeeterRemote.h | 2 +- include/cdll.h | 2 +- include/vmr.h | 30 ++++++------ src/cdll.c | 92 ++++++++++++++++++------------------- src/vmr.c | 30 ++++++------ src/vmrcli.c | 28 +++++------ 6 files changed, 92 insertions(+), 92 deletions(-) diff --git a/include/VoicemeeterRemote.h b/include/VoicemeeterRemote.h index e628143..d8103e5 100644 --- a/include/VoicemeeterRemote.h +++ b/include/VoicemeeterRemote.h @@ -763,7 +763,7 @@ extern "C" T_VBVMR_MacroButton_GetStatus VBVMR_MacroButton_GetStatus; T_VBVMR_MacroButton_SetStatus VBVMR_MacroButton_SetStatus; - } T_VBVMR_INTERFACE, *PT_VBVMR_INTERFACE, *LPT_VBVMR_INTERFACE; + } T_VBVMR_INTERFACE, *PT_VBVMR_INTERFACE, *LPT_VBVMR_INTERFACE, *PT_VMR; #ifdef VBUSE_LOCALLIB // internal used (not public) diff --git a/include/cdll.h b/include/cdll.h index 5464304..dd7ccf3 100644 --- a/include/cdll.h +++ b/include/cdll.h @@ -3,6 +3,6 @@ #include "VoicemeeterRemote.h" -long initialize_dll_interfaces(T_VBVMR_INTERFACE *iVMR); +long initialize_dll_interfaces(PT_VMR vmr); #endif /*__CDLL_H__*/ \ No newline at end of file diff --git a/include/vmr.h b/include/vmr.h index 111c502..94cc6d2 100644 --- a/include/vmr.h +++ b/include/vmr.h @@ -17,23 +17,23 @@ enum kind STREAMERVIEW }; -long login(T_VBVMR_INTERFACE *vmr, int kind); -long logout(T_VBVMR_INTERFACE *vmr); -long run_voicemeeter(T_VBVMR_INTERFACE *vmr, int kind); -long type(T_VBVMR_INTERFACE *vmr, long *type); -long version(T_VBVMR_INTERFACE *vmr, long *version); +long login(PT_VMR vmr, int kind); +long logout(PT_VMR vmr); +long run_voicemeeter(PT_VMR vmr, int kind); +long type(PT_VMR vmr, long *type); +long version(PT_VMR vmr, long *version); -bool is_pdirty(T_VBVMR_INTERFACE *vmr); -long get_parameter_float(T_VBVMR_INTERFACE *vmr, char *param, float *f); -long get_parameter_string(T_VBVMR_INTERFACE *vmr, char *param, unsigned short *s); -long set_parameter_float(T_VBVMR_INTERFACE *vmr, char *param, float val); -long set_parameter_string(T_VBVMR_INTERFACE *vmr, char *param, char *s); -long set_parameters(T_VBVMR_INTERFACE *vmr, char *command); +bool is_pdirty(PT_VMR vmr); +long get_parameter_float(PT_VMR vmr, char *param, float *f); +long get_parameter_string(PT_VMR vmr, char *param, unsigned short *s); +long set_parameter_float(PT_VMR vmr, char *param, float val); +long set_parameter_string(PT_VMR vmr, char *param, char *s); +long set_parameters(PT_VMR vmr, char *command); -bool is_mdirty(T_VBVMR_INTERFACE *vmr); -long macrobutton_getstatus(T_VBVMR_INTERFACE *vmr, long n, float *val, long mode); -long macrobutton_setstatus(T_VBVMR_INTERFACE *vmr, long n, float val, long mode); +bool is_mdirty(PT_VMR vmr); +long macrobutton_getstatus(PT_VMR vmr, long n, float *val, long mode); +long macrobutton_setstatus(PT_VMR vmr, long n, float val, long mode); -void clear_dirty(T_VBVMR_INTERFACE *vmr); +void clear_dirty(PT_VMR vmr); #endif /* __VMR_H__ */ \ No newline at end of file diff --git a/src/cdll.c b/src/cdll.c index c8bd483..b9d6aa8 100644 --- a/src/cdll.c +++ b/src/cdll.c @@ -59,11 +59,11 @@ bool __cdecl registry_get_voicemeeter_folder(char *szDir) /*******************************************************************************/ /** GET DLL INTERFACE **/ /*******************************************************************************/ -long initialize_dll_interfaces(T_VBVMR_INTERFACE *iVMR) +long initialize_dll_interfaces(PT_VMR vmr) { HMODULE G_H_Module = NULL; char szDllName[1024]; - memset(iVMR, 0, sizeof(T_VBVMR_INTERFACE)); + memset(vmr, 0, sizeof(T_VBVMR_INTERFACE)); // get Voicemeeter installation directory if (!registry_get_voicemeeter_folder(szDllName)) @@ -83,77 +83,77 @@ long initialize_dll_interfaces(T_VBVMR_INTERFACE *iVMR) return -101; // Get function pointers - iVMR->VBVMR_Login = (T_VBVMR_Login)GetProcAddress(G_H_Module, "VBVMR_Login"); - iVMR->VBVMR_Logout = (T_VBVMR_Logout)GetProcAddress(G_H_Module, "VBVMR_Logout"); - iVMR->VBVMR_RunVoicemeeter = (T_VBVMR_RunVoicemeeter)GetProcAddress(G_H_Module, "VBVMR_RunVoicemeeter"); - iVMR->VBVMR_GetVoicemeeterType = (T_VBVMR_GetVoicemeeterType)GetProcAddress(G_H_Module, "VBVMR_GetVoicemeeterType"); - iVMR->VBVMR_GetVoicemeeterVersion = (T_VBVMR_GetVoicemeeterVersion)GetProcAddress(G_H_Module, "VBVMR_GetVoicemeeterVersion"); + vmr->VBVMR_Login = (T_VBVMR_Login)GetProcAddress(G_H_Module, "VBVMR_Login"); + vmr->VBVMR_Logout = (T_VBVMR_Logout)GetProcAddress(G_H_Module, "VBVMR_Logout"); + vmr->VBVMR_RunVoicemeeter = (T_VBVMR_RunVoicemeeter)GetProcAddress(G_H_Module, "VBVMR_RunVoicemeeter"); + vmr->VBVMR_GetVoicemeeterType = (T_VBVMR_GetVoicemeeterType)GetProcAddress(G_H_Module, "VBVMR_GetVoicemeeterType"); + vmr->VBVMR_GetVoicemeeterVersion = (T_VBVMR_GetVoicemeeterVersion)GetProcAddress(G_H_Module, "VBVMR_GetVoicemeeterVersion"); - iVMR->VBVMR_IsParametersDirty = (T_VBVMR_IsParametersDirty)GetProcAddress(G_H_Module, "VBVMR_IsParametersDirty"); - iVMR->VBVMR_GetParameterFloat = (T_VBVMR_GetParameterFloat)GetProcAddress(G_H_Module, "VBVMR_GetParameterFloat"); - iVMR->VBVMR_GetParameterStringA = (T_VBVMR_GetParameterStringA)GetProcAddress(G_H_Module, "VBVMR_GetParameterStringA"); - iVMR->VBVMR_GetParameterStringW = (T_VBVMR_GetParameterStringW)GetProcAddress(G_H_Module, "VBVMR_GetParameterStringW"); - iVMR->VBVMR_GetLevel = (T_VBVMR_GetLevel)GetProcAddress(G_H_Module, "VBVMR_GetLevel"); - iVMR->VBVMR_GetMidiMessage = (T_VBVMR_GetMidiMessage)GetProcAddress(G_H_Module, "VBVMR_GetMidiMessage"); + vmr->VBVMR_IsParametersDirty = (T_VBVMR_IsParametersDirty)GetProcAddress(G_H_Module, "VBVMR_IsParametersDirty"); + vmr->VBVMR_GetParameterFloat = (T_VBVMR_GetParameterFloat)GetProcAddress(G_H_Module, "VBVMR_GetParameterFloat"); + vmr->VBVMR_GetParameterStringA = (T_VBVMR_GetParameterStringA)GetProcAddress(G_H_Module, "VBVMR_GetParameterStringA"); + vmr->VBVMR_GetParameterStringW = (T_VBVMR_GetParameterStringW)GetProcAddress(G_H_Module, "VBVMR_GetParameterStringW"); + vmr->VBVMR_GetLevel = (T_VBVMR_GetLevel)GetProcAddress(G_H_Module, "VBVMR_GetLevel"); + vmr->VBVMR_GetMidiMessage = (T_VBVMR_GetMidiMessage)GetProcAddress(G_H_Module, "VBVMR_GetMidiMessage"); - iVMR->VBVMR_SetParameterFloat = (T_VBVMR_SetParameterFloat)GetProcAddress(G_H_Module, "VBVMR_SetParameterFloat"); - iVMR->VBVMR_SetParameters = (T_VBVMR_SetParameters)GetProcAddress(G_H_Module, "VBVMR_SetParameters"); - iVMR->VBVMR_SetParametersW = (T_VBVMR_SetParametersW)GetProcAddress(G_H_Module, "VBVMR_SetParametersW"); - iVMR->VBVMR_SetParameterStringA = (T_VBVMR_SetParameterStringA)GetProcAddress(G_H_Module, "VBVMR_SetParameterStringA"); - iVMR->VBVMR_SetParameterStringW = (T_VBVMR_SetParameterStringW)GetProcAddress(G_H_Module, "VBVMR_SetParameterStringW"); + vmr->VBVMR_SetParameterFloat = (T_VBVMR_SetParameterFloat)GetProcAddress(G_H_Module, "VBVMR_SetParameterFloat"); + vmr->VBVMR_SetParameters = (T_VBVMR_SetParameters)GetProcAddress(G_H_Module, "VBVMR_SetParameters"); + vmr->VBVMR_SetParametersW = (T_VBVMR_SetParametersW)GetProcAddress(G_H_Module, "VBVMR_SetParametersW"); + vmr->VBVMR_SetParameterStringA = (T_VBVMR_SetParameterStringA)GetProcAddress(G_H_Module, "VBVMR_SetParameterStringA"); + vmr->VBVMR_SetParameterStringW = (T_VBVMR_SetParameterStringW)GetProcAddress(G_H_Module, "VBVMR_SetParameterStringW"); - iVMR->VBVMR_Output_GetDeviceNumber = (T_VBVMR_Output_GetDeviceNumber)GetProcAddress(G_H_Module, "VBVMR_Output_GetDeviceNumber"); - iVMR->VBVMR_Output_GetDeviceDescA = (T_VBVMR_Output_GetDeviceDescA)GetProcAddress(G_H_Module, "VBVMR_Output_GetDeviceDescA"); - iVMR->VBVMR_Output_GetDeviceDescW = (T_VBVMR_Output_GetDeviceDescW)GetProcAddress(G_H_Module, "VBVMR_Output_GetDeviceDescW"); - iVMR->VBVMR_Input_GetDeviceNumber = (T_VBVMR_Input_GetDeviceNumber)GetProcAddress(G_H_Module, "VBVMR_Input_GetDeviceNumber"); - iVMR->VBVMR_Input_GetDeviceDescA = (T_VBVMR_Input_GetDeviceDescA)GetProcAddress(G_H_Module, "VBVMR_Input_GetDeviceDescA"); - iVMR->VBVMR_Input_GetDeviceDescW = (T_VBVMR_Input_GetDeviceDescW)GetProcAddress(G_H_Module, "VBVMR_Input_GetDeviceDescW"); + vmr->VBVMR_Output_GetDeviceNumber = (T_VBVMR_Output_GetDeviceNumber)GetProcAddress(G_H_Module, "VBVMR_Output_GetDeviceNumber"); + vmr->VBVMR_Output_GetDeviceDescA = (T_VBVMR_Output_GetDeviceDescA)GetProcAddress(G_H_Module, "VBVMR_Output_GetDeviceDescA"); + vmr->VBVMR_Output_GetDeviceDescW = (T_VBVMR_Output_GetDeviceDescW)GetProcAddress(G_H_Module, "VBVMR_Output_GetDeviceDescW"); + vmr->VBVMR_Input_GetDeviceNumber = (T_VBVMR_Input_GetDeviceNumber)GetProcAddress(G_H_Module, "VBVMR_Input_GetDeviceNumber"); + vmr->VBVMR_Input_GetDeviceDescA = (T_VBVMR_Input_GetDeviceDescA)GetProcAddress(G_H_Module, "VBVMR_Input_GetDeviceDescA"); + vmr->VBVMR_Input_GetDeviceDescW = (T_VBVMR_Input_GetDeviceDescW)GetProcAddress(G_H_Module, "VBVMR_Input_GetDeviceDescW"); // check pointers are valid - if (iVMR->VBVMR_Login == NULL) + if (vmr->VBVMR_Login == NULL) return -1; - if (iVMR->VBVMR_Logout == NULL) + if (vmr->VBVMR_Logout == NULL) return -2; - if (iVMR->VBVMR_RunVoicemeeter == NULL) + if (vmr->VBVMR_RunVoicemeeter == NULL) return -2; - if (iVMR->VBVMR_GetVoicemeeterType == NULL) + if (vmr->VBVMR_GetVoicemeeterType == NULL) return -3; - if (iVMR->VBVMR_GetVoicemeeterVersion == NULL) + if (vmr->VBVMR_GetVoicemeeterVersion == NULL) return -4; - if (iVMR->VBVMR_IsParametersDirty == NULL) + if (vmr->VBVMR_IsParametersDirty == NULL) return -5; - if (iVMR->VBVMR_GetParameterFloat == NULL) + if (vmr->VBVMR_GetParameterFloat == NULL) return -6; - if (iVMR->VBVMR_GetParameterStringA == NULL) + if (vmr->VBVMR_GetParameterStringA == NULL) return -7; - if (iVMR->VBVMR_GetParameterStringW == NULL) + if (vmr->VBVMR_GetParameterStringW == NULL) return -8; - if (iVMR->VBVMR_GetLevel == NULL) + if (vmr->VBVMR_GetLevel == NULL) return -9; - if (iVMR->VBVMR_SetParameterFloat == NULL) + if (vmr->VBVMR_SetParameterFloat == NULL) return -10; - if (iVMR->VBVMR_SetParameters == NULL) + if (vmr->VBVMR_SetParameters == NULL) return -11; - if (iVMR->VBVMR_SetParametersW == NULL) + if (vmr->VBVMR_SetParametersW == NULL) return -12; - if (iVMR->VBVMR_SetParameterStringA == NULL) + if (vmr->VBVMR_SetParameterStringA == NULL) return -13; - if (iVMR->VBVMR_SetParameterStringW == NULL) + if (vmr->VBVMR_SetParameterStringW == NULL) return -14; - if (iVMR->VBVMR_GetMidiMessage == NULL) + if (vmr->VBVMR_GetMidiMessage == NULL) return -15; - if (iVMR->VBVMR_Output_GetDeviceNumber == NULL) + if (vmr->VBVMR_Output_GetDeviceNumber == NULL) return -30; - if (iVMR->VBVMR_Output_GetDeviceDescA == NULL) + if (vmr->VBVMR_Output_GetDeviceDescA == NULL) return -31; - if (iVMR->VBVMR_Output_GetDeviceDescW == NULL) + if (vmr->VBVMR_Output_GetDeviceDescW == NULL) return -32; - if (iVMR->VBVMR_Input_GetDeviceNumber == NULL) + if (vmr->VBVMR_Input_GetDeviceNumber == NULL) return -33; - if (iVMR->VBVMR_Input_GetDeviceDescA == NULL) + if (vmr->VBVMR_Input_GetDeviceDescA == NULL) return -34; - if (iVMR->VBVMR_Input_GetDeviceDescW == NULL) + if (vmr->VBVMR_Input_GetDeviceDescW == NULL) return -35; return 0; diff --git a/src/vmr.c b/src/vmr.c index 85f28d8..c021ee1 100644 --- a/src/vmr.c +++ b/src/vmr.c @@ -17,7 +17,7 @@ * @param kind * @return long */ -long login(T_VBVMR_INTERFACE *vmr, int kind) +long login(PT_VMR vmr, int kind) { int rep; long v; @@ -61,7 +61,7 @@ long login(T_VBVMR_INTERFACE *vmr, int kind) * @param vmr The API interface as a struct * @return long VBVMR_Logout return value */ -long logout(T_VBVMR_INTERFACE *vmr) +long logout(PT_VMR vmr) { int rep; @@ -72,76 +72,76 @@ long logout(T_VBVMR_INTERFACE *vmr) return rep; } -long run_voicemeeter(T_VBVMR_INTERFACE *vmr, int kind) +long run_voicemeeter(PT_VMR vmr, int kind) { log_trace("VBVMR_RunVoicemeeter(%d)", kind); return vmr->VBVMR_RunVoicemeeter((long)kind); } -long type(T_VBVMR_INTERFACE *vmr, long *type) +long type(PT_VMR vmr, long *type) { log_trace("VBVMR_GetVoicemeeterType( *t)"); return vmr->VBVMR_GetVoicemeeterType(type); } -long version(T_VBVMR_INTERFACE *vmr, long *version) +long version(PT_VMR vmr, long *version) { log_trace("VBVMR_GetVoicemeeterVersion( *v)"); return vmr->VBVMR_GetVoicemeeterVersion(version); } -bool is_pdirty(T_VBVMR_INTERFACE *vmr) +bool is_pdirty(PT_VMR vmr) { log_trace("VBVMR_IsParametersDirty()"); return vmr->VBVMR_IsParametersDirty() == 1; } -long get_parameter_float(T_VBVMR_INTERFACE *vmr, char *param, float *f) +long get_parameter_float(PT_VMR vmr, char *param, float *f) { log_trace("VBVMR_GetParameterFloat(%s, *f)", param); return vmr->VBVMR_GetParameterFloat(param, f); } -long get_parameter_string(T_VBVMR_INTERFACE *vmr, char *param, unsigned short *s) +long get_parameter_string(PT_VMR vmr, char *param, unsigned short *s) { log_trace("VBVMR_GetParameterStringW(%s, *s)", param); return vmr->VBVMR_GetParameterStringW(param, s); } -long set_parameter_float(T_VBVMR_INTERFACE *vmr, char *param, float val) +long set_parameter_float(PT_VMR vmr, char *param, float val) { log_trace("VBVMR_SetParameterFloat(%s, %.1f)", param, val); return vmr->VBVMR_SetParameterFloat(param, val); } -long set_parameter_string(T_VBVMR_INTERFACE *vmr, char *param, char *s) +long set_parameter_string(PT_VMR vmr, char *param, char *s) { log_trace("VBVMR_SetParameterStringA(%s, %s)", param, s); return vmr->VBVMR_SetParameterStringA(param, s); } -long set_parameters(T_VBVMR_INTERFACE *vmr, char *command) +long set_parameters(PT_VMR vmr, char *command) { log_trace("VBVMR_SetParameters(%s)", command); return vmr->VBVMR_SetParameters(command); } -bool is_mdirty(T_VBVMR_INTERFACE *vmr) +bool is_mdirty(PT_VMR vmr) { return vmr->VBVMR_MacroButton_IsDirty() == 1; } -long macrobutton_getstatus(T_VBVMR_INTERFACE *vmr, long n, float *val, long mode) +long macrobutton_getstatus(PT_VMR vmr, long n, float *val, long mode) { return vmr->VBVMR_MacroButton_GetStatus(n, val, mode); } -long macrobutton_setstatus(T_VBVMR_INTERFACE *vmr, long n, float val, long mode) +long macrobutton_setstatus(PT_VMR vmr, long n, float val, long mode) { return vmr->VBVMR_MacroButton_SetStatus(n, val, mode); } -void clear_dirty(T_VBVMR_INTERFACE *vmr) +void clear_dirty(PT_VMR vmr) { Sleep(30); while (is_pdirty(vmr)) diff --git a/src/vmrcli.c b/src/vmrcli.c index c42e586..8e6715a 100644 --- a/src/vmrcli.c +++ b/src/vmrcli.c @@ -36,15 +36,16 @@ struct result } val; }; +static T_VBVMR_INTERFACE iVMR; +bool vflag = false; + void help(void); enum kind set_kind(char *kval); -int init_voicemeeter(T_VBVMR_INTERFACE *vmr, enum kind kind); -void interactive(T_VBVMR_INTERFACE *vmr); -void parse_input(T_VBVMR_INTERFACE *vmr, char *input, int len); -void parse_command(T_VBVMR_INTERFACE *vmr, char *command); -void get(T_VBVMR_INTERFACE *vmr, char *command, struct result *res); - -bool vflag = false; +int init_voicemeeter(PT_VMR vmr, enum kind kind); +void interactive(PT_VMR vmr); +void parse_input(PT_VMR vmr, char *input, int len); +void parse_command(PT_VMR vmr, char *command); +void get(PT_VMR vmr, char *command, struct result *res); int main(int argc, char *argv[]) { @@ -108,8 +109,7 @@ int main(int argc, char *argv[]) } } - T_VBVMR_INTERFACE iVMR; - T_VBVMR_INTERFACE *vmr = &iVMR; + PT_VMR vmr = &iVMR; int rep = init_voicemeeter(vmr, kind); if (rep != 0) @@ -210,7 +210,7 @@ enum kind set_kind(char *kval) * @param kind * @return int */ -int init_voicemeeter(T_VBVMR_INTERFACE *vmr, enum kind kind) +int init_voicemeeter(PT_VMR vmr, enum kind kind) { int rep = initialize_dll_interfaces(vmr); if (rep < 0) @@ -243,7 +243,7 @@ int init_voicemeeter(T_VBVMR_INTERFACE *vmr, enum kind kind) * * @param vmr The API interface as a struct */ -void interactive(T_VBVMR_INTERFACE *vmr) +void interactive(PT_VMR vmr) { char input[MAX_LINE]; size_t len; @@ -271,7 +271,7 @@ void interactive(T_VBVMR_INTERFACE *vmr) * @param input Each input line, from stdin or CLI args * @param len The length of the input line */ -void parse_input(T_VBVMR_INTERFACE *vmr, char *input, int len) +void parse_input(PT_VMR vmr, char *input, int len) { char *token; @@ -292,7 +292,7 @@ void parse_input(T_VBVMR_INTERFACE *vmr, char *input, int len) * @param vmr The API interface as a struct * @param command Each token from the input line as its own command string */ -void parse_command(T_VBVMR_INTERFACE *vmr, char *command) +void parse_command(PT_VMR vmr, char *command) { log_debug("Parsing %s", command); @@ -352,7 +352,7 @@ void parse_command(T_VBVMR_INTERFACE *vmr, char *command) * @param command A parsed 'get' command as a string * @param res A struct holding the result of the API call. */ -void get(T_VBVMR_INTERFACE *vmr, char *command, struct result *res) +void get(PT_VMR vmr, char *command, struct result *res) { clear_dirty(vmr); if (get_parameter_float(vmr, command, &res->val.f) != 0)