From 0d7652dd82576326f63298e2b483282b95e1161f Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Fri, 17 May 2019 13:49:56 +0200 Subject: [PATCH] Several fixes. --- .swp | Bin 12288 -> 0 bytes MicroMDAEPiano.ino | 66 ++++++++++++++++++++++++--------------------- UI.hpp | 55 +++++++++++++++++++------------------ 3 files changed, 62 insertions(+), 59 deletions(-) delete mode 100644 .swp diff --git a/.swp b/.swp deleted file mode 100644 index d2a572e624d997186089d3ba34bfd44d80084ad3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI%O-sWt7zgmoi+EAd4`8g9$wEn|-4suPFa$kL@EH4I!}>;>;>$(U59@dEv}bL1 z&_nSg8~j6`JfuyUr$6YS^g-TT-|{nCGHSbvu4&(wj6LbXye?04N(x z;d7#72tWV=5P$##AOHafKmY;|fIx>pKT*#UrBlI+pv<$h3Zzi}OcsetParameter(MDA_EP_DECAY, 0.5); - ep->setParameter(MDA_EP_RELEASE, 0.5); - ep->setParameter(MDA_EP_HARDNESS, 0.7); - ep->setParameter(MDA_EP_TREBLE, 0.85); - ep->setParameter(MDA_EP_DETUNE, 0.1); - ep->setParameter(MDA_EP_VELOCITY_SENSE, 1.0); - ep->setParameter(MDA_EP_STEREO, 0.7); - ep->setParameter(MDA_EP_OVERDRIVE, 0.3); - - freeverb_r.roomsize(0.2); - freeverb_l.roomsize(0.2); - freeverb_r.damping(0.5); - freeverb_l.damping(0.5); - mixer_r.gain(0, 0.7); - mixer_l.gain(0, 0.7); - mixer_r.gain(1, 0.3); - mixer_l.gain(1, 0.3); + /*^ + ep->setParameter(MDA_EP_DECAY, 0.5); + ep->setParameter(MDA_EP_RELEASE, 0.5); + ep->setParameter(MDA_EP_HARDNESS, 0.7); + ep->setParameter(MDA_EP_TREBLE, 0.85); + ep->setParameter(MDA_EP_DETUNE, 0.1); + ep->setParameter(MDA_EP_VELOCITY_SENSE, 1.0); + ep->setParameter(MDA_EP_STEREO, 0.7); + ep->setParameter(MDA_EP_OVERDRIVE, 0.3); + + freeverb_r.roomsize(0.2); + freeverb_l.roomsize(0.2); + freeverb_r.damping(0.5); + freeverb_l.damping(0.5); + mixer_r.gain(0, 0.7); + mixer_l.gain(0, 0.7); + mixer_r.gain(1, 0.3); + mixer_l.gain(1, 0.3); + */ + set_complete_configuration(); AudioInterrupts(); @@ -449,28 +450,31 @@ bool checkMidiChannel(byte inChannel) return (true); } -void set_volume(float v, float p) +void set_master_volume(uint8_t value) { - configuration.loudness = v; - configuration.pan = p; - + uint16_t tmp = map(value, ENC_MASTER_VOLUME_MIN, ENC_MASTER_VOLUME_MAX, 0, 0x3ff); + float tmp2 = mapfloat(configuration.pan, ENC_MASTER_PAN_MIN, ENC_MASTER_PAN_MAX, 0.0, 1.0); + float tmp3 = (float)(tmp * (tmp + 2)) / (float)(1 << 20); #ifdef DEBUG + Serial.print(tmp, DEC); Serial.print(F("Setting volume: VOL=")); - Serial.print(v, DEC); + Serial.print(value, DEC); Serial.print(F("[")); - Serial.print(configuration.loudness, DEC); + Serial.print(tmp3, 3); Serial.print(F("] PAN=")); - Serial.print(F("[")); Serial.print(configuration.pan, DEC); + Serial.print(F("[")); + Serial.print(tmp2, 3); Serial.print(F("] ")); - Serial.print(pow(configuration.loudness * sinf(configuration.pan * PI / 2), VOLUME_CURVE), 3); + Serial.print(tmp3 * sinf(tmp2 * PI / 2), 3); Serial.print(F("/")); - Serial.println(pow(configuration.loudness * cosf( configuration.pan * PI / 2), VOLUME_CURVE), 3); + Serial.println(tmp3 * cosf(tmp2 * PI / 2), 3); #endif + // float v = (float)(a * (a + 2))/(float)(1 << 20); // (pseudo-) logarithmic curve for volume control // http://files.csound-tutorial.net/floss_manual/Release03/Cs_FM_03_ScrapBook/b-panning-and-spatialization.html - mixer_r.gain(0, sinf(p * PI / 2)); - mixer_l.gain(0, cosf(p * PI / 2)); + mixer_r.gain(0, tmp3 * sinf(tmp2 * PI / 2)); + mixer_l.gain(0, tmp3 * cosf(tmp2 * PI / 2)); } /****************************************************************************** diff --git a/UI.hpp b/UI.hpp index 9344fc0..640741d 100644 --- a/UI.hpp +++ b/UI.hpp @@ -93,7 +93,7 @@ int8_t menu_position[NUM_MENUS]; #define RIGHT_ENCODER 1 extern mdaEPiano* ep; -extern void set_volume(float v, float p); +extern void set_master_volume(uint8_t value); extern AudioControlSGTL5000 sgtl5000_1; extern AudioEffectFreeverb freeverb_r; extern AudioEffectFreeverb freeverb_l; @@ -520,7 +520,7 @@ LiquidMenu loudness_menu(lcd); MIDI_CHANNEL MENU ******************************************/ #define NUM_MIDI_CHANNEL_MENUS 1 -const char midi_channel_text1[] PROGMEM = "MIDI CHannel"; +const char midi_channel_text1[] PROGMEM = "MIDI Channel"; LiquidLine midi_channel_line1(1, 0, midi_channel_text1); LiquidLine midi_channel_line2(1, 1, configuration.midi_channel); LiquidScreen midi_channel_screen; @@ -753,7 +753,7 @@ void callback_pan_trem_frequency_function() menu_system.change_menu(pan_trem_frequency_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.pan_trem_frequency; - enc[RIGHT_ENCODER].write(configuration.pan_trem_frequency, 0, 99); + enc[RIGHT_ENCODER].write(configuration.pan_trem_frequency, ENC_PAN_TREM_FREQUENCY_MIN, ENC_PAN_TREM_FREQUENCY_MAX); menu_system.update(); } @@ -765,7 +765,7 @@ void callback_pan_trem_level_function() menu_system.change_menu(pan_trem_level_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.pan_trem_level; - enc[RIGHT_ENCODER].write(configuration.pan_trem_level, 0, 99); + enc[RIGHT_ENCODER].write(configuration.pan_trem_level, ENC_PAN_TREM_LEVEL_MIN, ENC_PAN_TREM_LEVEL_MAX); menu_system.update(); } @@ -777,7 +777,7 @@ void callback_overdrive_function() menu_system.change_menu(overdrive_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.overdrive; - enc[RIGHT_ENCODER].write(configuration.overdrive, 0, 99); + enc[RIGHT_ENCODER].write(configuration.overdrive, ENC_OVERDRIVE_MIN, ENC_OVERDRIVE_MAX); menu_system.update(); } @@ -789,7 +789,7 @@ void callback_comp_gain_function() menu_system.change_menu(comp_gain_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.comp_gain; - enc[RIGHT_ENCODER].write(configuration.comp_gain, 0, 99); + enc[RIGHT_ENCODER].write(configuration.comp_gain, ENC_COMP_GAIN_MIN, ENC_COMP_GAIN_MAX); menu_system.update(); } @@ -801,7 +801,7 @@ void callback_comp_response_function() menu_system.change_menu(comp_response_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.comp_response; - enc[RIGHT_ENCODER].write(configuration.comp_response, 0, 99); + enc[RIGHT_ENCODER].write(configuration.comp_response, ENC_COMP_RESPONSE_MIN, ENC_COMP_RESPONSE_MAX); menu_system.update(); } @@ -813,7 +813,7 @@ void callback_comp_limit_function() menu_system.change_menu(comp_limit_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.comp_limit; - enc[RIGHT_ENCODER].write(configuration.comp_limit, 0, 99); + enc[RIGHT_ENCODER].write(configuration.comp_limit, ENC_COMP_LIMIT_MIN, ENC_COMP_LIMIT_MAX); menu_system.update(); } @@ -825,7 +825,7 @@ void callback_comp_threshold_function() menu_system.change_menu(comp_threshold_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.comp_threshold; - enc[RIGHT_ENCODER].write(configuration.comp_threshold, 0, 99); + enc[RIGHT_ENCODER].write(configuration.comp_threshold, ENC_COMP_THRESHOLD_MIN, ENC_COMP_THRESHOLD_MAX); menu_system.update(); } @@ -837,7 +837,7 @@ void callback_comp_attack_function() menu_system.change_menu(comp_attack_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.comp_attack; - enc[RIGHT_ENCODER].write(configuration.comp_attack, 0, 99); + enc[RIGHT_ENCODER].write(configuration.comp_attack, ENC_COMP_ATTACK_MIN, ENC_COMP_ATTACK_MAX); menu_system.update(); } @@ -849,7 +849,7 @@ void callback_comp_decay_function() menu_system.change_menu(comp_decay_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.comp_decay; - enc[RIGHT_ENCODER].write(configuration.comp_decay, 0, 99); + enc[RIGHT_ENCODER].write(configuration.comp_decay, ENC_COMP_DECAY_MIN, ENC_COMP_DECAY_MAX); menu_system.update(); } @@ -861,7 +861,7 @@ void callback_reverb_roomsize_function() menu_system.change_menu(reverb_roomsize_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.reverb_roomsize; - enc[RIGHT_ENCODER].write(configuration.reverb_roomsize, 0, 99); + enc[RIGHT_ENCODER].write(configuration.reverb_roomsize, ENC_REVERB_ROOMSIZE_MIN, ENC_REVERB_ROOMSIZE_MAX); menu_system.update(); } @@ -873,7 +873,7 @@ void callback_reverb_damping_function() menu_system.change_menu(reverb_damping_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.reverb_damping; - enc[RIGHT_ENCODER].write(configuration.reverb_damping, 0, 99); + enc[RIGHT_ENCODER].write(configuration.reverb_damping, ENC_REVERB_DAMPING_MIN, ENC_REVERB_DAMPING_MAX); menu_system.update(); } @@ -885,7 +885,7 @@ void callback_reverb_level_function() menu_system.change_menu(reverb_level_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.reverb_level; - enc[RIGHT_ENCODER].write(configuration.reverb_level, 0, 99); + enc[RIGHT_ENCODER].write(configuration.reverb_level, ENC_REVERB_LEVEL_MIN, ENC_REVERB_LEVEL_MAX); menu_system.update(); } @@ -897,7 +897,7 @@ void callback_chorus_frequency_function() menu_system.change_menu(chorus_frequency_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.chorus_frequency; - enc[RIGHT_ENCODER].write(configuration.chorus_frequency, 0, 20); + enc[RIGHT_ENCODER].write(configuration.chorus_frequency, ENC_CHORUS_FREQUENCY_MIN, ENC_CHORUS_FREQUENCY_MAX); menu_system.update(); } @@ -909,7 +909,7 @@ void callback_chorus_delay_function() menu_system.change_menu(chorus_delay_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.chorus_delay; - enc[RIGHT_ENCODER].write(configuration.chorus_delay, 0, 20); + enc[RIGHT_ENCODER].write(configuration.chorus_delay, ENC_CHORUS_DELAY_MIN, ENC_CHORUS_DELAY_MAX); menu_system.update(); } @@ -921,7 +921,7 @@ void callback_chorus_level_function() menu_system.change_menu(chorus_level_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.chorus_level; - enc[RIGHT_ENCODER].write(configuration.chorus_level, 0, 99); + enc[RIGHT_ENCODER].write(configuration.chorus_level, ENC_CHORUS_LEVEL_MIN, ENC_CHORUS_LEVEL_MAX); menu_system.update(); } @@ -933,7 +933,7 @@ void callback_bass_lr_level_function() menu_system.change_menu(bass_lr_level_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.bass_lr_level; - enc[RIGHT_ENCODER].write(configuration.bass_lr_level, 0, 99); + enc[RIGHT_ENCODER].write(configuration.bass_lr_level, ENC_BASS_LR_LEVEL_MIN, ENC_BASS_LR_LEVEL_MAX); menu_system.update(); } @@ -945,7 +945,7 @@ void callback_bass_mono_level_function() menu_system.change_menu(bass_mono_level_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.bass_mono_level; - enc[RIGHT_ENCODER].write(configuration.bass_mono_level, 0, 99); + enc[RIGHT_ENCODER].write(configuration.bass_mono_level, ENC_BASS_MONO_LEVEL_MIN, ENC_BASS_MONO_LEVEL_MAX); menu_system.update(); } @@ -957,7 +957,7 @@ void callback_eq_bass_function() menu_system.change_menu(eq_bass_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.eq_bass; - enc[RIGHT_ENCODER].write(configuration.eq_bass, 0, 99); + enc[RIGHT_ENCODER].write(configuration.eq_bass, ENC_EQ_BASS_MIN, ENC_EQ_BASS_MAX); menu_system.update(); } @@ -969,7 +969,7 @@ void callback_eq_treble_function() menu_system.change_menu(eq_treble_menu); menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.eq_treble; - enc[RIGHT_ENCODER].write(configuration.eq_treble, 0, 99); + enc[RIGHT_ENCODER].write(configuration.eq_treble, ENC_EQ_TREBLE_MIN, ENC_EQ_TREBLE_MAX); menu_system.update(); } @@ -1021,7 +1021,7 @@ void callback_loudness_function() menu_system.change_menu(loudness_menu); menu_position[SYSTEM] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.loudness; - enc[RIGHT_ENCODER].write(configuration.loudness, 0, 99); + enc[RIGHT_ENCODER].write(configuration.loudness, ENC_LOUDNESS_MIN, ENC_LOUDNESS_MAX); menu_system.update(); } @@ -1033,7 +1033,7 @@ void callback_midi_channel_function() menu_system.change_menu(midi_channel_menu); menu_position[SYSTEM] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.midi_channel; - enc[RIGHT_ENCODER].write(configuration.midi_channel, 0, 16); + enc[RIGHT_ENCODER].write(configuration.midi_channel, ENC_MIDI_CHANNEL_MIN, ENC_MIDI_CHANNEL_MAX); menu_system.update(); } @@ -1045,7 +1045,7 @@ void callback_midi_soft_thru_function() menu_system.change_menu(midi_soft_thru_menu); menu_position[SYSTEM] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration.midi_soft_thru; - enc[RIGHT_ENCODER].write(configuration.midi_soft_thru, 0, 1); + enc[RIGHT_ENCODER].write(configuration.midi_soft_thru, ENC_MIDI_SOFT_THRU_MIN, ENC_MIDI_SOFT_THRU_MAX); menu_system.update(); } @@ -1057,7 +1057,7 @@ void callback_max_poly_function() menu_system.change_menu(max_poly_menu); menu_position[SYSTEM] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = configuration. max_poly; - enc[RIGHT_ENCODER].write(configuration.max_poly, 1, 32); + enc[RIGHT_ENCODER].write(configuration.max_poly, ENC_MAX_POLY_MIN, ENC_MAX_POLY_MAX); menu_system.update(); } @@ -1489,7 +1489,7 @@ void init_menus(void) // setup encoder for (i = 0; i < NUM_ENCODER; i++) but[i].update(); - enc[LEFT_ENCODER].write(master_volume, 0, 99); + enc[LEFT_ENCODER].write(master_volume, ENC_MASTER_VOLUME_MIN, ENC_MASTER_VOLUME_MAX); encoder_value[LEFT_ENCODER] = master_volume; enc[RIGHT_ENCODER].write(0, 0, NUM_MAIN_MENUS - 1); encoder_value[RIGHT_ENCODER] = 0; @@ -2306,8 +2306,7 @@ void handle_ui(void) if (encoder_tmp != encoder_value[LEFT_ENCODER]) { master_volume = encoder_tmp; - float tmp = mapfloat(float(master_volume), ENC_MASTER_VOLUME_MIN, ENC_MASTER_VOLUME_MAX, 0.0, 1.0); - set_volume(tmp, 0.5); + set_master_volume(master_volume); #ifdef DEBUG Serial.print(F("master_volume: ")); Serial.println(master_volume);