From 1bab42b0cc61e735e942719cc498f791e12075aa Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 11 Oct 2018 10:18:08 +0200 Subject: [PATCH] Effects-UI is ready for testing. --- MicroDexed.ino | 8 ++--- UI.cpp | 79 +++++++++++++++++++++++++++++++++++--------------- UI.h | 3 +- config.h | 7 +++++ 4 files changed, 69 insertions(+), 28 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 09e65c9..a181e56 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -104,10 +104,10 @@ uint8_t midi_timing_counter = 0; // 24 per qarter elapsedMillis midi_timing_timestep; uint16_t midi_timing_quarter = 0; elapsedMillis long_button_pressed; -uint16_t effect_filter_frq=100; -uint8_t effect_filter_resonance=0; -uint8_t effect_filter_octave=0; -uint16_t effect_delay_time=0; +uint16_t effect_filter_frq=930; +uint8_t effect_filter_resonance=(0.07*ENC_FILTER_RES_STEPS/4.3)+0.5; +uint8_t effect_filter_octave=(1.0*ENC_FILTER_RES_STEPS/8.0)+0.5; +uint8_t effect_delay_time=0; uint8_t effect_delay_feedback=0; bool effect_delay_sync=0; diff --git a/UI.cpp b/UI.cpp index fa8ccb8..a957ac2 100644 --- a/UI.cpp +++ b/UI.cpp @@ -288,31 +288,58 @@ void handle_ui(void) case UI_MAIN_FILTER_FRQ: if (enc[i].read() <= 0) enc[i].write(0); - else if (enc[i].read() > 100) - enc[i].write(100); - effect_filter_frq = map(enc[i].read(), 0, 100, 0, 20000); + else if (enc[i].read() > ENC_FILTER_FRQ_STEPS) + enc[i].write(ENC_FILTER_FRQ_STEPS); + effect_filter_frq = expf((float)map(enc[i].read(), 0, ENC_FILTER_FRQ_STEPS, 0, 1024) / 150.0) * 10.0 + 80.0; filter1.frequency(effect_filter_frq); break; case UI_MAIN_FILTER_RES: if (enc[i].read() <= 0) enc[i].write(0); - else if (enc[i].read() > 100) - enc[i].write(100); - effect_filter_resonance = map(enc[i].read(), 0, 100, 0.7, 5.0); - filter1.resonance(effect_filter_resonance); + else if (enc[i].read() > ENC_FILTER_RES_STEPS) + enc[i].write(ENC_FILTER_RES_STEPS); + effect_filter_resonance = enc[i].read(); + filter1.resonance(mapfloat(effect_filter_resonance, 0, ENC_FILTER_RES_STEPS, 0.7, 5.0)); break; case UI_MAIN_FILTER_OCT: if (enc[i].read() <= 0) enc[i].write(0); - else if (enc[i].read() > 9) - enc[i].write(100); - effect_filter_octave = map(enc[i].read(), 0, 9, 0.0, 9.0); - filter1.octaveControl(effect_filter_octave); + else if (enc[i].read() > ENC_FILTER_OCT_STEPS) + enc[i].write(ENC_FILTER_OCT_STEPS); + effect_filter_octave = enc[i].read(); + filter1.octaveControl(mapfloat(enc[i].read(), 0, ENC_FILTER_OCT_STEPS, 0.0, 7.0)); break; } ui_show_effects_filter(); break; case UI_EFFECTS_DELAY: + switch (ui_main_state) + { + case UI_MAIN_DELAY_TIME: + if (enc[i].read() <= 0) + enc[i].write(0); + else if (enc[i].read() > ENC_DELAY_TIME_STEPS) + enc[i].write(ENC_DELAY_TIME_STEPS); + effect_delay_time = enc[i].read();; + delay1.delay(0,map(effect_delay_feedback, 0, ENC_DELAY_TIME_STEPS, 0, DELAY_MAX_TIME)); + break; + case UI_MAIN_DELAY_FEEDBACK: + if (enc[i].read() <= 0) + enc[i].write(0); + else if (enc[i].read() > ENC_DELAY_FB_STEPS) + enc[i].write(ENC_DELAY_FB_STEPS); + effect_delay_feedback = enc[i].read(); + mixer1.gain(1, mapfloat(effect_delay_feedback,0,99,0.0,1.0)); + break; + case UI_MAIN_DELAY_SYNC: + if (enc[i].read() <= 0) + enc[i].write(0); + else if (enc[i].read() >= 1) + enc[i].write(1); + effect_delay_sync = enc[i].read(); + // Nothing to do here + break; + } ui_show_effects_delay(); break; } @@ -430,12 +457,12 @@ void ui_show_effects_filter(void) lcd.show(0, 0, LCD_CHARS, "Filter"); lcd.show(0, 7, 2, "F:"); lcd.show(1, 0, 4, "Res:"); - lcd.show(1, 9, 4, "Oct:"); + lcd.show(1, 8, 4, "Oct:"); } - lcd.show(0, 10, 4, effect_filter_frq); - lcd.show(1, 5, 3, effect_filter_resonance); - lcd.show(1, 14, 1, effect_filter_octave); + lcd.show(0, 10, 3, effect_filter_frq); + lcd.show(1, 5, 2, map(effect_filter_resonance, 0, ENC_FILTER_RES_STEPS, 0, 99)); + lcd.show(1, 13, 2, map(effect_filter_octave, 0, ENC_FILTER_OCT_STEPS, 0, 80)); if (ui_main_state == UI_MAIN_FILTER_FRQ) { @@ -451,22 +478,22 @@ void ui_show_effects_filter(void) if (ui_main_state == UI_MAIN_FILTER_RES) { lcd.show(1, 4, 1, "["); - lcd.show(1, 8, 1, "]"); + lcd.show(1, 7, 1, "]"); } else { lcd.show(1, 4, 1, " "); - lcd.show(1, 8, 1, " "); + lcd.show(1, 7, 1, " "); } if (ui_main_state == UI_MAIN_FILTER_OCT) { - lcd.show(1, 13, 1, "["); + lcd.show(1, 12, 1, "["); lcd.show(1, 15, 1, "]"); } else { - lcd.show(1, 13, 1, " "); + lcd.show(1, 12, 1, " "); lcd.show(1, 15, 1, " "); } @@ -485,8 +512,8 @@ void ui_show_effects_delay(void) lcd.show(1, 8, 5, "Sync:"); } - lcd.show(0, 9, 4, effect_delay_time); - lcd.show(1, 4, 3, effect_delay_feedback); + lcd.show(0, 9, 4, map(effect_delay_time, 0, ENC_DELAY_TIME_STEPS, 0, 1200)); + lcd.show(1, 4, 2, map(effect_delay_feedback, 0, ENC_DELAY_TIME_STEPS, 0, 99)); lcd.show(1, 14, 1, effect_delay_sync); if (ui_main_state == UI_MAIN_DELAY_TIME) @@ -503,12 +530,12 @@ void ui_show_effects_delay(void) if (ui_main_state == UI_MAIN_DELAY_FEEDBACK) { lcd.show(1, 3, 1, "["); - lcd.show(1, 7, 1, "]"); + lcd.show(1, 6, 1, "]"); } else { lcd.show(1, 3, 1, " "); - lcd.show(1, 7, 1, " "); + lcd.show(1, 6, 1, " "); } if (ui_main_state == UI_MAIN_DELAY_SYNC) @@ -524,4 +551,10 @@ void ui_show_effects_delay(void) ui_state = UI_EFFECTS_DELAY; } + +float mapfloat(long x, long in_min, long in_max, long out_min, long out_max) +{ + return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min; +} + #endif diff --git a/UI.h b/UI.h index 9812ac2..3dd3f25 100644 --- a/UI.h +++ b/UI.h @@ -55,7 +55,7 @@ extern elapsedMillis long_button_pressed; extern uint16_t effect_filter_frq; extern uint8_t effect_filter_resonance; extern uint8_t effect_filter_octave; -extern uint16_t effect_delay_time; +extern uint8_t effect_delay_time; extern uint8_t effect_delay_feedback; extern bool effect_delay_sync; extern AudioFilterStateVariable filter1; @@ -68,6 +68,7 @@ void ui_show_volume(void); void ui_show_midichannel(void); void ui_show_effects_filter(void); void ui_show_effects_delay(void); +float mapfloat(long x, long in_min, long in_max, long out_min, long out_max); enum ui_states {UI_MAIN, UI_VOLUME, UI_MIDICHANNEL, UI_EFFECTS_FILTER, UI_EFFECTS_DELAY}; enum ui_main_states {UI_MAIN_BANK, UI_MAIN_VOICE, UI_MAIN_BANK_SELECTED, UI_MAIN_VOICE_SELECTED, UI_MAIN_FILTER_FRQ, UI_MAIN_FILTER_RES, UI_MAIN_FILTER_OCT, UI_MAIN_DELAY_TIME, UI_MAIN_DELAY_FEEDBACK, UI_MAIN_DELAY_VOLUME, UI_MAIN_DELAY_SYNC}; diff --git a/config.h b/config.h index e22e389..e077735 100644 --- a/config.h +++ b/config.h @@ -60,6 +60,8 @@ #endif // EFFECTS +#define FILTER_MAX_FREQ 1000 +#define DELAY_MAX_TIME 1200 // Master key handling (comment for disabling) //#define MASTER_KEY_MIDI MIDI_C7 @@ -103,6 +105,11 @@ // Encoder with button #define ENC_VOL_STEPS 43 +#define ENC_FILTER_FRQ_STEPS 50 +#define ENC_FILTER_RES_STEPS 35 +#define ENC_FILTER_OCT_STEPS 27 +#define ENC_DELAY_TIME_STEPS 50 +#define ENC_DELAY_FB_STEPS 35 #define TIMER_UI_HANDLING_MS 100 #define NUM_ENCODER 2 #define ENC_L_PIN_A 3