add -I flag for disabling >> on the interactive prompt

return early from parse_input() if input is a comment

add comments to example_commands.txt

upd README.

minor ver bump
This commit is contained in:
onyx-and-iris 2024-07-10 10:51:53 +01:00
parent 39540e9c3e
commit b35a29396b
7 changed files with 59 additions and 24 deletions

View File

@ -13,13 +13,14 @@
## `Use` ## `Use`
```powershell ```powershell
.\vmrcli.exe [-h] [-i] [-k] [-D] [-v] [-c] [-m] [-s] <api commands> .\vmrcli.exe [-h] [-i|-I] [-k] [-D] [-v] [-c] [-m] [-s] <api commands>
``` ```
Where: Where:
- `h`: Prints the help message. - `h`: Prints the help message.
- `i`: Enable interactive mode. If set, any api commands passed on the command line will be ignored. - `i`: Enable interactive mode, use (-I) to disable the '>>' prompt.
- If set, any api commands passed on the command line will be ignored.
- `k`: The kind of Voicemeeter (basic, banana or potato). Use this to launch the GUI. - `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 - `D`: Set log level 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=FATAL
- `v`: Enable extra console output (toggle, set messages) - `v`: Enable extra console output (toggle, set messages)
@ -75,11 +76,13 @@ Scripts can be loaded from text files, for example in Powershell:
You may also pipe a scripts contents to the CLI: You may also pipe a scripts contents to the CLI:
```powershell ```powershell
$(Get-Content .\example_commands.txt) | .\vmrcli.exe -D1 -i $(Get-Content .\example_commands.txt) | .\vmrcli.exe -D1 -I
``` ```
Multiple API commands can be in a single line, they may be separated by space, `;` or `,`. Multiple API commands can be in a single line, they may be separated by space, `;` or `,`.
Lines starting with `#` will be interpreted as comments.
## `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/).

View File

@ -1,5 +1,14 @@
# Strip 0
strip[0].mute !strip[0].mute strip[0].mute strip[0].gain strip[0].label=podmic strip[0].label strip[0].mute !strip[0].mute strip[0].mute strip[0].gain strip[0].label=podmic strip[0].label
# Strip 1
strip[1].mute=1 strip[1].mute strip[1].limit-=8 strip[1].mute=1 strip[1].mute strip[1].limit-=8
# Strip 2
strip[2].gain-=5 strip[2].comp+=4.8 strip[2].gain-=5 strip[2].comp+=4.8
# Bus 0
bus[0].label bus[0].label
# Bus 1
bus[1].gain-=5.8 bus[1].gain-=5.8

View File

@ -11,5 +11,6 @@
void remove_last_part_of_path(char *fullpath); void remove_last_part_of_path(char *fullpath);
char *kind_as_string(char *s, int kind, int n); char *kind_as_string(char *s, int kind, int n);
char *version_as_string(char *s, long v, int n); char *version_as_string(char *s, long v, int n);
bool is_comment(char *s);
#endif /* __UTIL_H__ */ #endif /* __UTIL_H__ */

View File

@ -3,7 +3,7 @@
* @author Vincent Burel, Onyx and Iris (code@onyxandiris.online) * @author Vincent Burel, Onyx and Iris (code@onyxandiris.online)
* @brief Functions for initializing the iVMR interface. * @brief Functions for initializing the iVMR interface.
* Defines a single public function that returns a pointer to the interface. * Defines a single public function that returns a pointer to the interface.
* @version 0.7.0 * @version 0.8.0
* @date 2024-07-06 * @date 2024-07-06
* *
* @copyright Vincent Burel(c)2015-2021 All Rights Reserved * @copyright Vincent Burel(c)2015-2021 All Rights Reserved

View File

@ -2,7 +2,7 @@
* @file util.c * @file util.c
* @author Onyx and Iris (code@onyxandiris.online) * @author Onyx and Iris (code@onyxandiris.online)
* @brief Utility functions. * @brief Utility functions.
* @version 0.7.0 * @version 0.8.0
* @date 2024-07-06 * @date 2024-07-06
* *
* @copyright Copyright (c) 2024 * @copyright Copyright (c) 2024
@ -70,3 +70,15 @@ char *version_as_string(char *s, long v, int n)
snprintf(s, n, "%i.%i.%i.%i", (int)v1, (int)v2, (int)v3, (int)v4); snprintf(s, n, "%i.%i.%i.%i", (int)v1, (int)v2, (int)v3, (int)v4);
return s; return s;
} }
/**
* @brief Is the current input a comment
*
* @param s Pointer to the current input
* @return true
* @return false
*/
bool is_comment(char *s)
{
return s[0] == '#';
}

View File

@ -2,7 +2,7 @@
* @file vmrcli.c * @file vmrcli.c
* @author Onyx and Iris (code@onyxandiris.online) * @author Onyx and Iris (code@onyxandiris.online)
* @brief A Voicemeeter Remote Command Line Interface * @brief A Voicemeeter Remote Command Line Interface
* @version 0.7.0 * @version 0.8.0
* @date 2024-07-06 * @date 2024-07-06
* *
* @copyright Copyright (c) 2024 * @copyright Copyright (c) 2024
@ -21,17 +21,17 @@
#include "log.h" #include "log.h"
#include "util.h" #include "util.h"
#define USAGE "Usage: .\\vmrcli.exe [-h] [-i] [-k] [-D] [-v] [-c] [-m] [-s] <api commands>\n" \ #define USAGE "Usage: .\\vmrcli.exe [-h] [-i|-I] [-k] [-D] [-v] [-c] [-m] [-s] <api commands>\n" \
"Where: \n" \ "Where: \n" \
"\th: Prints the help message\n" \ "\th: Prints the help message\n" \
"\ti: Enable interactive mode\n" \ "\ti: Enable interactive mode, use (-I) to disable the '>>' prompt\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\n" \ "\tD: Set log level 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=FATAL\n" \
"\tv: Enable extra console output (toggle, set messages)\n" \ "\tv: Enable extra console output (toggle, set messages)\n" \
"\tc: Load a user configuration (give the full file path)\n" \ "\tc: Load a user configuration (give the full file path)\n" \
"\tm: Launch the MacroButtons application\n" \ "\tm: Launch the MacroButtons application\n" \
"\ts: Launch the StreamerView application" "\ts: Launch the StreamerView application"
#define OPTSTR ":hk:msc:iD:v" #define OPTSTR ":hk:msc:iID:v"
#define MAX_LINE 512 #define MAX_LINE 512
/** /**
@ -60,7 +60,7 @@ static bool vflag = false;
static void usage(void); static void usage(void);
enum kind set_kind(char *kval); enum kind set_kind(char *kval);
void interactive(PT_VMR vmr); void interactive(PT_VMR vmr, bool with_prompt);
void parse_input(PT_VMR vmr, char *input); void parse_input(PT_VMR vmr, char *input);
void parse_command(PT_VMR vmr, char *command); void parse_command(PT_VMR vmr, char *command);
void get(PT_VMR vmr, char *command, struct result *res); void get(PT_VMR vmr, char *command, struct result *res);
@ -70,7 +70,8 @@ int main(int argc, char *argv[])
bool iflag = false, bool iflag = false,
mflag = false, mflag = false,
sflag = false, sflag = false,
cflag = false; cflag = false,
with_prompt = true;
int opt; int opt;
int dvalue; int dvalue;
char *cvalue; char *cvalue;
@ -106,6 +107,9 @@ int main(int argc, char *argv[])
cflag = true; cflag = true;
cvalue = optarg; cvalue = optarg;
break; break;
case 'I':
with_prompt = false;
[[fallthrough]];
case 'i': case 'i':
iflag = true; iflag = true;
break; break;
@ -174,7 +178,7 @@ int main(int argc, char *argv[])
if (iflag) if (iflag)
{ {
puts("Interactive mode enabled. Enter 'Q' to exit."); puts("Interactive mode enabled. Enter 'Q' to exit.");
interactive(vmr); interactive(vmr, with_prompt);
} }
else else
{ {
@ -231,11 +235,12 @@ enum kind set_kind(char *kval)
* *
* @param vmr Pointer to the iVMR interface * @param vmr Pointer to the iVMR interface
*/ */
void interactive(PT_VMR vmr) void interactive(PT_VMR vmr, bool with_prompt)
{ {
char input[MAX_LINE]; char input[MAX_LINE];
printf(">> "); if (with_prompt)
printf(">> ");
while (fgets(input, MAX_LINE, stdin) != NULL) while (fgets(input, MAX_LINE, stdin) != NULL)
{ {
input[strcspn(input, "\n")] = 0; input[strcspn(input, "\n")] = 0;
@ -245,12 +250,14 @@ void interactive(PT_VMR vmr)
parse_input(vmr, input); parse_input(vmr, input);
memset(input, 0, MAX_LINE); /* reset input buffer */ memset(input, 0, MAX_LINE); /* reset input buffer */
printf(">> "); if (with_prompt)
printf(">> ");
} }
} }
/** /**
* @brief Walks through each line split by " \t;," delimiters. * @brief Returns early if input is a comment
* Walks through each line split by " \t;," delimiters.
* Each token is passed to parse_command() * Each token is passed to parse_command()
* *
* @param vmr Pointer to the iVMR interface * @param vmr Pointer to the iVMR interface
@ -258,6 +265,9 @@ void interactive(PT_VMR vmr)
*/ */
void parse_input(PT_VMR vmr, char *input) void parse_input(PT_VMR vmr, char *input)
{ {
if (is_comment(input))
return;
char *token, *p; char *token, *p;
token = strtok_r(input, " \t;,", &p); token = strtok_r(input, " \t;,", &p);

View File

@ -2,7 +2,7 @@
* @file wrapper.c * @file wrapper.c
* @author Onyx and Iris (code@onyxandiris.online) * @author Onyx and Iris (code@onyxandiris.online)
* @brief Provides public functions that wrap the iVMR calls * @brief Provides public functions that wrap the iVMR calls
* @version 0.7.0 * @version 0.8.0
* @date 2024-07-06 * @date 2024-07-06
* *
* @copyright Copyright (c) 2024 * @copyright Copyright (c) 2024