From ee10414a03695a354dc8cd1dafff2081a9a9f704 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Fri, 6 Aug 2021 09:50:58 +0200 Subject: [PATCH] Fixing drum filename handling. Adding drums and sequencer to T_3.6 menus. --- MicroDexed.ino | 11 ++++++++--- UI.hpp | 28 ++++++++++++++-------------- UI_FX.h | 32 ++++++++++++++++++++++---------- UI_FX_T4.h | 4 ++-- UI_NO_FX.h | 4 ++-- config.h | 1 + drums.cpp | 17 +++++++++++------ 7 files changed, 60 insertions(+), 37 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 12194c4..31c465e 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -112,7 +112,7 @@ AudioMixer8 drum_reverb_send_mixer_l; //AudioConnection patchCord[] = { // {wavetable[0], 0, mixer[0], 0}, {wavetable[1], 0, mixer[0], 1}, {wavetable[2], 0, mixer[0], 2}, {wavetable[3], 0, mixer[0], 3}, {mixer[0], 0, mixer[TOTAL_MIXERS - 2], 0}, - + // Audio chain tail #if defined(USE_FX) #ifdef USE_PLATEREVERB @@ -521,7 +521,7 @@ void setup() } else { - strcpy(drumset_name,"StdDrums"); + strcpy(drumset_name, "StdDrums"); num_drums = read_drum_config(drumset_name); check_and_create_directories(); @@ -776,7 +776,12 @@ void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity) drum_mixer_l.gain(slot, fsin * pseudo_log_curve(mapfloat(inVelocity, 0, 127, drum_config[d].vol_min, drum_config[d].vol_max))); drum_reverb_send_mixer_r.gain(slot, (1.0 - fsin) * pseudo_log_curve(drum_config[d].reverb_send)); drum_reverb_send_mixer_l.gain(slot, fsin * pseudo_log_curve(drum_config[d].reverb_send)); - Drum[slot]->play(drum_config[d].filename); + + char f[DRUM_CFG_GILENAME_LEN]; + strcpy(f, drum_config[d].filename); + strcat(f, ".wav"); + + Drum[slot]->play(f); #ifdef DEBUG Serial.print(F("Drum ")); diff --git a/UI.hpp b/UI.hpp index 2db98f3..92f8427 100644 --- a/UI.hpp +++ b/UI.hpp @@ -314,6 +314,8 @@ void UI_func_drum_main_volume(uint8_t param); void UI_func_drum_volume(uint8_t param); void UI_func_drum_pan(uint8_t param); +char* basename(const char* filename); +char* strip_extension(char* filename); // normal menu LCDMenuLib2_menu LCDML_0(255, 0, 0, NULL, NULL); // normal root menu element (do not change) @@ -3613,8 +3615,7 @@ void UI_func_drum_reverb_send(uint8_t param) sprintf(displayname, "%02d", activesample); lcd.print(displayname); lcd.setCursor(4, 1); - strncpy(displayname, drum_config[activesample].filename + 6 + strlen(drumset_name), 7); - lcd.print(displayname); + lcd.print(basename(drum_config[activesample].filename)); sprintf(displayname, "%03d", (int)(drum_config[activesample].reverb_send * 100) ); lcd.setCursor(12, 1); lcd.print(displayname); @@ -3641,7 +3642,7 @@ void UI_func_drum_reverb_send(uint8_t param) void UI_func_drum_main_volume(uint8_t param) { -; + ; } void UI_func_drum_volume(uint8_t param) @@ -3702,8 +3703,7 @@ void UI_func_drum_volume(uint8_t param) sprintf(displayname, "%02d", activesample); lcd.print(displayname); lcd.setCursor(4, 1); - strncpy(displayname, drum_config[activesample].filename + 6+ strlen(drumset_name), 7); - lcd.print(displayname); + lcd.print(basename(drum_config[activesample].filename)); sprintf(displayname, "%03d", (int)(drum_config[activesample].vol_max * 100) ); lcd.setCursor(12, 1); lcd.print(displayname); @@ -3791,8 +3791,7 @@ void UI_func_drum_pan(uint8_t param) sprintf(displayname, "%02d", activesample); lcd.print(displayname); lcd.setCursor(4, 1); - strncpy(displayname, drum_config[activesample].filename + 6 + strlen(drumset_name), 7); - lcd.print(displayname); + lcd.print(basename(drum_config[activesample].filename)); sprintf(displayname, "%+f", drum_config[activesample].pan); lcd.setCursor(12, 1); lcd.print(displayname); @@ -3935,17 +3934,13 @@ void UI_func_seq_lenght(uint8_t param) void UI_func_sequencer(uint8_t param) { - - char displayname[8]={0,0,0,0,0,0,0,0}; - if (LCDML.FUNC_setup()) // ****** SETUP ********* { encoderDir[ENC_R].reset(); seq_note_in = 0; // setup function lcd.setCursor(1, 0); - strncpy(displayname, drum_config[activesample].filename + 6 + strlen(drumset_name), 6); - lcd.print(displayname); + lcd.print(basename(drum_config[activesample].filename)); lcd.setCursor(9, 0); if (seq_running == false && seq_recording == false) { @@ -4067,8 +4062,7 @@ void UI_func_sequencer(uint8_t param) if (activesample < num_drums) { lcd.setCursor(1, 0); - strncpy(displayname, drum_config[activesample].filename + 6 + strlen(drumset_name), 6); - lcd.print(displayname); + lcd.print(basename(drum_config[activesample].filename)); } else if (activesample == num_drums) { lcd.setCursor(1, 0); lcd.print("EMPTY "); @@ -7293,5 +7287,11 @@ void save_favorite(uint8_t b, uint8_t v, uint8_t instance_id) } } +char* basename(const char* filename) +{ + char* p = strrchr (filename, '/'); + return p ? p + 1 : (char *) filename; +} + #endif #endif diff --git a/UI_FX.h b/UI_FX.h index f584a8b..1f05231 100644 --- a/UI_FX.h +++ b/UI_FX.h @@ -109,14 +109,26 @@ LCDML_add(75, LCDML_0_3, 5, "MIDI", NULL); LCDML_add(76, LCDML_0_3_5, 1, "MIDI Recv Bank", UI_func_sysex_receive_bank); LCDML_add(77, LCDML_0_3_5, 2, "MIDI Snd Bank", UI_func_sysex_send_bank); LCDML_add(78, LCDML_0_3_5, 3, "MIDI Snd Voice", UI_func_sysex_send_voice); -LCDML_add(79, LCDML_0, 4, "Sequencer", UI_func_sequencer); -LCDML_add(80, LCDML_0, 5, "Pattern Chain", UI_func_seq_pat_chain); -LCDML_add(81, LCDML_0, 6, "System", NULL); -LCDML_add(82, LCDML_0_6, 1, "Stereo/Mono", UI_func_stereo_mono); -LCDML_add(83, LCDML_0_6, 2, "MIDI Soft THRU", UI_func_midi_soft_thru); -LCDML_add(84, LCDML_0_6, 3, "Favorites", UI_func_favorites); -LCDML_add(85, LCDML_0_6, 4, "EEPROM Reset", UI_func_eeprom_reset); -LCDML_add(86, LCDML_0, 6, "Info", UI_func_information); -LCDML_addAdvanced(87, LCDML_0, 7, COND_hide, "Volume", UI_func_volume, 0, _LCDML_TYPE_default); -#define _LCDML_DISP_cnt 87 +LCDML_add(79, LCDML_0, 4, "Drums", NULL); +LCDML_add(80, LCDML_0_4, 1, "Drums Main Vol", UI_func_drum_main_volume); +LCDML_add(81, LCDML_0_4, 2, "Drum Volumes", UI_func_drum_volume); +LCDML_add(82, LCDML_0_4, 3, "Drum Pan", UI_func_drum_pan); +LCDML_add(83, LCDML_0_4, 4, "Drum Rev.Send", UI_func_drum_reverb_send); +LCDML_add(84, LCDML_0, 5, "Sequencer", NULL); +LCDML_add(85, LCDML_0_5, 1, "Sequencer", UI_func_sequencer); +LCDML_add(86, LCDML_0_5, 2, "Pattern Chain", UI_func_seq_pat_chain); +LCDML_add(87, LCDML_0_5, 3, "Seq. Length", UI_func_seq_lenght); +LCDML_add(88, LCDML_0_5, 4, "Tempo", NULL); +LCDML_add(89, LCDML_0_5, 5, "L.Transp.Key", UI_func_seq_live_transpose_oct); +LCDML_add(90, LCDML_0_5, 6, "L.Trp.Offset", NULL); +LCDML_add(91, LCDML_0_5, 7, "Pattern load", NULL); +LCDML_add(92, LCDML_0_5, 8, "Pattern save", NULL); +LCDML_add(93, LCDML_0, 6, "System", NULL); +LCDML_add(94, LCDML_0_6, 1, "Stereo/Mono", UI_func_stereo_mono); +LCDML_add(95, LCDML_0_6, 2, "MIDI Soft THRU", UI_func_midi_soft_thru); +LCDML_add(96, LCDML_0_6, 3, "Favorites", UI_func_favorites); +LCDML_add(97, LCDML_0_6, 4, "EEPROM Reset", UI_func_eeprom_reset); +LCDML_add(98, LCDML_0, 7, "Info", UI_func_information); +LCDML_addAdvanced(99, LCDML_0, 8, COND_hide, "Volume", UI_func_volume, 0, _LCDML_TYPE_default); +#define _LCDML_DISP_cnt 99 #endif diff --git a/UI_FX_T4.h b/UI_FX_T4.h index 285748c..737b69e 100644 --- a/UI_FX_T4.h +++ b/UI_FX_T4.h @@ -112,12 +112,12 @@ LCDML_add(78, LCDML_0_3, 5, "MIDI", NULL); LCDML_add(79, LCDML_0_3_5, 1, "MIDI Recv Bank", UI_func_sysex_receive_bank); LCDML_add(80, LCDML_0_3_5, 2, "MIDI Snd Bank", UI_func_sysex_send_bank); LCDML_add(81, LCDML_0_3_5, 3, "MIDI Snd Voice", UI_func_sysex_send_voice); -LCDML_add(82, LCDML_0, 4, "Drum Settings", NULL); +LCDML_add(82, LCDML_0, 4, "Drums", NULL); LCDML_add(83, LCDML_0_4, 1, "Drums Main Vol", UI_func_drum_main_volume); LCDML_add(84, LCDML_0_4, 2, "Drum Volumes", UI_func_drum_volume); LCDML_add(85, LCDML_0_4, 3, "Drum Pan", UI_func_drum_pan); LCDML_add(86, LCDML_0_4, 4, "Drum Rev.Send", UI_func_drum_reverb_send); -LCDML_add(87, LCDML_0, 5, "Sequencer Set.", NULL); +LCDML_add(87, LCDML_0, 5, "Sequencer", NULL); LCDML_add(88, LCDML_0_5, 1, "Sequencer", UI_func_sequencer); LCDML_add(89, LCDML_0_5, 2, "Pattern Chain", UI_func_seq_pat_chain); LCDML_add(90, LCDML_0_5, 3, "Seq. Length", UI_func_seq_lenght); diff --git a/UI_NO_FX.h b/UI_NO_FX.h index 778ec85..27105c3 100644 --- a/UI_NO_FX.h +++ b/UI_NO_FX.h @@ -85,11 +85,11 @@ LCDML_add(51, LCDML_0_2, 4, "MIDI", NULL); LCDML_add(52, LCDML_0_2_4, 1, "MIDI Recv Bank", UI_func_sysex_receive_bank); LCDML_add(53, LCDML_0_2_4, 2, "MIDI Snd Bank", UI_func_sysex_send_bank); LCDML_add(54, LCDML_0_2_4, 3, "MIDI Snd Voice", UI_func_sysex_send_voice); -LCDML_add(55, LCDML_0, 3, "Drum Settings", NULL); +LCDML_add(55, LCDML_0, 3, "Drum", NULL); LCDML_add(56, LCDML_0_3, 1, "Drums Main Vol", UI_func_drum_main_volume); LCDML_add(57, LCDML_0_3, 2, "Drum Volumes", UI_func_drum_volume); LCDML_add(58, LCDML_0_3, 3, "Drum Pan", UI_func_drum_pan); -LCDML_add(59, LCDML_0, 4, "Sequencer Set.", NULL); +LCDML_add(59, LCDML_0, 4, "Sequencer", NULL); LCDML_add(60, LCDML_0_4, 1, "Sequencer", UI_func_sequencer); LCDML_add(61, LCDML_0_4, 2, "Pattern Chain", UI_func_seq_pat_chain); LCDML_add(62, LCDML_0_4, 3, "Seq. Length", NULL); diff --git a/config.h b/config.h index 927378d..c32ace2 100644 --- a/config.h +++ b/config.h @@ -281,6 +281,7 @@ #define BANK_NAME_LEN 11 // 10 (plus '\0') #define VOICE_NAME_LEN 12 // 11 (plus '\0') #define FILENAME_LEN BANK_NAME_LEN + VOICE_NAME_LEN +#define DRUM_CFG_GILENAME_LEN 42 #define FX_CONFIG_PATH "FXCFG" #define FX_CONFIG_NAME "FXCFG" diff --git a/drums.cpp b/drums.cpp index b0cc97c..e45c960 100644 --- a/drums.cpp +++ b/drums.cpp @@ -89,12 +89,17 @@ uint8_t read_drum_config(const char* drumset) sprintf(ds, "/DRM/%s", drumset); for (JsonPair kv : root) { - sprintf(drum_config[drum].filename, "%s/%s.wav", ds, kv.key().c_str()); - if (!SD.exists(drum_config[drum].filename)) + sprintf(drum_config[drum].filename, "%s/%s", ds, kv.key().c_str()); + + char f[DRUM_CFG_GILENAME_LEN]; + strcpy(f, drum_config[drum].filename); + strcat(f, ".wav"); + + if (!SD.exists(f)) { #ifdef DEBUG Serial.print(F("Cannot find WAV file [")); - Serial.print(drum_config[drum].filename); + Serial.print(f); Serial.println(F("]")); #endif continue; @@ -259,7 +264,7 @@ uint8_t read_drum_config(const char* drumset) Serial.print(F("midinote = ")); Serial.println(drum_config[drum].midinote, DEC); Serial.print(F("filename = ")); - Serial.println(drum_config[drum].filename); + Serial.println(f); Serial.print(F("shortname = ")); Serial.println(drum_config[drum].shortname); Serial.print(F("pan = ")); @@ -283,7 +288,7 @@ uint8_t read_drum_config(const char* drumset) drum_config[drum].vol_max = 0.0; drum_config[drum].vol_min = 0.0; drum_config[drum].reverb_send = 0.0; - + return (drum); - + }