From 0d4f5886bf35d937b48624a3dbc1368550093b27 Mon Sep 17 00:00:00 2001 From: klemek Date: Thu, 6 Nov 2025 00:15:15 +0100 Subject: [PATCH] fix: allow demo even without midi --- README.md | 4 ++-- src/forge.c | 6 +++--- src/state.c | 20 +++++++++++--------- src/state.h | 4 ++-- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 16ff155..a9f11ad 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ TODO cool image and youtube link - [From release](#from-release) - [From repository (PKGBUILD)](#from-repository-pkgbuild) - [From repository (dev version)](#from-repository-dev-version) -- [Usage](#usage) +- [CLI usage](#cli-usage) - [Default Shaders and Config](#default-shaders-and-config) - [Sources and Effects](#sources-and-effects) - [Debug View](#debug-view) @@ -81,7 +81,7 @@ make make install ``` -## Usage +## CLI usage ```txt usage: forge [-h] [-v] [-hr] [-s=SCREEN] [-m=SCREEN] [-mo] [-f=DIR_PATH] [-c=CFG_PATH] [-sf=STATE_PATH] [-ls / -nls] [-ss / -nss] [-is=SIZE] [-v=FILE] [-vs=SIZE] [-t=TEMPO] [--demo] [-w] diff --git a/src/forge.c b/src/forge.c index 00ba393..8b22f6d 100644 --- a/src/forge.c +++ b/src/forge.c @@ -265,10 +265,10 @@ void forge_run(Parameters params) { if (!midi_background_listen(midi, context, midi_callback)) { return; } + } - if (!state_background_midi_write(context, state_config, midi)) { - return; - } + if (!state_background_write(context, state_config, midi)) { + return; } window_startup(error_callback); diff --git a/src/state.c b/src/state.c index 7a0f59f..8964e6c 100644 --- a/src/state.c +++ b/src/state.c @@ -272,8 +272,8 @@ void state_apply_event(SharedContext *context, StateConfig state_config, } } -bool state_background_midi_write(SharedContext *context, - StateConfig state_config, MidiDevice midi) { +bool state_background_write(SharedContext *context, StateConfig state_config, + MidiDevice midi) { pid_t pid; bool beat_active, last_active, change, last_change; @@ -287,9 +287,11 @@ bool state_background_midi_write(SharedContext *context, } log_info("(state) background writing started (pid: %d)", pid); - update_page(context, state_config, midi); - update_active(context, state_config, midi); - update_values(context, state_config, midi); + if (!midi.error) { + update_page(context, state_config, midi); + update_active(context, state_config, midi); + update_values(context, state_config, midi); + } last_active = false; last_change = false; @@ -297,20 +299,20 @@ bool state_background_midi_write(SharedContext *context, while (!context->stop) { beat_active = tempo_progress(context->tempo, 1.0) < 0.25; - if (beat_active != last_active) { + if (!midi.error && beat_active != last_active) { safe_midi_write(midi, state_config.tap_tempo_code, beat_active ? MIDI_MAX : 0); safe_midi_write(midi, state_config.select_frag_codes.values[context->selected], beat_active ? MIDI_MAX : 0); - - last_active = beat_active; } + last_active = beat_active; + change = tempo_progress(context->tempo, 4.0) < 0.25; - if (change && !last_change && context->demo) { + if (context->demo && change && !last_change) { state_randomize(context, state_config); } diff --git a/src/state.h b/src/state.h index 732e6fe..b5aee05 100644 --- a/src/state.h +++ b/src/state.h @@ -9,8 +9,8 @@ void state_apply_event(SharedContext *context, StateConfig state_config, MidiDevice midi, unsigned char code, unsigned char value, bool trace_midi); -bool state_background_midi_write(SharedContext *context, - StateConfig state_config, MidiDevice midi); +bool state_background_write(SharedContext *context, StateConfig state_config, + MidiDevice midi); void state_init(SharedContext *context, StateConfig state_config, bool demo, unsigned int base_tempo, char *state_file, bool load_state);