From b219264fcedc316ccee8235e18a41fbee9ab3036 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 20 Apr 2020 14:19:22 +0200 Subject: [PATCH] Several fixes for loading/storing voice/fx/performance. --- MicroDexed.ino | 61 ++++++++++++++++++++++++++++++++++++++++ UI.hpp | 75 +++++++++++++++++++++++--------------------------- config.h | 4 +++ dexed_sd.cpp | 17 ++++-------- 4 files changed, 105 insertions(+), 52 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 4e7d3ab..40fcf6d 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -383,6 +383,8 @@ void setup() } else { + check_and_create_directories(); + for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) { // read all bank names @@ -1767,6 +1769,65 @@ uint8_t check_sd_cards(void) return (ret); } +void check_and_create_directories(void) +{ + if (sd_card > 0) + { + uint8_t i; + char tmp[FILENAME_LEN]; + +#ifdef DEBUG + Serial.println(F("Directory check... ")); +#endif + // create directories for banks + for (i = 0; i < MAX_BANKS; i++) + { + sprintf(tmp, "/%d", i); + if (!SD.exists(tmp)) + { +#ifdef DEBUG + Serial.print(F("Creating directory ")); + Serial.println(tmp); +#endif + SD.mkdir(tmp); + } + } + + // create directories for confgiuration files + sprintf(tmp, "/%s", VOICE_CONFIG_PATH); + if (!SD.exists(tmp)) + { +#ifdef DEBUG + Serial.print(F("Creating directory ")); + Serial.println(tmp); +#endif + SD.mkdir(tmp); + } + sprintf(tmp, "/%s", PERFORMANCE_CONFIG_PATH); + if (!SD.exists(tmp)) + { +#ifdef DEBUG + Serial.print(F("Creating directory ")); + Serial.println(tmp); +#endif + SD.mkdir(tmp); + } + sprintf(tmp, "/%s", FX_CONFIG_PATH); + if (!SD.exists(tmp)) + { +#ifdef DEBUG + Serial.print(F("Creating directory ")); + Serial.println(tmp); +#endif + SD.mkdir(tmp); + } + } +#ifdef DEBUG +#else + Serial.println(F("No SD card for directory check available.")); +#endif +} + /****************************************************************************** DEBUG HELPER ******************************************************************************/ diff --git a/UI.hpp b/UI.hpp index aed00be..bf1e9a2 100644 --- a/UI.hpp +++ b/UI.hpp @@ -3350,18 +3350,16 @@ void UI_func_voice_select(uint8_t param) encoderDir[ENC_R].reset(); if (instance_id == 0) { - eeprom_update_var(offsetof(configuration_s, performance.voice[0]), configuration.performance.voice[0], "configuration.performance.voice[0]"); - eeprom_update_var(offsetof(configuration_s, performance.bank[0]), configuration.performance.bank[0], "configuration.performance.bank[0]"); - show_configuration(); - - //EEPROM.update(EEPROM_START_ADDRESS + offsetof(configuration_s, performance.voice[0]), configuration.performance.voice[0]); - //EEPROM.update(EEPROM_START_ADDRESS + offsetof(configuration_s, performance.bank[0]), configuration.performance.bank[0]); + //eeprom_update_var(offsetof(configuration_s, performance.voice[0]), configuration.performance.voice[0], "configuration.performance.voice[0]"); + //eeprom_update_var(offsetof(configuration_s, performance.bank[0]), configuration.performance.bank[0], "configuration.performance.bank[0]"); + EEPROM.update(EEPROM_START_ADDRESS + offsetof(configuration_s, performance.voice[0]), configuration.performance.voice[0]); + EEPROM.update(EEPROM_START_ADDRESS + offsetof(configuration_s, performance.bank[0]), configuration.performance.bank[0]); } #if NUM_DEXED > 1 else { - EEPROM.update(EEPROM_START_ADDRESS + offsetof(configuration_s, performance.voice[1]), configuration.performance.voice[1]); - EEPROM.update(EEPROM_START_ADDRESS + offsetof(configuration_s, performance.bank[1]), configuration.performance.bank[1]); + EEPROM.update(EEPROM_START_ADDRESS + offsetof(configuration_s, performance.voice[0]), configuration.performance.voice[1]); + EEPROM.update(EEPROM_START_ADDRESS + offsetof(configuration_s, performance.bank[0]), configuration.performance.bank[1]); } #endif } @@ -3451,13 +3449,23 @@ void UI_func_load_performance(uint8_t param) if (load_sd_performance(configuration.sys.performance_number) == false) lcd.print("Does not exist."); else + { + load_sd_voice(configuration.performance.bank[0], configuration.performance.voice[0], 0); + load_sd_voiceconfig(configuration.performance.voiceconfig_number[0], 0); + set_voiceconfig_params(0); +#if NUM_DEXED > 1 + set_voiceconfig_params(1); + load_sd_voice(configuration.performance.bank[0], configuration.performance.voice[1], 1); + load_sd_voiceconfig(configuration.performance.voiceconfig_number[1], 1); +#endif + load_sd_fx(configuration.performance.fx_number); + set_fx_params(); + lcd.print("Done. "); + } delay(500); - if (LCDML.MENU_getLastActivFunctionID() < 0xff) - LCDML.OTHER_jumpToID(LCDML.MENU_getLastActivFunctionID()); - else - LCDML.OTHER_setCursorToID(LCDML.MENU_getLastCursorPositionID()); + LCDML.FUNC_goBackToMenu(); } lcd.setCursor(0, 1); @@ -3513,7 +3521,7 @@ void UI_func_save_performance(uint8_t param) } char tmp[FILENAME_LEN]; - sprintf(tmp, "/%s%d.syx", PERFORMANCE_CONFIG_NAME, configuration.sys.performance_number); + sprintf(tmp, "/%s/%s%d.syx", PERFORMANCE_CONFIG_PATH, PERFORMANCE_CONFIG_NAME, configuration.sys.performance_number); if (SD.exists(tmp)) overwrite = true; else @@ -3554,7 +3562,7 @@ void UI_func_save_performance(uint8_t param) if (yesno == true) { char tmp[FILENAME_LEN]; - sprintf(tmp, "/%s%d.syx", PERFORMANCE_CONFIG_NAME, configuration.sys.performance_number); + sprintf(tmp, "/%s/%s%d.syx", PERFORMANCE_CONFIG_PATH, PERFORMANCE_CONFIG_NAME, configuration.sys.performance_number); SD.remove(tmp); } save_sd_performance(configuration.performance.fx_number); @@ -3563,17 +3571,14 @@ void UI_func_save_performance(uint8_t param) delay(500); } - if (LCDML.MENU_getLastActivFunctionID() < 0xff) - LCDML.OTHER_jumpToID(LCDML.MENU_getLastActivFunctionID()); - else - LCDML.OTHER_setCursorToID(LCDML.MENU_getLastCursorPositionID()); + LCDML.FUNC_goBackToMenu(); } } if (mode == 0) { char tmp[FILENAME_LEN]; - sprintf(tmp, "/%s%d.syx", PERFORMANCE_CONFIG_NAME, configuration.sys.performance_number); + sprintf(tmp, "/%s/%s%d.syx", PERFORMANCE_CONFIG_PATH, PERFORMANCE_CONFIG_NAME, configuration.sys.performance_number); if (SD.exists(tmp)) overwrite = true; else @@ -3679,10 +3684,7 @@ void UI_func_load_voiceconfig(uint8_t param) delay(500); - if (LCDML.MENU_getLastActivFunctionID() < 0xff) - LCDML.OTHER_jumpToID(LCDML.MENU_getLastActivFunctionID()); - else - LCDML.OTHER_setCursorToID(LCDML.MENU_getLastCursorPositionID()); + LCDML.FUNC_goBackToMenu(); } if (mode == 0) @@ -3759,7 +3761,7 @@ void UI_func_save_voiceconfig(uint8_t param) } char tmp[FILENAME_LEN]; - sprintf(tmp, "/%s%d.syx", VOICE_CONFIG_NAME, configuration.performance.voiceconfig_number[instance_id]); + sprintf(tmp, "/%s/%s%d.syx", VOICE_CONFIG_PATH, VOICE_CONFIG_NAME, configuration.performance.voiceconfig_number[instance_id]); if (SD.exists(tmp)) overwrite = true; else @@ -3805,7 +3807,7 @@ void UI_func_save_voiceconfig(uint8_t param) if (yesno == true) { char tmp[FILENAME_LEN]; - sprintf(tmp, "/%s%d.syx", VOICE_CONFIG_NAME, configuration.performance.voiceconfig_number[instance_id]); + sprintf(tmp, "/%s/%s%d.syx", VOICE_CONFIG_PATH, VOICE_CONFIG_NAME, configuration.performance.voiceconfig_number[instance_id]); SD.remove(tmp); } save_sd_voiceconfig(configuration.performance.voiceconfig_number[instance_id], instance_id); @@ -3814,10 +3816,7 @@ void UI_func_save_voiceconfig(uint8_t param) delay(500); } - if (LCDML.MENU_getLastActivFunctionID() < 0xff) - LCDML.OTHER_jumpToID(LCDML.MENU_getLastActivFunctionID()); - else - LCDML.OTHER_setCursorToID(LCDML.MENU_getLastCursorPositionID()); + LCDML.FUNC_goBackToMenu(); } } @@ -3829,7 +3828,7 @@ void UI_func_save_voiceconfig(uint8_t param) else if (mode == 1) { char tmp[FILENAME_LEN]; - sprintf(tmp, "/%s%d.syx", VOICE_CONFIG_NAME, configuration.performance.voiceconfig_number[instance_id]); + sprintf(tmp, "/%s/%s%d.syx", VOICE_CONFIG_PATH, VOICE_CONFIG_NAME, configuration.performance.voiceconfig_number[instance_id]); if (SD.exists(tmp)) overwrite = true; else @@ -3917,10 +3916,7 @@ void UI_func_load_fx(uint8_t param) delay(500); - if (LCDML.MENU_getLastActivFunctionID() < 0xff) - LCDML.OTHER_jumpToID(LCDML.MENU_getLastActivFunctionID()); - else - LCDML.OTHER_setCursorToID(LCDML.MENU_getLastCursorPositionID()); + LCDML.FUNC_goBackToMenu(); } lcd.setCursor(0, 1); @@ -3976,7 +3972,7 @@ void UI_func_save_fx(uint8_t param) } char tmp[FILENAME_LEN]; - sprintf(tmp, "/%s%d.syx", FX_CONFIG_NAME, configuration.performance.fx_number); + sprintf(tmp, "/%s/%s%d.syx", FX_CONFIG_PATH, FX_CONFIG_NAME, configuration.performance.fx_number); if (SD.exists(tmp)) overwrite = true; else @@ -4017,7 +4013,7 @@ void UI_func_save_fx(uint8_t param) if (yesno == true) { char tmp[FILENAME_LEN]; - sprintf(tmp, "/%s%d.syx", FX_CONFIG_NAME, configuration.performance.fx_number); + sprintf(tmp, "/%s/%s%d.syx", FX_CONFIG_PATH, FX_CONFIG_NAME, configuration.performance.fx_number); SD.remove(tmp); } save_sd_fx(configuration.performance.fx_number); @@ -4026,17 +4022,14 @@ void UI_func_save_fx(uint8_t param) delay(500); } - if (LCDML.MENU_getLastActivFunctionID() < 0xff) - LCDML.OTHER_jumpToID(LCDML.MENU_getLastActivFunctionID()); - else - LCDML.OTHER_setCursorToID(LCDML.MENU_getLastCursorPositionID()); + LCDML.FUNC_goBackToMenu(); } } if (mode == 0) { char tmp[FILENAME_LEN]; - sprintf(tmp, "/%s%d.syx", FX_CONFIG_NAME, configuration.performance.fx_number); + sprintf(tmp, "/%s/%s%d.syx", FX_CONFIG_PATH, FX_CONFIG_NAME, configuration.performance.fx_number); if (SD.exists(tmp)) overwrite = true; else diff --git a/config.h b/config.h index 72c6843..712047d 100644 --- a/config.h +++ b/config.h @@ -227,8 +227,12 @@ #define BANK_NAME_LEN 13 // FAT12 filenames (plus '\0') #define VOICE_NAME_LEN 11 // 10 (plus '\0') #define FILENAME_LEN BANK_NAME_LEN + VOICE_NAME_LEN + +#define FX_CONFIG_PATH "FXCFG" #define FX_CONFIG_NAME "FXCFG" +#define PERFORMANCE_CONFIG_PATH "PCFG" #define PERFORMANCE_CONFIG_NAME "PCFG" +#define VOICE_CONFIG_PATH "VCFG" #define VOICE_CONFIG_NAME "VCFG" //************************************************************************************************* diff --git a/dexed_sd.cpp b/dexed_sd.cpp index 781afa7..fd984ce 100644 --- a/dexed_sd.cpp +++ b/dexed_sd.cpp @@ -184,7 +184,7 @@ bool load_sd_voiceconfig(uint8_t vc, uint8_t instance_id) File sysex; char filename[FILENAME_LEN]; - sprintf(filename, "/%s%d.syx", VOICE_CONFIG_NAME, vc); + sprintf(filename, "/%s/%s%d.syx", VOICE_CONFIG_PATH, VOICE_CONFIG_NAME, vc); // first check if file exists... if (SD.exists(filename)) @@ -234,7 +234,7 @@ bool save_sd_voiceconfig(uint8_t vc, uint8_t instance_id) File sysex; char filename[FILENAME_LEN]; - sprintf(filename, "/%s%d.syx", VOICE_CONFIG_NAME, vc); + sprintf(filename, "/%s/%s%d.syx", VOICE_CONFIG_PATH, VOICE_CONFIG_NAME, vc); #ifdef DEBUG Serial.print(F("Saving voice config ")); @@ -281,7 +281,7 @@ bool load_sd_fx(uint8_t fx) File sysex; char filename[FILENAME_LEN]; - sprintf(filename, "/%s%d.syx", FX_CONFIG_NAME, fx); + sprintf(filename, "/%s/%s%d.syx", FX_CONFIG_PATH, FX_CONFIG_NAME, fx); // first check if file exists... if (SD.exists(filename)) @@ -332,7 +332,7 @@ bool save_sd_fx(uint8_t fx) File sysex; char filename[FILENAME_LEN]; - sprintf(filename, "/%s%d.syx", FX_CONFIG_NAME, fx); + sprintf(filename, "/%s/%s%d.syx", FX_CONFIG_PATH, FX_CONFIG_NAME, fx); #ifdef DEBUG Serial.print(F("Saving fx config ")); @@ -377,7 +377,7 @@ bool load_sd_performance(uint8_t p) File sysex; char filename[FILENAME_LEN]; - sprintf(filename, "/%s%d.syx", PERFORMANCE_CONFIG_NAME, p); + sprintf(filename, "/%s/%s%d.syx", PERFORMANCE_CONFIG_PATH, PERFORMANCE_CONFIG_NAME, p); // first check if file exists... if (SD.exists(filename)) @@ -426,7 +426,7 @@ bool save_sd_performance(uint8_t p) File sysex; char filename[FILENAME_LEN]; - sprintf(filename, "/%s%d.syx", PERFORMANCE_CONFIG_NAME, p); + sprintf(filename, "/%s/%s%d.syx", PERFORMANCE_CONFIG_PATH, PERFORMANCE_CONFIG_NAME, p); #ifdef DEBUG Serial.print(F("Saving performance config ")); @@ -778,11 +778,6 @@ uint8_t get_bank_names(uint8_t instance_id) File entry = root.openNextFile(); if (!entry.isDirectory()) { - while ((strncmp(entry.name(), VOICE_CONFIG_NAME, sizeof(VOICE_CONFIG_NAME) - 1) == 0)) - { - entry = root.openNextFile(); - } - strcpy(bank_names[instance_id][bank_counter], entry.name()); #ifdef DEBUG Serial.print(F("Found bank ["));