refactor(state): state_init

This commit is contained in:
2025-11-01 19:30:38 +01:00
parent 129ea6547f
commit 23f4ce27ee
4 changed files with 37 additions and 27 deletions
+28
View File
@@ -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;