Fixes for midi drum note learning. Still a small error exists...

dev
Holger Wirtz 2 years ago
parent 9e5e171fec
commit e64f16de5b
  1. 22
      MicroDexed.ino
  2. 85
      UI.hpp
  3. 3
      config.h

@ -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
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);

@ -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,14 +746,19 @@ 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();
}
}
}
}
if (encoderDir[ENC_L].ButtonPressed() == true && (millis() - g_LCDML_CONTROL_button_press_time[ENC_L]) >= LONG_BUTTON_PRESS) {
#ifdef DEBUG
@ -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("]"));
@ -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,46 +4472,69 @@ 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 {
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 (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 {
if (display_name == true) {
if (active_sample > 0)
active_sample--;
} else if (ask_before_quit_mode >= 0) {
--ask_before_quit_mode %= 3;
_check_yes_no_back(ask_before_quit_mode);
} else {
} 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;
}
}
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);
@ -4516,10 +4546,11 @@ void UI_func_drum_midi_note(uint8_t param) {
_check_display_name(display_name, 3);
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;
}
}
#endif
if (LCDML.FUNC_close()) // ****** STABLE END *********

@ -830,7 +830,8 @@ 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

Loading…
Cancel
Save