diff --git a/dexed_sd.cpp b/dexed_sd.cpp index 9822c23..4b14e59 100644 --- a/dexed_sd.cpp +++ b/dexed_sd.cpp @@ -438,35 +438,35 @@ bool load_sd_voiceconfig_json(int8_t vc, uint8_t instance_id) serializeJsonPretty(data_json, Serial); Serial.println(); #endif - configuration.dexed[instance_id].lowest_note = data_json["lowest_note"][instance_id]; - configuration.dexed[instance_id].highest_note = data_json["highest_note"][instance_id]; - configuration.dexed[instance_id].transpose = data_json["transpose"][instance_id]; - configuration.dexed[instance_id].tune = data_json["tune"][instance_id]; - configuration.dexed[instance_id].sound_intensity = data_json["sound_intensity"][instance_id]; - configuration.dexed[instance_id].pan = data_json["pan"][instance_id]; - configuration.dexed[instance_id].polyphony = data_json["polyphony"][instance_id]; - configuration.dexed[instance_id].velocity_level = data_json["velocity_level"][instance_id]; - configuration.dexed[instance_id].monopoly = data_json["monopoly"][instance_id]; - configuration.dexed[instance_id].note_refresh = data_json["note_refresh"][instance_id]; - configuration.dexed[instance_id].pb_range = data_json["pb_range"][instance_id]; - configuration.dexed[instance_id].pb_step = data_json["pb_step"][instance_id]; - configuration.dexed[instance_id].mw_range = data_json["mw_range"][instance_id]; - configuration.dexed[instance_id].mw_assign = data_json["mw_assign"][instance_id]; - configuration.dexed[instance_id].mw_mode = data_json["mw_mode"][instance_id]; - configuration.dexed[instance_id].fc_range = data_json["fc_range"][instance_id]; - configuration.dexed[instance_id].fc_assign = data_json["fc_assign"][instance_id]; - configuration.dexed[instance_id].fc_mode = data_json["fc_mode"][instance_id]; - configuration.dexed[instance_id].bc_range = data_json["bc_range"][instance_id]; - configuration.dexed[instance_id].bc_assign = data_json["bc_assign"][instance_id]; - configuration.dexed[instance_id].bc_mode = data_json["bc_mode"][instance_id]; - configuration.dexed[instance_id].at_range = data_json["at_range"][instance_id]; - configuration.dexed[instance_id].at_assign = data_json["at_assign"][instance_id]; - configuration.dexed[instance_id].at_mode = data_json["at_mode"][instance_id]; - configuration.dexed[instance_id].portamento_mode = data_json["portamento_mode"][instance_id]; - configuration.dexed[instance_id].portamento_glissando = data_json["portamento_glissando"][instance_id]; - configuration.dexed[instance_id].portamento_time = data_json["portamento_time"][instance_id]; - configuration.dexed[instance_id].op_enabled = data_json["op_enabled"][instance_id]; - configuration.dexed[instance_id].midi_channel = data_json["midi_channel"][instance_id]; + configuration.dexed[instance_id].lowest_note = data_json["lowest_note"]; + configuration.dexed[instance_id].highest_note = data_json["highest_note"]; + configuration.dexed[instance_id].transpose = data_json["transpose"]; + configuration.dexed[instance_id].tune = data_json["tune"]; + configuration.dexed[instance_id].sound_intensity = data_json["sound_intensity"]; + configuration.dexed[instance_id].pan = data_json["pan"]; + configuration.dexed[instance_id].polyphony = data_json["polyphony"]; + configuration.dexed[instance_id].velocity_level = data_json["velocity_level"]; + configuration.dexed[instance_id].monopoly = data_json["monopoly"]; + configuration.dexed[instance_id].note_refresh = data_json["note_refresh"]; + configuration.dexed[instance_id].pb_range = data_json["pb_range"]; + configuration.dexed[instance_id].pb_step = data_json["pb_step"]; + configuration.dexed[instance_id].mw_range = data_json["mw_range"]; + configuration.dexed[instance_id].mw_assign = data_json["mw_assign"]; + configuration.dexed[instance_id].mw_mode = data_json["mw_mode"]; + configuration.dexed[instance_id].fc_range = data_json["fc_range"]; + configuration.dexed[instance_id].fc_assign = data_json["fc_assign"]; + configuration.dexed[instance_id].fc_mode = data_json["fc_mode"]; + configuration.dexed[instance_id].bc_range = data_json["bc_range"]; + configuration.dexed[instance_id].bc_assign = data_json["bc_assign"]; + configuration.dexed[instance_id].bc_mode = data_json["bc_mode"]; + configuration.dexed[instance_id].at_range = data_json["at_range"]; + configuration.dexed[instance_id].at_assign = data_json["at_assign"]; + configuration.dexed[instance_id].at_mode = data_json["at_mode"]; + configuration.dexed[instance_id].portamento_mode = data_json["portamento_mode"]; + configuration.dexed[instance_id].portamento_glissando = data_json["portamento_glissando"]; + configuration.dexed[instance_id].portamento_time = data_json["portamento_time"]; + configuration.dexed[instance_id].op_enabled = data_json["op_enabled"]; + configuration.dexed[instance_id].midi_channel = data_json["midi_channel"]; set_voiceconfig_params(instance_id); @@ -521,36 +521,36 @@ bool save_sd_voiceconfig_json(uint8_t vc, uint8_t instance_id) { StaticJsonDocument data_json; - data_json["lowest_note"][instance_id] = configuration.dexed[instance_id].lowest_note; - data_json["highest_note"][instance_id] = configuration.dexed[instance_id].highest_note; - data_json["transpose"][instance_id] = configuration.dexed[instance_id].transpose; - data_json["tune"][instance_id] = configuration.dexed[instance_id].tune; - data_json["sound_intensity"][instance_id] = configuration.dexed[instance_id].sound_intensity; - data_json["pan"][instance_id] = configuration.dexed[instance_id].pan; - data_json["polyphony"][instance_id] = configuration.dexed[instance_id].polyphony; - data_json["velocity_level"][instance_id] = configuration.dexed[instance_id].velocity_level; - data_json["monopoly"][instance_id] = configuration.dexed[instance_id].monopoly; - data_json["monopoly"][instance_id] = configuration.dexed[instance_id].monopoly; - data_json["note_refresh"][instance_id] = configuration.dexed[instance_id].note_refresh; - data_json["pb_range"][instance_id] = configuration.dexed[instance_id].pb_range; - data_json["pb_step"][instance_id] = configuration.dexed[instance_id].pb_step; - data_json["mw_range"][instance_id] = configuration.dexed[instance_id].mw_range; - data_json["mw_assign"][instance_id] = configuration.dexed[instance_id].mw_assign; - data_json["mw_mode"][instance_id] = configuration.dexed[instance_id].mw_mode; - data_json["fc_range"][instance_id] = configuration.dexed[instance_id].fc_range; - data_json["fc_assign"][instance_id] = configuration.dexed[instance_id].fc_assign; - data_json["fc_mode"][instance_id] = configuration.dexed[instance_id].fc_mode; - data_json["bc_range"][instance_id] = configuration.dexed[instance_id].bc_range; - data_json["bc_assign"][instance_id] = configuration.dexed[instance_id].bc_assign; - data_json["bc_mode"][instance_id] = configuration.dexed[instance_id].bc_mode; - data_json["at_range"][instance_id] = configuration.dexed[instance_id].at_range; - data_json["at_assign"][instance_id] = configuration.dexed[instance_id].at_assign; - data_json["at_mode"][instance_id] = configuration.dexed[instance_id].at_mode; - data_json["portamento_mode"][instance_id] = configuration.dexed[instance_id].portamento_mode; - data_json["portamento_glissando"][instance_id] = configuration.dexed[instance_id].portamento_glissando; - data_json["portamento_time"][instance_id] = configuration.dexed[instance_id].portamento_time; - data_json["op_enabled"][instance_id] = configuration.dexed[instance_id].op_enabled; - data_json["midi_channel"][instance_id] = configuration.dexed[instance_id].midi_channel; + data_json["lowest_note"] = configuration.dexed[instance_id].lowest_note; + data_json["highest_note"] = configuration.dexed[instance_id].highest_note; + data_json["transpose"] = configuration.dexed[instance_id].transpose; + data_json["tune"] = configuration.dexed[instance_id].tune; + data_json["sound_intensity"] = configuration.dexed[instance_id].sound_intensity; + data_json["pan"] = configuration.dexed[instance_id].pan; + data_json["polyphony"] = configuration.dexed[instance_id].polyphony; + data_json["velocity_level"] = configuration.dexed[instance_id].velocity_level; + data_json["monopoly"] = configuration.dexed[instance_id].monopoly; + data_json["monopoly"] = configuration.dexed[instance_id].monopoly; + data_json["note_refresh"] = configuration.dexed[instance_id].note_refresh; + data_json["pb_range"] = configuration.dexed[instance_id].pb_range; + data_json["pb_step"] = configuration.dexed[instance_id].pb_step; + data_json["mw_range"] = configuration.dexed[instance_id].mw_range; + data_json["mw_assign"] = configuration.dexed[instance_id].mw_assign; + data_json["mw_mode"] = configuration.dexed[instance_id].mw_mode; + data_json["fc_range"] = configuration.dexed[instance_id].fc_range; + data_json["fc_assign"] = configuration.dexed[instance_id].fc_assign; + data_json["fc_mode"] = configuration.dexed[instance_id].fc_mode; + data_json["bc_range"] = configuration.dexed[instance_id].bc_range; + data_json["bc_assign"] = configuration.dexed[instance_id].bc_assign; + data_json["bc_mode"] = configuration.dexed[instance_id].bc_mode; + data_json["at_range"] = configuration.dexed[instance_id].at_range; + data_json["at_assign"] = configuration.dexed[instance_id].at_assign; + data_json["at_mode"] = configuration.dexed[instance_id].at_mode; + data_json["portamento_mode"] = configuration.dexed[instance_id].portamento_mode; + data_json["portamento_glissando"] = configuration.dexed[instance_id].portamento_glissando; + data_json["portamento_time"] = configuration.dexed[instance_id].portamento_time; + data_json["op_enabled"] = configuration.dexed[instance_id].op_enabled; + data_json["midi_channel"] = configuration.dexed[instance_id].midi_channel; #ifdef DEBUG Serial.println(F("Write JSON data:")); @@ -797,7 +797,6 @@ bool load_sd_performance_json(int8_t p) for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) { - load_sd_voice(configuration.performance.bank[instance_id], configuration.performance.voice[instance_id], instance_id); load_sd_voiceconfig_json(configuration.performance.voiceconfig_number[instance_id], instance_id); MicroDexed[instance_id]->ControllersRefresh(); @@ -838,8 +837,6 @@ bool save_sd_performance_json(uint8_t p) { File json; - sprintf(filename, "/%s/%s%d.json", PERFORMANCE_CONFIG_PATH, PERFORMANCE_CONFIG_NAME, p); - #ifdef DEBUG Serial.print(F("Saving performance config as JSON")); Serial.print(p); @@ -848,6 +845,34 @@ bool save_sd_performance_json(uint8_t p) #endif AudioNoInterrupts(); + + // Check if voice- and fx-config exist. If not, save the actual state + sprintf(filename, "/%s/%s%d.json", FX_CONFIG_PATH, FX_CONFIG_NAME, configuration.performance.fx_number); + if (!SD.exists(filename)) + { +#ifdef DEBUG + Serial.print(F("FX-Config ")); + Serial.print(configuration.performance.fx_number); + Serial.println(F(" does not exists, creating one.")); +#endif + save_sd_performance_json(configuration.performance.fx_number); + } + for (uint8_t i = 0; i < MAX_DEXED; i++) + { + sprintf(filename, "/%s/%s%d.json", VOICE_CONFIG_PATH, VOICE_CONFIG_NAME, configuration.performance.voiceconfig_number[i]); + if (!SD.exists(filename)) + { +#ifdef DEBUG + Serial.print(F("Voice-Config ")); + Serial.print(configuration.performance.voiceconfig_number[i]); + Serial.println(F(" does not exists, creating one.")); +#endif + save_sd_voiceconfig_json(configuration.performance.voiceconfig_number[i], i); + } + } + + sprintf(filename, "/%s/%s%d.json", PERFORMANCE_CONFIG_PATH, PERFORMANCE_CONFIG_NAME, p); + json = SD.open(filename, FILE_WRITE); if (json) {