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"
|
2024-06-26 16:44:28 +01:00
|
|
|
#include "log.h"
|
2024-06-27 19:18:28 +01:00
|
|
|
#include "util.h"
|
2024-06-25 04:34:28 +01:00
|
|
|
|
2024-06-26 05:00:30 +01:00
|
|
|
#define MAX_LINE 512
|
2024-06-25 04:34:28 +01:00
|
|
|
|
2024-07-02 11:15:17 +01:00
|
|
|
/**
|
|
|
|
* @brief An enum used to define the kind of value
|
|
|
|
* a 'get' call returns.
|
|
|
|
*
|
|
|
|
*/
|
2024-06-25 23:32:32 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
FLOAT_T,
|
|
|
|
STRING_T,
|
|
|
|
};
|
|
|
|
|
2024-07-02 11:15:17 +01:00
|
|
|
/**
|
|
|
|
* @brief A struct holding the result of a get call.
|
|
|
|
*
|
|
|
|
*/
|
2024-06-25 23:32:32 +01:00
|
|
|
struct result
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
union val
|
|
|
|
{
|
|
|
|
float f;
|
2024-06-27 23:26:46 +01:00
|
|
|
wchar_t s[MAX_LINE];
|
2024-06-25 23:32:32 +01:00
|
|
|
} val;
|
|
|
|
};
|
|
|
|
|
|
|
|
void help(void);
|
2024-06-29 03:05:51 +01:00
|
|
|
enum kind set_kind(char *kval);
|
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
|
|
|
void interactive(T_VBVMR_INTERFACE *vmr);
|
2024-07-02 10:13:37 +01:00
|
|
|
void parse_input(T_VBVMR_INTERFACE *vmr, char *input, int len);
|
2024-06-25 23:32:32 +01:00
|
|
|
void parse_command(T_VBVMR_INTERFACE *vmr, char *command);
|
2024-06-27 10:06:22 +01:00
|
|
|
void get(T_VBVMR_INTERFACE *vmr, char *command, struct result *res);
|
2024-06-25 04:34:28 +01:00
|
|
|
|
2024-07-02 10:13:37 +01:00
|
|
|
bool vflag = false;
|
|
|
|
|
2024-06-25 04:34:28 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
bool iflag = false;
|
2024-07-02 17:49:51 +01:00
|
|
|
bool mflag = false;
|
|
|
|
bool sflag = false;
|
2024-06-25 20:01:38 +01:00
|
|
|
int opt;
|
|
|
|
char *kvalue = "";
|
2024-06-26 16:44:28 +01:00
|
|
|
int dvalue;
|
2024-06-29 03:05:51 +01:00
|
|
|
enum kind kind = BANANAX64;
|
2024-06-25 04:34:28 +01:00
|
|
|
|
2024-06-26 16:58:10 +01:00
|
|
|
if (argc == 1)
|
|
|
|
{
|
|
|
|
help();
|
2024-06-27 01:17:59 +01:00
|
|
|
exit(EXIT_SUCCESS);
|
2024-06-26 16:58:10 +01:00
|
|
|
}
|
|
|
|
|
2024-06-27 01:17:59 +01:00
|
|
|
log_set_level(LOG_WARN);
|
2024-06-26 16:44:28 +01:00
|
|
|
|
2024-07-02 17:49:51 +01:00
|
|
|
while ((opt = getopt(argc, argv, "hk:msiD:v")) != -1)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-06-25 20:01:38 +01:00
|
|
|
switch (opt)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-07-02 17:49:51 +01:00
|
|
|
case 'h':
|
|
|
|
help();
|
|
|
|
exit(EXIT_SUCCESS);
|
2024-06-25 16:46:35 +01:00
|
|
|
case 'k':
|
|
|
|
kvalue = optarg;
|
2024-06-26 16:44:28 +01:00
|
|
|
kind = set_kind(kvalue);
|
2024-06-25 16:46:35 +01:00
|
|
|
break;
|
2024-07-02 17:49:51 +01:00
|
|
|
case 'm':
|
|
|
|
mflag = true;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
sflag = true;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
iflag = true;
|
|
|
|
break;
|
2024-06-26 16:44:28 +01:00
|
|
|
case 'D':
|
2024-06-27 01:17:59 +01:00
|
|
|
dvalue = atoi(optarg);
|
|
|
|
if (dvalue >= LOG_TRACE && dvalue <= LOG_FATAL)
|
2024-06-26 16:44:28 +01:00
|
|
|
{
|
|
|
|
log_set_level(dvalue);
|
|
|
|
}
|
2024-06-27 01:17:59 +01:00
|
|
|
else
|
|
|
|
{
|
2024-06-27 08:27:49 +01:00
|
|
|
log_error(
|
2024-06-27 01:17:59 +01:00
|
|
|
"-D arg out of range, expected value from 0 up to 5\n"
|
2024-06-27 08:27:49 +01:00
|
|
|
"Log level will default to LOG_WARN (3).\n");
|
2024-06-27 01:17:59 +01:00
|
|
|
}
|
2024-06-26 16:44:28 +01:00
|
|
|
break;
|
2024-07-02 10:13:37 +01:00
|
|
|
case 'v':
|
|
|
|
vflag = true;
|
|
|
|
break;
|
2024-06-25 04:34:28 +01:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-26 06:01:01 +01:00
|
|
|
T_VBVMR_INTERFACE iVMR;
|
2024-06-25 04:34:28 +01:00
|
|
|
T_VBVMR_INTERFACE *vmr = &iVMR;
|
|
|
|
|
2024-06-25 16:46:35 +01:00
|
|
|
int rep = init_voicemeeter(vmr, kind);
|
2024-06-25 17:22:46 +01:00
|
|
|
if (rep != 0)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:49:51 +01:00
|
|
|
if (mflag)
|
|
|
|
{
|
|
|
|
log_info("MacroButtons app launched");
|
|
|
|
run_voicemeeter(vmr, MACROBUTTONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sflag)
|
|
|
|
{
|
|
|
|
log_info("StreamerView app launched");
|
|
|
|
run_voicemeeter(vmr, STREAMERVIEW);
|
|
|
|
}
|
|
|
|
|
2024-06-25 04:34:28 +01:00
|
|
|
if (iflag)
|
|
|
|
{
|
|
|
|
puts("Interactive mode enabled. Enter 'Q' to exit.");
|
|
|
|
interactive(vmr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = optind; i < argc; i++)
|
|
|
|
{
|
2024-07-02 10:13:37 +01:00
|
|
|
parse_input(vmr, argv[i], strlen(argv[i]));
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rep = logout(vmr);
|
2024-06-25 17:22:46 +01:00
|
|
|
if (rep == 0)
|
2024-06-25 04:34:28 +01:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
else
|
|
|
|
return EXIT_FAILURE;
|
2024-06-25 16:46:35 +01:00
|
|
|
}
|
|
|
|
|
2024-06-29 03:05:51 +01:00
|
|
|
/**
|
2024-07-02 11:15:17 +01:00
|
|
|
* @brief prints the help message
|
2024-06-29 03:05:51 +01:00
|
|
|
*
|
|
|
|
*/
|
2024-06-25 23:32:32 +01:00
|
|
|
void help()
|
2024-06-25 20:01:38 +01:00
|
|
|
{
|
2024-06-25 23:32:32 +01:00
|
|
|
puts(
|
2024-07-02 17:49:51 +01:00
|
|
|
"Usage: ./vmrcli.exe [-h] [-i] [-k] [-D] [-v] [-m] [-s] <api commands>\n"
|
2024-06-25 20:01:38 +01:00
|
|
|
"Where: \n"
|
2024-07-02 11:15:17 +01:00
|
|
|
"\th: Prints the help message\n"
|
2024-06-25 20:01:38 +01:00
|
|
|
"\ti: Enable interactive mode\n"
|
2024-06-26 16:44:28 +01:00
|
|
|
"\tk: The kind of Voicemeeter (basic, banana, potato)\n"
|
2024-07-02 10:25:25 +01:00
|
|
|
"\tD: Set log level 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=FATAL\n"
|
2024-07-02 17:49:51 +01:00
|
|
|
"\tv: Enable extra console output (toggle, set messages)\n"
|
|
|
|
"\tm: Launch the MacroButtons application\n"
|
2024-07-02 17:59:44 +01:00
|
|
|
"\ts: Launch the StreamerView application");
|
2024-06-25 20:01:38 +01:00
|
|
|
}
|
|
|
|
|
2024-06-29 03:05:51 +01:00
|
|
|
/**
|
|
|
|
* @brief Set the kind object
|
|
|
|
*
|
|
|
|
* @param kval
|
|
|
|
* @return enum kind
|
|
|
|
*/
|
|
|
|
enum kind set_kind(char *kval)
|
2024-06-25 16:46:35 +01:00
|
|
|
{
|
|
|
|
if (strcmp(kval, "basic") == 0)
|
|
|
|
{
|
2024-06-29 03:05:51 +01:00
|
|
|
if (sizeof(void *) == 8)
|
|
|
|
return BASICX64;
|
|
|
|
else
|
|
|
|
return BASIC;
|
2024-06-25 16:46:35 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(kval, "banana") == 0)
|
|
|
|
{
|
2024-06-29 03:05:51 +01:00
|
|
|
if (sizeof(void *) == 8)
|
|
|
|
return BANANAX64;
|
|
|
|
else
|
|
|
|
return BANANA;
|
2024-06-25 16:46:35 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(kval, "potato") == 0)
|
|
|
|
{
|
|
|
|
if (sizeof(void *) == 8)
|
|
|
|
return POTATOX64;
|
|
|
|
else
|
|
|
|
return POTATO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-06-27 08:27:49 +01:00
|
|
|
log_error("Unknown Voicemeeter kind '%s'\n", kval);
|
2024-06-25 16:46:35 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
2024-07-02 11:15:17 +01:00
|
|
|
/**
|
|
|
|
* @brief Defines the DLL interface as a struct.
|
|
|
|
* Logs into the API.
|
|
|
|
*
|
|
|
|
* @param vmr The API interface as a struct
|
|
|
|
* @param kind
|
|
|
|
* @return int
|
|
|
|
*/
|
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)
|
|
|
|
{
|
2024-06-27 08:27:49 +01:00
|
|
|
log_error("Voicemeeter is not installed");
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-06-27 08:27:49 +01:00
|
|
|
log_error("Error loading Voicemeeter dll with code %d\n", rep);
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2024-06-27 08:27:49 +01:00
|
|
|
log_error("Error logging into Voicemeeter");
|
2024-06-25 04:34:28 +01:00
|
|
|
return rep;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-07-02 11:15:17 +01:00
|
|
|
/**
|
|
|
|
* @brief Continuously read lines from stdin.
|
|
|
|
* Break if 'Q' is entered on the interactive prompt.
|
|
|
|
* Each line is passed to parse_input()
|
|
|
|
*
|
|
|
|
* @param vmr The API interface as a struct
|
|
|
|
*/
|
2024-06-25 04:34:28 +01:00
|
|
|
void interactive(T_VBVMR_INTERFACE *vmr)
|
|
|
|
{
|
2024-07-02 10:13:37 +01:00
|
|
|
char input[MAX_LINE];
|
2024-06-27 22:06:15 +01:00
|
|
|
size_t len;
|
2024-06-25 04:34:28 +01:00
|
|
|
|
2024-06-27 22:06:15 +01:00
|
|
|
printf(">> ");
|
2024-06-25 04:34:28 +01:00
|
|
|
while (fgets(input, MAX_LINE, stdin) != NULL)
|
|
|
|
{
|
2024-06-26 16:44:28 +01:00
|
|
|
input[strcspn(input, "\n")] = 0;
|
2024-06-27 22:06:15 +01:00
|
|
|
len = strlen(input);
|
|
|
|
if (len == 1 && toupper(input[0]) == 'Q')
|
2024-06-25 04:34:28 +01:00
|
|
|
break;
|
|
|
|
|
2024-07-02 10:13:37 +01:00
|
|
|
parse_input(vmr, input, len);
|
2024-06-26 05:54:13 +01:00
|
|
|
|
2024-06-28 01:23:40 +01:00
|
|
|
memset(input, '\0', MAX_LINE); /* reset input buffer */
|
2024-06-27 22:06:15 +01:00
|
|
|
printf(">> ");
|
2024-06-25 23:32:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-02 11:15:17 +01:00
|
|
|
/**
|
|
|
|
* @brief Walks through each line split by a space delimiter.
|
|
|
|
* Each token is passed to parse_command()
|
|
|
|
*
|
|
|
|
* @param vmr The API interface as a struct
|
|
|
|
* @param input Each input line, from stdin or CLI args
|
|
|
|
* @param len The length of the input line
|
|
|
|
*/
|
2024-07-02 10:13:37 +01:00
|
|
|
void parse_input(T_VBVMR_INTERFACE *vmr, char *input, int len)
|
|
|
|
{
|
|
|
|
char *token;
|
|
|
|
|
|
|
|
replace_multiple_space_with_one(input, len);
|
|
|
|
token = strtok(input, " ");
|
|
|
|
while (token != NULL)
|
|
|
|
{
|
|
|
|
parse_command(vmr, token);
|
|
|
|
token = strtok(NULL, " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-02 11:15:17 +01:00
|
|
|
/**
|
|
|
|
* @brief Execute each command according to type.
|
|
|
|
* See command type definitions in:
|
|
|
|
* https://github.com/onyx-and-iris/vmrcli?tab=readme-ov-file#api-commands
|
|
|
|
*
|
|
|
|
* @param vmr The API interface as a struct
|
|
|
|
* @param command Each token from the input line as its own command string
|
|
|
|
*/
|
2024-06-25 23:32:32 +01:00
|
|
|
void parse_command(T_VBVMR_INTERFACE *vmr, char *command)
|
|
|
|
{
|
2024-06-26 16:44:28 +01:00
|
|
|
log_debug("Parsing %s", command);
|
|
|
|
|
2024-06-25 23:32:32 +01:00
|
|
|
if (command[0] == '!') /* toggle */
|
|
|
|
{
|
2024-06-26 00:03:50 +01:00
|
|
|
command++;
|
|
|
|
struct result res = {.type = FLOAT_T};
|
|
|
|
|
|
|
|
get(vmr, command, &res);
|
|
|
|
if (res.type == FLOAT_T)
|
|
|
|
{
|
2024-07-01 03:40:33 +01:00
|
|
|
if (res.val.f == 1 || res.val.f == 0)
|
2024-07-02 10:13:37 +01:00
|
|
|
{
|
2024-07-01 03:40:33 +01:00
|
|
|
set_parameter_float(vmr, command, 1 - res.val.f);
|
2024-07-02 10:13:37 +01:00
|
|
|
if (vflag)
|
|
|
|
{
|
|
|
|
printf("Toggling %s\n", command);
|
|
|
|
}
|
|
|
|
}
|
2024-07-01 03:40:33 +01:00
|
|
|
else
|
|
|
|
log_warn("%s does not appear to be a boolean parameter", command);
|
2024-06-26 00:03:50 +01:00
|
|
|
}
|
2024-06-25 23:32:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strchr(command, '=') != NULL) /* set */
|
|
|
|
{
|
|
|
|
set_parameters(vmr, command);
|
2024-07-02 10:13:37 +01:00
|
|
|
if (vflag)
|
|
|
|
{
|
|
|
|
printf("Setting %s\n", command);
|
|
|
|
}
|
2024-06-25 23:32:32 +01:00
|
|
|
}
|
|
|
|
else /* get */
|
|
|
|
{
|
|
|
|
struct result res = {.type = FLOAT_T};
|
|
|
|
|
|
|
|
get(vmr, command, &res);
|
|
|
|
switch (res.type)
|
|
|
|
{
|
|
|
|
case FLOAT_T:
|
2024-07-02 10:13:37 +01:00
|
|
|
printf("%s: %.1f\n", command, res.val.f);
|
2024-06-25 23:32:32 +01:00
|
|
|
break;
|
|
|
|
case STRING_T:
|
2024-07-02 10:13:37 +01:00
|
|
|
printf("%s: %ls\n", command, res.val.s);
|
2024-06-25 23:32:32 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-02 11:15:17 +01:00
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
*
|
|
|
|
* @param vmr The API interface as a struct
|
|
|
|
* @param command A parsed 'get' command as a string
|
|
|
|
* @param res A struct holding the result of the API call.
|
|
|
|
*/
|
2024-06-27 10:06:22 +01:00
|
|
|
void get(T_VBVMR_INTERFACE *vmr, char *command, struct result *res)
|
2024-06-25 23:32:32 +01:00
|
|
|
{
|
2024-06-26 00:03:50 +01:00
|
|
|
clear_dirty(vmr);
|
2024-06-25 23:32:32 +01:00
|
|
|
if (get_parameter_float(vmr, command, &res->val.f) != 0)
|
|
|
|
{
|
|
|
|
res->type = STRING_T;
|
2024-06-26 05:54:13 +01:00
|
|
|
if (get_parameter_string(vmr, command, res->val.s) != 0)
|
|
|
|
{
|
|
|
|
res->val.s[0] = 0;
|
2024-06-27 22:06:15 +01:00
|
|
|
log_error("Unknown parameter '%s'", command);
|
2024-06-26 05:54:13 +01:00
|
|
|
}
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
}
|