From 30624db43b34bdf78787615067883e122317df53 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Wed, 8 Feb 2023 16:21:14 +0100 Subject: [PATCH] Added functionality for asking for storing when drum midi notes are changed. --- UI.hpp | 53 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/UI.hpp b/UI.hpp index 496201f..eb3ad59 100644 --- a/UI.hpp +++ b/UI.hpp @@ -4376,13 +4376,18 @@ void UI_func_drum_midi_note(uint8_t param) { } #else static bool display_name; - static bool store_flag; + static uint8_t midinote_old[NUM_DRUMSET_CONFIG]; + static int8_t ask_before_quit_mode; + char tmp_val[4]; char tmp_name[9]; if (LCDML.FUNC_setup()) // ****** SETUP ********* { - store_flag = false; + ask_before_quit_mode = -1; + + for (uint8_t i = 0; i < NUM_DRUMSET_CONFIG; i++) + midinote_old[i] = configuration.drums.midinote[i]; if (!display_name) midi_learn_mode = MIDI_LEARN_MODE_NOTE; @@ -4400,16 +4405,21 @@ void UI_func_drum_midi_note(uint8_t param) { if (LCDML.FUNC_loop()) // ****** LOOP ********* { - if (ask_before_quit == true) { - if (store_flag == true) { + if (ask_before_quit == true && ask_before_quit_mode == false) { + uint8_t num_changes = 0; + + for (uint8_t i = 0; i < NUM_DRUMSET_CONFIG; i++) { + if (midinote_old[i] != configuration.drums.midinote[i]) + num_changes++; + } + if (num_changes > 0) { display.show(0, 0, LCD_cols, "Store changes?"); - display.show(1, 0, LCD_cols, "[NO] YES"); - delay(1000); + display.show(1, 0, LCD_cols, " NO YES [BACK]"); + ask_before_quit_mode = 0; + } else { + ask_before_quit = false; + LCDML.FUNC_goBackToMenu(); } - ask_before_quit = false; - LCDML.FUNC_goBackToMenu(); - /*LCDML.BT_quit(); - LCDML.OTHER_updateFunc();*/ } if (midi_learn_mode >= DRUMS_MIDI_NOTE_MIN) @@ -4420,20 +4430,37 @@ void UI_func_drum_midi_note(uint8_t param) { if (display_name == true) { if (active_sample < NUM_DRUMSET_CONFIG - 2) active_sample++; + } else if (ask_before_quit_mode >= 0) { + ++ask_before_quit_mode %= 3; + // TODO: Display selection is missing } else { configuration.drums.midinote[active_sample] = constrain(configuration.drums.midinote[active_sample] + ENCODER[ENC_L].speed(), DRUMS_MIDI_NOTE_MIN, DRUMS_MIDI_NOTE_MAX); - store_flag = true; } + } else if (LCDML.BT_checkUp()) { if (display_name == true) { if (active_sample > 0) active_sample--; + } else if (ask_before_quit_mode >= 0) { + --ask_before_quit_mode %= 3; + // TODO: Display selection is missing } else { configuration.drums.midinote[active_sample] = constrain(configuration.drums.midinote[active_sample] - ENCODER[ENC_L].speed(), DRUMS_MIDI_NOTE_MIN, DRUMS_MIDI_NOTE_MAX); - store_flag = true; } } else if (LCDML.BT_checkEnter()) { - display_name = !display_name; + if (ask_before_quit_mode >= 0) { + if (ask_before_quit_mode == 0) { //NO + ask_before_quit = false; + LCDML.FUNC_goBackToMenu(); + } else if (ask_before_quit_mode == 1) { // YES + for (uint8_t i = 0; i < NUM_DRUMSET_CONFIG; i++) + configuration.drums.midinote[i] = midinote_old[i]; + } else if (ask_before_quit_mode == 2) { // BACK + ask_before_quit_mode = -1; + ask_before_quit = false; + LCDML.OTHER_updateFunc(); // TODO: Is this the right function for going back? + } + } else display_name = !display_name; } }