2024-06-25 04:34:28 +01:00
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
2024-06-27 02:51:27 +01:00
|
|
|
#include <time.h>
|
2024-06-25 04:34:28 +01:00
|
|
|
#include "vmr.h"
|
2024-06-26 16:44:28 +01:00
|
|
|
#include "log.h"
|
2024-06-28 03:21:38 +01:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#define VERSION_STR_LEN 128
|
2024-06-29 03:05:51 +01:00
|
|
|
#define KIND_STR_LEN 64
|
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.
|
|
|
|
*
|
|
|
|
* @param vmr
|
|
|
|
* @param kind
|
|
|
|
* @return long
|
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
long login(PT_VMR vmr, int kind)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
|
|
|
int 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
|
|
|
int timeout = 2;
|
|
|
|
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));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Sleep(50);
|
|
|
|
} while (time(NULL) < start + timeout);
|
|
|
|
|
2024-06-25 16:46:35 +01:00
|
|
|
if (rep == 0)
|
|
|
|
{
|
2024-06-27 10:06:22 +01:00
|
|
|
clear_dirty(vmr);
|
2024-06-25 16:46:35 +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.
|
|
|
|
*
|
|
|
|
* @param vmr The API interface as a struct
|
|
|
|
* @return long VBVMR_Logout return value
|
|
|
|
*/
|
2024-07-04 09:14:14 +01:00
|
|
|
long logout(PT_VMR vmr)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-06-26 16:44:28 +01:00
|
|
|
int rep;
|
|
|
|
|
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-06-27 10:06:22 +01:00
|
|
|
rep = vmr->VBVMR_Logout();
|
2024-06-26 16:44:28 +01:00
|
|
|
if (rep == 0)
|
|
|
|
log_info("Successfully logged out of the Voicemeeter API");
|
|
|
|
return rep;
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
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-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-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-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-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-04 09:14:14 +01:00
|
|
|
long get_parameter_string(PT_VMR vmr, char *param, unsigned short *s)
|
2024-06-25 23:32:32 +01:00
|
|
|
{
|
2024-06-28 01:23:40 +01:00
|
|
|
log_trace("VBVMR_GetParameterStringW(%s, <unsigned short> *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-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-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-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-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-06-27 10:06:22 +01:00
|
|
|
return vmr->VBVMR_MacroButton_IsDirty() == 1;
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
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-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-04 09:14:14 +01:00
|
|
|
void clear_dirty(PT_VMR vmr)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
|
|
|
Sleep(30);
|
2024-06-27 10:06:22 +01:00
|
|
|
while (is_pdirty(vmr))
|
2024-06-25 04:34:28 +01:00
|
|
|
Sleep(1);
|
|
|
|
}
|