vmrcli/src/vmr.c

154 lines
3.7 KiB
C
Raw Normal View History

2024-06-25 04:34:28 +01:00
#include <windows.h>
#include <stdio.h>
#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"
#include "util.h"
#define VERSION_STR_LEN 128
#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
*/
long login(PT_VMR vmr, int kind)
2024-06-25 04:34:28 +01:00
{
int rep;
long v;
2024-06-25 04:34:28 +01:00
log_trace("VBVMR_Login()");
rep = vmr->VBVMR_Login();
2024-06-25 04:34:28 +01:00
if (rep == 1)
{
run_voicemeeter(vmr, kind);
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-07-02 14:49:42 +01:00
int timeout = 2;
time_t start = time(NULL);
do
{
if ((rep = version(vmr, &v)) == 0)
{
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);
if (rep == 0)
{
clear_dirty(vmr);
}
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
*/
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 */
log_trace("VBVMR_Logout()");
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
}
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);
return vmr->VBVMR_RunVoicemeeter((long)kind);
2024-06-25 04:34:28 +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)");
return vmr->VBVMR_GetVoicemeeterType(type);
2024-06-25 04:34:28 +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)");
return vmr->VBVMR_GetVoicemeeterVersion(version);
2024-06-25 04:34:28 +01:00
}
bool is_pdirty(PT_VMR vmr)
2024-06-25 04:34:28 +01:00
{
log_trace("VBVMR_IsParametersDirty()");
return vmr->VBVMR_IsParametersDirty() == 1;
2024-06-25 04:34:28 +01:00
}
long get_parameter_float(PT_VMR vmr, char *param, float *f)
2024-06-25 23:32:32 +01:00
{
log_trace("VBVMR_GetParameterFloat(%s, <float> *f)", param);
return vmr->VBVMR_GetParameterFloat(param, f);
2024-06-25 23:32:32 +01:00
}
long get_parameter_string(PT_VMR vmr, char *param, unsigned short *s)
2024-06-25 23:32:32 +01:00
{
log_trace("VBVMR_GetParameterStringW(%s, <unsigned short> *s)", param);
return vmr->VBVMR_GetParameterStringW(param, s);
2024-06-25 23:32:32 +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);
return vmr->VBVMR_SetParameterFloat(param, val);
2024-06-25 23:32:32 +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);
return vmr->VBVMR_SetParameterStringA(param, s);
2024-06-25 23:32:32 +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);
return vmr->VBVMR_SetParameters(command);
2024-06-25 04:34:28 +01:00
}
bool is_mdirty(PT_VMR vmr)
2024-06-25 04:34:28 +01:00
{
log_trace("VBVMR_MacroButton_IsDirty()");
return vmr->VBVMR_MacroButton_IsDirty() == 1;
2024-06-25 04:34:28 +01:00
}
long macrobutton_getstatus(PT_VMR vmr, long n, float *val, long mode)
2024-06-25 04:34:28 +01:00
{
log_trace("VBVMR_MacroButton_GetStatus(%ld, <float> *v, %ld)", n, mode);
return vmr->VBVMR_MacroButton_GetStatus(n, val, mode);
2024-06-25 04:34:28 +01:00
}
long macrobutton_setstatus(PT_VMR vmr, long n, float val, long mode)
2024-06-25 04:34:28 +01:00
{
log_trace("VBVMR_MacroButton_SetStatus(%ld, %d, %ld)", n, (int)val, mode);
return vmr->VBVMR_MacroButton_SetStatus(n, val, mode);
2024-06-25 04:34:28 +01:00
}
void clear_dirty(PT_VMR vmr)
2024-06-25 04:34:28 +01:00
{
Sleep(30);
while (is_pdirty(vmr))
2024-06-25 04:34:28 +01:00
Sleep(1);
}