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

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

@ -824,7 +824,7 @@ void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity) {
// //
// MIDI learn mode // 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); int8_t tmp_channel = handle_midi_learn(inNumber);
if (tmp_channel >= 0) if (tmp_channel >= 0)
inChannel = tmp_channel; inChannel = tmp_channel;
@ -890,6 +890,13 @@ void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity) {
if (drum_counter >= NUM_DRUMS) if (drum_counter >= NUM_DRUMS)
drum_counter = 0; 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 #ifdef DEBUG
char note_name[4]; char note_name[4];
getNoteName(note_name, inNumber); getNoteName(note_name, inNumber);
@ -953,7 +960,7 @@ void handleNoteOff(byte inChannel, byte inNumber, byte inVelocity) {
// //
// MIDI learn mode // 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); int8_t tmp_channel = handle_midi_learn(inNumber);
if (tmp_channel >= 0) if (tmp_channel >= 0)
inChannel = tmp_channel; inChannel = tmp_channel;
@ -2202,8 +2209,7 @@ int8_t handle_midi_learn(int8_t note) {
int8_t ret_channel = -1; int8_t ret_channel = -1;
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("MIDI learning for ")); Serial.printf(PSTR("MIDI learning for %d with midi learn mode %d\n"), note, midi_learn_mode);
Serial.println(note);
#endif #endif
if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_drum_pan)) { 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); LCDML.OTHER_jumpToFunc(UI_func_drum_vol_min_max);
} else if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_drum_midi_note)) { } else if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_drum_midi_note)) {
ret_channel = configuration.drums.midi_channel; 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); active_sample = get_drums_id_by_note(note);
else else {
midi_learn_mode = note; if (midi_learn_mode != MIDI_LEARN_MODE_DRUM_NOTE)
LCDML.OTHER_jumpToFunc(UI_func_drum_midi_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)) { } else if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_drum_pitch)) {
ret_channel = configuration.drums.midi_channel; ret_channel = configuration.drums.midi_channel;
active_sample = get_drums_id_by_note(note); active_sample = get_drums_id_by_note(note);

113
UI.hpp

@ -139,7 +139,7 @@ extern bool save_sys_flag;
elapsedMillis back_from_volume; elapsedMillis back_from_volume;
uint8_t instance_num[8][8]; uint8_t instance_num[8][8];
const char accepted_chars[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-abcdefghijklmnopqrstuvwxyz"; 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 active_perform_page = 1;
uint8_t orig_attack_values[2][7]; uint8_t orig_attack_values[2][7];
uint8_t orig_release_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()); LCDML.OTHER_setCursorToID(LCDML.MENU_getLastCursorPositionID());
} else if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_drum_midi_note) && ask_before_quit == false) { } else if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_drum_midi_note) && ask_before_quit == false) {
ask_before_quit = true; ask_before_quit = true;
Serial.printf("ask_before_quit = %d\n", ask_before_quit);
encoderDir[ENC_L].reset(); encoderDir[ENC_L].reset();
encoderDir[ENC_R].reset(); encoderDir[ENC_R].reset();
LCDML.OTHER_updateFunc(); 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(); LCDML.BT_quit();
}
} }
} }
} }
@ -3860,10 +3865,10 @@ void _check_yes_no_back(uint8_t state) {
if (state == 0) { // BACK if (state == 0) { // BACK
display.setCursor(0, 1); display.setCursor(0, 1);
display.print(F(" ")); display.print(F(" "));
display.setCursor(3, 1);
display.print(F(" "));
display.setCursor(4, 1); display.setCursor(4, 1);
display.print(F(" ")); display.print(F(" "));
display.setCursor(5, 1);
display.print(F(" "));
display.setCursor(8, 1); display.setCursor(8, 1);
display.print(F(" ")); display.print(F(" "));
display.setCursor(9, 1); display.setCursor(9, 1);
@ -3873,9 +3878,9 @@ void _check_yes_no_back(uint8_t state) {
} else if (state == 1) { // NO } else if (state == 1) { // NO
display.setCursor(0, 1); display.setCursor(0, 1);
display.print(F("[")); display.print(F("["));
display.setCursor(3, 1);
display.print(F("]"));
display.setCursor(4, 1); display.setCursor(4, 1);
display.print(F("]"));
display.setCursor(5, 1);
display.print(F(" ")); display.print(F(" "));
display.setCursor(8, 1); display.setCursor(8, 1);
display.print(F(" ")); display.print(F(" "));
@ -3886,9 +3891,9 @@ void _check_yes_no_back(uint8_t state) {
} else { // YES } else { // YES
display.setCursor(0, 1); display.setCursor(0, 1);
display.print(F(" ")); display.print(F(" "));
display.setCursor(3, 1);
display.print(F(" "));
display.setCursor(4, 1); display.setCursor(4, 1);
display.print(F(" "));
display.setCursor(5, 1);
display.print(F("[")); display.print(F("["));
display.setCursor(8, 1); display.setCursor(8, 1);
display.print(F("]")); display.print(F("]"));
@ -3904,7 +3909,7 @@ void _check_display_name(bool display_name, uint8_t digits) {
display.setCursor(0, 1); display.setCursor(0, 1);
display.print(F("[")); display.print(F("["));
display.setCursor(9, 1); display.setCursor(9, 1);
display.print(F("]")); display.print(F("] "));
display.setCursor(LCD_cols - digits - 2, 1); display.setCursor(LCD_cols - digits - 2, 1);
display.print(F(" ")); display.print(F(" "));
display.setCursor(LCD_cols - 1, 1); 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.setCursor(0, 1);
display.print(F(" ")); display.print(F(" "));
display.setCursor(9, 1); display.setCursor(9, 1);
display.print(F(" ")); display.print(F(" "));
display.setCursor(LCD_cols - digits - 2, 1); display.setCursor(LCD_cols - digits - 2, 1);
display.print(F("[")); display.print(F("["));
display.setCursor(LCD_cols - 1, 1); 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]; midinote_old[i] = configuration.drums.midinote[i];
if (!display_name) if (!display_name)
midi_learn_mode = MIDI_LEARN_MODE_NOTE; midi_learn_mode = MIDI_LEARN_MODE_DRUM_NOTE;
else else
midi_learn_mode = MIDI_LEARN_MODE_ON; 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 (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; uint8_t num_changes = 0;
for (uint8_t i = 0; i < NUM_DRUMSET_CONFIG; i++) { for (uint8_t i = 0; i < NUM_DRUMSET_CONFIG; i++) {
if (midinote_old[i] != configuration.drums.midinote[i]) if (midinote_old[i] != configuration.drums.midinote[i])
num_changes++; num_changes++;
} }
if (num_changes > 0) { if (num_changes > 0) {
ask_before_quit_mode = 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); _check_yes_no_back(ask_before_quit_mode);
} else { } else {
ask_before_quit = false; 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) 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() && encoderDir[ENC_R].Down()) || (LCDML.BT_checkUp() && encoderDir[ENC_R].Up()) || (LCDML.BT_checkEnter() && encoderDir[ENC_R].ButtonShort())) {
if (LCDML.BT_checkDown()) { if (LCDML.BT_checkDown()) {
if (display_name == true) { if (ask_before_quit_mode >= 0) {
if (active_sample < NUM_DRUMSET_CONFIG - 2)
active_sample++;
} else if (ask_before_quit_mode >= 0) {
++ask_before_quit_mode %= 3; ++ask_before_quit_mode %= 3;
_check_yes_no_back(ask_before_quit_mode); _check_yes_no_back(ask_before_quit_mode);
LCDML.OTHER_updateFunc();
LCDML.loop_menu();
} 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); 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()) { } else if (LCDML.BT_checkUp()) {
if (display_name == true) { if (ask_before_quit_mode >= 0) {
if (active_sample > 0) if (ask_before_quit_mode > 0)
active_sample--; ask_before_quit_mode--;
} else if (ask_before_quit_mode >= 0) { else
--ask_before_quit_mode %= 3; ask_before_quit_mode = 2;
_check_yes_no_back(ask_before_quit_mode); _check_yes_no_back(ask_before_quit_mode);
LCDML.OTHER_updateFunc();
LCDML.loop_menu();
} 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); 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()) { } else if (LCDML.BT_checkEnter()) {
if (ask_before_quit_mode >= 0) { 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; ask_before_quit = false;
display.show(1, 0, 16, "Canceled.");
delay(MESSAGE_WAIT_TIME);
LCDML.FUNC_goBackToMenu(); LCDML.FUNC_goBackToMenu();
} else if (ask_before_quit_mode == 1) { // YES } else if (ask_before_quit_mode == 1) { // YES
for (uint8_t i = 0; i < NUM_DRUMSET_CONFIG; i++) ask_before_quit = false;
configuration.drums.midinote[i] = midinote_old[i]; display.show(1, 0, 16, "Done.");
} else if (ask_before_quit_mode == 2) { // BACK delay(MESSAGE_WAIT_TIME);
LCDML.FUNC_goBackToMenu();
} else if (ask_before_quit_mode == 0) { // BACK
ask_before_quit_mode = -1; ask_before_quit_mode = -1;
ask_before_quit = false; 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]); if (ask_before_quit_mode < 0) {
strlcpy(tmp_name, drum_config[active_sample].name, sizeof(drum_config[active_sample].name)); getNoteName(tmp_val, configuration.drums.midinote[active_sample]);
display.show(1, 1, 8, tmp_name); strlcpy(tmp_name, drum_config[active_sample].name, sizeof(drum_config[active_sample].name));
display.show(1, LCD_cols - strlen(tmp_val) - 1, strlen(tmp_val), tmp_val); display.show(1, 1, 8, tmp_name);
display.show(1, LCD_cols - strlen(tmp_val) - 1, strlen(tmp_val), tmp_val);
#ifdef DEBUG #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 #endif
_check_display_name(display_name, 3); _check_display_name(display_name, 3);
if (!display_name) if (!display_name)
midi_learn_mode = MIDI_LEARN_MODE_NOTE; midi_learn_mode = MIDI_LEARN_MODE_DRUM_NOTE;
else else
midi_learn_mode = MIDI_LEARN_MODE_ON; midi_learn_mode = MIDI_LEARN_MODE_ON;
}
} }
#endif #endif

@ -145,9 +145,9 @@
#define SAMPLE_RATE 44100 #define SAMPLE_RATE 44100
#ifdef USE_DELAY_8M #ifdef USE_DELAY_8M
#define AUDIO_MEM 36 + 14 // Delay in EXTMEM #define AUDIO_MEM 36 + 14 // Delay in EXTMEM
#else #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 #endif
#ifdef TEENSY_AUDIO_BOARD #ifdef TEENSY_AUDIO_BOARD
@ -830,8 +830,9 @@ enum reverb_mixer_ports {
enum midi_learn_modes { enum midi_learn_modes {
MIDI_LEARN_MODE_OFF, MIDI_LEARN_MODE_OFF,
MIDI_LEARN_MODE_ON, MIDI_LEARN_MODE_ON,
MIDI_LEARN_MODE_NOTE MIDI_LEARN_MODE_NOTE,
}; MIDI_LEARN_MODE_DRUM_NOTE
};
#ifndef _MAPFLOAT #ifndef _MAPFLOAT
#define _MAPFLOAT #define _MAPFLOAT

Loading…
Cancel
Save