Compare commits

..

3 Commits

Author SHA1 Message Date
a383aaa36b reword
add link defs
2024-07-02 10:21:37 +01:00
28945b72c5 modify example_commands to show multiple instructions per line
Add note in README about change.
2024-07-02 10:14:25 +01:00
97fc9ca9ce use strtok to walk through the input string
vflag added for extra console output (toggle, set operations)
2024-07-02 10:13:37 +01:00
4 changed files with 67 additions and 56 deletions

View File

@ -68,18 +68,25 @@ Scripts can be loaded from text files, for example in Powershell:
./vmrcli.exe -D1 $(Get-Content .\example_commands.txt) ./vmrcli.exe -D1 $(Get-Content .\example_commands.txt)
``` ```
Multiple API commands can be in a single line but they should be space separated.
## `Build` ## `Build`
Run the included `makefile` with [GNU Make](https://www.gnu.org/software/make/). Run the included `makefile` with [GNU Make](https://www.gnu.org/software/make/).
By default the log.c module is built with coloured logging enabled. To disable this you can override the `LOG_USE_COLOR` variable, for example: The binary in [Releases][releases] is compiled with coloured logging enabled. To disable this you can override the `LOG_USE_COLOR` variable, for example:
`make LOG_USE_COLOR=no` `make LOG_USE_COLOR=no`
## `Official Documentation` ## `Official Documentation`
- [Voicemeeter Remote C API](https://github.com/onyx-and-iris/Voicemeeter-SDK/blob/main/VoicemeeterRemoteAPI.pdf) - [Voicemeeter Remote C API][remoteapi-docs]
## `Special Thanks` ## `Special Thanks`
- [rxi](https://github.com/rxi) for writing the [log.c](https://github.com/rxi/log.c) package - [rxi][rxi-user] for writing the [log.c][log-c] package
[releases]: https://github.com/onyx-and-iris/vmrcli/releases
[remoteapi-docs]: https://github.com/onyx-and-iris/Voicemeeter-SDK/blob/main/VoicemeeterRemoteAPI.pdf
[rxi-user]: https://github.com/rxi
[log-c]: https://github.com/rxi/log.c

View File

@ -1,8 +1,3 @@
strip[0].mute strip[0].mute !strip[0].mute strip[0].mute strip[0].gain strip[0].label=podmic strip[0].label
!strip[0].mute strip[1].mute=1 strip[1].mute
strip[0].mute bus[0].label bus[0].gain=-8.3
strip[1].mute=1
strip[1].mute
strip[0].gain
strip[0].label=podmic
strip[0].label

View File

@ -14,23 +14,23 @@ enum kind
POTATOX64, POTATOX64,
}; };
long login(T_VBVMR_INTERFACE *iVMR, int kind); long login(T_VBVMR_INTERFACE *vmr, int kind);
long logout(T_VBVMR_INTERFACE *iVMR); long logout(T_VBVMR_INTERFACE *vmr);
long run_voicemeeter(T_VBVMR_INTERFACE *iVMR, int kind); long run_voicemeeter(T_VBVMR_INTERFACE *vmr, int kind);
long type(T_VBVMR_INTERFACE *iVMR, long *type); long type(T_VBVMR_INTERFACE *vmr, long *type);
long version(T_VBVMR_INTERFACE *iVMR, long *version); long version(T_VBVMR_INTERFACE *vmr, long *version);
bool is_pdirty(T_VBVMR_INTERFACE *iVMR); bool is_pdirty(T_VBVMR_INTERFACE *vmr);
long get_parameter_float(T_VBVMR_INTERFACE *iVMR, char *param, float *f); long get_parameter_float(T_VBVMR_INTERFACE *vmr, char *param, float *f);
long get_parameter_string(T_VBVMR_INTERFACE *iVMR, char *param, unsigned short *s); long get_parameter_string(T_VBVMR_INTERFACE *vmr, char *param, unsigned short *s);
long set_parameter_float(T_VBVMR_INTERFACE *iVMR, char *param, float val); long set_parameter_float(T_VBVMR_INTERFACE *vmr, char *param, float val);
long set_parameter_string(T_VBVMR_INTERFACE *iVMR, char *param, char *s); long set_parameter_string(T_VBVMR_INTERFACE *vmr, char *param, char *s);
long set_parameters(T_VBVMR_INTERFACE *iVMR, char *command); long set_parameters(T_VBVMR_INTERFACE *vmr, char *command);
bool is_mdirty(T_VBVMR_INTERFACE *iVMR); bool is_mdirty(T_VBVMR_INTERFACE *vmr);
long macrobutton_getstatus(T_VBVMR_INTERFACE *iVMR, long n, float *val, long mode); long macrobutton_getstatus(T_VBVMR_INTERFACE *vmr, long n, float *val, long mode);
long macrobutton_setstatus(T_VBVMR_INTERFACE *iVMR, long n, float val, long mode); long macrobutton_setstatus(T_VBVMR_INTERFACE *vmr, long n, float val, long mode);
void clear_dirty(T_VBVMR_INTERFACE *iVMR); void clear_dirty(T_VBVMR_INTERFACE *vmr);
#endif #endif /* __VMR_H__ */

View File

@ -29,9 +29,12 @@ void help(void);
enum kind set_kind(char *kval); enum kind set_kind(char *kval);
int init_voicemeeter(T_VBVMR_INTERFACE *vmr, int kind); int init_voicemeeter(T_VBVMR_INTERFACE *vmr, int kind);
void interactive(T_VBVMR_INTERFACE *vmr); void interactive(T_VBVMR_INTERFACE *vmr);
void parse_input(T_VBVMR_INTERFACE *vmr, char *input, int len);
void parse_command(T_VBVMR_INTERFACE *vmr, char *command); void parse_command(T_VBVMR_INTERFACE *vmr, char *command);
void get(T_VBVMR_INTERFACE *vmr, char *command, struct result *res); void get(T_VBVMR_INTERFACE *vmr, char *command, struct result *res);
bool vflag = false;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
bool iflag = false; bool iflag = false;
@ -48,7 +51,7 @@ int main(int argc, char *argv[])
log_set_level(LOG_WARN); log_set_level(LOG_WARN);
while ((opt = getopt(argc, argv, "k:ihD:")) != -1) while ((opt = getopt(argc, argv, "k:ihD:v")) != -1)
{ {
switch (opt) switch (opt)
{ {
@ -75,6 +78,9 @@ int main(int argc, char *argv[])
"Log level will default to LOG_WARN (3).\n"); "Log level will default to LOG_WARN (3).\n");
} }
break; break;
case 'v':
vflag = true;
break;
default: default:
abort(); abort();
} }
@ -98,7 +104,7 @@ int main(int argc, char *argv[])
{ {
for (int i = optind; i < argc; i++) for (int i = optind; i < argc; i++)
{ {
parse_command(vmr, argv[i]); parse_input(vmr, argv[i], strlen(argv[i]));
} }
} }
@ -116,12 +122,13 @@ int main(int argc, char *argv[])
void help() void help()
{ {
puts( puts(
"Usage: ./vmrcli.exe [-h] [-i] [-k] [-D] <api commands>\n" "Usage: ./vmrcli.exe [-h] [-i] [-k] [-D] [-v] <api commands>\n"
"Where: \n" "Where: \n"
"\th: Prints the help dialogue\n" "\th: Prints the help dialogue\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)\n"
"\tD: Set log level 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=FATAL"); "\tD: Set log level 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=FATAL"
"\tv: Enable extra console output (toggle, set messages)\n");
} }
/** /**
@ -188,9 +195,7 @@ int init_voicemeeter(T_VBVMR_INTERFACE *vmr, int kind)
void interactive(T_VBVMR_INTERFACE *vmr) void interactive(T_VBVMR_INTERFACE *vmr)
{ {
char input[MAX_LINE], command[MAX_LINE]; char input[MAX_LINE];
char *p = input;
int i;
size_t len; size_t len;
printf(">> "); printf(">> ");
@ -201,32 +206,26 @@ void interactive(T_VBVMR_INTERFACE *vmr)
if (len == 1 && toupper(input[0]) == 'Q') if (len == 1 && toupper(input[0]) == 'Q')
break; break;
replace_multiple_space_with_one(input, len); parse_input(vmr, input, len);
while (*p)
{
if (isspace(*p))
{
p++;
continue;
}
log_trace("commands still in buffer: %s", p);
i = 0;
while (*p && !isspace(*p))
command[i++] = *p++;
command[i] = '\0';
if (command[0] != '\0')
parse_command(vmr, command);
memset(command, '\0', MAX_LINE);
}
p = input; /* reset pointer */
memset(input, '\0', MAX_LINE); /* reset input buffer */ memset(input, '\0', MAX_LINE); /* reset input buffer */
printf(">> "); printf(">> ");
} }
} }
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, " ");
}
}
void parse_command(T_VBVMR_INTERFACE *vmr, char *command) void parse_command(T_VBVMR_INTERFACE *vmr, char *command)
{ {
log_debug("Parsing %s", command); log_debug("Parsing %s", command);
@ -240,7 +239,13 @@ void parse_command(T_VBVMR_INTERFACE *vmr, char *command)
if (res.type == FLOAT_T) if (res.type == FLOAT_T)
{ {
if (res.val.f == 1 || res.val.f == 0) if (res.val.f == 1 || res.val.f == 0)
{
set_parameter_float(vmr, command, 1 - res.val.f); set_parameter_float(vmr, command, 1 - res.val.f);
if (vflag)
{
printf("Toggling %s\n", command);
}
}
else else
log_warn("%s does not appear to be a boolean parameter", command); log_warn("%s does not appear to be a boolean parameter", command);
} }
@ -250,6 +255,10 @@ void parse_command(T_VBVMR_INTERFACE *vmr, char *command)
if (strchr(command, '=') != NULL) /* set */ if (strchr(command, '=') != NULL) /* set */
{ {
set_parameters(vmr, command); set_parameters(vmr, command);
if (vflag)
{
printf("Setting %s\n", command);
}
} }
else /* get */ else /* get */
{ {
@ -259,10 +268,10 @@ void parse_command(T_VBVMR_INTERFACE *vmr, char *command)
switch (res.type) switch (res.type)
{ {
case FLOAT_T: case FLOAT_T:
printf("%.1f\n", res.val.f); printf("%s: %.1f\n", command, res.val.f);
break; break;
case STRING_T: case STRING_T:
printf("%ls\n", res.val.s); printf("%s: %ls\n", command, res.val.s);
break; break;
default: default:
break; break;