From dfefe879c939f514fcd2ed2147e830a9df28b6fa Mon Sep 17 00:00:00 2001 From: klemek Date: Mon, 11 May 2026 08:36:32 +0200 Subject: [PATCH] feat: video reconnect cli arg --- README.md | 12 ++++++++---- src/args.c | 16 ++++++++++++++++ src/forge.c | 13 +++++++++---- src/types.h | 1 + 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2176c42..0e5c728 100644 --- a/README.md +++ b/README.md @@ -160,10 +160,10 @@ When running, the following hotkeys are available: | Hotkey | Function | | ------ | -------- | -| Esc | Exit FORGE | +| Esc | Exit FORGE | | R | Randomize internal values | | Shift + R | Reset internal values to 0 | -| D | Demo mode On/Off | +| D | Demo mode On/Off | | A | Auto Random mode On/Off | | / | Auto Random Cycle -/+ 1 | | / | BPM +/- 1 | @@ -175,14 +175,16 @@ These are configurable in the [`forge_project.cfg`](#forge_projectcfg). ### CLI arguments ```txt -usage: forge [-h] [-v] [-p=PROJECT_PATH] [-c=CFG_FILE] [-hr] [-s=SCREEN] [-m=SCREEN] [-mo] [-w] [-t=TEMPO] [-d] [-ar / -nar] [-arc=CYCLES] [-vi=FILE] [-vs=SIZE] [-is=SIZE] [-ls / -nls] [-ss / -nss] [-tm] [-tf] +forge steel-dev + +usage: forge [-h] [-v] [-p=PROJECT_PATH] [-c=CFG_FILE] [-hr] [-s=SCREEN] [-m=SCREEN] [-mo] [-w] [-t=TEMPO] [-d] [-ar / -nar] [-arc=CYCLES] [-vi=FILE] [-vs=SIZE] [-vr / -nvr] [-is=SIZE] [-ls / -nls] [-ss / -nss] [-tm] [-tf] Fusion Of Real-time Generative Effects. options: -h, --help show this help message and exit -v, --version print version - -p, --project forge project directory (default: /usr/share/forge/default) + -p, --project forge project directory (default: ./default) -c, --config config file name (default: forge_project.cfg) -hr, --hot-reload hot reload of shaders scripts -s, --screen output screen number (default: primary) @@ -196,6 +198,8 @@ options: -arc, --auto-random-cycle auto random cycle length (default: 4) -vi, --video-in path to video capture device (multiple allowed) -vs, --video-size video capture desired height (default: internal texture height) + -vr, --video-reconnect auto-reconnect video (default) + -nvr, --no-video-reconnect do not auto-reconnect video -is, --internal-size internal texture height (default: 720) -ls, --load-state load saved state (default) -nls, --no-load-state do not load saved state diff --git a/src/args.c b/src/args.c index 04aa113..bad6ba1 100644 --- a/src/args.c +++ b/src/args.c @@ -32,6 +32,7 @@ static void print_help(int status_code) { #ifdef VIDEO_IN "[-vi=FILE] " "[-vs=SIZE] " + "[-vr / -nvr] " #endif /* VIDEO_IN */ "[-is=SIZE] " "[-ls / -nls] " @@ -63,6 +64,8 @@ static void print_help(int status_code) { "allowed)\n" " -vs, --video-size video capture desired height (default: " "internal texture height)\n" + " -vr, --video-reconnect auto-reconnect video (default)\n" + " -nvr, --no-video-reconnect do not auto-reconnect video\n" #endif /* VIDEO_IN */ " -is, --internal-size internal texture height (default: 720)\n" " -ls, --load-state load saved state (default)\n" @@ -130,6 +133,7 @@ void args_parse(Parameters *params, int argc, char **argv) { params->auto_random_cycle = 4; params->video_in.length = 0; params->video_size = 0; + params->video_reconnect = true; params->internal_size = 720; params->load_state = true; params->save_state = true; @@ -195,6 +199,18 @@ void args_parse(Parameters *params, int argc, char **argv) { } #else invalid_arg(arg); +#endif /* VIDEO_IN */ + } else if (is_arg(arg, "-vr") || is_arg(arg, "--video-reconnect")) { +#ifdef VIDEO_IN + params->video_reconnect = true; +#else + invalid_arg(arg); +#endif /* VIDEO_IN */ + } else if (is_arg(arg, "-nvr") || is_arg(arg, "--no-video-reconnect")) { +#ifdef VIDEO_IN + params->video_reconnect = false; +#else + invalid_arg(arg); #endif /* VIDEO_IN */ } else if (is_arg(arg, "-is") || is_arg(arg, "--internal-size")) { params->internal_size = parse_uint(arg, value); diff --git a/src/forge.c b/src/forge.c index 58cf919..2462244 100644 --- a/src/forge.c +++ b/src/forge.c @@ -121,6 +121,9 @@ static bool start_video_captures(unsigned int video_count, bool trace_fps) { return false; } } + if (!init_params.video_reconnect) { + return true; + } pid = fork(); if (pid < 0) { log_error("Could not create subprocess"); @@ -268,10 +271,12 @@ static bool loop(bool hr, bool trace_fps) { } #ifdef VIDEO_IN - for (unsigned int i = 0; i < context->inputs.length; i++) { - if (context->inputs.values[i].needs_reload) { - shaders_relink_input(&program, &project, &context->inputs, i); - context->inputs.values[i].needs_reload = false; + if (init_params.video_reconnect) { + for (unsigned int i = 0; i < context->inputs.length; i++) { + if (context->inputs.values[i].needs_reload) { + shaders_relink_input(&program, &project, &context->inputs, i); + context->inputs.values[i].needs_reload = false; + } } } #endif /* VIDEO_IN */ diff --git a/src/types.h b/src/types.h index 0f58520..5a2d9cd 100644 --- a/src/types.h +++ b/src/types.h @@ -48,6 +48,7 @@ typedef struct Parameters { StringArray video_in; unsigned int video_size; unsigned int internal_size; + bool video_reconnect; bool load_state; bool save_state; bool trace_midi;