Skip to content

Commit

Permalink
add -I flag for disabling >> on the interactive prompt
Browse files Browse the repository at this point in the history
return early from parse_input() if input is a comment

add comments to example_commands.txt

upd README.

minor ver bump
  • Loading branch information
onyx-and-iris committed Jul 10, 2024
1 parent 39540e9 commit b35a293
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 24 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
## `Use`

```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:

- `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.
- `D`: Set log level 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=FATAL
- `v`: Enable extra console output (toggle, set messages)
Expand Down Expand Up @@ -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:

```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 `,`.

Lines starting with `#` will be interpreted as comments.

## `Build`

Run the included `makefile` with [GNU Make](https://www.gnu.org/software/make/).
Expand Down
9 changes: 9 additions & 0 deletions example_commands.txt
Original file line number Diff line number Diff line change
@@ -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 1
strip[1].mute=1 strip[1].mute strip[1].limit-=8

# Strip 2
strip[2].gain-=5 strip[2].comp+=4.8

# Bus 0
bus[0].label

# Bus 1
bus[1].gain-=5.8
1 change: 1 addition & 0 deletions include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
void remove_last_part_of_path(char *fullpath);
char *kind_as_string(char *s, int kind, int n);
char *version_as_string(char *s, long v, int n);
bool is_comment(char *s);

#endif /* __UTIL_H__ */
2 changes: 1 addition & 1 deletion src/ivmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Vincent Burel, Onyx and Iris (code@onyxandiris.online)
* @brief Functions for initializing the iVMR 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
*
* @copyright Vincent Burel(c)2015-2021 All Rights Reserved
Expand Down
14 changes: 13 additions & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file util.c
* @author Onyx and Iris (code@onyxandiris.online)
* @brief Utility functions.
* @version 0.7.0
* @version 0.8.0
* @date 2024-07-06
*
* @copyright Copyright (c) 2024
Expand Down Expand Up @@ -69,4 +69,16 @@ char *version_as_string(char *s, long v, int n)
v4 = (v & 0x000000FF);
snprintf(s, n, "%i.%i.%i.%i", (int)v1, (int)v2, (int)v3, (int)v4);
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] == '#';
}
46 changes: 28 additions & 18 deletions src/vmrcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file vmrcli.c
* @author Onyx and Iris (code@onyxandiris.online)
* @brief A Voicemeeter Remote Command Line Interface
* @version 0.7.0
* @version 0.8.0
* @date 2024-07-06
*
* @copyright Copyright (c) 2024
Expand All @@ -21,17 +21,17 @@
#include "log.h"
#include "util.h"

#define USAGE "Usage: .\\vmrcli.exe [-h] [-i] [-k] [-D] [-v] [-c] [-m] [-s] <api commands>\n" \
"Where: \n" \
"\th: Prints the help message\n" \
"\ti: Enable interactive mode\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" \
"\tv: Enable extra console output (toggle, set messages)\n" \
"\tc: Load a user configuration (give the full file path)\n" \
"\tm: Launch the MacroButtons application\n" \
#define USAGE "Usage: .\\vmrcli.exe [-h] [-i|-I] [-k] [-D] [-v] [-c] [-m] [-s] <api commands>\n" \
"Where: \n" \
"\th: Prints the help message\n" \
"\ti: Enable interactive mode, use (-I) to disable the '>>' prompt\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" \
"\tv: Enable extra console output (toggle, set messages)\n" \
"\tc: Load a user configuration (give the full file path)\n" \
"\tm: Launch the MacroButtons application\n" \
"\ts: Launch the StreamerView application"
#define OPTSTR ":hk:msc:iD:v"
#define OPTSTR ":hk:msc:iID:v"
#define MAX_LINE 512

/**
Expand Down Expand Up @@ -60,7 +60,7 @@ static bool vflag = false;

static void usage(void);
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_command(PT_VMR vmr, char *command);
void get(PT_VMR vmr, char *command, struct result *res);
Expand All @@ -70,7 +70,8 @@ int main(int argc, char *argv[])
bool iflag = false,
mflag = false,
sflag = false,
cflag = false;
cflag = false,
with_prompt = true;
int opt;
int dvalue;
char *cvalue;
Expand Down Expand Up @@ -106,6 +107,9 @@ int main(int argc, char *argv[])
cflag = true;
cvalue = optarg;
break;
case 'I':
with_prompt = false;
[[fallthrough]];
case 'i':
iflag = true;
break;
Expand Down Expand Up @@ -174,7 +178,7 @@ int main(int argc, char *argv[])
if (iflag)
{
puts("Interactive mode enabled. Enter 'Q' to exit.");
interactive(vmr);
interactive(vmr, with_prompt);
}
else
{
Expand Down Expand Up @@ -231,11 +235,12 @@ enum kind set_kind(char *kval)
*
* @param vmr Pointer to the iVMR interface
*/
void interactive(PT_VMR vmr)
void interactive(PT_VMR vmr, bool with_prompt)
{
char input[MAX_LINE];

printf(">> ");
if (with_prompt)
printf(">> ");
while (fgets(input, MAX_LINE, stdin) != NULL)
{
input[strcspn(input, "\n")] = 0;
Expand All @@ -245,19 +250,24 @@ void interactive(PT_VMR vmr)
parse_input(vmr, input);

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()
*
* @param vmr Pointer to the iVMR interface
* @param input Each input line, from stdin or CLI args
*/
void parse_input(PT_VMR vmr, char *input)
{
if (is_comment(input))
return;

char *token, *p;

token = strtok_r(input, " \t;,", &p);
Expand Down
2 changes: 1 addition & 1 deletion src/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file wrapper.c
* @author Onyx and Iris (code@onyxandiris.online)
* @brief Provides public functions that wrap the iVMR calls
* @version 0.7.0
* @version 0.8.0
* @date 2024-07-06
*
* @copyright Copyright (c) 2024
Expand Down

0 comments on commit b35a293

Please sign in to comment.