2024-07-06 09:03:13 +01:00
|
|
|
/**
|
|
|
|
* @file wrapper.c
|
|
|
|
* @author Onyx and Iris (code@onyxandiris.online)
|
|
|
|
* @brief Provides public functions that wrap the iVMR calls
|
2024-07-13 11:50:47 +01:00
|
|
|
* @version 0.10.0
|
2024-07-06 09:03:13 +01:00
|
|
|
* @date 2024-07-06
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2024
|
|
|
|
* https://github.com/onyx-and-iris/vmrcli/blob/main/LICENSE
|
|
|
|
*/
|
|
|
|
|
2024-06-25 04:34:28 +01:00
|
|
|
#include <windows.h>
|
2024-07-06 09:03:13 +01:00
|
|
|
#include "wrapper.h"
|
2024-06-26 16:44:28 +01:00
|
|
|
#include "log.h"
|
2024-06-28 03:21:38 +01:00
|
|
|
#include "util.h"
|
|
|
|
|
2024-06-29 03:05:51 +01:00
|
|
|
#define KIND_STR_LEN 64
|
2024-07-06 09:03:13 +01:00
|
|
|
#define VERSION_STR_LEN 32
|
2024-07-10 18:11:58 +01:00
|
|
|
#define LOGIN_TIMEOUT 2
|
2024-06-25 04:34:28 +01:00
|
|
|
|
2024-07-02 11:15:17 +01:00
|
|
|
/**
|
|
|
|
* @brief Logs into the API.
|
|
|
|
* Tests for valid connection for up to 2 seconds.
|
|
|
|
* If successful initializes the dirty parameters.
|
|
|
|
*
|
2024-07-06 09:03:13 +01:00
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @param kind The kind of Voicemeeter Gui to launch.
|
2024-07-13 11:45:30 +01:00
|
|
|
* @return long
|
|
|
|
* 0: OK (no error).
|
|
|
|
* -2: Login timed out.
|
2024-07-02 11:15:17 +01:00
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
long login(PT_VMR vmr, int kind)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-07-09 15:11:48 +01:00
|
|
|
long rep;
|
2024-06-27 02:51:27 +01:00
|
|
|
long v;
|
2024-06-25 04:34:28 +01:00
|
|
|
|
2024-07-04 12:19:04 +01:00
|
|
|
log_trace("VBVMR_Login()");
|
2024-06-27 10:06:22 +01:00
|
|
|
rep = vmr->VBVMR_Login();
|
2024-06-25 04:34:28 +01:00
|
|
|
if (rep == 1)
|
|
|
|
{
|
2024-06-27 10:06:22 +01:00
|
|
|
run_voicemeeter(vmr, kind);
|
2024-06-29 03:05:51 +01:00
|
|
|
char kind_s[KIND_STR_LEN];
|
2024-06-29 03:08:03 +01:00
|
|
|
log_info(
|
|
|
|
"Launching Voicemeeter %s GUI",
|
|
|
|
kind_as_string(kind_s, kind, KIND_STR_LEN));
|
2024-07-02 14:49:42 +01:00
|
|
|
}
|
2024-06-25 16:46:35 +01:00
|
|
|
|
2024-07-02 14:49:42 +01:00
|
|
|
time_t start = time(NULL);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if ((rep = version(vmr, &v)) == 0)
|
2024-06-27 02:51:27 +01:00
|
|
|
{
|
2024-07-02 14:49:42 +01:00
|
|
|
char version_s[VERSION_STR_LEN];
|
|
|
|
log_info(
|
|
|
|
"Successfully logged into the Voicemeeter API v%s",
|
|
|
|
version_as_string(version_s, v, VERSION_STR_LEN));
|
2024-07-13 11:45:30 +01:00
|
|
|
clear(vmr, is_pdirty);
|
2024-07-02 14:49:42 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
Sleep(50);
|
2024-07-10 18:11:58 +01:00
|
|
|
} while (difftime(time(NULL), start) < LOGIN_TIMEOUT);
|
2024-07-02 14:49:42 +01:00
|
|
|
|
2024-06-25 04:34:28 +01:00
|
|
|
return rep;
|
|
|
|
}
|
|
|
|
|
2024-07-02 11:15:17 +01:00
|
|
|
/**
|
|
|
|
* @brief Logs out of the API giving a short wait to allow a
|
|
|
|
* final instruction to complete.
|
|
|
|
*
|
2024-07-06 09:03:13 +01:00
|
|
|
* @param vmr Pointer to the iVMR interface
|
2024-07-13 11:45:30 +01:00
|
|
|
* @return long See:
|
|
|
|
* https://github.com/onyx-and-iris/vmrcli/blob/main/include/VoicemeeterRemote.h#L56
|
2024-07-02 11:15:17 +01:00
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
long logout(PT_VMR vmr)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
|
|
|
Sleep(20); /* give time for last command */
|
2024-07-04 12:19:04 +01:00
|
|
|
log_trace("VBVMR_Logout()");
|
2024-07-13 11:45:30 +01:00
|
|
|
return vmr->VBVMR_Logout();
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
2024-07-13 11:45:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Launches Voicemeeter or other utility apps
|
|
|
|
*
|
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @param kind The kind of app to launch
|
|
|
|
* @return long See:
|
|
|
|
* https://github.com/onyx-and-iris/vmrcli/blob/main/include/VoicemeeterRemote.h#L66
|
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
long run_voicemeeter(PT_VMR vmr, int kind)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-06-27 01:18:17 +01:00
|
|
|
log_trace("VBVMR_RunVoicemeeter(%d)", kind);
|
2024-06-27 10:06:22 +01:00
|
|
|
return vmr->VBVMR_RunVoicemeeter((long)kind);
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
2024-07-13 11:45:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Get Voicemeeter type
|
|
|
|
*
|
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @param type Pointer to a long object receiving the type
|
|
|
|
* @return long See:
|
|
|
|
* https://github.com/onyx-and-iris/vmrcli/blob/main/include/VoicemeeterRemote.h#L107
|
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
long type(PT_VMR vmr, long *type)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-06-27 03:23:48 +01:00
|
|
|
log_trace("VBVMR_GetVoicemeeterType(<long> *t)");
|
2024-06-27 10:06:22 +01:00
|
|
|
return vmr->VBVMR_GetVoicemeeterType(type);
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
2024-07-13 11:45:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Get Voicemeeter version
|
|
|
|
*
|
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @param version Pointer to a long object receiving the version
|
|
|
|
* @return long See:
|
|
|
|
* https://github.com/onyx-and-iris/vmrcli/blob/main/include/VoicemeeterRemote.h#L122
|
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
long version(PT_VMR vmr, long *version)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-06-27 03:23:48 +01:00
|
|
|
log_trace("VBVMR_GetVoicemeeterVersion(<long> *v)");
|
2024-06-27 10:06:22 +01:00
|
|
|
return vmr->VBVMR_GetVoicemeeterVersion(version);
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
2024-07-13 11:45:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Polling function, use it to determine if there are parameter
|
|
|
|
* states to be updated.
|
|
|
|
*
|
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @return true New parameters yet to be updated
|
|
|
|
* @return false No new parameters, safe to make a get call
|
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
bool is_pdirty(PT_VMR vmr)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-06-27 02:51:27 +01:00
|
|
|
log_trace("VBVMR_IsParametersDirty()");
|
2024-06-27 10:06:22 +01:00
|
|
|
return vmr->VBVMR_IsParametersDirty() == 1;
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
2024-07-13 11:45:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Get the parameter float object
|
|
|
|
*
|
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @param param The parameter to be queried
|
|
|
|
* @param f Pointer to a float object receiving the value
|
|
|
|
* @return long See:
|
|
|
|
* https://github.com/onyx-and-iris/vmrcli/blob/main/include/VoicemeeterRemote.h#L159
|
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
long get_parameter_float(PT_VMR vmr, char *param, float *f)
|
2024-06-25 23:32:32 +01:00
|
|
|
{
|
2024-06-28 01:23:40 +01:00
|
|
|
log_trace("VBVMR_GetParameterFloat(%s, <float> *f)", param);
|
2024-06-27 10:06:22 +01:00
|
|
|
return vmr->VBVMR_GetParameterFloat(param, f);
|
2024-06-25 23:32:32 +01:00
|
|
|
}
|
|
|
|
|
2024-07-13 11:45:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Get the parameter string object
|
|
|
|
*
|
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @param param The parameter to be queried
|
|
|
|
* @param s Pointer to a character buffer receiving the string value
|
|
|
|
* @return long See:
|
|
|
|
* https://github.com/onyx-and-iris/vmrcli/blob/main/include/VoicemeeterRemote.h#L173
|
|
|
|
*/
|
|
|
|
long get_parameter_string(PT_VMR vmr, char *param, wchar_t *s)
|
2024-06-25 23:32:32 +01:00
|
|
|
{
|
2024-07-13 11:45:30 +01:00
|
|
|
log_trace("VBVMR_GetParameterStringW(%s, <wchar_t> *s)", param);
|
2024-06-27 23:26:46 +01:00
|
|
|
return vmr->VBVMR_GetParameterStringW(param, s);
|
2024-06-25 23:32:32 +01:00
|
|
|
}
|
|
|
|
|
2024-07-13 11:45:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Set the parameter float object
|
|
|
|
*
|
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @param param The parameter to be updated
|
|
|
|
* @param val The new value
|
|
|
|
* @return long See:
|
|
|
|
* https://github.com/onyx-and-iris/vmrcli/blob/main/include/VoicemeeterRemote.h#L309
|
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
long set_parameter_float(PT_VMR vmr, char *param, float val)
|
2024-06-25 23:32:32 +01:00
|
|
|
{
|
2024-06-27 03:23:48 +01:00
|
|
|
log_trace("VBVMR_SetParameterFloat(%s, %.1f)", param, val);
|
2024-06-27 10:06:22 +01:00
|
|
|
return vmr->VBVMR_SetParameterFloat(param, val);
|
2024-06-25 23:32:32 +01:00
|
|
|
}
|
|
|
|
|
2024-07-13 11:45:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Set the parameter string object
|
|
|
|
*
|
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @param param The parameter to be updated
|
|
|
|
* @param s Pointer to a char[] object containing the new value
|
|
|
|
* @return long See:
|
|
|
|
* https://github.com/onyx-and-iris/vmrcli/blob/main/include/VoicemeeterRemote.h#L327
|
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
long set_parameter_string(PT_VMR vmr, char *param, char *s)
|
2024-06-25 23:32:32 +01:00
|
|
|
{
|
2024-06-27 01:18:17 +01:00
|
|
|
log_trace("VBVMR_SetParameterStringA(%s, %s)", param, s);
|
2024-06-27 10:06:22 +01:00
|
|
|
return vmr->VBVMR_SetParameterStringA(param, s);
|
2024-06-25 23:32:32 +01:00
|
|
|
}
|
|
|
|
|
2024-07-13 11:45:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Run a script possibly containing multiple instructions
|
|
|
|
*
|
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @param command Pointer to a char[] object containing the script
|
|
|
|
* @return long See:
|
|
|
|
* https://github.com/onyx-and-iris/vmrcli/blob/main/include/VoicemeeterRemote.h#L351
|
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
long set_parameters(PT_VMR vmr, char *command)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-06-27 01:18:17 +01:00
|
|
|
log_trace("VBVMR_SetParameters(%s)", command);
|
2024-06-27 10:06:22 +01:00
|
|
|
return vmr->VBVMR_SetParameters(command);
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
2024-07-13 11:45:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Polling function, use it to determine if there are macrobutton
|
|
|
|
* states to be updated.
|
|
|
|
*
|
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @return true Macrobutton states yet to be udpated
|
|
|
|
* @return false No new macrobutton states
|
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
bool is_mdirty(PT_VMR vmr)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-07-04 12:19:04 +01:00
|
|
|
log_trace("VBVMR_MacroButton_IsDirty()");
|
2024-07-13 11:45:30 +01:00
|
|
|
return vmr->VBVMR_MacroButton_IsDirty() >= 0;
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
2024-07-13 11:45:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Get the current status of macrobutton[n].{mode}
|
|
|
|
*
|
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @param n Index of the macrobutton
|
|
|
|
* @param val Pointer to a float object the current value will be stored in
|
|
|
|
* @param mode The mode (stateonly, state, trigger)
|
|
|
|
* @return long See:
|
|
|
|
* https://github.com/onyx-and-iris/vmrcli/blob/main/include/VoicemeeterRemote.h#L663
|
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
long macrobutton_getstatus(PT_VMR vmr, long n, float *val, long mode)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-07-04 12:19:04 +01:00
|
|
|
log_trace("VBVMR_MacroButton_GetStatus(%ld, <float> *v, %ld)", n, mode);
|
2024-06-27 10:06:22 +01:00
|
|
|
return vmr->VBVMR_MacroButton_GetStatus(n, val, mode);
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
2024-07-13 11:45:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Set the current status of macrobutton[n].{mode}
|
|
|
|
*
|
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @param n Index of the macrobutton
|
|
|
|
* @param val Value to be updated
|
|
|
|
* @param mode The mode (stateonly, state, trigger)
|
|
|
|
* @return long See:
|
|
|
|
* https://github.com/onyx-and-iris/vmrcli/blob/main/include/VoicemeeterRemote.h#L677
|
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
long macrobutton_setstatus(PT_VMR vmr, long n, float val, long mode)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-07-04 12:19:04 +01:00
|
|
|
log_trace("VBVMR_MacroButton_SetStatus(%ld, %d, %ld)", n, (int)val, mode);
|
2024-06-27 10:06:22 +01:00
|
|
|
return vmr->VBVMR_MacroButton_SetStatus(n, val, mode);
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
2024-07-13 11:45:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Continuously polls an is_{}dirty function until it clears.
|
|
|
|
*
|
|
|
|
* @param vmr Pointer to the iVMR interface
|
|
|
|
* @param f Pointer to a polling function
|
|
|
|
*/
|
|
|
|
void clear(PT_VMR vmr, bool (*f)(PT_VMR))
|
|
|
|
{
|
|
|
|
Sleep(30);
|
|
|
|
while (f(vmr))
|
|
|
|
Sleep(1);
|
|
|
|
}
|