Several fixes and improvements for name editing.

pull/32/head
Holger Wirtz 5 years ago
parent 315cb548c6
commit ccc37a34c5
  1. 93
      UI.hpp

@ -3637,9 +3637,9 @@ void UI_func_voice_select(uint8_t param)
char voice_name[VOICE_NAME_LEN]; char voice_name[VOICE_NAME_LEN];
if (!get_bank_name(configuration.performance.bank[selected_instance_id], bank_name, sizeof(bank_name))) if (!get_bank_name(configuration.performance.bank[selected_instance_id], bank_name, sizeof(bank_name)))
strncpy(bank_name, "*ERROR*", sizeof(bank_name)); strcpy(bank_name, "*ERROR*");
if (!get_voice_by_bank_name(configuration.performance.bank[selected_instance_id], bank_name, configuration.performance.voice[selected_instance_id], voice_name, sizeof(voice_name))) if (!get_voice_by_bank_name(configuration.performance.bank[selected_instance_id], bank_name, configuration.performance.voice[selected_instance_id], voice_name, sizeof(voice_name)))
strncpy(voice_name, "*ERROR*", sizeof(voice_name)); strcpy(voice_name, "*ERROR*");
lcd.setCursor(14, 0); lcd.setCursor(14, 0);
lcd.write(0); lcd.write(0);
@ -3756,22 +3756,22 @@ void UI_func_voice_select(uint8_t param)
if (strlen(g_bank_name[selected_instance_id]) > 0) if (strlen(g_bank_name[selected_instance_id]) > 0)
{ {
strncpy(bank_name, g_bank_name[selected_instance_id], sizeof(bank_name)); strcpy(bank_name, g_bank_name[selected_instance_id]);
} }
else else
{ {
if (!get_bank_name(configuration.performance.bank[selected_instance_id], bank_name, sizeof(bank_name))) if (!get_bank_name(configuration.performance.bank[selected_instance_id], bank_name, sizeof(bank_name)))
strncpy(bank_name, "*ERROR*", sizeof(bank_name)); strcpy(bank_name, "*ERROR*");
} }
if (strlen(g_voice_name[selected_instance_id]) > 0) if (strlen(g_voice_name[selected_instance_id]) > 0)
{ {
strncpy(voice_name, g_voice_name[selected_instance_id], sizeof(voice_name)); strcpy(voice_name, g_voice_name[selected_instance_id]);
} }
else else
{ {
if (!get_voice_by_bank_name(configuration.performance.bank[selected_instance_id], bank_name, configuration.performance.voice[selected_instance_id], voice_name, sizeof(voice_name))) if (!get_voice_by_bank_name(configuration.performance.bank[selected_instance_id], bank_name, configuration.performance.voice[selected_instance_id], voice_name, sizeof(voice_name)))
strncpy(voice_name, "*ERROR*", sizeof(voice_name)); strcpy(voice_name, "*ERROR*");
} }
lcd.show(0, 0, 2, configuration.performance.bank[selected_instance_id]); lcd.show(0, 0, 2, configuration.performance.bank[selected_instance_id]);
@ -4520,7 +4520,7 @@ void UI_func_save_voice(uint8_t param)
char bank_name[BANK_NAME_LEN]; char bank_name[BANK_NAME_LEN];
if (!get_bank_name(configuration.performance.bank[selected_instance_id], bank_name, sizeof(bank_name))) if (!get_bank_name(configuration.performance.bank[selected_instance_id], bank_name, sizeof(bank_name)))
strncpy(bank_name, "*ERROR*", sizeof(bank_name)); strcpy(bank_name, "*ERROR*");
lcd.setCursor(0, 0); lcd.setCursor(0, 0);
lcd.print(F("Save to Bank")); lcd.print(F("Save to Bank"));
@ -4565,7 +4565,7 @@ void UI_func_save_voice(uint8_t param)
configuration.performance.bank[selected_instance_id] = constrain(configuration.performance.bank[selected_instance_id] - ENCODER[ENC_R].speed(), 0, MAX_BANKS - 1); configuration.performance.bank[selected_instance_id] = constrain(configuration.performance.bank[selected_instance_id] - ENCODER[ENC_R].speed(), 0, MAX_BANKS - 1);
if (!get_bank_name(configuration.performance.bank[selected_instance_id], bank_name, sizeof(bank_name))) if (!get_bank_name(configuration.performance.bank[selected_instance_id], bank_name, sizeof(bank_name)))
strncpy(bank_name, "*ERROR*", sizeof(bank_name)); strcpy(bank_name, "*ERROR*");
lcd.show(1, 0, 2, configuration.performance.bank[selected_instance_id]); lcd.show(1, 0, 2, configuration.performance.bank[selected_instance_id]);
lcd.show(1, 4, 10, bank_name); lcd.show(1, 4, 10, bank_name);
@ -4702,7 +4702,7 @@ void UI_func_sysex_receive_bank(uint8_t param)
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
lcd.print(F("[ ]")); lcd.print(F("[ ]"));
if (!get_bank_name(configuration.performance.bank[selected_instance_id], receive_bank_filename, sizeof(receive_bank_filename))) if (!get_bank_name(configuration.performance.bank[selected_instance_id], receive_bank_filename, sizeof(receive_bank_filename)))
strncpy(receive_bank_filename, "*ERROR*", 7); strcpy(receive_bank_filename, "*ERROR*");
lcd.show(1, 1, 2, bank_number); lcd.show(1, 1, 2, bank_number);
lcd.show(1, 5, 10, receive_bank_filename); lcd.show(1, 5, 10, receive_bank_filename);
} }
@ -4718,7 +4718,7 @@ void UI_func_sysex_receive_bank(uint8_t param)
case 0: case 0:
bank_number = constrain(bank_number + ENCODER[ENC_R].speed(), 0, MAX_BANKS - 1); bank_number = constrain(bank_number + ENCODER[ENC_R].speed(), 0, MAX_BANKS - 1);
if (!get_bank_name(bank_number, receive_bank_filename, sizeof(receive_bank_filename))) if (!get_bank_name(bank_number, receive_bank_filename, sizeof(receive_bank_filename)))
strncpy(receive_bank_filename, "*ERROR*", 7); strcpy(receive_bank_filename, "*ERROR*");
lcd.show(1, 1, 2, bank_number); lcd.show(1, 1, 2, bank_number);
lcd.show(1, 5, 10, receive_bank_filename); lcd.show(1, 5, 10, receive_bank_filename);
break; break;
@ -4741,7 +4741,7 @@ void UI_func_sysex_receive_bank(uint8_t param)
case 0: case 0:
bank_number = constrain(bank_number - ENCODER[ENC_R].speed(), 0, MAX_BANKS - 1); bank_number = constrain(bank_number - ENCODER[ENC_R].speed(), 0, MAX_BANKS - 1);
if (!get_bank_name(bank_number, receive_bank_filename, sizeof(receive_bank_filename))) if (!get_bank_name(bank_number, receive_bank_filename, sizeof(receive_bank_filename)))
strncpy(receive_bank_filename, "*ERROR*", sizeof(receive_bank_filename)); strcpy(receive_bank_filename, "*ERROR*");
lcd.show(1, 1, 2, bank_number); lcd.show(1, 1, 2, bank_number);
lcd.show(1, 5, 10, receive_bank_filename); lcd.show(1, 5, 10, receive_bank_filename);
break; break;
@ -4762,11 +4762,14 @@ void UI_func_sysex_receive_bank(uint8_t param)
{ {
if (mode == 0) if (mode == 0)
{ {
if (!strncmp(receive_bank_filename, "*ERROR*", sizeof(receive_bank_filename))) if (!strcmp(receive_bank_filename, "*ERROR*"))
{ {
yesno = true; yesno = true;
strncpy(receive_bank_filename, "NONAME", 6); strcpy(receive_bank_filename, "NONAME");
mode += 2; mode = 2;
lcd.setCursor(0, 1);
lcd.print(F("[ ] "));
ui_select_name_state = UI_select_name(1, 1, receive_bank_filename, BANK_NAME_LEN - 1, true);
lcd.blink(); lcd.blink();
} }
else else
@ -4781,8 +4784,8 @@ void UI_func_sysex_receive_bank(uint8_t param)
mode = 2; mode = 2;
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
lcd.print(F("[ ] ")); lcd.print(F("[ ] "));
lcd.blink();
ui_select_name_state = UI_select_name(1, 1, receive_bank_filename, BANK_NAME_LEN - 1, true); ui_select_name_state = UI_select_name(1, 1, receive_bank_filename, BANK_NAME_LEN - 1, true);
lcd.blink();
} }
else if (mode == 2) else if (mode == 2)
{ {
@ -4797,7 +4800,7 @@ void UI_func_sysex_receive_bank(uint8_t param)
Serial.println(F("]")); Serial.println(F("]"));
#endif #endif
char tmp[FILENAME_LEN]; char tmp[FILENAME_LEN];
strncpy(tmp, receive_bank_filename, strlen(receive_bank_filename)); strcpy(tmp, receive_bank_filename);
sprintf(receive_bank_filename, "/%d/%s.syx", bank_number, tmp); sprintf(receive_bank_filename, "/%d/%s.syx", bank_number, tmp);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Receiving into bank ")); Serial.print(F("Receiving into bank "));
@ -5083,15 +5086,21 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i
static int8_t edit_pos; static int8_t edit_pos;
static bool edit_mode; static bool edit_mode;
static uint8_t edit_value; static uint8_t edit_value;
static uint8_t last_char_pos;
if (init == true) if (init == true)
{ {
lcd.setCursor(x, y);
lcd.print(edit_string);
edit_mode = false; edit_mode = false;
edit_pos = 0; edit_pos = 0;
edit_value = search_accepted_char(edit_string[edit_pos]); edit_value = search_accepted_char(edit_string[edit_pos]);
last_char_pos = strlen(edit_string);
string_trim(edit_string); // just to be sure
lcd.setCursor(x, y); lcd.setCursor(x, y);
lcd.print(edit_string);
lcd.setCursor(x, y);
return (false); return (false);
} }
@ -5105,6 +5114,9 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i
if (edit_value < sizeof(accepted_chars) - 2) if (edit_value < sizeof(accepted_chars) - 2)
edit_value++; edit_value++;
if (edit_value == 0 && edit_string[constrain(edit_pos + 1, 0, len)] > 0)
edit_value = 1;
edit_string[edit_pos] = accepted_chars[edit_value]; edit_string[edit_pos] = accepted_chars[edit_value];
lcd.setCursor(x + edit_pos, y); lcd.setCursor(x + edit_pos, y);
@ -5112,7 +5124,13 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i
} }
else else
{ {
edit_pos = constrain(edit_pos + 1, 0, len); if (edit_string[edit_pos] != 0 && edit_string[edit_pos] != 32)
edit_pos = constrain(edit_pos + 1, 0, len);
else
{
if (edit_pos + 1 > last_char_pos)
edit_pos = len;
}
if (edit_pos == len) if (edit_pos == len)
{ {
@ -5134,6 +5152,8 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i
if (edit_value >= 1) if (edit_value >= 1)
edit_value--; edit_value--;
if (edit_value == 0 && edit_string[constrain(edit_pos + 1, 0, len)] > 0)
edit_value = 1;
edit_string[edit_pos] = accepted_chars[edit_value]; edit_string[edit_pos] = accepted_chars[edit_value];
lcd.setCursor(x + edit_pos, y); lcd.setCursor(x + edit_pos, y);
@ -5141,9 +5161,12 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i
} }
else else
{ {
edit_pos = constrain(edit_pos - 1, 0, len - 1); if (edit_pos - 1 > last_char_pos)
edit_pos = last_char_pos;
else
edit_pos = constrain(edit_pos - 1, 0, len - 1);
if (edit_pos == len - 1) if (edit_pos == last_char_pos)
{ {
lcd.setCursor(x - 1, y); lcd.setCursor(x - 1, y);
lcd.print(F("[")); lcd.print(F("["));
@ -5158,18 +5181,33 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i
} }
else if (LCDML.BT_checkEnter()) else if (LCDML.BT_checkEnter())
{ {
last_char_pos = strlen(edit_string);
if (edit_pos >= len) if (edit_pos >= len)
{ {
edit_pos = 0; edit_pos = 0;
edit_mode = false; edit_mode = false;
string_trim(edit_string); //string_trim(edit_string);
return (true); return (true);
} }
else else
{ {
last_char_pos = strlen(edit_string);
edit_mode = !edit_mode; edit_mode = !edit_mode;
} }
if (edit_mode == false && edit_pos < len && edit_string[edit_pos] != 0 && edit_string[edit_pos] != 32)
edit_pos++;
if (edit_mode == true)
{
lcd.setCursor(x + len + 1, y);
lcd.print(F("*"));
}
else
{
lcd.setCursor(x + len + 1, y);
lcd.print(F(" "));
}
} }
lcd.setCursor(x + edit_pos, y); lcd.setCursor(x + edit_pos, y);
encoderDir[ENC_R].reset(); encoderDir[ENC_R].reset();
@ -5179,11 +5217,16 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i
uint8_t search_accepted_char(uint8_t c) uint8_t search_accepted_char(uint8_t c)
{ {
if (c == 0) //if (c == 0)
c = 32; // c = 32;
for (uint8_t i = 0; i < sizeof(accepted_chars); i++) for (uint8_t i = 0; i < sizeof(accepted_chars) - 1; i++)
{ {
Serial.print(i, DEC);
Serial.print(":");
Serial.print(c);
Serial.print("==");
Serial.println(accepted_chars[i], DEC);
if (c == accepted_chars[i]) if (c == accepted_chars[i])
return (i); return (i);
} }

Loading…
Cancel
Save