From 5de7b39670c17718b875c422f9879cd81e5b09a5 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sun, 25 Dec 2022 18:48:56 +0100 Subject: [PATCH] Save the state. --- UI.hpp | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- config.h | 3 +- 2 files changed, 123 insertions(+), 4 deletions(-) diff --git a/UI.hpp b/UI.hpp index 929b519..a7325ff 100644 --- a/UI.hpp +++ b/UI.hpp @@ -4003,6 +4003,41 @@ void _check_display_name(bool display_name, uint8_t digits) { } } +void _check_display_name_min_max(uint8_t display_name, uint8_t digits) { + switch (display_name) { + case 0: + display.setCursor(0, 1); + display.print(F("[")); + display.setCursor(9, 1); + display.print(F("]")); + display.setCursor(LCD_cols - digits - 2, 1); + display.print(F(" ")); + display.setCursor(LCD_cols - 1, 1); + display.print(F(" ")); + break; + case 1: + display.setCursor(0, 1); + display.print(F(" ")); + display.setCursor(9, 1); + display.print(F(" ")); + display.setCursor(LCD_cols - digits - 2, 1); + display.print(F("[")); + display.setCursor(LCD_cols - 1, 1); + display.print(F("]")); + break; + case 2: + display.setCursor(0, 1); + display.print(F(" ")); + display.setCursor(9, 1); + display.print(F(" ")); + display.setCursor(LCD_cols - digits - 2, 1); + display.print(F("[")); + display.setCursor(LCD_cols - 1, 1); + display.print(F("]")); + break; + } +} + void UI_func_drum_midi_channel(uint8_t param) { if (LCDML.FUNC_setup()) // ****** SETUP ********* { @@ -4142,7 +4177,92 @@ void UI_func_drum_pitch(uint8_t param) { } void UI_func_drum_vol_min_max(uint8_t param) { - ; + static uint8_t input_mode; + static uint8_t input_type; + char tmp_val[5]; + char tmp_name[9]; + + if (LCDML.FUNC_setup()) // ****** SETUP ********* + { + midi_learn_mode = MIDI_LEARN_MODE_ON; + + memset(tmp_name, ' ', 8); + strncpy(tmp_name, drum_config[active_sample].name, strlen(drum_config[active_sample].name)); + tmp_name[8] = '\0'; + + display.setCursor(0, 0); + display.print(F("Vol [Min]/ Max ")); + display.setCursor(1, 1); + display.print(tmp_name); + display.setCursor(LCD_cols - 5, 1); + snprintf_P(tmp_val, sizeof(tmp_val), PSTR("%4.1f"), configuration.drums.pitch[active_sample] / 10.0); + display.print(tmp_val); + _check_display_name_min_max(input_mode, 4); + } + + if (LCDML.FUNC_loop()) // ****** LOOP ********* + { + if ((LCDML.BT_checkDown() && encoderDir[ENC_R].Down()) || (LCDML.BT_checkUp() && encoderDir[ENC_R].Up()) || (LCDML.BT_checkEnter() && encoderDir[ENC_R].ButtonShort())) { + if (LCDML.BT_checkDown()) { + switch (input_mode) { + case 0: + if (active_sample < NUM_DRUMSET_CONFIG - 2) { + active_sample++; + display.setCursor(LCD_cols - 5, 1); + snprintf_P(tmp_val, sizeof(tmp_val), PSTR("%4.1f"), configuration.drums.pitch[active_sample] / 10.0); + display.print(tmp_val); + } + break; + case 1: + configuration.drums.pitch[active_sample] = constrain(configuration.drums.pitch[active_sample] + ENCODER[ENC_L].speed(), DRUMS_PITCH_MIN, DRUMS_PITCH_MAX); + break; + case 2: + break; + } + } else if (LCDML.BT_checkUp()) { + switch (input_mode) { + case 0: + if (active_sample > 0) { + active_sample--; + display.setCursor(LCD_cols - 5, 1); + snprintf_P(tmp_val, sizeof(tmp_val), PSTR("%4.1f"), configuration.drums.pitch[active_sample] / 10.0); + display.print(tmp_val); + } + break; + case 1: + configuration.drums.pitch[active_sample] = constrain(configuration.drums.pitch[active_sample] - ENCODER[ENC_L].speed(), DRUMS_PITCH_MIN, DRUMS_PITCH_MAX); + break; + case 2: + break; + } + } else if (LCDML.BT_checkEnter()) { + input_mode = input_mode++ % 3; + } + } +#ifdef DEBUG + if (input_type == 0) + Serial.printf_P(PSTR("Drum volume MIN for active_sample=%d [%s]=%d\n"), active_sample, drum_config[active_sample].name, configuration.drums.vol_min[active_sample]); + else + Serial.printf_P(PSTR("Drum volume MAX for active_sample=%d [%s]=%d\n"), active_sample, drum_config[active_sample].name, configuration.drums.vol_max[active_sample]); +#endif + memset(tmp_name, ' ', 8); + strncpy(tmp_name, drum_config[active_sample].name, strlen(drum_config[active_sample].name)); + tmp_name[8] = '\0'; + + display.setCursor(1, 1); + display.print(tmp_name); + display.setCursor(LCD_cols - 5, 1); + snprintf_P(tmp_val, sizeof(tmp_val), PSTR("%4.1f"), configuration.drums.pitch[active_sample] / 10.0); + display.print(tmp_val); + + _check_display_name_min_max(input_mode, 4); + } + + if (LCDML.FUNC_close()) // ****** STABLE END ********* + { + encoderDir[ENC_L].reset(); + midi_learn_mode = MIDI_LEARN_MODE_OFF; + } } void UI_func_drum_pan(uint8_t param) { @@ -4324,7 +4444,7 @@ void UI_func_drum_midi_note(uint8_t param) { if (LCDML.FUNC_loop()) // ****** LOOP ********* { - if (midi_learn_mode > MIDI_LEARN_MODE_NULL) + if (midi_learn_mode >= DRUMS_MIDI_NOTE_MIN) configuration.drums.midinote[active_sample] = midi_learn_mode; if ((LCDML.BT_checkDown() && encoderDir[ENC_R].Down()) || (LCDML.BT_checkUp() && encoderDir[ENC_R].Up()) || (LCDML.BT_checkEnter() && encoderDir[ENC_R].ButtonShort())) { diff --git a/config.h b/config.h index c5b66e9..84f86f7 100644 --- a/config.h +++ b/config.h @@ -955,8 +955,7 @@ enum reverb_mixer_ports { enum midi_learn_modes { MIDI_LEARN_MODE_OFF, MIDI_LEARN_MODE_ON, - MIDI_LEARN_MODE_NOTE, - MIDI_LEARN_MODE_NULL + MIDI_LEARN_MODE_NOTE }; #ifndef _MAPFLOAT