From 054758b42647a37999b0d2e3f8f493af00bff293 Mon Sep 17 00:00:00 2001 From: positionhigh Date: Fri, 30 Jul 2021 16:01:32 +0200 Subject: [PATCH] =?UTF-8?q?Dateien=20hochladen=20nach=20=E2=80=9E=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MicroDexed.ino | 59 +---------------------------- UI.hpp | 64 +++++++++++++++++++------------ sequencer.cpp | 101 +++++++++++++++++++++++++++++++++++++++++++++++++ sequencer.h | 17 +++++++++ 4 files changed, 159 insertions(+), 82 deletions(-) create mode 100644 sequencer.cpp create mode 100644 sequencer.h diff --git a/MicroDexed.ino b/MicroDexed.ino index e103a6e..b77fb0d 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -283,7 +283,6 @@ int16_t _midi_bpm = -1; elapsedMillis midi_bpm_timer; elapsedMillis long_button_pressed; elapsedMillis control_rate; -elapsedMillis sequencer_timer; uint8_t active_voices[NUM_DEXED]; uint8_t midi_voices[NUM_DEXED]; #ifdef SHOW_CPU_LOAD_MSEC @@ -304,17 +303,6 @@ char g_voice_name[NUM_DEXED][VOICE_NAME_LEN]; char g_bank_name[NUM_DEXED][BANK_NAME_LEN]; char receive_bank_filename[FILENAME_LEN]; uint8_t selected_instance_id = 0; -uint8_t seqsteptimer = 0; -uint32_t seqtimer_old = 0; -bool seq_running = false; -bool seq_recording = false; -uint8_t seq_note_in; -//uint8_t seqdata[1][16]={48,48,54,48,49,54,54,48,54,54,48,54,49,54,54,54}; -//uint8_t seqdata[1][16]={72,72,78,72,75,78,78,72,78,78,72,78,75,78,78,78}; -uint8_t seqdata[3][16] = {72, 72, 0, 72, 75, 0, 0, 72, 0, 0, 72, 0, 75, 0, 0, 0, - 73, 73, 0, 73, 0, 0, 73, 73, 0, 0, 73, 73, 0, 0, 0, 0, - 78, 0, 0, 78, 0, 0, 78, 0, 78, 78, 0, 0, 0, 0, 0, 0 - }; #ifdef TEENSY4 #if NUM_DEXED>1 int8_t midi_decay[NUM_DEXED] = { -1, -1}; @@ -340,6 +328,7 @@ int16_t delayline[NUM_DEXED][MOD_DELAY_SAMPLE_BUFFER]; extern uint8_t drum_counter; extern uint8_t drum_type[NUM_DRUMS]; extern drum_config_t drum_config[NUM_DRUMCONFIG]; +extern void sequencer(void); #endif #ifdef ENABLE_LCD_UI @@ -628,51 +617,7 @@ void loop() ENCODER[ENC_R].update(); if (seq_running) { - - if (sequencer_timer > seqtimer_old + 125) - - { - seqtimer_old = sequencer_timer; - - if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_sequencer)) { - - - //write to sequencer if in sequencer menu (step recording and live recording) - if (seq_note_in > 0 && seq_recording == true) { - seqdata[active_seq_track][seqsteptimer] = seq_note_in; - seq_note_in = 0; - } - lcd.setCursor(seqsteptimer, 1); - lcd.print("X"); - if (seqsteptimer == 0) { - lcd.setCursor(15, 1); - lcd.print(seq_find_shortname(15)); - } - else - { - lcd.setCursor(seqsteptimer - 1, 1); - lcd.print(seq_find_shortname(seqsteptimer - 1)); - } - } - if (seqdata[0][seqsteptimer] > 0) - { - handleNoteOn(DRUM_MIDI_CHANNEL, seqdata[0][seqsteptimer] , 99); - } - if (seqdata[1][seqsteptimer] > 0) - { - handleNoteOn(DRUM_MIDI_CHANNEL, seqdata[1][seqsteptimer] , 99); - } - if (seqdata[2][seqsteptimer] > 0) - { - handleNoteOn(DRUM_MIDI_CHANNEL, seqdata[2][seqsteptimer] , 99); - } - seqsteptimer++; - - if (seqsteptimer > 15) { - seqsteptimer = 0; - } - - } + sequencer(); } #ifdef ENABLE_LCD_UI LCDML.loop(); diff --git a/UI.hpp b/UI.hpp index 42ee64e..0426ce0 100644 --- a/UI.hpp +++ b/UI.hpp @@ -28,6 +28,7 @@ #include "config.h" #include "disp_plus.h" + #include "effect_modulated_delay.h" #include "effect_stereo_mono.h" #ifdef USE_PLATEREVERB @@ -63,12 +64,16 @@ extern void eeprom_update_dexed(uint8_t instance_id); extern float pseudo_log_curve(float value); extern uint8_t selected_instance_id; extern char receive_bank_filename[FILENAME_LEN]; -extern uint8_t seqdata[3][16]; -extern uint8_t seqsteptimer; +extern uint8_t seq_data[4][16]; +extern uint8_t seq_step_timer; extern bool seq_running; extern bool seq_recording; uint8_t seq_active_function = 99; uint8_t activesample; +extern uint8_t seq_active_track; +extern elapsedMillis seq_millis_timer; +extern uint8_t seq_menu; +extern bool seq_button_r; #if NUM_DRUMS > 0 #include "drums.h" #endif @@ -115,6 +120,7 @@ extern int perform_release_mod[NUM_DEXED]; extern float midi_ticks_factor[10]; extern uint8_t midi_bpm; + /*********************************************************************** GLOBAL ************************************************************************/ @@ -124,9 +130,6 @@ const char accepted_chars[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-abcdefghijk uint8_t active_perform_page = 1; uint8_t orig_attack_values[2][7]; uint8_t orig_release_values[2][7]; -uint8_t active_seq_track = 0; -uint8_t seq_menu; -bool seq_button_r = false; #ifdef I2C_DISPLAY #include @@ -3535,21 +3538,28 @@ void UI_handle_OP(uint8_t param) } -const char* seq_find_shortname(uint8_t seqstep) +const char* seq_find_shortname(uint8_t sstep) { const char* shortname = " "; bool found = false; - for (uint8_t d = 0; d < NUM_DRUMCONFIG - 1; d++) - { - if (seqdata[active_seq_track][seqstep] == drum_config[d].midinote) + + if (seq_active_track < 3) { + for (uint8_t d = 0; d < NUM_DRUMCONFIG - 1; d++) { - shortname = drum_config[d].shortname; - found = true; - break; + if (seq_data[seq_active_track][sstep] == drum_config[d].midinote) + { + shortname = drum_config[d].shortname; + found = true; + break; + } } - } - if (found == false) shortname = "-"; + if (found == false) shortname = "-"; + } else + { + if (seq_data[seq_active_track][sstep] > 0) shortname = "*"; else shortname = "-"; + + } return shortname; } @@ -3557,7 +3567,7 @@ const char* seq_find_shortname(uint8_t seqstep) void UI_func_sequencer(uint8_t param) { - char displayname[9]; + char displayname[7]; if (LCDML.FUNC_setup()) // ****** SETUP ********* { @@ -3582,8 +3592,7 @@ void UI_func_sequencer(uint8_t param) lcd.print("STP"); } lcd.setCursor(14, 0); - lcd.print(active_seq_track + 1); - lcd.setCursor(10, 0); + lcd.print(seq_active_track + 1); for (int i = 0; i < 16; i++) { lcd.setCursor(i, 1); lcd.print(seq_find_shortname(i) ); @@ -3612,9 +3621,9 @@ void UI_func_sequencer(uint8_t param) if ((LCDML.BT_checkDown() && encoderDir[ENC_R].Down()) || (LCDML.BT_checkUp() && encoderDir[ENC_R].Up())) { if (LCDML.BT_checkDown()) - active_seq_track = constrain(active_seq_track + 1, 0, 2); + seq_active_track = constrain(seq_active_track + 1, 0, 3); else if (LCDML.BT_checkUp()) - active_seq_track = constrain(active_seq_track - 1, 0, 2); + seq_active_track = constrain(seq_active_track - 1, 0, 3); } } if (seq_button_r) //handle button presses during menu >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> @@ -3626,16 +3635,16 @@ void UI_func_sequencer(uint8_t param) } else if ( seq_menu == 0 && seq_active_function == 0) { if (activesample == NUM_DRUMCONFIG + 2) { - memset(seqdata[0], 0, sizeof(seqdata[0])); - memset(seqdata[1], 0, sizeof(seqdata[1])); - memset(seqdata[2], 0, sizeof(seqdata[2])); + memset(seq_data[0], 0, sizeof(seq_data[0])); + memset(seq_data[1], 0, sizeof(seq_data[1])); + memset(seq_data[2], 0, sizeof(seq_data[2])); for (int i = 0; i < 16; i++) { lcd.setCursor(i, 1); lcd.print(seq_find_shortname(i) ); } } else if (activesample == NUM_DRUMCONFIG + 1) { - memset(seqdata[active_seq_track], 0, sizeof(seqdata[active_seq_track])); + memset(seq_data[seq_active_track], 0, sizeof(seq_data[seq_active_track])); for (int i = 0; i < 16; i++) { lcd.setCursor(i, 1); lcd.print(seq_find_shortname(i) ); @@ -3665,6 +3674,7 @@ void UI_func_sequencer(uint8_t param) seq_recording = false; seq_note_in = 0; lcd.print("PLY"); + MicroDexed[0]->panic(); } } else if ( seq_menu == 2) @@ -3673,7 +3683,7 @@ void UI_func_sequencer(uint8_t param) } else if (seq_menu > 2) { if (seq_active_function == 99) { - seqdata[active_seq_track][seq_menu - 3] = drum_config[activesample].midinote; + seq_data[seq_active_track][seq_menu - 3] = drum_config[activesample].midinote; } else seq_active_function = 99; @@ -3741,7 +3751,7 @@ void UI_func_sequencer(uint8_t param) lcd.setCursor(13, 0); lcd.print("["); lcd.setCursor(14, 0); - lcd.print(active_seq_track + 1); + lcd.print(seq_active_track + 1); lcd.setCursor(15, 0); lcd.print("]"); lcd.setCursor(0, 1); @@ -3773,6 +3783,10 @@ void UI_func_sequencer(uint8_t param) if (LCDML.FUNC_close()) // ****** STABLE END ********* { encoderDir[ENC_R].reset(); + seq_running = false; + seq_recording = false; + seq_note_in = 0; + MicroDexed[0]->panic(); } } diff --git a/sequencer.cpp b/sequencer.cpp new file mode 100644 index 0000000..a0dbfd8 --- /dev/null +++ b/sequencer.cpp @@ -0,0 +1,101 @@ + +#include "config.h" +#include "sequencer.h" +#include +#include + +extern LCDMenuLib2 LCDML; +extern LiquidCrystal_I2C lcd; +extern config_t configuration; +extern void handleNoteOn(byte , byte , byte ); +extern void handleNoteOff(byte , byte , byte ); +extern void UI_func_sequencer(uint8_t); +extern const char* seq_find_shortname(uint8_t); + +void sequencer() +{ + bool seq_noteoffsent = false; + + if (seq_note_in > 0 && seq_recording == false && seq_active_track == 3 && seq_note_in < 71) { + handleNoteOff(configuration.dexed[0].midi_channel, seq_data[3][seq_step_timer] + seq_transpose , 0); + handleNoteOff(configuration.dexed[0].midi_channel, seq_data[3][seq_step_timer - 1] + seq_transpose , 0); + + seq_transpose = seq_note_in - 6 * 12 + 3; + seq_note_in = 0; + } + + if (seq_millis_timer > seq_timer_previous + 136) + + { + seq_timer_previous = seq_millis_timer; + + if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_sequencer)) { + + //write to sequencer if in sequencer menu (step recording and live recording) + if (seq_note_in > 0 && seq_recording == true) { + + if (seq_active_track == 3) handleNoteOff(configuration.dexed[0].midi_channel, seq_data[3][seq_step_timer] + seq_transpose , 0); + + seq_data[seq_active_track][seq_step_timer] = seq_note_in; + seq_note_in = 0; + } + lcd.setCursor(seq_step_timer, 1); + lcd.print("X"); + if (seq_step_timer == 0) { + lcd.setCursor(15, 1); + lcd.print(seq_find_shortname(15)); + } + else + { + lcd.setCursor(seq_step_timer - 1, 1); + lcd.print(seq_find_shortname(seq_step_timer - 1)); + } + } + if (seq_data[0][seq_step_timer] > 0) + { + handleNoteOn(DRUM_MIDI_CHANNEL, seq_data[0][seq_step_timer] , 99); + } + if (seq_data[1][seq_step_timer] > 0) + { + handleNoteOn(DRUM_MIDI_CHANNEL, seq_data[1][seq_step_timer] , 99); + } + if (seq_data[2][seq_step_timer] > 0) + { + handleNoteOn(DRUM_MIDI_CHANNEL, seq_data[2][seq_step_timer] , 99); + } + if (seq_data[3][seq_step_timer] > 0) //test instrument sequencer Instance=2 + { + handleNoteOn(configuration.dexed[0].midi_channel, seq_data[3][seq_step_timer] + seq_transpose , 99); + } + + seq_noteoffsent = false; + seq_step_timer++; + + if (seq_step_timer > 15) { + seq_step_timer = 0; + } + + } + + if (seq_millis_timer > seq_timer_previous + 80 && seq_noteoffsent == false) + + { + if (seq_step_timer > 0) { + if (seq_data[3][seq_step_timer - 1] > 0) //test instrument sequencer Instance=2 + { + handleNoteOff(configuration.dexed[0].midi_channel, seq_data[3][seq_step_timer - 1] + seq_transpose , 0); + } + } else + { + if (seq_step_timer == 0) { + if (seq_data[3][15] > 0) //test instrument sequencer Instance=2 + { + handleNoteOff(configuration.dexed[0].midi_channel, seq_data[3][15] + seq_transpose , 0); + ; + } + + } + } + seq_noteoffsent = true; + } +} diff --git a/sequencer.h b/sequencer.h new file mode 100644 index 0000000..4a2bab3 --- /dev/null +++ b/sequencer.h @@ -0,0 +1,17 @@ + +uint8_t seq_active_track = 0; +uint8_t seq_menu; +bool seq_button_r = false; +bool seq_noteoffsent = false; +elapsedMillis seq_millis_timer; +uint8_t seq_step_timer = 0; +uint32_t seq_timer_previous = 0; +bool seq_running = false; +bool seq_recording = false; +uint8_t seq_note_in; +int seq_transpose; +uint8_t seq_data[4][16] = {72, 0, 0, 0, 72, 0, 0, 0, 72, 0, 0, 0, 72, 0, 0, 0, + 0, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 75, 0, 0, 0, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 45, 45, 57, 57, 45, 45, 57, 57, 45, 45, 57, 57, 45, 45, 57, 57, + };