From cee32d9462bab36c8d4e0021b6e8bad7d8cfce3f Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 14 Oct 2021 17:28:04 +0200 Subject: [PATCH] Fixing several errors while saving a performance. Fixing allover volume. --- MicroDexed.ino | 20 ++++++- UI.hpp | 12 ++-- config.h | 2 + dexed_sd.cpp | 145 ++++++++++++++++++++++++++++++++++--------------- dexed_sd.h | 2 + 5 files changed, 128 insertions(+), 53 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index d28409c..26f6d82 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -418,7 +418,7 @@ void setup() sgtl5000.enable(); sgtl5000.lineOutLevel(SGTL5000_LINEOUT_LEVEL); sgtl5000.dacVolumeRamp(); - sgtl5000.dacVolume(1.0); + //sgtl5000.dacVolume(1.0); // doing this at the end of setup() //sgtl5000.dacVolumeRampLinear(); //sgtl5000.dacVolumeRampDisable(); sgtl5000.unmuteHeadphone(); @@ -645,6 +645,10 @@ void setup() strcpy(seq_name, "INIT Perf"); LCDML.OTHER_jumpToFunc(UI_func_voice_select); + +#if defined(TEENSY_AUDIO_BOARD) + sgtl5000.dacVolume(1.0); +#endif } void loop() @@ -1873,8 +1877,8 @@ void set_volume(uint8_t v, uint8_t m) Serial.println(volume_transform(tmp_v / 100.0)); #endif - volume_r.gain(volume_transform(tmp_v / 100.0)); - volume_l.gain(volume_transform(tmp_v / 100.0)); + volume_r.gain(volume_transform(tmp_v / 100.0)*VOLUME_MULTIPLIER); + volume_l.gain(volume_transform(tmp_v / 100.0)*VOLUME_MULTIPLIER); switch (m) { @@ -2576,6 +2580,16 @@ void check_and_create_directories(void) } } + sprintf(tmp, "/%s", PERFORMANCE_CONFIG_PATH); + if (!SD.exists(tmp)) + { +#ifdef DEBUG + Serial.print(F("Creating directory ")); + Serial.println(tmp); +#endif + SD.mkdir(tmp); + } + /* // create directories for configuration files sprintf(tmp, "/%s", VOICE_CONFIG_PATH); diff --git a/UI.hpp b/UI.hpp index a4e185e..3a5fc76 100644 --- a/UI.hpp +++ b/UI.hpp @@ -6220,7 +6220,7 @@ void UI_func_load_performance(uint8_t param) mode = 0; encoderDir[ENC_R].reset(); lcd.setCursor(0, 0); - lcd.print(F("Load Seq. state ")); + lcd.print(F("Load Performance ")); lcd.setCursor(0, 1); sprintf(tmp, "[%2d]", param); lcd.print(tmp); @@ -6295,11 +6295,11 @@ void UI_func_save_performance(uint8_t param) mode = 0; encoderDir[ENC_R].reset(); lcd.setCursor(0, 0); - lcd.print(F("Save Seq. state:")); + lcd.print(F("Save Performance")); lcd.setCursor(0, 1); sprintf(tmp, "[%2d]", temp_int); lcd.print(tmp); - sprintf(tmp, "/%s/%d-S.json", PERFORMANCE_CONFIG_PATH, temp_int); + sprintf(tmp, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, temp_int, PERFORMANCE_CONFIG_NAME); if (SD.exists(tmp)) overwrite = true; else @@ -6347,7 +6347,7 @@ void UI_func_save_performance(uint8_t param) if (yesno == true) { char tmp[FILENAME_LEN]; - sprintf(tmp, "/%s/%d-S.json", PERFORMANCE_CONFIG_PATH, temp_int); + sprintf(tmp, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, temp_int, PERFORMANCE_CONFIG_NAME); SD.remove(tmp); } save_sd_performance_json(temp_int); @@ -6370,7 +6370,7 @@ void UI_func_save_performance(uint8_t param) if (mode == 0) { char tmp[FILENAME_LEN]; - sprintf(tmp, "/%s/%d-S.json", PERFORMANCE_CONFIG_PATH, temp_int); + sprintf(tmp, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, temp_int, PERFORMANCE_CONFIG_NAME); if (SD.exists(tmp)) overwrite = true; else @@ -6381,7 +6381,7 @@ void UI_func_save_performance(uint8_t param) lcd.print(tmp); lcd.setCursor(5, 1); if (overwrite == false) { - lcd.print("-- empty --"); + lcd.print("-- EMPTY --"); } else if (check_sd_performance_exists(temp_int)) { get_sd_performance_name_json(temp_int); diff --git a/config.h b/config.h index 963b354..eb29dc3 100644 --- a/config.h +++ b/config.h @@ -676,6 +676,8 @@ #define FAVORITES_NUM_MAX 100 #define FAVORITES_NUM_DEFAULT 0 +#define VOLUME_MULTIPLIER 1.3 + // Buffer-size define for load/save configuration as JSON #define JSON_BUFFER_SIZE 8192 diff --git a/dexed_sd.cpp b/dexed_sd.cpp index 9049fe6..85d84c8 100644 --- a/dexed_sd.cpp +++ b/dexed_sd.cpp @@ -537,55 +537,69 @@ bool save_sd_drumsettings_json(uint8_t number) File json; StaticJsonDocument data_json; - sprintf(filename, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, number, DRUMS_CONFIG_NAME); + if (check_performance_directory(number)) + { + sprintf(filename, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, number, DRUMS_CONFIG_NAME); #ifdef DEBUG - Serial.print(F("Saving drums config ")); - Serial.print(number); - Serial.print(F(" to ")); - Serial.println(filename); + Serial.print(F("Saving drums config ")); + Serial.print(number); + Serial.print(F(" to ")); + Serial.println(filename); #endif - AudioNoInterrupts(); - if (SD.exists(filename)) { - Serial.println("remove old drumsettings file"); - SD.begin(); - SD.remove(filename); - } - json = SD.open(filename, FILE_WRITE); - if (json) - { - data_json["drums_volume"] = drums_volume; - for (uint8_t i = 0; i < NUM_DRUMSET_CONFIG - 1; i++) + AudioNoInterrupts(); + if (SD.exists(filename)) { + Serial.println("remove old drumsettings file"); + SD.begin(); + SD.remove(filename); + } + json = SD.open(filename, FILE_WRITE); + if (json) { - data_json["note"][i] = get_sample_note(i); - data_json["pitch"][i] = get_sample_pitch(i); - data_json["p_offset"][i] = get_sample_p_offset(i); - data_json["pan"][i] = get_sample_pan(i); - data_json["vol_max"][i] = get_sample_vol_max(i); - data_json["vol_min"][i] = get_sample_vol_min(i); - data_json["reverb_send"][i] = get_sample_reverb_send(i); + data_json["drums_volume"] = drums_volume; + for (uint8_t i = 0; i < NUM_DRUMSET_CONFIG - 1; i++) + { + data_json["note"][i] = get_sample_note(i); + data_json["pitch"][i] = get_sample_pitch(i); + data_json["p_offset"][i] = get_sample_p_offset(i); + data_json["pan"][i] = get_sample_pan(i); + data_json["vol_max"][i] = get_sample_vol_max(i); + data_json["vol_min"][i] = get_sample_vol_min(i); + data_json["reverb_send"][i] = get_sample_reverb_send(i); + } +#ifdef DEBUG + Serial.println(F("Write JSON data:")); + serializeJsonPretty(data_json, Serial); + Serial.println(); +#endif + serializeJsonPretty(data_json, json); + json.close(); + AudioInterrupts(); + return (true); } + else + { #ifdef DEBUG - Serial.println(F("Write JSON data:")); - serializeJsonPretty(data_json, Serial); - Serial.println(); + Serial.print(F("E : Cannot open ")); + Serial.print(filename); + Serial.println(F(" on SD.")); #endif - serializeJsonPretty(data_json, json); - json.close(); + AudioInterrupts(); + return (false); + } + } + else + { AudioInterrupts(); - return (true); + return (false); } - json.close(); - AudioInterrupts(); } +#ifdef DEBUG else { -#ifdef DEBUG - Serial.print(F("E : Cannot open ")); - Serial.print(filename); - Serial.println(F(" on SD.")); -#endif + Serial.println(F("E: SD card not available")); } +#endif return (false); } @@ -694,7 +708,7 @@ bool save_sd_voiceconfig_json(uint8_t vc, uint8_t instance_id) { File json; StaticJsonDocument data_json; - sprintf(filename, "/%s/%d/%s%d.json", PERFORMANCE_CONFIG_PATH, vc, VOICE_CONFIG_NAME, instance_id); + sprintf(filename, "/%s/%d/%s%d.json", PERFORMANCE_CONFIG_PATH, vc, VOICE_CONFIG_NAME, instance_id + 1); #ifdef DEBUG Serial.print(F("Saving voice config ")); @@ -1134,7 +1148,7 @@ bool save_sd_seq_sub_patterns_json(uint8_t seq_number) { File json; StaticJsonDocument data_json; - sprintf(filename, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, seq_number, VELOCITY_CONFIG_NAME); + sprintf(filename, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, seq_number, PATTERN_CONFIG_NAME); #ifdef DEBUG Serial.print(F("Saving sequencer patterns ")); Serial.print(seq_number); @@ -1192,22 +1206,24 @@ bool save_sd_performance_json(uint8_t seq_number) handleStop(); } dac_mute(); + AudioNoInterrupts(); + save_sd_seq_sub_vel_json(seq_number); save_sd_seq_sub_patterns_json(seq_number); + #ifdef DEBUG Serial.print(F("Write performance config ")); - Serial.print(seq_number); - Serial.print(F(" ")); + Serial.println(seq_number); #endif + save_sd_fx_json(seq_number); for (uint8_t i = 0; i < MAX_DEXED; i++) { sprintf(filename, "/%s/%d/%s%d.json", PERFORMANCE_CONFIG_PATH, seq_number, VOICE_CONFIG_NAME, i); #ifdef DEBUG Serial.print(F("Write Voice-Config for sequencer")); - Serial.print(filename); - Serial.print(F(" ")); + Serial.println(filename); #endif save_sd_voiceconfig_json(seq_number, i); } @@ -1226,7 +1242,6 @@ bool save_sd_performance_json(uint8_t seq_number) int columns = sizeof(seq_patternchain[0]); int rows = total / columns; Serial.print(F(" ")); - SD.begin(); SD.remove(filename); json = SD.open(filename, FILE_WRITE); if (json) @@ -1290,14 +1305,56 @@ bool save_sd_performance_json(uint8_t seq_number) } json.close(); } +#ifdef DEBUG else { -#ifdef DEBUG Serial.print(F("E : Cannot open ")); Serial.print(filename); Serial.println(F(" on SD.")); + } #endif + + return (false); +} + +bool check_performance_directory(uint8_t seq_number) +{ + char dir[CONFIG_FILENAME_LEN]; + + if (sd_card > 0) + { + sprintf(dir, "/%s/%d", PERFORMANCE_CONFIG_PATH, seq_number); + + AudioNoInterrupts(); + SD.begin(); + if (!SD.exists(dir)) + { +#ifdef DEBUG + if (SD.mkdir(dir)) + { + Serial.print(F("Creating directory ")); + Serial.println(dir); + } + else + { + Serial.print(F("E: Cannot create ")); + Serial.println(dir); + AudioInterrupts(); + return (false); + } +#else + SD.mkdir(dir); +#endif + } + AudioInterrupts(); + return (true); } +#ifdef DEBUG + else + { + Serial.println(F("E: SD card not available")); + } +#endif return (false); } diff --git a/dexed_sd.h b/dexed_sd.h index 08e2b51..28f17b2 100644 --- a/dexed_sd.h +++ b/dexed_sd.h @@ -66,6 +66,8 @@ bool save_sd_performance_json(uint8_t p); bool load_sd_seq_json(uint8_t p); bool save_sd_seq_json(uint8_t p); +bool check_performance_directory(uint8_t seq_number); + bool get_sd_data(File sysex, uint8_t format, uint8_t* conf); bool write_sd_data(File sysex, uint8_t format, uint8_t* data, uint16_t len);