diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 472eca4..4f719da 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -113,7 +113,7 @@ make -f Makefile.dev release-arch - [x] Documentation in default config file - [x] Clone "shaders" and config in system path at setup - [ ] Minimal sample shaders - - [ ] Hotkey `0` to reset everything + - [x] Hotkey `0` to reset everything - [x] Printable PDF of default scr/fx - [x] Add NanoKontrol setup file - [x] Find and fix opengl errors 0500 ? diff --git a/README.md b/README.md index 56e6de2..8ad9000 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,8 @@ make install When running, the following hotkeys are available: * Esc: Exit window -* R: Randomize shader state +* R: Randomize internal values +* 0: Reset internal values to 0 * D: Demo mode On/Off * A: Auto Random mode On/Off diff --git a/src/forge.c b/src/forge.c index 02b2c23..5292f48 100644 --- a/src/forge.c +++ b/src/forge.c @@ -125,8 +125,14 @@ static void key_callback(Window *window, int key, window_close(window); } else if (window_char_key(key, action, 82)) { // R: randomize - log_info("[R] Randomizing..."); + log_info("[R] Randomized"); state_randomize(context, &project.state_config); + state_apply(context, &project.state_config, &midi); + } else if (window_char_key(key, action, 48)) { + // 0: reset + log_info("[0] Reset"); + state_reset(context); + state_apply(context, &project.state_config, &midi); } else if (window_char_key(key, action, 68)) { // D: demo on/off log_info((context->demo ? "[D] Demo OFF" : "[D] Demo ON")); diff --git a/src/state.c b/src/state.c index ba332be..bd7552f 100644 --- a/src/state.c +++ b/src/state.c @@ -279,6 +279,13 @@ void state_apply_event(SharedContext *context, const StateConfig *state_config, } } +void state_apply(SharedContext *context, const StateConfig *state_config, + const MidiDevice *midi) { + if (!midi->error) { + update_values(context, state_config, midi); + } +} + bool state_background_write(SharedContext *context, const StateConfig *state_config, const MidiDevice *midi) { @@ -322,6 +329,8 @@ bool state_background_write(SharedContext *context, if (context->auto_random && change && !last_change) { state_randomize(context, state_config); + + state_apply(context, state_config, midi); } last_change = change; @@ -403,7 +412,17 @@ void state_init(SharedContext *context, const StateConfig *state_config, } } +void state_reset(SharedContext *context) { + memset(context->values, 0, sizeof(context->values)); + memset(context->state.values, 0, sizeof(context->state.values)); +} + void state_randomize(SharedContext *context, const StateConfig *state_config) { + for (unsigned int i = 0; i < state_config->midi_codes.length; i++) { + context->values[i][0] = (float)rand_uint(MIDI_MAX) / MIDI_MAX; + context->values[i][1] = (float)rand_uint(MIDI_MAX) / MIDI_MAX; + context->values[i][2] = (float)rand_uint(MIDI_MAX) / MIDI_MAX; + } for (unsigned int i = 0; i < context->state.length; i++) { context->state.values[i] = rand_uint(state_config->state_max); } diff --git a/src/state.h b/src/state.h index b21258d..2ad1df8 100644 --- a/src/state.h +++ b/src/state.h @@ -17,8 +17,13 @@ void state_init(SharedContext *context, const StateConfig *state_config, bool demo, bool auto_random, unsigned int base_tempo, const char *state_file, bool load_state); +void state_reset(SharedContext *context); + void state_randomize(SharedContext *context, const StateConfig *state_config); +void state_apply(SharedContext *context, const StateConfig *state_config, + const MidiDevice *midi); + void state_save(const SharedContext *context, const StateConfig *state_config, const char *state_file);