mirror of
https://github.com/onyx-and-iris/vmrcli.git
synced 2025-04-20 13:03:49 +01:00
Compare commits
No commits in common. "050a4d9e60009e57d2faf69085ab1f82455e952a" and "7d33496c1de65999c320a4885b85a5101371f56b" have entirely different histories.
050a4d9e60
...
7d33496c1d
53
README.md
53
README.md
@ -1,53 +0,0 @@
|
|||||||
# VMRCLI Command Line Utility
|
|
||||||
|
|
||||||
## `Tested against`
|
|
||||||
|
|
||||||
- Basic 1.1.1.1
|
|
||||||
- Banana 2.1.1.1
|
|
||||||
- Potato 3.1.1.1
|
|
||||||
|
|
||||||
## `Requirements`
|
|
||||||
|
|
||||||
- [Voicemeeter](https://voicemeeter.com/)
|
|
||||||
|
|
||||||
## `Use`
|
|
||||||
|
|
||||||
`./vmrcli.exe [-i] [-k] [-D] <api commands>`
|
|
||||||
|
|
||||||
Where:
|
|
||||||
|
|
||||||
- `i`: Enable interactive mode. If set any api commands passed will be ignored.
|
|
||||||
- `k`: The kind of Voicemeeter (basic, banana or potato). Use this to launch the GUI.
|
|
||||||
- `D`: Set log level 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=FATAL
|
|
||||||
|
|
||||||
## `API Commands`
|
|
||||||
|
|
||||||
- Commands starting with `!` will be toggled, use it with boolean parameters.
|
|
||||||
- Commands containing `=` will set a value.
|
|
||||||
- All other commands with get a value.
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
|
|
||||||
Launch basic GUI, set log level to INFO, Toggle Strip 0 Mute, then print its new value
|
|
||||||
|
|
||||||
`./vmrcli.exe -kbasic -D2 !strip[0].mute strip[0].mute`
|
|
||||||
|
|
||||||
Launch banana GUI, set log level to DEBUG, set Strip 0 label to podmic then print Strip 2 label
|
|
||||||
|
|
||||||
`./vmrcli.exe -kbanana -D1 strip[0].label=podmic strip[2].label`
|
|
||||||
|
|
||||||
## `Script files`
|
|
||||||
|
|
||||||
Scripts can be loaded from text files, for example:
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
./vbantxt-cli -D1 $(Get-Content .\example_commands.txt)
|
|
||||||
```
|
|
||||||
|
|
||||||
## `Official Documentation`
|
|
||||||
|
|
||||||
- [Voicemeeter Remote C API](https://github.com/onyx-and-iris/Voicemeeter-SDK/blob/main/VoicemeeterRemoteAPI.pdf)
|
|
||||||
|
|
||||||
## `Special Thanks`
|
|
||||||
|
|
||||||
- [rxi](https://github.com/rxi) for writing the [log.c](https://github.com/rxi/log.c) package
|
|
@ -1,8 +0,0 @@
|
|||||||
strip[0].mute
|
|
||||||
!strip[0].mute
|
|
||||||
strip[0].mute
|
|
||||||
strip[1].mute=1
|
|
||||||
strip[1].mute
|
|
||||||
strip[0].gain
|
|
||||||
strip[0].label=podmic
|
|
||||||
strip[0].label
|
|
@ -1,58 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2020 rxi
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the MIT license. See `log.c` for details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LOG_H
|
|
||||||
#define LOG_H
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#define LOG_VERSION "0.1.0"
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
const char *fmt;
|
|
||||||
const char *file;
|
|
||||||
struct tm *time;
|
|
||||||
void *udata;
|
|
||||||
int line;
|
|
||||||
int level;
|
|
||||||
} log_Event;
|
|
||||||
|
|
||||||
typedef void (*log_LogFn)(log_Event *ev);
|
|
||||||
typedef void (*log_LockFn)(bool lock, void *udata);
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
LOG_TRACE,
|
|
||||||
LOG_DEBUG,
|
|
||||||
LOG_INFO,
|
|
||||||
LOG_WARN,
|
|
||||||
LOG_ERROR,
|
|
||||||
LOG_FATAL
|
|
||||||
};
|
|
||||||
|
|
||||||
#define log_trace(...) log_log(LOG_TRACE, __FILE__, __LINE__, __VA_ARGS__)
|
|
||||||
#define log_debug(...) log_log(LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
|
|
||||||
#define log_info(...) log_log(LOG_INFO, __FILE__, __LINE__, __VA_ARGS__)
|
|
||||||
#define log_warn(...) log_log(LOG_WARN, __FILE__, __LINE__, __VA_ARGS__)
|
|
||||||
#define log_error(...) log_log(LOG_ERROR, __FILE__, __LINE__, __VA_ARGS__)
|
|
||||||
#define log_fatal(...) log_log(LOG_FATAL, __FILE__, __LINE__, __VA_ARGS__)
|
|
||||||
|
|
||||||
const char *log_level_string(int level);
|
|
||||||
void log_set_lock(log_LockFn fn, void *udata);
|
|
||||||
void log_set_level(int level);
|
|
||||||
void log_set_quiet(bool enable);
|
|
||||||
int log_add_callback(log_LogFn fn, void *udata, int level);
|
|
||||||
int log_add_fp(FILE *fp, int level);
|
|
||||||
|
|
||||||
void log_log(int level, const char *file, int line, const char *fmt, ...);
|
|
||||||
|
|
||||||
#endif
|
|
179
src/log.c
179
src/log.c
@ -1,179 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2020 rxi
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
#define MAX_CALLBACKS 32
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
log_LogFn fn;
|
|
||||||
void *udata;
|
|
||||||
int level;
|
|
||||||
} Callback;
|
|
||||||
|
|
||||||
static struct
|
|
||||||
{
|
|
||||||
void *udata;
|
|
||||||
log_LockFn lock;
|
|
||||||
int level;
|
|
||||||
bool quiet;
|
|
||||||
Callback callbacks[MAX_CALLBACKS];
|
|
||||||
} L;
|
|
||||||
|
|
||||||
static const char *level_strings[] = {
|
|
||||||
"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"};
|
|
||||||
|
|
||||||
#ifdef LOG_USE_COLOR
|
|
||||||
static const char *level_colors[] = {
|
|
||||||
"\x1b[94m", "\x1b[36m", "\x1b[32m", "\x1b[33m", "\x1b[31m", "\x1b[35m"};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void stdout_callback(log_Event *ev)
|
|
||||||
{
|
|
||||||
char buf[16];
|
|
||||||
buf[strftime(buf, sizeof(buf), "%H:%M:%S", ev->time)] = '\0';
|
|
||||||
#ifdef LOG_USE_COLOR
|
|
||||||
fprintf(
|
|
||||||
ev->udata, "%s %s%-5s\x1b[0m \x1b[90m%s:%d:\x1b[0m ",
|
|
||||||
buf, level_colors[ev->level], level_strings[ev->level],
|
|
||||||
ev->file, ev->line);
|
|
||||||
#else
|
|
||||||
fprintf(
|
|
||||||
ev->udata, "%s %-5s %s:%d: ",
|
|
||||||
buf, level_strings[ev->level], ev->file, ev->line);
|
|
||||||
#endif
|
|
||||||
vfprintf(ev->udata, ev->fmt, ev->ap);
|
|
||||||
fprintf(ev->udata, "\n");
|
|
||||||
fflush(ev->udata);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void file_callback(log_Event *ev)
|
|
||||||
{
|
|
||||||
char buf[64];
|
|
||||||
buf[strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ev->time)] = '\0';
|
|
||||||
fprintf(
|
|
||||||
ev->udata, "%s %-5s %s:%d: ",
|
|
||||||
buf, level_strings[ev->level], ev->file, ev->line);
|
|
||||||
vfprintf(ev->udata, ev->fmt, ev->ap);
|
|
||||||
fprintf(ev->udata, "\n");
|
|
||||||
fflush(ev->udata);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void lock(void)
|
|
||||||
{
|
|
||||||
if (L.lock)
|
|
||||||
{
|
|
||||||
L.lock(true, L.udata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void unlock(void)
|
|
||||||
{
|
|
||||||
if (L.lock)
|
|
||||||
{
|
|
||||||
L.lock(false, L.udata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *log_level_string(int level)
|
|
||||||
{
|
|
||||||
return level_strings[level];
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_set_lock(log_LockFn fn, void *udata)
|
|
||||||
{
|
|
||||||
L.lock = fn;
|
|
||||||
L.udata = udata;
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_set_level(int level)
|
|
||||||
{
|
|
||||||
L.level = level;
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_set_quiet(bool enable)
|
|
||||||
{
|
|
||||||
L.quiet = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
int log_add_callback(log_LogFn fn, void *udata, int level)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < MAX_CALLBACKS; i++)
|
|
||||||
{
|
|
||||||
if (!L.callbacks[i].fn)
|
|
||||||
{
|
|
||||||
L.callbacks[i] = (Callback){fn, udata, level};
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int log_add_fp(FILE *fp, int level)
|
|
||||||
{
|
|
||||||
return log_add_callback(file_callback, fp, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void init_event(log_Event *ev, void *udata)
|
|
||||||
{
|
|
||||||
if (!ev->time)
|
|
||||||
{
|
|
||||||
time_t t = time(NULL);
|
|
||||||
ev->time = localtime(&t);
|
|
||||||
}
|
|
||||||
ev->udata = udata;
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_log(int level, const char *file, int line, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
log_Event ev = {
|
|
||||||
.fmt = fmt,
|
|
||||||
.file = file,
|
|
||||||
.line = line,
|
|
||||||
.level = level,
|
|
||||||
};
|
|
||||||
|
|
||||||
lock();
|
|
||||||
|
|
||||||
if (!L.quiet && level >= L.level)
|
|
||||||
{
|
|
||||||
init_event(&ev, stderr);
|
|
||||||
va_start(ev.ap, fmt);
|
|
||||||
stdout_callback(&ev);
|
|
||||||
va_end(ev.ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < MAX_CALLBACKS && L.callbacks[i].fn; i++)
|
|
||||||
{
|
|
||||||
Callback *cb = &L.callbacks[i];
|
|
||||||
if (level >= cb->level)
|
|
||||||
{
|
|
||||||
init_event(&ev, cb->udata);
|
|
||||||
va_start(ev.ap, fmt);
|
|
||||||
cb->fn(&ev);
|
|
||||||
va_end(ev.ap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unlock();
|
|
||||||
}
|
|
18
src/vmr.c
18
src/vmr.c
@ -1,7 +1,6 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "vmr.h"
|
#include "vmr.h"
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
long login(T_VBVMR_INTERFACE *iVMR, int kind)
|
long login(T_VBVMR_INTERFACE *iVMR, int kind)
|
||||||
{
|
{
|
||||||
@ -15,16 +14,16 @@ long login(T_VBVMR_INTERFACE *iVMR, int kind)
|
|||||||
switch (kind)
|
switch (kind)
|
||||||
{
|
{
|
||||||
case BASIC:
|
case BASIC:
|
||||||
log_info("Launching Voicemeeter Basic GUI");
|
puts("Launching Voicemeeter Basic GUI");
|
||||||
break;
|
break;
|
||||||
case BANANA:
|
case BANANA:
|
||||||
log_info("Launching Voicemeeter Banana GUI");
|
puts("Launching Voicemeeter Banana GUI");
|
||||||
break;
|
break;
|
||||||
case POTATO:
|
case POTATO:
|
||||||
log_info("Launching Voicemeeter Potato GUI");
|
puts("Launching Voicemeeter Potato GUI");
|
||||||
break;
|
break;
|
||||||
case POTATOX64:
|
case POTATOX64:
|
||||||
log_info("Launching Voicemeeter Potato x64 GUI");
|
puts("Launching Voicemeeter Potato x64 GUI");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ long login(T_VBVMR_INTERFACE *iVMR, int kind)
|
|||||||
}
|
}
|
||||||
if (rep == 0)
|
if (rep == 0)
|
||||||
{
|
{
|
||||||
log_info("Successfully logged into the Voicemeeter API");
|
puts("Successfully logged into the Voicemeeter API");
|
||||||
clear_dirty(iVMR);
|
clear_dirty(iVMR);
|
||||||
}
|
}
|
||||||
return rep;
|
return rep;
|
||||||
@ -40,13 +39,8 @@ long login(T_VBVMR_INTERFACE *iVMR, int kind)
|
|||||||
|
|
||||||
long logout(T_VBVMR_INTERFACE *iVMR)
|
long logout(T_VBVMR_INTERFACE *iVMR)
|
||||||
{
|
{
|
||||||
int rep;
|
|
||||||
|
|
||||||
Sleep(20); /* give time for last command */
|
Sleep(20); /* give time for last command */
|
||||||
rep = iVMR->VBVMR_Logout();
|
return iVMR->VBVMR_Logout();
|
||||||
if (rep == 0)
|
|
||||||
log_info("Successfully logged out of the Voicemeeter API");
|
|
||||||
return rep;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long run_voicemeeter(T_VBVMR_INTERFACE *iVMR, int kind)
|
long run_voicemeeter(T_VBVMR_INTERFACE *iVMR, int kind)
|
||||||
|
39
src/vmrcli.c
39
src/vmrcli.c
@ -4,7 +4,6 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include "cdll.h"
|
#include "cdll.h"
|
||||||
#include "vmr.h"
|
#include "vmr.h"
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
#define MAX_LINE 512
|
#define MAX_LINE 512
|
||||||
|
|
||||||
@ -36,18 +35,9 @@ int main(int argc, char *argv[])
|
|||||||
bool iflag = false;
|
bool iflag = false;
|
||||||
int opt;
|
int opt;
|
||||||
char *kvalue = "";
|
char *kvalue = "";
|
||||||
int dvalue;
|
|
||||||
int kind = BANANA;
|
int kind = BANANA;
|
||||||
|
|
||||||
if (argc == 1)
|
while ((opt = getopt(argc, argv, "k:ih")) != -1)
|
||||||
{
|
|
||||||
help();
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_set_level(LOG_INFO);
|
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "k:ihD:")) != -1)
|
|
||||||
{
|
{
|
||||||
switch (opt)
|
switch (opt)
|
||||||
{
|
{
|
||||||
@ -56,17 +46,10 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
kvalue = optarg;
|
kvalue = optarg;
|
||||||
kind = set_kind(kvalue);
|
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
help();
|
help();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
case 'D':
|
|
||||||
if ((dvalue = atoi(optarg)) && dvalue >= LOG_TRACE && dvalue <= LOG_FATAL)
|
|
||||||
{
|
|
||||||
log_set_level(dvalue);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -74,6 +57,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
T_VBVMR_INTERFACE iVMR;
|
T_VBVMR_INTERFACE iVMR;
|
||||||
T_VBVMR_INTERFACE *vmr = &iVMR;
|
T_VBVMR_INTERFACE *vmr = &iVMR;
|
||||||
|
if (kvalue && kvalue[0] != '\0')
|
||||||
|
{
|
||||||
|
kind = set_kind(kvalue);
|
||||||
|
}
|
||||||
|
|
||||||
int rep = init_voicemeeter(vmr, kind);
|
int rep = init_voicemeeter(vmr, kind);
|
||||||
if (rep != 0)
|
if (rep != 0)
|
||||||
@ -96,9 +83,14 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
rep = logout(vmr);
|
rep = logout(vmr);
|
||||||
if (rep == 0)
|
if (rep == 0)
|
||||||
|
{
|
||||||
|
puts("Successfully logged out of the Voicemeeter API");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void help()
|
void help()
|
||||||
@ -107,8 +99,7 @@ void help()
|
|||||||
"Usage: ./vmrcli.exe [-i] [-k] <api commands>\n"
|
"Usage: ./vmrcli.exe [-i] [-k] <api commands>\n"
|
||||||
"Where: \n"
|
"Where: \n"
|
||||||
"\ti: Enable interactive mode\n"
|
"\ti: Enable interactive mode\n"
|
||||||
"\tk: The kind of Voicemeeter (basic, banana, potato)\n"
|
"\tk: The kind of Voicemeeter (basic, banana, potato)");
|
||||||
"\tD: Set log level 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=FATAL");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int set_kind(char *kval)
|
int set_kind(char *kval)
|
||||||
@ -168,8 +159,7 @@ void interactive(T_VBVMR_INTERFACE *vmr)
|
|||||||
|
|
||||||
while (fgets(input, MAX_LINE, stdin) != NULL)
|
while (fgets(input, MAX_LINE, stdin) != NULL)
|
||||||
{
|
{
|
||||||
input[strcspn(input, "\n")] = 0;
|
if (strlen(input) == 2 && (strncmp(input, "Q", 1) == 0 || strncmp(input, "q", 1) == 0))
|
||||||
if (strlen(input) == 1 && (strncmp(input, "Q", 1) == 0 || strncmp(input, "q", 1) == 0))
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
while (*p)
|
while (*p)
|
||||||
@ -177,7 +167,7 @@ void interactive(T_VBVMR_INTERFACE *vmr)
|
|||||||
char command[MAX_LINE];
|
char command[MAX_LINE];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (!isspace(*p) && *p != EOF)
|
while (!isspace(*p))
|
||||||
command[i++] = *p++;
|
command[i++] = *p++;
|
||||||
command[i] = '\0';
|
command[i] = '\0';
|
||||||
p++; /* shift to next char */
|
p++; /* shift to next char */
|
||||||
@ -191,8 +181,7 @@ void interactive(T_VBVMR_INTERFACE *vmr)
|
|||||||
|
|
||||||
void parse_command(T_VBVMR_INTERFACE *vmr, char *command)
|
void parse_command(T_VBVMR_INTERFACE *vmr, char *command)
|
||||||
{
|
{
|
||||||
log_debug("Parsing %s", command);
|
printf("Parsing %s\n", command);
|
||||||
|
|
||||||
if (command[0] == '!') /* toggle */
|
if (command[0] == '!') /* toggle */
|
||||||
{
|
{
|
||||||
command++;
|
command++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user