From c046111e404555df3b0fe43badf17ee8b51df2a2 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 29 Apr 2019 14:47:01 +0200 Subject: [PATCH] Implemented soft volume changing. Changed volume displaying towards a simpler display algorithm. Small fixes. --- MicroDexed.ino | 21 +++++++++++++++++++-- UI.cpp | 40 +++++++++++++++++++++++++++------------- UI.h | 1 + config.h | 11 +++++++++-- 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 94d5cee..45aaa2a 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -72,8 +72,8 @@ AudioConnection patchCord10(volume_l, 0, i2s1, 1); AudioControlSGTL5000 sgtl5000_1; #elif defined(TGA_AUDIO_BOARD) AudioOutputI2S i2s1; -AudioConnection patchCord9(volume_r, 0, i2s1, 1); -AudioConnection patchCord10(volume_l, 0, i2s1, 0); +AudioConnection patchCord9(volume_r, 0, i2s1, 0); +AudioConnection patchCord10(volume_l, 0, i2s1, 1); AudioControlWM8731master wm8731_1; #else AudioOutputPT8211 pt8211_1; @@ -111,6 +111,7 @@ elapsedMillis cpu_mem_millis; #endif config_t configuration = {0xffff, 0, 0, VOLUME, 0.5f, DEFAULT_MIDI_CHANNEL}; bool eeprom_update_flag = false; +value_change_t soften_volume = {0.0, 0}; void setup() { @@ -323,6 +324,22 @@ void loop() // Shutdown unused voices active_voices = dexed->getNumNotesPlaying(); + + // check for value changes + if (soften_volume.steps > 0) + { + // soften volume value + soften_volume.steps--; + set_volume(configuration.vol + soften_volume.diff, configuration.pan); +#ifdef DEBUG + Serial.print(F("Volume: ")); + Serial.print(configuration.vol, 5); + Serial.print(F(" Volume step: ")); + Serial.print(soften_volume.steps); + Serial.print(F(" Volume diff: ")); + Serial.println(soften_volume.diff, 5); +#endif + } } #ifdef I2C_DISPLAY diff --git a/UI.cpp b/UI.cpp index da81939..f727286 100644 --- a/UI.cpp +++ b/UI.cpp @@ -203,6 +203,7 @@ void handle_ui(void) switch (i) { case 0: // left encoder moved + float tmp; switch (ui_state) { case UI_MAIN: @@ -211,7 +212,18 @@ void handle_ui(void) enc[i].write(0); else if (enc[i].read() >= ENC_VOL_STEPS) enc[i].write(ENC_VOL_STEPS); - set_volume(float(map(enc[i].read(), 0, ENC_VOL_STEPS, 0, 100)) / 100, configuration.pan); + //set_volume(float(map(enc[i].read(), 0, ENC_VOL_STEPS, 0, 100)) / 100, configuration.pan); + tmp = (float(map(enc[i].read(), 0, ENC_VOL_STEPS, 0, 100)) / 100) - configuration.vol; + soften_volume.diff = tmp / SOFTEN_VALUE_CHANGE_STEPS; + soften_volume.steps = SOFTEN_VALUE_CHANGE_STEPS; +#ifdef DEBUG + Serial.print(F("Setting soften volume from: ")); + Serial.print(configuration.vol, 5); + Serial.print(F(" Volume step: ")); + Serial.print(soften_volume.steps); + Serial.print(F(" Volume diff: ")); + Serial.println(soften_volume.diff, 5); +#endif eeprom_write(); ui_show_volume(); break; @@ -416,28 +428,30 @@ void ui_show_main(void) void ui_show_volume(void) { + uint8_t pos; + static uint8_t old_pos; + ui_back_to_main = 0; + // erase old marker and show new marker + pos = map(configuration.vol * 100, 0, 100, 0, LCD_CHARS); + if (ui_state != UI_VOLUME) { lcd.clear(); lcd.show(0, 0, LCD_CHARS, "Volume"); + lcd.show(1, pos, 1, "*"); + old_pos = pos; } + // show value lcd.show(0, LCD_CHARS - 3, 3, configuration.vol * 100); - if (configuration.vol == 0.0) - lcd.show(1, 0, LCD_CHARS , " "); - else + + if (pos != old_pos) { - if (configuration.vol < (float(LCD_CHARS) / 100)) - lcd.show(1, 0, LCD_CHARS, "*"); - else - { - for (uint8_t i = 0; i < map(configuration.vol * 100, 0, 100, 0, LCD_CHARS); i++) - lcd.show(1, i, 1, "*"); - for (uint8_t i = map(configuration.vol * 100, 0, 100, 0, LCD_CHARS); i < LCD_CHARS; i++) - lcd.show(1, i, 1, " "); - } + lcd.show(1, pos, 1, "*"); + lcd.show(1, old_pos, 1, " "); + old_pos=pos; } ui_state = UI_VOLUME; diff --git a/UI.h b/UI.h index c720677..40c5435 100644 --- a/UI.h +++ b/UI.h @@ -56,6 +56,7 @@ extern bool effect_delay_sync; extern AudioEffectDelay delay1; extern AudioMixer4 mixer1; extern AudioMixer4 mixer2; +extern value_change_t soften_volume; void handle_ui(void); void ui_show_main(void); diff --git a/config.h b/config.h index f271e29..d60fc31 100644 --- a/config.h +++ b/config.h @@ -46,7 +46,7 @@ // AUDIO // If nothing is defined PT8211 is used as audio output device! #define TEENSY_AUDIO_BOARD 1 -//#define TGA_AUDIO_BOARD +//#define TGA_AUDIO_BOARD //************************************************************************************************* //* MIDI SETTINGS @@ -89,11 +89,12 @@ #define REDUCE_LOUDNESS 1 #endif #define SAMPLE_RATE 44100 +#define SOFTEN_VALUE_CHANGE_STEPS 10 //************************************************************************************************* //* UI AND DATA-STORE SETTINGS //************************************************************************************************* -#define CONTROL_RATE_MS 200 +#define CONTROL_RATE_MS 100 #define TIMER_UI_HANDLING_MS 100 //************************************************************************************************* @@ -192,4 +193,10 @@ struct config_t { float pan; uint8_t midi_channel; }; + +// struct for smoothing value changes +struct value_change_t { + float diff; + uint16_t steps; +}; #endif // CONFIG_H_INCLUDED