From a9e20ca7a0adb556a3fac74e10b67918e8de0974 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sat, 9 Oct 2021 18:05:29 +0200 Subject: [PATCH] Adding auto-store for configuration.sys (only when no voice is playing and after the last change of data) (currently only when volume changes). --- MicroDexed.ino | 43 +++++++++++++++++++++++++++++++++++++++++-- UI.hpp | 4 +++- config.h | 1 + 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 1438745..01fd586 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -302,6 +302,7 @@ int16_t _midi_bpm = -1; elapsedMillis midi_bpm_timer; elapsedMillis long_button_pressed; elapsedMillis control_rate; +elapsedMillis save_sys; uint8_t active_voices[NUM_DEXED]; uint8_t midi_voices[NUM_DEXED]; #ifdef SHOW_CPU_LOAD_MSEC @@ -562,7 +563,7 @@ void setup() timer1.begin(sequencer, seq_tempo_ms / 2, false); // Load initial Performance or the last used one - initial_values_from_eeprom(false); + initial_values(false); #ifdef DISPLAY_LCD_SPI change_disp_sd(true); @@ -689,6 +690,7 @@ void loop() } } } + // CONTROL-RATE-EVENT-HANDLING if (control_rate > CONTROL_RATE_MS) { @@ -747,6 +749,43 @@ void loop() else yield(); + // SAVE-SYS-EVENT-HANDLING + if (save_sys > SAVE_SYS_MS) + { +#ifdef DEBUG + Serial.println(F("Check if we can save configuration.sys")); +#endif + bool instance_is_playing = false; + for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) + { + if (active_voices[instance_id] > 0) + { + instance_is_playing = true; + break; + } + } + if (instance_is_playing == false) + { + for (uint8_t instance_id = 0; instance_id < NUM_DRUMS; instance_id++) + { + if (Drum[instance_id]->isPlaying()) + { + instance_is_playing = true; + break; + } + } + } + if (instance_is_playing == false) + save_sd_sys_json(); + else + { +#ifdef DEBUG + Serial.println(F("System is playing, next try...")); +#endif + save_sys = 0; + } + } + #if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC) if (cpu_mem_millis >= SHOW_CPU_LOAD_MSEC) { @@ -1867,7 +1906,7 @@ void set_volume(uint8_t v, uint8_t m) EEPROM HELPER ******************************************************************************/ -void initial_values_from_eeprom(bool init) +void initial_values(bool init) { uint16_t _m_; diff --git a/UI.hpp b/UI.hpp index 654f177..1a94be8 100644 --- a/UI.hpp +++ b/UI.hpp @@ -162,6 +162,7 @@ extern uint8_t midi_bpm; GLOBAL ************************************************************************/ elapsedMillis back_from_volume; +extern elapsedMillis save_sys; uint8_t instance_num[8][8]; const char accepted_chars[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-abcdefghijklmnopqrstuvwxyz"; const char noteNames[12][3] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" }; @@ -7014,7 +7015,8 @@ void UI_func_volume(uint8_t param) lcd_special_chars(SCROLLBAR); encoderDir[ENC_L].reset(); - EEPROM.update(EEPROM_START_ADDRESS + 3, configuration.sys.vol); + //EEPROM.update(EEPROM_START_ADDRESS + 3, configuration.sys.vol); + save_sys = 0; } } diff --git a/config.h b/config.h index da1b2d0..f3715cc 100644 --- a/config.h +++ b/config.h @@ -330,6 +330,7 @@ //************************************************************************************************* #define MAX_DEXED 2 // No! - even don't think about increasing this number! IT _WILL_ PRODUCE MASSIVE PROBLEMS! #define CONTROL_RATE_MS 50 +#define SAVE_SYS_MS 5000 #define VOL_MAX_FLOAT 0.95 #define EEPROM_MARKER 0x4242