vmrcli/src/vmr.c

143 lines
3.6 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"
2024-06-25 04:34:28 +01:00
long login(T_VBVMR_INTERFACE *iVMR, int kind)
2024-06-25 04:34:28 +01:00
{
int rep;
long v;
2024-06-25 04:34:28 +01:00
rep = iVMR->VBVMR_Login();
if (rep == 1)
{
run_voicemeeter(iVMR, kind);
switch (kind)
{
case BASIC:
2024-06-26 16:44:28 +01:00
log_info("Launching Voicemeeter Basic GUI");
break;
case BANANA:
2024-06-26 16:44:28 +01:00
log_info("Launching Voicemeeter Banana GUI");
break;
case POTATO:
2024-06-26 16:44:28 +01:00
log_info("Launching Voicemeeter Potato GUI");
break;
case POTATOX64:
2024-06-26 16:44:28 +01:00
log_info("Launching Voicemeeter Potato x64 GUI");
break;
}
time_t endwait;
int timeout = 2;
endwait = time(NULL) + timeout;
do
{
Sleep(100);
if ((rep = version(iVMR, &v)) == 0)
break;
} while (time(NULL) < endwait);
2024-06-25 04:34:28 +01:00
}
if (rep == 0)
{
version(iVMR, &v);
long v1 = (v & 0xFF000000) >> 24,
v2 = (v & 0x00FF0000) >> 16,
v3 = (v & 0x0000FF00) >> 8,
v4 = (v & 0x000000FF);
char version_s[128];
sprintf(version_s, "%i.%i.%i.%i", (int)v1, (int)v2, (int)v3, (int)v4);
log_info("Successfully logged into the Voicemeeter API v%s", version_s);
clear_dirty(iVMR);
}
2024-06-25 04:34:28 +01:00
return rep;
}
long logout(T_VBVMR_INTERFACE *iVMR)
{
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-06-26 16:44:28 +01:00
rep = iVMR->VBVMR_Logout();
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(T_VBVMR_INTERFACE *iVMR, 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-25 04:34:28 +01:00
return iVMR->VBVMR_RunVoicemeeter((long)kind);
}
long type(T_VBVMR_INTERFACE *iVMR, long *type)
{
2024-06-27 03:23:48 +01:00
log_trace("VBVMR_GetVoicemeeterType(<long> *t)");
2024-06-25 04:34:28 +01:00
return iVMR->VBVMR_GetVoicemeeterType(type);
}
long version(T_VBVMR_INTERFACE *iVMR, long *version)
{
2024-06-27 03:23:48 +01:00
log_trace("VBVMR_GetVoicemeeterVersion(<long> *v)");
return iVMR->VBVMR_GetVoicemeeterVersion(version);
2024-06-25 04:34:28 +01:00
}
2024-06-26 05:05:13 +01:00
bool is_pdirty(T_VBVMR_INTERFACE *iVMR)
2024-06-25 04:34:28 +01:00
{
log_trace("VBVMR_IsParametersDirty()");
2024-06-25 04:34:28 +01:00
return iVMR->VBVMR_IsParametersDirty() == 1;
}
2024-06-25 23:32:32 +01:00
long get_parameter_float(T_VBVMR_INTERFACE *iVMR, char *param, float *f)
{
log_trace("VBVMR_GetParameterFloat(%s, <float> *f)", param, f);
2024-06-25 23:32:32 +01:00
return iVMR->VBVMR_GetParameterFloat(param, f);
}
long get_parameter_string(T_VBVMR_INTERFACE *iVMR, char *param, char *s)
{
log_trace("VBVMR_GetParameterStringA(%s, <char> *s)", param, s);
2024-06-25 23:32:32 +01:00
return iVMR->VBVMR_GetParameterStringA(param, s);
}
long set_parameter_float(T_VBVMR_INTERFACE *iVMR, char *param, float val)
{
2024-06-27 03:23:48 +01:00
log_trace("VBVMR_SetParameterFloat(%s, %.1f)", param, val);
2024-06-25 23:32:32 +01:00
return iVMR->VBVMR_SetParameterFloat(param, val);
}
long set_parameter_string(T_VBVMR_INTERFACE *iVMR, char *param, char *s)
{
2024-06-27 01:18:17 +01:00
log_trace("VBVMR_SetParameterStringA(%s, %s)", param, s);
2024-06-25 23:32:32 +01:00
return iVMR->VBVMR_SetParameterStringA(param, s);
}
2024-06-25 04:34:28 +01:00
long set_parameters(T_VBVMR_INTERFACE *iVMR, char *command)
{
2024-06-27 01:18:17 +01:00
log_trace("VBVMR_SetParameters(%s)", command);
2024-06-25 04:34:28 +01:00
return iVMR->VBVMR_SetParameters(command);
}
2024-06-26 05:07:06 +01:00
bool is_mdirty(T_VBVMR_INTERFACE *iVMR)
2024-06-25 04:34:28 +01:00
{
return iVMR->VBVMR_MacroButton_IsDirty() == 1;
}
long macrobutton_getstatus(T_VBVMR_INTERFACE *iVMR, long n, float *val, long mode)
{
return iVMR->VBVMR_MacroButton_GetStatus(n, val, mode);
}
long macrobutton_setstatus(T_VBVMR_INTERFACE *iVMR, long n, float val, long mode)
{
return iVMR->VBVMR_MacroButton_SetStatus(n, val, mode);
}
void clear_dirty(T_VBVMR_INTERFACE *iVMR)
{
Sleep(30);
2024-06-26 05:05:13 +01:00
while (is_pdirty(iVMR))
2024-06-25 04:34:28 +01:00
Sleep(1);
}