diff --git a/MicroDexed.ino b/MicroDexed.ino index 19f7bc8..24456af 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -824,7 +824,7 @@ void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity) { // // MIDI learn mode // - if (midi_learn_mode == MIDI_LEARN_MODE_ON || midi_learn_mode == MIDI_LEARN_MODE_NOTE) { + if (midi_learn_mode != MIDI_LEARN_MODE_OFF) { int8_t tmp_channel = handle_midi_learn(inNumber); if (tmp_channel >= 0) inChannel = tmp_channel; @@ -890,6 +890,13 @@ void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity) { if (drum_counter >= NUM_DRUMS) drum_counter = 0; + if (!(midi_learn_mode & 0x80)) { + inNumber = configuration.drums.midinote[active_sample]; + } else { + inNumber = midi_learn_mode & 0x7f; + midi_learn_mode = MIDI_LEARN_MODE_DRUM_NOTE; + } + #ifdef DEBUG char note_name[4]; getNoteName(note_name, inNumber); @@ -953,7 +960,7 @@ void handleNoteOff(byte inChannel, byte inNumber, byte inVelocity) { // // MIDI learn mode // - if (midi_learn_mode == MIDI_LEARN_MODE_ON || midi_learn_mode == MIDI_LEARN_MODE_NOTE) { + if (midi_learn_mode != MIDI_LEARN_MODE_OFF) { int8_t tmp_channel = handle_midi_learn(inNumber); if (tmp_channel >= 0) inChannel = tmp_channel; @@ -2202,8 +2209,7 @@ int8_t handle_midi_learn(int8_t note) { int8_t ret_channel = -1; #ifdef DEBUG - Serial.print(F("MIDI learning for ")); - Serial.println(note); + Serial.printf(PSTR("MIDI learning for %d with midi learn mode %d\n"), note, midi_learn_mode); #endif if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_drum_pan)) { @@ -2220,11 +2226,15 @@ int8_t handle_midi_learn(int8_t note) { LCDML.OTHER_jumpToFunc(UI_func_drum_vol_min_max); } else if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_drum_midi_note)) { ret_channel = configuration.drums.midi_channel; - if (midi_learn_mode != MIDI_LEARN_MODE_NOTE) + if (midi_learn_mode != MIDI_LEARN_MODE_NOTE && midi_learn_mode != MIDI_LEARN_MODE_DRUM_NOTE) active_sample = get_drums_id_by_note(note); - else - midi_learn_mode = note; - LCDML.OTHER_jumpToFunc(UI_func_drum_midi_note); + else { + if (midi_learn_mode != MIDI_LEARN_MODE_DRUM_NOTE) + midi_learn_mode = note; + else + midi_learn_mode = note & 0x80; + LCDML.OTHER_jumpToFunc(UI_func_drum_midi_note); + } } else if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_drum_pitch)) { ret_channel = configuration.drums.midi_channel; active_sample = get_drums_id_by_note(note); diff --git a/UI.hpp b/UI.hpp index 21f355f..e8ffe89 100644 --- a/UI.hpp +++ b/UI.hpp @@ -139,7 +139,7 @@ extern bool save_sys_flag; elapsedMillis back_from_volume; uint8_t instance_num[8][8]; const char accepted_chars[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-abcdefghijklmnopqrstuvwxyz"; -const char noteNames[12][3] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" }; +//const char noteNames[12][3] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" }; uint8_t active_perform_page = 1; uint8_t orig_attack_values[2][7]; uint8_t orig_release_values[2][7]; @@ -746,11 +746,16 @@ void lcdml_menu_control(void) { LCDML.OTHER_setCursorToID(LCDML.MENU_getLastCursorPositionID()); } else if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_drum_midi_note) && ask_before_quit == false) { ask_before_quit = true; + Serial.printf("ask_before_quit = %d\n", ask_before_quit); encoderDir[ENC_L].reset(); encoderDir[ENC_R].reset(); LCDML.OTHER_updateFunc(); - } else + LCDML.loop_menu(); + } else { + ask_before_quit = false; + Serial.printf("ask_before_quit = %d\n", ask_before_quit); LCDML.BT_quit(); + } } } } @@ -3860,10 +3865,10 @@ void _check_yes_no_back(uint8_t state) { if (state == 0) { // BACK display.setCursor(0, 1); display.print(F(" ")); - display.setCursor(3, 1); - display.print(F(" ")); display.setCursor(4, 1); display.print(F(" ")); + display.setCursor(5, 1); + display.print(F(" ")); display.setCursor(8, 1); display.print(F(" ")); display.setCursor(9, 1); @@ -3873,9 +3878,9 @@ void _check_yes_no_back(uint8_t state) { } else if (state == 1) { // NO display.setCursor(0, 1); display.print(F("[")); - display.setCursor(3, 1); - display.print(F("]")); display.setCursor(4, 1); + display.print(F("]")); + display.setCursor(5, 1); display.print(F(" ")); display.setCursor(8, 1); display.print(F(" ")); @@ -3886,9 +3891,9 @@ void _check_yes_no_back(uint8_t state) { } else { // YES display.setCursor(0, 1); display.print(F(" ")); - display.setCursor(3, 1); - display.print(F(" ")); display.setCursor(4, 1); + display.print(F(" ")); + display.setCursor(5, 1); display.print(F("[")); display.setCursor(8, 1); display.print(F("]")); @@ -3904,7 +3909,7 @@ void _check_display_name(bool display_name, uint8_t digits) { display.setCursor(0, 1); display.print(F("[")); display.setCursor(9, 1); - display.print(F("]")); + display.print(F("] ")); display.setCursor(LCD_cols - digits - 2, 1); display.print(F(" ")); display.setCursor(LCD_cols - 1, 1); @@ -3913,7 +3918,7 @@ void _check_display_name(bool display_name, uint8_t digits) { display.setCursor(0, 1); display.print(F(" ")); display.setCursor(9, 1); - display.print(F(" ")); + display.print(F(" ")); display.setCursor(LCD_cols - digits - 2, 1); display.print(F("[")); display.setCursor(LCD_cols - 1, 1); @@ -4433,7 +4438,7 @@ void UI_func_drum_midi_note(uint8_t param) { midinote_old[i] = configuration.drums.midinote[i]; if (!display_name) - midi_learn_mode = MIDI_LEARN_MODE_NOTE; + midi_learn_mode = MIDI_LEARN_MODE_DRUM_NOTE; else midi_learn_mode = MIDI_LEARN_MODE_ON; @@ -4448,15 +4453,17 @@ void UI_func_drum_midi_note(uint8_t param) { if (LCDML.FUNC_loop()) // ****** LOOP ********* { - if (ask_before_quit == true && ask_before_quit_mode == false) { + if (ask_before_quit == true && ask_before_quit_mode <= 0) { 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) { ask_before_quit_mode = 0; + midi_learn_mode = MIDI_LEARN_MODE_OFF; + display.show(0, 0, 16, "Use this setup?"); + display.show(1, 0, 16, " YES NO [BACK]"); _check_yes_no_back(ask_before_quit_mode); } else { ask_before_quit = false; @@ -4465,60 +4472,84 @@ void UI_func_drum_midi_note(uint8_t param) { } if (midi_learn_mode >= DRUMS_MIDI_NOTE_MIN) - configuration.drums.midinote[active_sample] = midi_learn_mode; + configuration.drums.midinote[active_sample] = midi_learn_mode & 0x7f; 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()) { - if (display_name == true) { - if (active_sample < NUM_DRUMSET_CONFIG - 2) - active_sample++; - } else if (ask_before_quit_mode >= 0) { + if (ask_before_quit_mode >= 0) { ++ask_before_quit_mode %= 3; _check_yes_no_back(ask_before_quit_mode); + LCDML.OTHER_updateFunc(); + LCDML.loop_menu(); } else { - configuration.drums.midinote[active_sample] = constrain(configuration.drums.midinote[active_sample] + ENCODER[ENC_L].speed(), DRUMS_MIDI_NOTE_MIN, DRUMS_MIDI_NOTE_MAX); + if (display_name == true) { + if (active_sample < NUM_DRUMSET_CONFIG - 2) + active_sample++; + } else + configuration.drums.midinote[active_sample] = constrain(configuration.drums.midinote[active_sample] + ENCODER[ENC_L].speed(), DRUMS_MIDI_NOTE_MIN, DRUMS_MIDI_NOTE_MAX); } } 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; + if (ask_before_quit_mode >= 0) { + if (ask_before_quit_mode > 0) + ask_before_quit_mode--; + else + ask_before_quit_mode = 2; _check_yes_no_back(ask_before_quit_mode); + LCDML.OTHER_updateFunc(); + LCDML.loop_menu(); } else { - configuration.drums.midinote[active_sample] = constrain(configuration.drums.midinote[active_sample] - ENCODER[ENC_L].speed(), DRUMS_MIDI_NOTE_MIN, DRUMS_MIDI_NOTE_MAX); + if (display_name == true) { + if (active_sample > 0) + active_sample--; + } else + configuration.drums.midinote[active_sample] = constrain(configuration.drums.midinote[active_sample] - ENCODER[ENC_L].speed(), DRUMS_MIDI_NOTE_MIN, DRUMS_MIDI_NOTE_MAX); } } else if (LCDML.BT_checkEnter()) { if (ask_before_quit_mode >= 0) { - if (ask_before_quit_mode == 0) { // NO + if (ask_before_quit_mode == 2) { // NO + for (uint8_t i = 0; i < NUM_DRUMSET_CONFIG; i++) + configuration.drums.midinote[i] = midinote_old[i]; ask_before_quit = false; + display.show(1, 0, 16, "Canceled."); + delay(MESSAGE_WAIT_TIME); 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 = false; + display.show(1, 0, 16, "Done."); + delay(MESSAGE_WAIT_TIME); + LCDML.FUNC_goBackToMenu(); + } else if (ask_before_quit_mode == 0) { // BACK ask_before_quit_mode = -1; ask_before_quit = false; - LCDML.OTHER_updateFunc(); // TODO: Is this the right function for going back? + if (!display_name) + midi_learn_mode = MIDI_LEARN_MODE_DRUM_NOTE; + else + midi_learn_mode = MIDI_LEARN_MODE_ON; + LCDML.OTHER_updateFunc(); + LCDML.loop_menu(); } - } else display_name = !display_name; + } else { + display_name = !display_name; + } } } - getNoteName(tmp_val, configuration.drums.midinote[active_sample]); - strlcpy(tmp_name, drum_config[active_sample].name, sizeof(drum_config[active_sample].name)); - display.show(1, 1, 8, tmp_name); - display.show(1, LCD_cols - strlen(tmp_val) - 1, strlen(tmp_val), tmp_val); + if (ask_before_quit_mode < 0) { + getNoteName(tmp_val, configuration.drums.midinote[active_sample]); + strlcpy(tmp_name, drum_config[active_sample].name, sizeof(drum_config[active_sample].name)); + display.show(1, 1, 8, tmp_name); + display.show(1, LCD_cols - strlen(tmp_val) - 1, strlen(tmp_val), tmp_val); #ifdef DEBUG - Serial.printf("Drum midinote for active_sample=%d [%s]=%d (%s)\n", active_sample, drum_config[active_sample].name, configuration.drums.midinote[active_sample], tmp_val); + Serial.printf("Drum midinote for active_sample=%d [%s]=%d (%s)\n", active_sample, drum_config[active_sample].name, configuration.drums.midinote[active_sample], tmp_val); #endif - _check_display_name(display_name, 3); - if (!display_name) - midi_learn_mode = MIDI_LEARN_MODE_NOTE; - else - midi_learn_mode = MIDI_LEARN_MODE_ON; + _check_display_name(display_name, 3); + if (!display_name) + midi_learn_mode = MIDI_LEARN_MODE_DRUM_NOTE; + else + midi_learn_mode = MIDI_LEARN_MODE_ON; + } } #endif diff --git a/config.h b/config.h index 5d788fa..014830b 100644 --- a/config.h +++ b/config.h @@ -145,9 +145,9 @@ #define SAMPLE_RATE 44100 #ifdef USE_DELAY_8M -#define AUDIO_MEM 36 + 14 // Delay in EXTMEM +#define AUDIO_MEM 36 + 14 // Delay in EXTMEM #else -#define AUDIO_MEM 36 + 14 +SAMPLE_RATE* NUM_DEXED* DELAY_MAX_TIME / 128000 // Delay in AUDIO_MEM +#define AUDIO_MEM 36 + 14 + SAMPLE_RATE* NUM_DEXED* DELAY_MAX_TIME / 128000 // Delay in AUDIO_MEM #endif #ifdef TEENSY_AUDIO_BOARD @@ -830,8 +830,9 @@ enum reverb_mixer_ports { enum midi_learn_modes { MIDI_LEARN_MODE_OFF, MIDI_LEARN_MODE_ON, - MIDI_LEARN_MODE_NOTE -}; + MIDI_LEARN_MODE_NOTE, + MIDI_LEARN_MODE_DRUM_NOTE + }; #ifndef _MAPFLOAT #define _MAPFLOAT