diff --git a/MicroDexed.ino b/MicroDexed.ino index 517be67..bc5325c 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -104,7 +104,7 @@ 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=930; +uint8_t effect_filter_frq=ENC_FILTER_FRQ_STEPS; 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; diff --git a/UI.cpp b/UI.cpp index 644747a..5dfc542 100644 --- a/UI.cpp +++ b/UI.cpp @@ -290,8 +290,12 @@ void handle_ui(void) enc[i].write(0); 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); + effect_filter_frq = enc[i].read(); + filter1.frequency(EXP_FUNC((float)map(enc[i].read(), 0, ENC_FILTER_FRQ_STEPS, 0, 1024) / 150.0) * 10.0 + 80.0); +#ifdef DEBUG + Serial.print(F("Setting filter frequency to: ")); + Serial.println(EXP_FUNC((float)map(enc[i].read(), 0, ENC_FILTER_FRQ_STEPS, 0, 1024) / 150.0) * 10.0 + 80.0, DEC); +#endif break; case UI_MAIN_FILTER_RES: if (enc[i].read() <= 0) @@ -300,6 +304,10 @@ void handle_ui(void) 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)); +#ifdef DEBUG + Serial.print(F("Setting filter resonance to: ")); + Serial.println(mapfloat(effect_filter_resonance, 0, ENC_FILTER_RES_STEPS, 0.7, 5.0), 2); +#endif break; case UI_MAIN_FILTER_OCT: if (enc[i].read() <= 0) @@ -308,6 +316,10 @@ void handle_ui(void) enc[i].write(ENC_FILTER_OCT_STEPS); effect_filter_octave = enc[i].read(); filter1.octaveControl(mapfloat(effect_filter_octave, 0, ENC_FILTER_OCT_STEPS, 0.0, 7.0)); +#ifdef DEBUG + Serial.print(F("Setting filter octave control to: ")); + Serial.println(mapfloat(effect_filter_octave, 0, ENC_FILTER_OCT_STEPS, 0.0, 7.0), 2); +#endif break; } ui_show_effects_filter(); @@ -321,7 +333,11 @@ void handle_ui(void) 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)); + delay1.delay(0, map(effect_delay_time, 0, ENC_DELAY_TIME_STEPS, 0, DELAY_MAX_TIME)); +#ifdef DEBUG + Serial.print(F("Setting delay time to: ")); + Serial.println(map(effect_delay_time, 0, ENC_DELAY_TIME_STEPS, 0, DELAY_MAX_TIME)); +#endif break; case UI_MAIN_DELAY_FEEDBACK: if (enc[i].read() <= 0) @@ -329,7 +345,11 @@ void handle_ui(void) 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)); + mixer1.gain(1, mapfloat(float(effect_delay_feedback), 0, ENC_DELAY_FB_STEPS, 0.0, 1.0)); +#ifdef DEBUG + Serial.print(F("Setting delay feedback to: ")); + Serial.println(mapfloat(float(effect_delay_feedback), 0, ENC_DELAY_FB_STEPS, 0.0, 1.0)); +#endif break; case UI_MAIN_DELAY_SYNC: if (enc[i].read() <= 0) @@ -338,6 +358,10 @@ void handle_ui(void) enc[i].write(1); effect_delay_sync = enc[i].read(); // Nothing to do here +#ifdef DEBUG + Serial.print(F("Setting delay sync to: ")); + Serial.println(effect_delay_sync); +#endif break; } ui_show_effects_delay(); @@ -460,19 +484,19 @@ void ui_show_effects_filter(void) lcd.show(1, 8, 4, "Oct:"); } - lcd.show(0, 10, 3, effect_filter_frq); + lcd.show(0, 10, 4, uint16_t(EXP_FUNC((float)map(effect_filter_frq, 0, ENC_FILTER_FRQ_STEPS, 0, 1024) / 150.0) * 10.0 + 80.5)); 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) { lcd.show(0, 9, 1, "["); - lcd.show(0, 13, 1, "]"); + lcd.show(0, 14, 1, "]"); } else { lcd.show(0, 9, 1, " "); - lcd.show(0, 13, 1, " "); + lcd.show(0, 14, 1, " "); } if (ui_main_state == UI_MAIN_FILTER_RES) @@ -513,7 +537,7 @@ void ui_show_effects_delay(void) } 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, 4, 2, map(effect_delay_feedback, 0, ENC_DELAY_FB_STEPS, 0, 99)); lcd.show(1, 14, 1, effect_delay_sync); if (ui_main_state == UI_MAIN_DELAY_TIME) @@ -552,9 +576,8 @@ 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) +float mapfloat(float val, float in_min, float in_max, float out_min, float out_max) { - return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min; + return (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } - #endif diff --git a/UI.h b/UI.h index 3dd3f25..e9b5e1e 100644 --- a/UI.h +++ b/UI.h @@ -52,7 +52,7 @@ extern void eeprom_write(uint8_t status); extern void set_volume(float v, float vr, float vl); extern elapsedMillis autostore; extern elapsedMillis long_button_pressed; -extern uint16_t effect_filter_frq; +extern uint8_t effect_filter_frq; extern uint8_t effect_filter_resonance; extern uint8_t effect_filter_octave; extern uint8_t effect_delay_time; @@ -68,7 +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); +float mapfloat(float val, float in_min, float in_max, float out_min, float 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 e077735..8db4949 100644 --- a/config.h +++ b/config.h @@ -60,7 +60,7 @@ #endif // EFFECTS -#define FILTER_MAX_FREQ 1000 +#define FILTER_MAX_FREQ 10000 #define DELAY_MAX_TIME 1200 // Master key handling (comment for disabling)