From 23f4ce27ee954fc246a7126df4b3779cd5a128b4 Mon Sep 17 00:00:00 2001 From: klemek Date: Sat, 1 Nov 2025 19:30:38 +0100 Subject: [PATCH] refactor(state): state_init --- README.md | 3 ++- src/forge.c | 30 ++++-------------------------- src/state.c | 28 ++++++++++++++++++++++++++++ src/state.h | 3 +++ 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 35319b1..6b675b3 100644 --- a/README.md +++ b/README.md @@ -157,4 +157,5 @@ make -f Makefile.dev release-arch - [ ] Find and fix opengl errors 0500 ? - [ ] Bonus - [ ] Record show as text files - - [ ] Play from record text file \ No newline at end of file + - [ ] Play from record text file + - [ ] Try to write NanoKontrol config \ No newline at end of file diff --git a/src/forge.c b/src/forge.c index 834db2d..cbe2573 100644 --- a/src/forge.c +++ b/src/forge.c @@ -11,7 +11,6 @@ #include "file.h" #include "forge.h" #include "midi.h" -#include "rand.h" #include "shaders.h" #include "shared.h" #include "state.h" @@ -56,34 +55,13 @@ static void compute_fps() { } } -static void init_context(Parameters params, unsigned int in_count, - unsigned int frag_count) { +static void init_context(Parameters params, unsigned int in_count) { unsigned int i; - context->tempo = tempo_init(); - tempo_set(&context->tempo, params.base_tempo); - context->demo = params.demo; + state_init(context, state_config, params.demo, params.base_tempo); + context->monitor = params.monitor; - context->state.length = frag_count; - memset(context->state.values, 0, sizeof(context->state.values)); - - if (params.demo) { - state_randomize(context, state_config); - } - - memset(context->active, 0, sizeof(context->active)); - memset(context->values, 0, sizeof(context->values)); - - context->page = 0; - context->selected = 0; - - memset(context->seeds, 0, sizeof(context->seeds)); - - for (i = 0; i < frag_count; i++) { - context->seeds[i] = rand_uint(1000); - } - memset(context->input_resolutions, 0, sizeof(context->input_resolutions)); memset(context->input_formats, 0, sizeof(context->input_formats)); memset(context->input_fps, 0, sizeof(context->input_fps)); @@ -269,7 +247,7 @@ void forge_run(Parameters params) { init_inputs(params.video_in, params.video_size); - init_context(params, in_count, frag_count); + init_context(params, in_count); if (!start_video_captures(params.video_in.length)) { return; diff --git a/src/state.c b/src/state.c index 6a2e1d3..bf31f29 100644 --- a/src/state.c +++ b/src/state.c @@ -317,6 +317,34 @@ bool state_background_midi_write(SharedContext *context, return false; } +void state_init(SharedContext *context, StateConfig state_config, bool demo, + unsigned int base_tempo) { + unsigned int i; + + context->tempo = tempo_init(); + tempo_set(&context->tempo, base_tempo); + context->demo = demo; + + context->state.length = state_config.select_frag_codes.length; + memset(context->state.values, 0, sizeof(context->state.values)); + + if (demo) { + state_randomize(context, state_config); + } + + memset(context->active, 0, sizeof(context->active)); + memset(context->values, 0, sizeof(context->values)); + + context->page = 0; + context->selected = 0; + + memset(context->seeds, 0, sizeof(context->seeds)); + + for (i = 0; i < state_config.select_frag_codes.length; i++) { + context->seeds[i] = rand_uint(1000); + } +} + void state_randomize(SharedContext *context, StateConfig state_config) { unsigned int i; diff --git a/src/state.h b/src/state.h index 3e32d29..f2a8c94 100644 --- a/src/state.h +++ b/src/state.h @@ -12,6 +12,9 @@ void state_apply_event(SharedContext *context, StateConfig state_config, bool state_background_midi_write(SharedContext *context, StateConfig state_config, MidiDevice midi); +void state_init(SharedContext *context, StateConfig state_config, bool demo, + unsigned int base_tempo); + void state_randomize(SharedContext *context, StateConfig state_config); #endif /* STATE_H */ \ No newline at end of file