Replaced sprintf() by snprintf_P() for putting the format strings into FLASH.

Note: compiling with "Smallest code" does disable s(n)printf(_P) functions!
o you have to use "Faster"!
dev
Holger Wirtz 2 years ago
parent 2a6187349a
commit d0944d43be
  1. 84
      UI.hpp

@ -1914,7 +1914,7 @@ void getNoteName(char* noteName, uint8_t noteNumber)
uint8_t oct_index = noteNumber - 12; uint8_t oct_index = noteNumber - 12;
noteNumber -= 21; noteNumber -= 21;
sprintf(noteName, "%2s%1d", notes[noteNumber % 12], oct_index / 12); snprintf_P(noteName, strlen(noteName), PSTR("%2s%1d"), notes[noteNumber % 12], oct_index / 12);
} }
void UI_func_lowest_note(uint8_t param) void UI_func_lowest_note(uint8_t param)
@ -4362,7 +4362,7 @@ void UI_func_drum_reverb_send(uint8_t param)
display.setCursor(0, 0); display.setCursor(0, 0);
display.print("Drum Rev. Send"); display.print("Drum Rev. Send");
display.setCursor(1, 1); display.setCursor(1, 1);
sprintf(displayname, "%02d", activesample); snprintf_P(displayname, strlen(displayname), PSTR("%02d"), activesample);
display.print(displayname); display.print(displayname);
display.show(4, 5, 6, basename(drum_config[activesample].name)); display.show(4, 5, 6, basename(drum_config[activesample].name));
} }
@ -4388,7 +4388,7 @@ void UI_func_drum_reverb_send(uint8_t param)
display.print("["); display.print("[");
display.setCursor(15, 1); display.setCursor(15, 1);
display.print("]"); display.print("]");
sprintf(displayname, "%03d", temp_int); snprintf_P(displayname, strlen(displayname), PSTR("%03d"), temp_int);
display.setCursor(12, 1); display.setCursor(12, 1);
display.print(displayname); display.print(displayname);
drum_config[activesample].reverb_send = mapfloat(temp_int, 0, 100, 0.0, 1.0); drum_config[activesample].reverb_send = mapfloat(temp_int, 0, 100, 0.0, 1.0);
@ -4453,7 +4453,7 @@ void UI_func_drums_main_volume(uint8_t param)
} }
} }
display.setCursor(5, 1); display.setCursor(5, 1);
sprintf(displayname, "%03d", temp_int); snprintf_P(displayname, strlen(displayname), PSTR("%03d"), temp_int);
display.print(displayname); display.print(displayname);
display.setCursor(8, 1); display.setCursor(8, 1);
display.print("/100"); display.print("/100");
@ -4478,7 +4478,7 @@ void UI_func_drum_tune_offset(uint8_t param)
display.print("DrumSmp. Tune"); display.print("DrumSmp. Tune");
display.setCursor(1, 1); display.setCursor(1, 1);
display.setCursor(1, 1); display.setCursor(1, 1);
sprintf(displayname, "%02d", activesample); snprintf_P(displayname, strlen(displayname), PSTR("%02d"), activesample);
display.print(displayname); display.print(displayname);
display.show(1, 4, 7, basename(drum_config[activesample].name)); display.show(1, 4, 7, basename(drum_config[activesample].name));
@ -4508,7 +4508,7 @@ void UI_func_drum_tune_offset(uint8_t param)
display.print("["); display.print("[");
display.setCursor(15, 1); display.setCursor(15, 1);
display.print("]"); display.print("]");
sprintf(displayname, "%03d", temp_int); snprintf_P(displayname, strlen(displayname), PSTR("%03d"), temp_int);
display.setCursor(12, 1); display.setCursor(12, 1);
display.print(displayname); display.print(displayname);
drum_config[activesample].p_offset = temp_float; drum_config[activesample].p_offset = temp_float;
@ -4530,7 +4530,7 @@ void UI_func_drum_pitch(uint8_t param)
display.print("DrumSmp. Pitch"); display.print("DrumSmp. Pitch");
display.setCursor(1, 1); display.setCursor(1, 1);
display.setCursor(1, 1); display.setCursor(1, 1);
sprintf(displayname, "%02d", activesample); snprintf_P(displayname, strlen(displayname), PSTR("%02d"), activesample);
display.print(displayname); display.print(displayname);
display.show(1, 4, 7, basename(drum_config[activesample].name)); display.show(1, 4, 7, basename(drum_config[activesample].name));
@ -4558,7 +4558,7 @@ void UI_func_drum_pitch(uint8_t param)
display.print("["); display.print("[");
display.setCursor(15, 1); display.setCursor(15, 1);
display.print("]"); display.print("]");
sprintf(displayname, "%03d", temp_int); snprintf_P(displayname, strlen(displayname), PSTR("%03d"), temp_int);
display.setCursor(12, 1); display.setCursor(12, 1);
display.print(displayname); display.print(displayname);
drum_config[activesample].pitch = temp_float; drum_config[activesample].pitch = temp_float;
@ -4581,7 +4581,7 @@ void UI_func_drum_volume(uint8_t param)
display.print("DrumSmp. Volume"); display.print("DrumSmp. Volume");
display.setCursor(1, 1); display.setCursor(1, 1);
display.setCursor(1, 1); display.setCursor(1, 1);
sprintf(displayname, "%02d", activesample); snprintf_P(displayname, strlen(displayname), PSTR("%02d"), activesample);
display.print(displayname); display.print(displayname);
display.show(1, 4, 7, basename(drum_config[activesample].name)); display.show(1, 4, 7, basename(drum_config[activesample].name));
@ -4597,7 +4597,7 @@ void UI_func_drum_volume(uint8_t param)
display.print("["); display.print("[");
display.setCursor(15, 1); display.setCursor(15, 1);
display.print("]"); display.print("]");
sprintf(displayname, "%03d", temp_int); snprintf_P(displayname, strlen(displayname), PSTR("%03d"), temp_int);
display.setCursor(12, 1); display.setCursor(12, 1);
display.print(displayname); display.print(displayname);
drum_config[activesample].vol_max = temp_float; drum_config[activesample].vol_max = temp_float;
@ -4619,7 +4619,7 @@ void UI_func_drum_pan(uint8_t param)
display.setCursor(0, 0); display.setCursor(0, 0);
display.print("DrmSmp. Panorama"); display.print("DrmSmp. Panorama");
display.setCursor(1, 1); display.setCursor(1, 1);
sprintf(displayname, "%02d", activesample); snprintf_P(displayname, strlen(displayname), PSTR("%02d"), activesample);
display.print(displayname); display.print(displayname);
display.show(1, 4, 6, basename(drum_config[activesample].name)); display.show(1, 4, 6, basename(drum_config[activesample].name));
} }
@ -4659,7 +4659,7 @@ void UI_func_drum_pan(uint8_t param)
else { else {
display.print("C"); display.print("C");
} }
sprintf(displayname, "%02d", abs(temp_int)); snprintf_P(displayname, strlen(displayname), PSTR("%02d"), abs(temp_int));
display.setCursor(13, 1); display.setCursor(13, 1);
display.print( displayname); display.print( displayname);
} }
@ -4685,9 +4685,9 @@ void UI_func_save_performance(uint8_t param)
display.setCursor(0, 0); display.setCursor(0, 0);
display.print(F("Save Performance")); display.print(F("Save Performance"));
display.setCursor(0, 1); display.setCursor(0, 1);
sprintf(tmp, "[%2d]", temp_int); snprintf_P(tmp, strlen(tmp), PSTR("[%2d]"), temp_int);
display.print(tmp); display.print(tmp);
sprintf(tmp, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, temp_int, PERFORMANCE_CONFIG_NAME); snprintf_P(tmp, strlen(tmp), PSTR("/%s/%d/%s.json"), PERFORMANCE_CONFIG_PATH, temp_int, PERFORMANCE_CONFIG_NAME);
if (SD.exists(tmp)) if (SD.exists(tmp))
overwrite = true; overwrite = true;
else else
@ -4742,7 +4742,7 @@ void UI_func_save_performance(uint8_t param)
mode = 0; mode = 0;
display.setCursor(0, 1); display.setCursor(0, 1);
sprintf(tmp, "[%2d] ", temp_int); snprintf_P(tmp, strlen(tmp), PSTR("[%2d] "), temp_int);
display.print(tmp); display.print(tmp);
} }
} }
@ -4750,7 +4750,7 @@ void UI_func_save_performance(uint8_t param)
if (mode == 0) if (mode == 0)
{ {
char tmp[CONFIG_FILENAME_LEN]; char tmp[CONFIG_FILENAME_LEN];
sprintf(tmp, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, temp_int, PERFORMANCE_CONFIG_NAME); snprintf_P(tmp, strlen(tmp), PSTR("/%s/%d/%s.json"), PERFORMANCE_CONFIG_PATH, temp_int, PERFORMANCE_CONFIG_NAME);
if (SD.exists(tmp)) if (SD.exists(tmp))
overwrite = true; overwrite = true;
@ -4758,7 +4758,7 @@ void UI_func_save_performance(uint8_t param)
overwrite = false; overwrite = false;
display.setCursor(0, 1); display.setCursor(0, 1);
sprintf(tmp, "[%2d]", temp_int); snprintf_P(tmp, strlen(tmp), PSTR("[%2d]"), temp_int);
display.print(tmp); display.print(tmp);
display.setCursor(5, 1); display.setCursor(5, 1);
if (overwrite == false) { if (overwrite == false) {
@ -4812,7 +4812,7 @@ void UI_func_load_performance(uint8_t param)
display.setCursor(0, 0); display.setCursor(0, 0);
display.print(F("Load Performance ")); display.print(F("Load Performance "));
display.setCursor(0, 1); display.setCursor(0, 1);
sprintf(tmp, "[%2d]", param); snprintf_P(tmp, strlen(tmp), PSTR("[%2d]"), param);
display.print(tmp); display.print(tmp);
} }
if (LCDML.FUNC_loop()) // ****** LOOP ********* if (LCDML.FUNC_loop()) // ****** LOOP *********
@ -4844,7 +4844,7 @@ void UI_func_load_performance(uint8_t param)
} }
display.setCursor(0, 1); display.setCursor(0, 1);
char tmp[10]; char tmp[10];
sprintf(tmp, "[%2d]", temp_int); snprintf_P(tmp, strlen(tmp), PSTR("[%2d]"), temp_int);
display.print(tmp); display.print(tmp);
if (check_sd_performance_exists(temp_int)) if (check_sd_performance_exists(temp_int))
{ {
@ -5275,7 +5275,7 @@ void UI_func_volume(uint8_t param)
display.setCursor(0, 1); display.setCursor(0, 1);
display.print("Attack = "); display.print("Attack = ");
display.setCursor(13, 1); display.setCursor(13, 1);
sprintf(tmp, "%03d", perform_attack_mod[selected_instance_id]); snprintf_P(tmp, strlen(tmp), PSTR("%03d"), perform_attack_mod[selected_instance_id]);
display.print(tmp); display.print(tmp);
back_from_volume = 0; back_from_volume = 0;
} }
@ -5287,7 +5287,7 @@ void UI_func_volume(uint8_t param)
display.setCursor(11, 1); display.setCursor(11, 1);
display.print("Release = "); display.print("Release = ");
display.setCursor(13, 1); display.setCursor(13, 1);
sprintf(tmp, "%03d", perform_release_mod[selected_instance_id]); snprintf_P(tmp, strlen(tmp), PSTR("%03d"), perform_release_mod[selected_instance_id]);
display.print(tmp); display.print(tmp);
back_from_volume = 0; back_from_volume = 0;
} }
@ -5400,7 +5400,7 @@ void UI_func_volume(uint8_t param)
display.setCursor(0, 1); display.setCursor(0, 1);
display.print("Attack = "); display.print("Attack = ");
display.setCursor(13, 1); display.setCursor(13, 1);
sprintf(tmp, "%03d", perform_attack_mod[selected_instance_id]); snprintf_P(tmp, strlen(tmp), PSTR("%03d"), perform_attack_mod[selected_instance_id]);
display.print(tmp); display.print(tmp);
back_from_volume = 0; back_from_volume = 0;
} }
@ -5410,7 +5410,7 @@ void UI_func_volume(uint8_t param)
display.setCursor(0, 1); display.setCursor(0, 1);
display.print("Release = "); display.print("Release = ");
display.setCursor(13, 1); display.setCursor(13, 1);
sprintf(tmp, "%03d", perform_release_mod[selected_instance_id]); snprintf_P(tmp, strlen(tmp), PSTR("%03d"), perform_release_mod[selected_instance_id]);
display.print(tmp); display.print(tmp);
back_from_volume = 0; back_from_volume = 0;
} }
@ -5720,7 +5720,7 @@ void UI_func_sysex_receive_bank(uint8_t param)
#endif #endif
char tmp[CONFIG_FILENAME_LEN]; char tmp[CONFIG_FILENAME_LEN];
strcpy(tmp, receive_bank_filename); strcpy(tmp, receive_bank_filename);
sprintf(receive_bank_filename, "/%d/%s.syx", bank_number, tmp); snprintf_P(receive_bank_filename, strlen(receive_bank_filename), PSTR("/%d/%s.syx"), bank_number, tmp);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Receiving into bank ")); Serial.print(F("Receiving into bank "));
Serial.print(bank_number); Serial.print(bank_number);
@ -5878,7 +5878,7 @@ void UI_func_sysex_send_bank(uint8_t param)
if (get_bank_name(bank_number, bank_name, sizeof(bank_name))) if (get_bank_name(bank_number, bank_name, sizeof(bank_name)))
{ {
sprintf(filename, "/%d/%s.syx", bank_number, bank_name); snprintf_P(filename, strlen(filename), PSTR("/%d/%s.syx"), bank_number, bank_name);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Send bank ")); Serial.print(F("Send bank "));
Serial.print(filename); Serial.print(filename);
@ -6022,7 +6022,7 @@ void UI_func_sysex_send_voice(uint8_t param)
if (get_bank_name(bank_number, bank_name, sizeof(bank_name))) if (get_bank_name(bank_number, bank_name, sizeof(bank_name)))
{ {
sprintf(filename, "/%d/%s.syx", bank_number, bank_name); snprintf_P(filename, strlen(filename), PSTR("/%d/%s.syx"), bank_number, bank_name);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Send voice ")); Serial.print(F("Send voice "));
Serial.print(voice_number); Serial.print(voice_number);
@ -6710,24 +6710,24 @@ void display_float(float var, uint8_t size_number, uint8_t size_fraction, bool z
if (size_fraction > 0) if (size_fraction > 0)
{ {
if (zeros == true && sign == true) if (zeros == true && sign == true)
sprintf(s, "%+0*.*f", size_number + size_fraction + 2, size_fraction, var); snprintf_P(s, strlen(s), PSTR("%+0*.*f"), size_number + size_fraction + 2, size_fraction, var);
else if (zeros == true && sign == false) else if (zeros == true && sign == false)
sprintf(s, "%0*.*f", size_number + size_fraction + 1, size_fraction, var); snprintf_P(s, strlen(s), PSTR("%0*.*f"), size_number + size_fraction + 1, size_fraction, var);
else if (zeros == false && sign == true) else if (zeros == false && sign == true)
sprintf(s, "%+*.*f", size_number + size_fraction + 2, size_fraction, var); snprintf_P(s, strlen(s), PSTR("%+*.*f"), size_number + size_fraction + 2, size_fraction, var);
else if (zeros == false && sign == false) else if (zeros == false && sign == false)
sprintf(s, "%*.*f", size_number + size_fraction + 1, size_fraction, var); snprintf_P(s, strlen(s), PSTR("%*.*f"), size_number + size_fraction + 1, size_fraction, var);
} }
else else
{ {
if (zeros == true && sign == true) if (zeros == true && sign == true)
sprintf(s, "%+0*d", size_number + 1, var); snprintf_P(s, strlen(s), PSTR("%+0*d"), size_number + 1, var);
else if (zeros == true && sign == false) else if (zeros == true && sign == false)
sprintf(s, "%0*d", size_number, var); snprintf_P(s, strlen(s), PSTR("%0*d"), size_number, var);
else if (zeros == false && sign == true) else if (zeros == false && sign == true)
sprintf(s, "%+*d", size_number + 1, var); snprintf_P(s, strlen(s), PSTR("%+*d"), size_number + 1, var);
else if (zeros == false && sign == false) else if (zeros == false && sign == false)
sprintf(s, "%*d", size_number, var); snprintf_P(s, strlen(s), PSTR("%*d"), size_number, var);
} }
if (brackets == true) if (brackets == true)
@ -6735,7 +6735,7 @@ void display_float(float var, uint8_t size_number, uint8_t size_fraction, bool z
char tmp[LCD_cols + 1]; char tmp[LCD_cols + 1];
strcpy(tmp, s); strcpy(tmp, s);
sprintf(s, "[%s]", tmp); snprintf_P(s, strlen(s), PSTR("[%s]"), tmp);
} }
Serial.println(var); Serial.println(var);
@ -7280,7 +7280,7 @@ bool check_favorite(uint8_t b, uint8_t v, uint8_t instance_id)
File myFav; File myFav;
if (sd_card > 0) if (sd_card > 0)
{ {
sprintf(tmp, "/%s/%d/%d.fav", FAV_CONFIG_PATH, b, v); snprintf_P(tmp, strlen(tmp), PSTR("/%s/%d/%d.fav"), FAV_CONFIG_PATH, b, v);
#ifdef DEBUG #ifdef DEBUG
Serial.print("check if Voice is a Favorite: "); Serial.print("check if Voice is a Favorite: ");
Serial.print(tmp); Serial.print(tmp);
@ -7314,7 +7314,7 @@ void draw_favorite_icon(uint8_t b, uint8_t v, uint8_t instance_id)
File myFav; File myFav;
if (sd_card > 0) if (sd_card > 0)
{ {
sprintf(tmp, "/%s/%d/%d.fav", FAV_CONFIG_PATH, b, v); snprintf_P(tmp, strlen(tmp), PSTR("/%s/%d/%d.fav"), FAV_CONFIG_PATH, b, v);
if (SD.exists(tmp)) if (SD.exists(tmp))
{ //is Favorite { //is Favorite
#ifdef TESTDISPLAY20x4 #ifdef TESTDISPLAY20x4
@ -7343,7 +7343,7 @@ bool quick_check_favorites_in_bank(uint8_t b, uint8_t instance_id)
if (sd_card > 0) if (sd_card > 0)
{ {
sprintf(tmp, "/%s/%d", FAV_CONFIG_PATH, b); snprintf_P(tmp, strlen(tmp), PSTR("/%s/%d"), FAV_CONFIG_PATH, b);
#ifdef DEBUG #ifdef DEBUG
Serial.print("check if there is a Favorite in Bank: "); Serial.print("check if there is a Favorite in Bank: ");
Serial.print(tmp); Serial.print(tmp);
@ -7381,8 +7381,8 @@ void save_favorite(uint8_t b, uint8_t v, uint8_t instance_id)
uint8_t i = 0, countfavs = 0; uint8_t i = 0, countfavs = 0;
if (sd_card > 0) if (sd_card > 0)
{ {
sprintf(tmp, "/%s/%d/%d.fav", FAV_CONFIG_PATH, b, v); snprintf_P(tmp, strlen(tmp), PSTR("/%s/%d/%d.fav"), FAV_CONFIG_PATH, b, v);
sprintf(tmpfolder, "/%s/%d", FAV_CONFIG_PATH, b); snprintf_P(tmpfolder, strlen(tmpfolder), PSTR("/%s/%d"), FAV_CONFIG_PATH, b);
#ifdef DEBUG #ifdef DEBUG
Serial.println("Save Favorite to SD card..."); Serial.println("Save Favorite to SD card...");
Serial.println(tmp); Serial.println(tmp);
@ -7413,11 +7413,11 @@ void save_favorite(uint8_t b, uint8_t v, uint8_t instance_id)
Serial.println("Removed from Favorites..."); Serial.println("Removed from Favorites...");
#endif #endif
for (i = 0; i < 32; i++) { //if no other favs exist in current bank, remove folder for (i = 0; i < 32; i++) { //if no other favs exist in current bank, remove folder
sprintf(tmp, "/%s/%d/%d.fav", FAV_CONFIG_PATH, b, i); snprintf_P(tmp, strlen(tmp), PSTR("/%s/%d/%d.fav"), FAV_CONFIG_PATH, b, i);
if (SD.exists(tmp)) countfavs++; if (SD.exists(tmp)) countfavs++;
} }
if (countfavs == 0) { if (countfavs == 0) {
sprintf(tmp, "/%s/%d", FAV_CONFIG_PATH, b); snprintf_P(tmp, strlen(tmp), PSTR("/%s/%d"), FAV_CONFIG_PATH, b);
SD.rmdir(tmp); SD.rmdir(tmp);
#ifdef DEBUG #ifdef DEBUG
Serial.println("Fav count in bank:"); Serial.println("Fav count in bank:");

Loading…
Cancel
Save