Added load/save sys functions.

Small fixes.
pull/111/head
Holger Wirtz 3 years ago
parent 87f1a072f9
commit 871b2be0b2
  1. 12
      MicroDexed.ino
  2. 6
      config.h
  3. 126
      dexed_sd.cpp
  4. 3
      dexed_sd.h

@ -737,7 +737,7 @@ void loop()
#endif
}
#ifdef TEENSY4
if (midi_decay_timer > 250)
if (midi_decay_timer > MIDI_DECAY_LEVEL_TIME)
{
midi_decay_timer = 0;
}
@ -1894,6 +1894,7 @@ void initial_values_from_eeprom(bool init)
#endif
load_sd_performance_json(eeprom_performance);
load_sd_sys_json();
}
#ifdef DEBUG
Serial.println(F("OK, loaded!"));
@ -1924,6 +1925,7 @@ void check_configuration_sys(void)
configuration.sys.mono = constrain(configuration.sys.mono, MONO_MIN, MONO_MAX);
configuration.sys.soft_midi_thru = constrain(configuration.sys.soft_midi_thru, SOFT_MIDI_THRU_MIN, SOFT_MIDI_THRU_MAX);
configuration.sys.performance_number = constrain(configuration.sys.performance_number, PERFORMANCE_NUM_MIN, PERFORMANCE_NUM_MAX);
configuration.sys.favorites = constrain(configuration.sys.favorites, FAVORITES_NUM_MIN, FAVORITES_NUM_MAX);
}
void check_configuration_fx(void)
@ -2625,10 +2627,10 @@ void check_and_create_directories(void)
if (!SD.exists(tmp))
SD.mkdir(tmp); // Set Marker so that the Cleanup loops only run once.
}
/* #ifdef DEBUG
else
Serial.println(F("No SD card for directory check available."));
#endif */
/* #ifdef DEBUG
else
Serial.println(F("No SD card for directory check available."));
#endif */
}
}

@ -321,6 +321,7 @@
#define VELOCITY_CONFIG_NAME "velocity"
#define FX_CONFIG_NAME "fx"
#define VOICE_CONFIG_NAME "voice"
#define SYS_CONFIG_NAME "sys"
#define MAX_PERF_MOD 30
@ -341,6 +342,7 @@
// Teensy-4.x settings
#ifdef TEENSY4
#define MAX_NOTES 32
#define MIDI_DECAY_LEVEL_TIME 500
#endif
// Teensy-3.6 settings
@ -669,6 +671,10 @@
#define EQ_7_MAX 18
#define EQ_7_DEFAULT 15
#define FAVORITES_NUM_MIN 0
#define FAVORITES_NUM_MAX 100
#define FAVORITES_NUM_DEFAULT 0
// Buffer-size define for load/save configuration as JSON
#define JSON_BUFFER_SIZE 8192

@ -81,6 +81,7 @@ extern void handleStop(void);
extern void handleStart(void);
extern void dac_mute(void);
extern void dac_unmute(void);
extern void check_configuration_sys(void);
extern uint8_t get_sample_note(uint8_t sample);
extern float get_sample_pitch(uint8_t sample);
extern float get_sample_p_offset(uint8_t sample);
@ -944,6 +945,129 @@ bool save_sd_fx_json(uint8_t fx)
return (false);
}
/******************************************************************************
SD SYS
******************************************************************************/
bool load_sd_sys_json(void)
{
if (sd_card > 0)
{
File json;
StaticJsonDocument<JSON_BUFFER_SIZE> data_json;
char filename[CONFIG_FILENAME_LEN];
sprintf(filename, "/%s.json", SYS_CONFIG_NAME);
// first check if file exists...
AudioNoInterrupts();
if (SD.exists(filename))
{
// ... and if: load
#ifdef DEBUG
Serial.print(F("Found sys configuration"));
#endif
json = SD.open(filename);
if (json)
{
deserializeJson(data_json, json);
json.close();
AudioInterrupts();
#ifdef DEBUG
Serial.println(F("Read JSON data:"));
serializeJsonPretty(data_json, Serial);
Serial.println();
#endif
configuration.sys.instances = data_json["instances"];
configuration.sys.vol = data_json["vol"];
configuration.sys.mono = data_json["mono"];
configuration.sys.soft_midi_thru = data_json["soft_midi_thru"];
configuration.sys.performance_number = data_json["performance_number"];
configuration.sys.favorites = data_json["favorites"];
check_configuration_sys();
//set_sys_params(); //TODO
return (true);
}
#ifdef DEBUG
else
{
Serial.print(F("E : Cannot open "));
Serial.print(filename);
Serial.println(F(" on SD."));
}
}
else
{
Serial.print(F("No "));
Serial.print(filename);
Serial.println(F(" available."));
#endif
}
}
AudioInterrupts();
return (false);
}
bool save_sd_sys_json(void)
{
char filename[CONFIG_FILENAME_LEN];
if (sd_card > 0)
{
File json;
StaticJsonDocument<JSON_BUFFER_SIZE> data_json;
sprintf(filename, "/%s.json", SYS_CONFIG_NAME);
#ifdef DEBUG
Serial.print(F("Saving sys config to "));
Serial.println(filename);
#endif
AudioNoInterrupts();
SD.begin();
SD.remove(filename);
json = SD.open(filename, FILE_WRITE);
if (json)
{
data_json["instances"] = configuration.sys.instances;
data_json["vol"] = configuration.sys.vol;
data_json["mono"] = configuration.sys.mono;
data_json["soft_midi_thru"] = configuration.sys.soft_midi_thru;
data_json["performance_number"] = configuration.sys.performance_number;
data_json["favorites"] = configuration.sys.favorites;
#ifdef DEBUG
Serial.println(F("Write JSON data:"));
serializeJsonPretty(data_json, Serial);
Serial.println();
#endif
serializeJsonPretty(data_json, json);
json.close();
AudioInterrupts();
return (true);
}
json.close();
}
else
{
#ifdef DEBUG
Serial.print(F("E : Cannot open "));
Serial.print(filename);
Serial.println(F(" on SD."));
#endif
}
AudioInterrupts();
return (false);
}
/******************************************************************************
SD SEQUENCER
******************************************************************************/
bool save_sd_seq_sub_vel_json(uint8_t seq_number)
{
char filename[CONFIG_FILENAME_LEN];
@ -1383,6 +1507,7 @@ bool load_sd_performance_json(uint8_t seq_number)
Serial.print(filename);
Serial.println(F("]... loading..."));
#endif
AudioNoInterrupts();
json = SD.open(filename);
if (json)
{
@ -1474,6 +1599,7 @@ bool load_sd_performance_json(uint8_t seq_number)
#ifdef DEBUG
else
{
AudioInterrupts();
Serial.print(F("E : Cannot open "));
Serial.print(filename);
Serial.println(F(" on SD."));

@ -57,6 +57,9 @@ bool save_sd_voiceconfig_json(uint8_t vc, uint8_t instance_id);
bool load_sd_fx_json(uint8_t fx);
bool save_sd_fx_json(uint8_t fx);
bool load_sd_sys_json(void);
bool save_sd_sys_json(void);
bool load_sd_performance_json(uint8_t p);
bool save_sd_performance_json(uint8_t p);

Loading…
Cancel
Save