2024-06-25 04:34:28 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include "cdll.h"
|
|
|
|
#include "vmr.h"
|
|
|
|
|
|
|
|
#define MAX_LINE 1024
|
|
|
|
|
2024-06-25 16:46:35 +01:00
|
|
|
int set_kind(char *kval);
|
|
|
|
int init_voicemeeter(T_VBVMR_INTERFACE *vmr, int kind);
|
2024-06-25 04:34:28 +01:00
|
|
|
void interactive(T_VBVMR_INTERFACE *vmr);
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
bool iflag = false;
|
|
|
|
int c;
|
2024-06-25 16:46:35 +01:00
|
|
|
char *kvalue;
|
|
|
|
int kind = BANANA;
|
2024-06-25 04:34:28 +01:00
|
|
|
|
2024-06-25 16:46:35 +01:00
|
|
|
while ((c = getopt(argc, argv, "k:i")) != -1)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'i':
|
|
|
|
iflag = true;
|
|
|
|
break;
|
2024-06-25 16:46:35 +01:00
|
|
|
case 'k':
|
|
|
|
kvalue = optarg;
|
|
|
|
kind = set_kind(kvalue);
|
|
|
|
break;
|
2024-06-25 04:34:28 +01:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static T_VBVMR_INTERFACE iVMR;
|
|
|
|
T_VBVMR_INTERFACE *vmr = &iVMR;
|
|
|
|
|
2024-06-25 16:46:35 +01:00
|
|
|
int rep = init_voicemeeter(vmr, kind);
|
2024-06-25 04:34:28 +01:00
|
|
|
if (rep)
|
|
|
|
{
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iflag)
|
|
|
|
{
|
|
|
|
puts("Interactive mode enabled. Enter 'Q' to exit.");
|
|
|
|
interactive(vmr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = optind; i < argc; i++)
|
|
|
|
{
|
|
|
|
set_parameters(vmr, argv[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rep = logout(vmr);
|
|
|
|
if (!rep)
|
2024-06-25 16:46:35 +01:00
|
|
|
{
|
|
|
|
puts("Successfully logged out of Voicemeeter API");
|
2024-06-25 04:34:28 +01:00
|
|
|
return EXIT_SUCCESS;
|
2024-06-25 16:46:35 +01:00
|
|
|
}
|
2024-06-25 04:34:28 +01:00
|
|
|
else
|
2024-06-25 16:46:35 +01:00
|
|
|
{
|
2024-06-25 04:34:28 +01:00
|
|
|
return EXIT_FAILURE;
|
2024-06-25 16:46:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int set_kind(char *kval)
|
|
|
|
{
|
|
|
|
if (strcmp(kval, "basic") == 0)
|
|
|
|
{
|
|
|
|
return BASIC;
|
|
|
|
}
|
|
|
|
else if (strcmp(kval, "banana") == 0)
|
|
|
|
{
|
|
|
|
return BANANA;
|
|
|
|
}
|
|
|
|
else if (strcmp(kval, "potato") == 0)
|
|
|
|
{
|
|
|
|
if (sizeof(void *) == 8)
|
|
|
|
return POTATOX64;
|
|
|
|
else
|
|
|
|
return POTATO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unknown Voicemeeter kind '%s'\n", kval);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
2024-06-25 16:46:35 +01:00
|
|
|
int init_voicemeeter(T_VBVMR_INTERFACE *vmr, int kind)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
|
|
|
int rep = initialize_dll_interfaces(vmr);
|
|
|
|
if (rep < 0)
|
|
|
|
{
|
|
|
|
if (rep == -100)
|
|
|
|
{
|
|
|
|
fputs("Voicemeeter is not installed", stderr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error loading Voicemeeter dll with code %d\n", rep);
|
|
|
|
}
|
|
|
|
return rep;
|
|
|
|
}
|
|
|
|
|
2024-06-25 16:46:35 +01:00
|
|
|
rep = login(vmr, kind);
|
2024-06-25 04:34:28 +01:00
|
|
|
if (rep != 0)
|
|
|
|
{
|
|
|
|
fputs("Error logging into Voicemeeter", stderr);
|
|
|
|
return rep;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void interactive(T_VBVMR_INTERFACE *vmr)
|
|
|
|
{
|
|
|
|
char input[MAX_LINE];
|
|
|
|
|
|
|
|
while (fgets(input, MAX_LINE, stdin) != NULL)
|
|
|
|
{
|
|
|
|
if (strncmp(input, "Q", 1) == 0 || strncmp(input, "q", 1) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
set_parameters(vmr, input);
|
|
|
|
}
|
|
|
|
}
|