diff --git a/Encoder4.h b/Encoder4.h index e495fcd..c043811 100644 --- a/Encoder4.h +++ b/Encoder4.h @@ -21,7 +21,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ - +//#define ENCODER_DO_NOT_USE_INTERRUPTS #include #include "limits.h" diff --git a/MicroMDAEPiano.ino b/MicroMDAEPiano.ino index 90bf4db..376f877 100644 --- a/MicroMDAEPiano.ino +++ b/MicroMDAEPiano.ino @@ -35,10 +35,6 @@ #else #include "mdaEPianoData.h" #endif -#include -#include "Encoder4.h" -#include -#include #include "UI.hpp" #include "midi_devices.hpp" @@ -89,12 +85,51 @@ AudioConnection patchCord13(volume_l, 0, pt8211_1, 0); // Objects mdaEPiano* ep; -LiquidCrystal_I2C lcd(LCD_I2C_ADDRESS, LCD_CHARS, LCD_LINES); -Encoder4 enc[2] = {Encoder4(ENC_L_PIN_A, ENC_L_PIN_B), Encoder4(ENC_R_PIN_A, ENC_R_PIN_B)}; -Bounce but[2] = {Bounce(BUT_L_PIN, BUT_DEBOUNCE_MS), Bounce(BUT_R_PIN, BUT_DEBOUNCE_MS)}; -// Variables +extern void init_menus(void); +extern int32_t encoder_value[NUM_ENCODER]; + +// vars fot menus +uint8_t sound = 1; +// +uint8_t decay = 0; +uint8_t release = 0; +uint8_t hardness = 0; +uint8_t treble = 0; +int8_t stereo = 0; +int8_t transpose = 0; +int8_t tune = 0; +uint8_t detune = 0; +uint8_t velocity_sense = 0; +// +uint8_t pan_trem_frequency = 0; // LFO +uint8_t pan_trem_level = 0; +uint8_t overdrive = 0; +uint8_t comp_gain = 0; +uint8_t comp_response = 0; +uint8_t comp_limit = 0; +uint8_t comp_threshold = 0; +uint8_t comp_attack = 0; +uint8_t comp_decay = 0; +uint8_t reverb_roomsize = 0; +uint8_t reverb_damping = 0; +uint8_t reverb_level = 0; +uint8_t chorus_frequency = 0; // LFO +uint8_t chorus_delay = 0; +uint8_t chorus_level = 0; +uint8_t bass_lr_level = 0; +uint8_t bass_mono_level = 0; +uint8_t eq_bass = 0; +uint8_t eq_treble = 0; +// +uint8_t loudness = 80; uint8_t midi_channel = DEFAULT_MIDI_CHANNEL; +uint8_t midi_soft_thru = 1; +uint8_t max_poly = 32; +// +uint8_t master_volume = 99; + +// more variables uint32_t xrun = 0; uint32_t overload = 0; uint32_t peak = 0; @@ -109,7 +144,7 @@ bool eeprom_update_flag = false; elapsedMillis cpu_mem_millis; #endif -enum MDA_EP_PARAM { DECAY, RELEASE, HARDNESS, TREBLE, PAN_TREM, LFO_RATE, VELOCITY_SENSE, STEREO, MAX_POLY, TUNE, DETUNE, OVERDRIVE }; +enum MDA_EP_PARAM { MDA_EP_DECAY, MDA_EP_RELEASE, MDA_EP_HARDNESS, MDA_EP_TREBLE, MDA_EP_PAN_TREM, MDA_EP_LFO_RATE, MDA_EP_VELOCITY_SENSE, MDA_EP_STEREO, MDA_EP_MAX_POLY, MDA_EP_TUNE, MDA_EP_DETUNE, MDA_EP_OVERDRIVE }; //************************************************************************************************* //* SETUP FUNCTION @@ -122,21 +157,11 @@ void setup() pinMode(BUT_L_PIN, INPUT_PULLUP); pinMode(BUT_R_PIN, INPUT_PULLUP); - menu_init(); - - lcd.clear(); - lcd.setCursor(1, 0); - lcd.print(F("MicroMDAEpiano")); - lcd.setCursor(0, 1); - lcd.print(F("(c)parasiTstudio")); + init_menus(); Serial.begin(SERIAL_SPEED); delay(500); - // Encoder setup - enc[0].write(INITIAL_ENC_L_VALUE); - enc[1].write(INITIAL_ENC_R_VALUE); - // Debug output Serial.println(F("MicroMDAEPiano based on https://sourceforge.net/projects/mda-vst")); Serial.println(F("(c)2018/2019 H. Wirtz ")); @@ -212,14 +237,14 @@ void setup() Serial.print(audio_block_time_us); Serial.println(F("ms)")); - ep->setParameter(DECAY, 0.5); - ep->setParameter(RELEASE, 0.5); - ep->setParameter(HARDNESS, 0.7); - ep->setParameter(TREBLE, 0.85); - ep->setParameter(DETUNE, 0.1); - ep->setParameter(VELOCITY_SENSE, 1.0); - ep->setParameter(STEREO, 0.7); - ep->setParameter(OVERDRIVE, 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); @@ -234,9 +259,6 @@ void setup() Serial.println(F("")); - menu_system.update(); - menu_system.switch_focus(); - #if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC) show_cpu_and_mem_usage(); cpu_mem_millis = 0; @@ -304,7 +326,6 @@ void loop() if (control_rate > CONTROL_RATE_MS) { control_rate = 0; - handle_ui(); } } diff --git a/UI.hpp b/UI.hpp index 95031ae..c60eb10 100644 --- a/UI.hpp +++ b/UI.hpp @@ -1,24 +1,24 @@ /* - MicroMDAEPiano + LiquidMenuTest +*/ + +/* Don't forget to change in MAX_FUNCTIONS to 24 in ../libraries/LiquidMenu/src/LiquidMenu_config.h + + /// Configures the number of available variables per line. + const uint8_t MAX_VARIABLES = 5; ///< @note Default: 5 - MicroMDAEPiano is a port of the MDA-EPiano sound engine - (https://sourceforge.net/projects/mda-vst/) for the Teensy-3.5/3.6 with audio shield. + /// Configures the number of available functions per line. + const uint8_t MAX_FUNCTIONS = 39; ///< @note Default: 8 - (c)2019 H. Wirtz + /// Configures the number of available lines per screen. + const uint8_t MAX_LINES = 19; ///< @note Default: 12 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. + /// Configures the number of available screens per menu. + const uint8_t MAX_SCREENS = 14; ///< @note Default: 14 - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + /// Configures the number of available menus per menus system. + const uint8_t MAX_MENUS = 41; ///< @note Default: 8 - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef UI_HPP_INCLUDED @@ -28,66 +28,1128 @@ #include #include #include "Encoder4.h" +#include "config.h" + +LiquidCrystal_I2C lcd(LCD_I2C_ADDRESS, LCD_CHARS, LCD_LINES); +Encoder4 enc[NUM_ENCODER] = {Encoder4(ENC_L_PIN_A, ENC_L_PIN_B), Encoder4(ENC_R_PIN_A, ENC_R_PIN_B)}; +int32_t encoder_value[NUM_ENCODER]; +Bounce but[NUM_ENCODER] = {Bounce(BUT_L_PIN, BUT_DEBOUNCE_MS), Bounce(BUT_R_PIN, BUT_DEBOUNCE_MS)}; +LiquidScreen* old_screen; +elapsedMillis back_to_main;; + +extern uint8_t sound; +extern uint8_t decay; +extern uint8_t release; +extern uint8_t hardness; +extern uint8_t treble; +extern int8_t stereo; +extern int8_t transpose; +extern int8_t tune; +extern uint8_t detune; +extern uint8_t velocity_sense; +extern uint8_t pan_trem_frequency; +extern uint8_t pan_trem_level; +extern uint8_t overdrive; +extern uint8_t comp_gain; +extern uint8_t comp_response; +extern uint8_t comp_limit; +extern uint8_t comp_threshold; +extern uint8_t comp_attack; +extern uint8_t comp_decay; +extern uint8_t reverb_roomsize; +extern uint8_t reverb_damping; +extern uint8_t reverb_level; +extern uint8_t chorus_frequency; +extern uint8_t chorus_delay; +extern uint8_t chorus_level; +extern uint8_t bass_lr_level; +extern uint8_t bass_mono_level; +extern uint8_t eq_bass; +extern uint8_t eq_treble; +extern uint8_t loudness; +extern uint8_t midi_channel; +extern uint8_t midi_soft_thru; +extern uint8_t max_poly; +extern uint8_t master_volume; + +#define NUM_MENUS 41 + +#define MAIN 0 +/*************************************/ +#define LOAD_SOUND 1 +#define EDIT_SOUND 2 +#define EFFECTS 3 +#define SAVE_SOUND 4 +#define SYSTEM 5 +#define INFO 6 +/*************************************/ +#define DECAY 7 +#define RELEASE 8 +#define HARDNESS 9 +#define TREBLE 10 +#define STEREO_LEVEL 11 +#define TRANSPOSE 12 +#define TUNE 13 +#define DETUNE 14 +#define VELOCITY_SENSE 15 +/*************************************/ +#define PAN_TREM_FREQUENCY 16 +#define PAN_TREM_LEVEL 17 +#define OVERDRIVE 18 +#define COMP_GAIN 19 +#define COMP_RESPONSE 20 +#define COMP_LIMIT 21 +#define COMP_THRESHOLD 22 +#define COMP_ATTACK 23 +#define COMP_DECAY 24 +#define REV_ROOMSIZE 25 +#define REV_DAMPING 26 +#define REV_LEVEL 27 +#define CHORUS_FREQ 28 +#define CHORUS_DELAY 29 +#define CHORUS_LEVEL 30 +#define BASS_LR_LEVEL 31 +#define BASS_MONO_LEVEL 32 +#define EQ_BASS 33 +#define EQ_TREBLE 34 +/*************************************/ +#define LOUDNESS 35 +#define MIDI_CHANNEL 36 +#define MIDI_SOFT_THRU 37 +#define MAX_POLY 38 +/*************************************/ +#define MASTER_VOLUME 39 + +int8_t menu_position[NUM_MENUS]; + +#define LEFT_ENCODER 0 +#define RIGHT_ENCODER 1 + +/****************************************** + MAIN MENU + ******************************************/ +#define NUM_MAIN_MENUS 6 +const char main_text1[] PROGMEM = "Load Sound"; +const char main_text2[] PROGMEM = "Edit Sound"; +const char main_text3[] PROGMEM = "Effects"; +const char main_text4[] PROGMEM = "Save Sound"; +const char main_text5[] PROGMEM = "System"; +const char main_text6[] PROGMEM = "Info"; +LiquidLine main_line1(1, 0, main_text1); +LiquidLine main_line2(1, 1, main_text2); +LiquidLine main_line3(1, 1, main_text3); +LiquidLine main_line4(1, 1, main_text4); +LiquidLine main_line5(1, 1, main_text5); +LiquidLine main_line6(1, 1, main_text6); +LiquidScreen main_screen; +LiquidMenu main_menu(lcd); + +/****************************************** + LOAD SOUND MENU + ******************************************/ +#define NUM_LOAD_SOUNDS_MENUS 1 +const char load_sound_text1[] PROGMEM = "Load Sound"; +LiquidLine load_sound_line1(1, 0, load_sound_text1); +LiquidLine load_sound_line2(1, 1, sound); +LiquidScreen load_sound_screen; +LiquidMenu load_sound_menu(lcd); + +/****************************************** + EDIT SOUND MENU + ******************************************/ +#define NUM_EDIT_SOUND_MENUS 8 +const char edit_sound_text1[] PROGMEM = "Decay"; +const char edit_sound_text2[] PROGMEM = "Release"; +const char edit_sound_text3[] PROGMEM = "Hardness"; +const char edit_sound_text4[] PROGMEM = "Treble"; +const char edit_sound_text5[] PROGMEM = "Stereo Level"; +const char edit_sound_text6[] PROGMEM = "Transpose"; +const char edit_sound_text7[] PROGMEM = "Tune"; +const char edit_sound_text8[] PROGMEM = "Detune"; +const char edit_sound_text9[] PROGMEM = "Velocity Sense"; +LiquidLine edit_sound_line1(1, 0, edit_sound_text1); +LiquidLine edit_sound_line2(1, 1, edit_sound_text2); +LiquidLine edit_sound_line3(1, 1, edit_sound_text3); +LiquidLine edit_sound_line4(1, 1, edit_sound_text4); +LiquidLine edit_sound_line5(1, 1, edit_sound_text5); +LiquidLine edit_sound_line6(1, 1, edit_sound_text6); +LiquidLine edit_sound_line7(1, 1, edit_sound_text7); +LiquidLine edit_sound_line8(1, 1, edit_sound_text8); +LiquidLine edit_sound_line9(1, 1, edit_sound_text9); +LiquidScreen edit_sound_screen; +LiquidMenu edit_sound_menu(lcd); + +/****************************************** + DECAY MENU + ******************************************/ +#define NUM_DECAY_MENUS 1 +const char decay_text1[] PROGMEM = "Decay"; +LiquidLine decay_line1(1, 0, decay_text1); +LiquidLine decay_line2(1, 1, decay); +LiquidScreen decay_screen; +LiquidMenu decay_menu(lcd); + +/****************************************** + RELEASE MENU + ******************************************/ +#define NUM_RELEASE_MENUS 1 +const char release_text1[] PROGMEM = "Release"; +LiquidLine release_line1(1, 0, release_text1); +LiquidLine release_line2(1, 1, release); +LiquidScreen release_screen; +LiquidMenu release_menu(lcd); + +/****************************************** + HARDNESS MENU + ******************************************/ +#define NUM_HARDNESS_MENUS 1 +const char hardness_text1[] PROGMEM = "Hardness"; +LiquidLine hardness_line1(1, 0, hardness_text1); +LiquidLine hardness_line2(1, 1, hardness); +LiquidScreen hardness_screen; +LiquidMenu hardness_menu(lcd); + +/****************************************** + TREBLE MENU + ******************************************/ +#define NUM_TREBLE_MENUS 1 +const char treble_text1[] PROGMEM = "Treble"; +LiquidLine treble_line1(1, 0, treble_text1); +LiquidLine treble_line2(1, 1, treble); +LiquidScreen treble_screen; +LiquidMenu treble_menu(lcd); + +/****************************************** + STEREO MENU + ******************************************/ +#define NUM_TREBLE_MENUS 1 +const char stereo_text1[] PROGMEM = "Stereo"; +LiquidLine stereo_line1(1, 0, stereo_text1); +LiquidLine stereo_line2(1, 1, stereo); +LiquidScreen stereo_screen; +LiquidMenu stereo_menu(lcd); + +/****************************************** + TRANSPOSE MENU + ******************************************/ +#define NUM_TRANSPOSE_MENUS 1 +const char transpose_text1[] PROGMEM = "Transpose"; +LiquidLine transpose_line1(1, 0, transpose_text1); +LiquidLine transpose_line2(1, 1, transpose); +LiquidScreen transpose_screen; +LiquidMenu transpose_menu(lcd); + +/****************************************** + TUNE MENU + ******************************************/ +#define NUM_TUNE_MENUS 1 +const char tune_text1[] PROGMEM = "Tune"; +LiquidLine tune_line1(1, 0, tune_text1); +LiquidLine tune_line2(1, 1, tune); +LiquidScreen tune_screen; +LiquidMenu tune_menu(lcd); + +/****************************************** + DETUNE MENU + ******************************************/ +#define NUM_DETUNE_MENUS 1 +const char detune_text1[] PROGMEM = "Detune"; +LiquidLine detune_line1(1, 0, detune_text1); +LiquidLine detune_line2(1, 1, detune); +LiquidScreen detune_screen; +LiquidMenu detune_menu(lcd); + +/****************************************** + VELOCITY MENU + ******************************************/ +#define NUM_VELOCITY_MENUS 1 +const char velocity_sense_text1[] PROGMEM = "Velocity Sense"; +LiquidLine velocity_sense_line1(1, 0, velocity_sense_text1); +LiquidLine velocity_sense_line2(1, 1, velocity_sense); +LiquidScreen velocity_sense_screen; +LiquidMenu velocity_sense_menu(lcd); + +/****************************************** + EFFECTS MENU + ******************************************/ +#define NUM_EFFECTS_MENUS 19 +const char effects_text1[] PROGMEM = "Pan/Trem Freq."; +const char effects_text2[] PROGMEM = "Pan/Trem Level"; +const char effects_text3[] PROGMEM = "Overdrive"; +const char effects_text4[] PROGMEM = "Comp. Gain"; +const char effects_text5[] PROGMEM = "Comp. Response"; +const char effects_text6[] PROGMEM = "Comp. Limit"; +const char effects_text7[] PROGMEM = "Comp. Threshold"; +const char effects_text8[] PROGMEM = "Comp. Attack"; +const char effects_text9[] PROGMEM = "Comp. Decay"; +const char effects_text10[] PROGMEM = "Rev. Roomsize"; +const char effects_text11[] PROGMEM = "Rev. Damping"; +const char effects_text12[] PROGMEM = "Rev. Level"; +const char effects_text13[] PROGMEM = "Chorus Freq."; +const char effects_text14[] PROGMEM = "Chorus Delay"; +const char effects_text15[] PROGMEM = "Chorus Level"; +const char effects_text16[] PROGMEM = "Bass LR Level"; +const char effects_text17[] PROGMEM = "Bass M Level"; +const char effects_text18[] PROGMEM = "EQ Bass"; +const char effects_text19[] PROGMEM = "EQ Treble"; +LiquidLine effects_line1(1, 0, effects_text1); +LiquidLine effects_line2(1, 1, effects_text2); +LiquidLine effects_line3(1, 1, effects_text3); +LiquidLine effects_line4(1, 1, effects_text4); +LiquidLine effects_line5(1, 1, effects_text5); +LiquidLine effects_line6(1, 1, effects_text6); +LiquidLine effects_line7(1, 1, effects_text7); +LiquidLine effects_line8(1, 1, effects_text8); +LiquidLine effects_line9(1, 1, effects_text9); +LiquidLine effects_line10(1, 1, effects_text10); +LiquidLine effects_line11(1, 1, effects_text11); +LiquidLine effects_line12(1, 1, effects_text12); +LiquidLine effects_line13(1, 1, effects_text13); +LiquidLine effects_line14(1, 1, effects_text14); +LiquidLine effects_line15(1, 1, effects_text15); +LiquidLine effects_line16(1, 1, effects_text16); +LiquidLine effects_line17(1, 1, effects_text17); +LiquidLine effects_line18(1, 1, effects_text18); +LiquidLine effects_line19(1, 1, effects_text19); +LiquidScreen effects_screen; +LiquidMenu effects_menu(lcd); + +/****************************************** + PAN_TREM_FRQUENCY MENU + ******************************************/ +#define NUM_PAN_TREM_FRQUENCY_MENUS 1 +const char pan_trem_frequency_text1[] PROGMEM = "PAN/Trem Freq."; +LiquidLine pan_trem_frequency_line1(1, 0, pan_trem_frequency_text1); +LiquidLine pan_trem_frequency_line2(1, 1, pan_trem_frequency); +LiquidScreen pan_trem_frequency_screen; +LiquidMenu pan_trem_frequency_menu(lcd); + +/****************************************** + PAN_TREM_LEVEL MENU + ******************************************/ +#define NUM_PAN_TREM_LEVEL_MENUS 1 +const char pan_trem_level_text1[] PROGMEM = "Pan/Trem Level"; +LiquidLine pan_trem_level_line1(1, 0, pan_trem_level_text1); +LiquidLine pan_trem_level_line2(1, 1, pan_trem_level); +LiquidScreen pan_trem_level_screen; +LiquidMenu pan_trem_level_menu(lcd); + +/****************************************** + OVERDRIVE MENU + ******************************************/ +#define NUM_OVERDRIVE_MENUS 1 +const char overdrive_text1[] PROGMEM = "Overdrive"; +LiquidLine overdrive_line1(1, 0, overdrive_text1); +LiquidLine overdrive_line2(1, 1, overdrive); +LiquidScreen overdrive_screen; +LiquidMenu overdrive_menu(lcd); + +/****************************************** + COMP_GAIN MENU + ******************************************/ +#define NUM_COMP_GAIN_MENUS 1 +const char comp_gain_text1[] PROGMEM = "Comp. Gain"; +LiquidLine comp_gain_line1(1, 0, comp_gain_text1); +LiquidLine comp_gain_line2(1, 1, comp_gain); +LiquidScreen comp_gain_screen; +LiquidMenu comp_gain_menu(lcd); + +/****************************************** + COMP_RESPONSE MENU + ******************************************/ +#define NUM_COMP_RESPONSE_MENUS 1 +const char comp_response_text1[] PROGMEM = "Comp. Response"; +LiquidLine comp_response_line1(1, 0, comp_response_text1); +LiquidLine comp_response_line2(1, 1, comp_response); +LiquidScreen comp_response_screen; +LiquidMenu comp_response_menu(lcd); + +/****************************************** + COMP_LIMIT MENU + ******************************************/ +#define NUM_COMP_LIMIT_MENUS 1 +const char comp_limit_text1[] PROGMEM = "Comp. Limit"; +LiquidLine comp_limit_line1(1, 0, comp_limit_text1); +LiquidLine comp_limit_line2(1, 1, comp_limit); +LiquidScreen comp_limit_screen; +LiquidMenu comp_limit_menu(lcd); + +/****************************************** + COMP_THRESHOLD MENU + ******************************************/ +#define NUM_COMP_THRESHOLD_MENUS 1 +const char comp_threshold_text1[] PROGMEM = "Comp. Threshold"; +LiquidLine comp_threshold_line1(1, 0, comp_threshold_text1); +LiquidLine comp_threshold_line2(1, 1, comp_threshold); +LiquidScreen comp_threshold_screen; +LiquidMenu comp_threshold_menu(lcd); + +/****************************************** + COMP_ATTACK MENU + ******************************************/ +#define NUM_COMP_ATTACK_MENUS 1 +const char comp_attack_text1[] PROGMEM = "Comp. Attack"; +LiquidLine comp_attack_line1(1, 0, comp_attack_text1); +LiquidLine comp_attack_line2(1, 1, comp_attack); +LiquidScreen comp_attack_screen; +LiquidMenu comp_attack_menu(lcd); + +/****************************************** + COMP_DECAY MENU + ******************************************/ +#define NUM_COMP_DECAY_MENUS 1 +const char comp_decay_text1[] PROGMEM = "Comp. Decay"; +LiquidLine comp_decay_line1(1, 0, comp_decay_text1); +LiquidLine comp_decay_line2(1, 1, comp_decay); +LiquidScreen comp_decay_screen; +LiquidMenu comp_decay_menu(lcd); + +/****************************************** + REVERB_ROOMSIZE MENU + ******************************************/ +#define NUM_REVERB_ROOMSIZE_MENUS 1 +const char reverb_roomsize_text1[] PROGMEM = "Reverb Roomsize"; +LiquidLine reverb_roomsize_line1(1, 0, reverb_roomsize_text1); +LiquidLine reverb_roomsize_line2(1, 1, reverb_roomsize); +LiquidScreen reverb_roomsize_screen; +LiquidMenu reverb_roomsize_menu(lcd); + +/****************************************** + REVERB_DAMPING MENU + ******************************************/ +#define NUM_REVERB_DAMPING_MENUS 1 +const char reverb_damping_text1[] PROGMEM = "Reverb Damping"; +LiquidLine reverb_damping_line1(1, 0, reverb_damping_text1); +LiquidLine reverb_damping_line2(1, 1, reverb_damping); +LiquidScreen reverb_damping_screen; +LiquidMenu reverb_damping_menu(lcd); + +/****************************************** + REVERB_LEVEL MENU + ******************************************/ +#define NUM_REVERB_LEVEL_MENUS 1 +const char reverb_level_text1[] PROGMEM = "Reverb Level"; +LiquidLine reverb_level_line1(1, 0, reverb_level_text1); +LiquidLine reverb_level_line2(1, 1, reverb_level); +LiquidScreen reverb_level_screen; +LiquidMenu reverb_level_menu(lcd); + +/****************************************** + CHORUS_FREQUENCY MENU + ******************************************/ +#define NUM_CHORUS_FREQUENCY_MENUS 1 +const char chorus_frequency_text1[] PROGMEM = "Chorus Frequency"; +LiquidLine chorus_frequency_line1(1, 0, chorus_frequency_text1); +LiquidLine chorus_frequency_line2(1, 1, chorus_frequency); +LiquidScreen chorus_frequency_screen; +LiquidMenu chorus_frequency_menu(lcd); + +/****************************************** + CHORUS_DELAY MENU + ******************************************/ +#define NUM_CHORUS_DELAY_MENUS 1 +const char chorus_delay_text1[] PROGMEM = "Chorus Delay"; +LiquidLine chorus_delay_line1(1, 0, chorus_delay_text1); +LiquidLine chorus_delay_line2(1, 1, chorus_delay); +LiquidScreen chorus_delay_screen; +LiquidMenu chorus_delay_menu(lcd); + +/****************************************** + CHORUS_LEVEL MENU + ******************************************/ +#define NUM_CHORUS_LEVEL_MENUS 1 +const char chorus_level_text1[] PROGMEM = "Chorus Level"; +LiquidLine chorus_level_line1(1, 0, chorus_level_text1); +LiquidLine chorus_level_line2(1, 1, chorus_level); +LiquidScreen chorus_level_screen; +LiquidMenu chorus_level_menu(lcd); + +/****************************************** + BASS_LR_LEVEL MENU + ******************************************/ +#define NUM_BASS_LR_LEVEL_MENUS 1 +const char bass_lr_level_text1[] PROGMEM = "Bass L/R Level"; +LiquidLine bass_lr_level_line1(1, 0, bass_lr_level_text1); +LiquidLine bass_lr_level_line2(1, 1, bass_lr_level); +LiquidScreen bass_lr_level_screen; +LiquidMenu bass_lr_level_menu(lcd); + +/****************************************** + BASS_MONO_LEVEL MENU + ******************************************/ +#define NUM_BASS_MONO_LEVEL_MENUS 1 +const char bass_mono_level_text1[] PROGMEM = "Bass mono Level"; +LiquidLine bass_mono_level_line1(1, 0, bass_mono_level_text1); +LiquidLine bass_mono_level_line2(1, 1, bass_mono_level); +LiquidScreen bass_mono_level_screen; +LiquidMenu bass_mono_level_menu(lcd); + +/****************************************** + EQ_BASS MENU + ******************************************/ +#define NUM_EQ_BASS_MENUS 1 +const char eq_bass_text1[] PROGMEM = "EQ Bass"; +LiquidLine eq_bass_line1(1, 0, eq_bass_text1); +LiquidLine eq_bass_line2(1, 1, eq_bass); +LiquidScreen eq_bass_screen; +LiquidMenu eq_bass_menu(lcd); + +/****************************************** + EQ_TREBLE MENU + ******************************************/ +#define NUM_EQ_TREBLE_MENUS 1 +const char eq_treble_text1[] PROGMEM = "EQ Treble"; +LiquidLine eq_treble_line1(1, 0, eq_treble_text1); +LiquidLine eq_treble_line2(1, 1, eq_treble); +LiquidScreen eq_treble_screen; +LiquidMenu eq_treble_menu(lcd); + +/****************************************** + SAVE SOUND MENU + ******************************************/ +#define NUM_SAVE_SOUNDS_MENUS 1 +const char save_sound_text1[] PROGMEM = "Save Sound"; +LiquidLine save_sound_line1(1, 0, save_sound_text1); +LiquidLine save_sound_line2(1, 1, sound); +LiquidScreen save_sound_screen; +LiquidMenu save_sound_menu(lcd); + +/****************************************** + SYSTEM MENU + ******************************************/ +#define NUM_SYSTEM_MENUS 4 +const char system_text1[] PROGMEM = "Loudness"; +const char system_text2[] PROGMEM = "MIDI Channel"; +const char system_text3[] PROGMEM = "MIDI Soft-Thru"; +const char system_text4[] PROGMEM = "Max. Polyphony"; +LiquidLine system_line1(1, 0, system_text1); +LiquidLine system_line2(1, 1, system_text2); +LiquidLine system_line3(1, 1, system_text3); +LiquidLine system_line4(1, 1, system_text4); +LiquidScreen system_screen; +LiquidMenu system_menu(lcd); + +/****************************************** + LOUDNESS MENU + ******************************************/ +#define NUM_LOUDNESS_MENUS 1 +const char loudness_text1[] PROGMEM = "Loudness"; +LiquidLine loudness_line1(1, 0, loudness_text1); +LiquidLine loudness_line2(1, 1, loudness); +LiquidScreen loudness_screen; +LiquidMenu loudness_menu(lcd); + +/****************************************** + MIDI_CHANNEL MENU + ******************************************/ +#define NUM_MIDI_CHANNEL_MENUS 1 +const char midi_channel_text1[] PROGMEM = "MIDI CHannel"; +LiquidLine midi_channel_line1(1, 0, midi_channel_text1); +LiquidLine midi_channel_line2(1, 1, midi_channel); +LiquidScreen midi_channel_screen; +LiquidMenu midi_channel_menu(lcd); + +/****************************************** + MIDI_SOFT_THRU MENU + ******************************************/ +#define NUM_MIDI_SOFT_THRU_MENUS 1 +const char midi_soft_thru_text1[] PROGMEM = "MIDI Soft Thru"; +LiquidLine midi_soft_thru_line1(1, 0, midi_soft_thru_text1); +LiquidLine midi_soft_thru_line2(1, 1, midi_soft_thru); +LiquidScreen midi_soft_thru_screen; +LiquidMenu midi_soft_thru_menu(lcd); + +/****************************************** + MAX_POLY MENU + ******************************************/ +#define NUM_MAX_POLY_MENUS 1 +const char max_poly_text1[] PROGMEM = "Max. Polyphony"; +LiquidLine max_poly_line1(1, 0, max_poly_text1); +LiquidLine max_poly_line2(1, 1, max_poly); +LiquidScreen max_poly_screen; +LiquidMenu max_poly_menu(lcd); + +/****************************************** + INFO MENU + ******************************************/ +#define NUM_INFO_MENUS 1 +const char info_text1[] PROGMEM = "MicroMDAEPiano"; +const char info_text2[] PROGMEM = "Version 0.0"; +LiquidLine info_line1(0, 0, info_text1); +LiquidLine info_line2(0, 1, info_text2); +LiquidScreen info_screen; +LiquidMenu info_menu(lcd); + +/****************************************** + MASTER_VOLUME DISPLAY + ******************************************/ +const char master_volume_text1[] PROGMEM = "Master Volume"; +LiquidLine master_volume_line1(1, 0, master_volume_text1); +LiquidLine master_volume_line2(1, 1, master_volume); +LiquidScreen master_volume_screen; +LiquidMenu master_volume_menu(lcd); + +/****************************************** + GLOBAL MENU OBJECTS + ******************************************/ +LiquidSystem menu_system; + +/****************************************** + LOAD SOUND CALLBACKS + ******************************************/ +void callback_load_sound_function() { +#ifdef DEBUG + Serial.println(F("callback_load_sound_function")); +#endif + menu_system.change_menu(load_sound_menu); + menu_position[MAIN] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = sound; + enc[RIGHT_ENCODER].write(sound, 1, 99); + menu_system.update(); +} + +/****************************************** + EDIT SOUND CALLBACKS + ******************************************/ +void callback_edit_sound_function() +{ +#ifdef DEBUG + Serial.println(F("callback_edit_sound_function")); +#endif + menu_system.change_menu(edit_sound_menu); + menu_system.set_focusPosition(Position::LEFT); + menu_position[MAIN] = encoder_value[RIGHT_ENCODER]; + if (menu_position[EDIT_SOUND] < 0) + { + menu_position[EDIT_SOUND] = 0; + encoder_value[RIGHT_ENCODER] = 0; + enc[RIGHT_ENCODER].write(0, 0, NUM_EDIT_SOUND_MENUS - 1); + menu_system.switch_focus(); + } + else + { + encoder_value[RIGHT_ENCODER] = menu_position[EDIT_SOUND]; + enc[RIGHT_ENCODER].write(menu_position[EDIT_SOUND], 0, NUM_EDIT_SOUND_MENUS - 1); + } + menu_system.update(); +} + +void callback_decay_function() +{ +#ifdef DEBUG + Serial.println(F("callback_decay_function")); +#endif + menu_system.change_menu(decay_menu); + menu_position[EDIT_SOUND] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = decay; + enc[RIGHT_ENCODER].write(decay, 0, 99); + menu_system.update(); +} + +void callback_release_function() +{ +#ifdef DEBUG + Serial.println(F("callback_release_function")); +#endif + menu_system.change_menu(release_menu); + menu_position[EDIT_SOUND] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = release; + enc[RIGHT_ENCODER].write(release, 0, 99); + menu_system.update(); +} + +void callback_hardness_function() +{ +#ifdef DEBUG + Serial.println(F("callback_hardness_function")); +#endif + menu_system.change_menu(hardness_menu); + menu_position[EDIT_SOUND] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = hardness; + enc[RIGHT_ENCODER].write(hardness, 0, 99); + menu_system.update(); +} + +void callback_treble_function() +{ +#ifdef DEBUG + Serial.println(F("callback_treble_function")); +#endif + menu_system.change_menu(treble_menu); + menu_position[EDIT_SOUND] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = treble; + enc[RIGHT_ENCODER].write(treble, 0, 99); + menu_system.update(); +} + +void callback_stereo_function() +{ +#ifdef DEBUG + Serial.println(F("callback_stereo_function")); +#endif + menu_system.change_menu(stereo_menu); + menu_position[EDIT_SOUND] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = stereo; + enc[RIGHT_ENCODER].write(stereo, -10, 10); + menu_system.update(); +} + +void callback_transpose_function() +{ +#ifdef DEBUG + Serial.println(F("callback_transpose_function")); +#endif + menu_system.change_menu(transpose_menu); + menu_position[EDIT_SOUND] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = transpose; + enc[RIGHT_ENCODER].write(transpose, -36, 36); + menu_system.update(); +} + +void callback_tune_function() +{ +#ifdef DEBUG + Serial.println(F("callback_tune_function")); +#endif + menu_system.change_menu(tune_menu); + menu_position[EDIT_SOUND] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = tune; + enc[RIGHT_ENCODER].write(tune, -50, 50); + menu_system.update(); +} + +void callback_detune_function() +{ +#ifdef DEBUG + Serial.println(F("callback_detune_function")); +#endif + menu_system.change_menu(detune_menu); + menu_position[EDIT_SOUND] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = detune; + enc[RIGHT_ENCODER].write(detune, 0, 50); + menu_system.update(); +} + +void callback_velocity_sense_function() +{ +#ifdef DEBUG + Serial.println(F("callback_velocity_sense_function")); +#endif + menu_system.change_menu(velocity_sense_menu); + menu_position[EDIT_SOUND] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = velocity_sense; + enc[RIGHT_ENCODER].write(velocity_sense, 0, 99); + menu_system.update(); +} + +/****************************************** + EFFECTS CALLBACKS + ******************************************/ +void callback_effect_function() +{ +#ifdef DEBUG + Serial.println(F("callback_effect_function")); +#endif + menu_system.change_menu(effects_menu); + menu_system.set_focusPosition(Position::LEFT); + menu_position[MAIN] = encoder_value[RIGHT_ENCODER]; + if (menu_position[EFFECTS] < 0) + { + menu_position[EFFECTS] = 0; + encoder_value[RIGHT_ENCODER] = 0; + enc[RIGHT_ENCODER].write(0, 0, NUM_EFFECTS_MENUS - 1); + menu_system.switch_focus(); + } + else + { + encoder_value[RIGHT_ENCODER] = menu_position[EFFECTS]; + enc[RIGHT_ENCODER].write(menu_position[EFFECTS], 0, NUM_EFFECTS_MENUS - 1); + } + menu_system.update(); +} + +void callback_pan_trem_frequency_function() +{ +#ifdef DEBUG + Serial.println(F("callback_pan_trem_frequency_function")); +#endif + menu_system.change_menu(pan_trem_frequency_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = pan_trem_frequency; + enc[RIGHT_ENCODER].write(pan_trem_frequency, 0, 99); + menu_system.update(); +} + +void callback_pan_trem_level_function() +{ +#ifdef DEBUG + Serial.println(F("callback_pan_trem_level_function")); +#endif + menu_system.change_menu(pan_trem_level_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = pan_trem_level; + enc[RIGHT_ENCODER].write(pan_trem_level, 0, 99); + menu_system.update(); +} + +void callback_overdrive_function() +{ +#ifdef DEBUG + Serial.println(F("callback_overdrive_function")); +#endif + menu_system.change_menu(overdrive_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = overdrive; + enc[RIGHT_ENCODER].write(overdrive, 0, 99); + menu_system.update(); +} + +void callback_comp_gain_function() +{ +#ifdef DEBUG + Serial.println(F("callback_comp_gain_function")); +#endif + menu_system.change_menu(comp_gain_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = comp_gain; + enc[RIGHT_ENCODER].write(comp_gain, 0, 99); + menu_system.update(); +} + +void callback_comp_response_function() +{ +#ifdef DEBUG + Serial.println(F("callback_comp_response_function")); +#endif + menu_system.change_menu(comp_response_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = comp_response; + enc[RIGHT_ENCODER].write(comp_response, 0, 99); + menu_system.update(); +} + +void callback_comp_limit_function() +{ +#ifdef DEBUG + Serial.println(F("callback_comp_limit_function")); +#endif + menu_system.change_menu(comp_limit_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = comp_limit; + enc[RIGHT_ENCODER].write(comp_limit, 0, 99); + menu_system.update(); +} + +void callback_comp_threshold_function() +{ +#ifdef DEBUG + Serial.println(F("callback_comp_threshold_function")); +#endif + menu_system.change_menu(comp_threshold_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = comp_threshold; + enc[RIGHT_ENCODER].write(comp_threshold, 0, 99); + menu_system.update(); +} + +void callback_comp_attack_function() +{ +#ifdef DEBUG + Serial.println(F("callback_comp_attack_function")); +#endif + menu_system.change_menu(comp_attack_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = comp_attack; + enc[RIGHT_ENCODER].write(comp_attack, 0, 99); + menu_system.update(); +} + +void callback_comp_decay_function() +{ +#ifdef DEBUG + Serial.println(F("callback_comp_decay_function")); +#endif + menu_system.change_menu(comp_decay_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = comp_decay; + enc[RIGHT_ENCODER].write(comp_decay, 0, 99); + menu_system.update(); +} -extern LiquidCrystal_I2C lcd; -extern Encoder4 enc[2]; -extern Bounce but[2]; +void callback_reverb_roomsize_function() +{ +#ifdef DEBUG + Serial.println(F("callback_reverb_roomsize_function")); +#endif + menu_system.change_menu(reverb_roomsize_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = reverb_roomsize; + enc[RIGHT_ENCODER].write(reverb_roomsize, 0, 99); + menu_system.update(); +} -// Global vars -uint8_t main_menu_selector = 0; +void callback_reverb_damping_function() +{ +#ifdef DEBUG + Serial.println(F("callback_reverb_damping_function")); +#endif + menu_system.change_menu(reverb_damping_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = reverb_damping; + enc[RIGHT_ENCODER].write(reverb_damping, 0, 99); + menu_system.update(); +} + +void callback_reverb_level_function() +{ +#ifdef DEBUG + Serial.println(F("callback_reverb_level_function")); +#endif + menu_system.change_menu(reverb_level_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = reverb_level; + enc[RIGHT_ENCODER].write(reverb_level, 0, 99); + menu_system.update(); +} + +void callback_chorus_frequency_function() +{ +#ifdef DEBUG + Serial.println(F("callback_chorus_frequency_function")); +#endif + menu_system.change_menu(chorus_frequency_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = chorus_frequency; + enc[RIGHT_ENCODER].write(chorus_frequency, 0, 20); + menu_system.update(); +} + +void callback_chorus_delay_function() +{ +#ifdef DEBUG + Serial.println(F("callback_chorus_delay_function")); +#endif + menu_system.change_menu(chorus_delay_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = chorus_delay; + enc[RIGHT_ENCODER].write(chorus_delay, 0, 20); + menu_system.update(); +} + +void callback_chorus_level_function() +{ +#ifdef DEBUG + Serial.println(F("callback_chorus_level_function")); +#endif + menu_system.change_menu(chorus_level_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = chorus_level; + enc[RIGHT_ENCODER].write(chorus_level, 0, 99); + menu_system.update(); +} + +void callback_bass_lr_level_function() +{ +#ifdef DEBUG + Serial.println(F("callback_bass_lr_level_function")); +#endif + menu_system.change_menu(bass_lr_level_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = bass_lr_level; + enc[RIGHT_ENCODER].write(bass_lr_level, 0, 99); + menu_system.update(); +} + +void callback_bass_mono_level_function() +{ +#ifdef DEBUG + Serial.println(F("callback_bass_mono_level_function")); +#endif + menu_system.change_menu(bass_mono_level_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = bass_mono_level; + enc[RIGHT_ENCODER].write(bass_mono_level, 0, 99); + menu_system.update(); +} + +void callback_eq_bass_function() +{ +#ifdef DEBUG + Serial.println(F("callback_eq_bass_function")); +#endif + menu_system.change_menu(eq_bass_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = eq_bass; + enc[RIGHT_ENCODER].write(eq_bass, 0, 99); + menu_system.update(); +} + +void callback_eq_treble_function() +{ +#ifdef DEBUG + Serial.println(F("callback_eq_treble_function")); +#endif + menu_system.change_menu(eq_treble_menu); + menu_position[EFFECTS] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = eq_treble; + enc[RIGHT_ENCODER].write(eq_treble, 0, 99); + menu_system.update(); +} + +/****************************************** + SAVE SOUND CALLBACKS + ******************************************/ +void callback_save_sound_function() { +#ifdef DEBUG + Serial.println(F("callback_save_sound_function")); +#endif + menu_system.change_menu(save_sound_menu); + menu_position[MAIN] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = sound; + enc[RIGHT_ENCODER].write(sound, 1, 99); + menu_system.update(); +} + +/****************************************** + SYSTEM MENU CALLBACKS + ******************************************/ +void callback_system_function() +{ +#ifdef DEBUG + Serial.println(F("callback_system_function")); +#endif + menu_system.change_menu(system_menu); + menu_system.set_focusPosition(Position::LEFT); + menu_position[MAIN] = encoder_value[RIGHT_ENCODER]; + if (menu_position[SYSTEM] < 0) + { + menu_position[SYSTEM] = 0; + encoder_value[RIGHT_ENCODER] = 0; + enc[RIGHT_ENCODER].write(0, 0, NUM_SYSTEM_MENUS - 1); + menu_system.switch_focus(); + } + else + { + encoder_value[RIGHT_ENCODER] = menu_position[SYSTEM]; + enc[RIGHT_ENCODER].write(menu_position[SYSTEM], 0, NUM_SYSTEM_MENUS - 1); + } + menu_system.update(); +} + +void callback_loudness_function() +{ +#ifdef DEBUG + Serial.println(F("callback_loudness_function")); +#endif + menu_system.change_menu(loudness_menu); + menu_position[SYSTEM] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = loudness; + enc[RIGHT_ENCODER].write(loudness, 0, 99); + menu_system.update(); +} + +void callback_midi_channel_function() +{ +#ifdef DEBUG + Serial.println(F("callback_midi_channel_function")); +#endif + menu_system.change_menu(midi_channel_menu); + menu_position[SYSTEM] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = midi_channel; + enc[RIGHT_ENCODER].write(midi_channel, 0, 16); + menu_system.update(); +} + +void callback_midi_soft_thru_function() +{ +#ifdef DEBUG + Serial.println(F("callback_midi_soft_thru_function")); +#endif + menu_system.change_menu(midi_soft_thru_menu); + menu_position[SYSTEM] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = midi_soft_thru; + enc[RIGHT_ENCODER].write(midi_soft_thru, 0, 1); + menu_system.update(); +} + +void callback_max_poly_function() +{ +#ifdef DEBUG + Serial.println(F("callback_max_poly_function")); +#endif + menu_system.change_menu(max_poly_menu); + menu_position[SYSTEM] = encoder_value[RIGHT_ENCODER]; + encoder_value[RIGHT_ENCODER] = max_poly; + enc[RIGHT_ENCODER].write(max_poly, 1, 32); + menu_system.update(); +} -enum { BUT_L, BUT_R }; +/****************************************** + INFO MENU CALLBACKS + ******************************************/ +void callback_info_function() +{ +#ifdef DEBUG + Serial.println(F("callback_info_function")); +#endif + menu_system.change_menu(info_menu); + menu_position[MAIN] = encoder_value[RIGHT_ENCODER]; + menu_system.update(); +} -// Main menu -const char text10[] PROGMEM = "Favorites "; -const char text11[] PROGMEM = "Sound "; -const char text12[] PROGMEM = "Store "; -const char text13[] PROGMEM = "Info "; -LiquidLine main_line1(0, 0, text10); -LiquidLine main_line2(0, 1, text11); -LiquidLine main_line3(0, 1, text12); -LiquidLine main_line4(0, 1, text13); -LiquidScreen main_screen; -LiquidMenu main_menu(lcd); +/****************************************** + HELPER FUCTIONS + ******************************************/ -// Sound menu -const char text20[] PROGMEM = "Decay "; -const char text21[] PROGMEM = "Release "; -const char text22[] PROGMEM = "Hardness "; -const char text23[] PROGMEM = "Treble "; -LiquidLine sound_line1(0, 0, text20); -LiquidLine sound_line2(0, 1, text21); -LiquidLine sound_line3(0, 1, text22); -LiquidLine sound_line4(0, 1, text23); -LiquidScreen sound_screen(sound_line1, sound_line2, sound_line3, sound_line4); -LiquidMenu sound_menu(lcd, sound_screen); +void encoder_switch_focus(uint8_t encoder_last, uint8_t encoder_value) +{ + uint8_t i; + int8_t diff; -// Info menu -const char text40[] PROGMEM = "INFO "; -LiquidLine info_line1(0, 0, text40); -LiquidScreen info_screen(info_line1); -LiquidMenu info_menu(lcd, info_screen); + diff = encoder_value - encoder_last; -// System menu -LiquidSystem menu_system(main_menu, sound_menu, info_menu); + for (i = 0; i < abs(diff); i++) + { + if (diff < 0) + menu_system.switch_focus(true); + else + menu_system.switch_focus(false); + } +} -void callback_favorites_function() { - Serial.println(F("callback_favorites_function")); +void goto_main_menu(void) +{ + menu_system.change_menu(main_menu); + menu_system.set_focusPosition(Position::LEFT); + encoder_value[RIGHT_ENCODER] = menu_position[MAIN]; + enc[RIGHT_ENCODER].write(menu_position[MAIN], 0, NUM_MAIN_MENUS - 1); } -void callback_sound_function() { - Serial.println(F("callback_sound_function")); +void goto_edit_sound_menu(void) +{ + menu_system.change_menu(edit_sound_menu); + menu_system.set_focusPosition(Position::LEFT); + encoder_value[RIGHT_ENCODER] = menu_position[EDIT_SOUND]; + enc[RIGHT_ENCODER].write(menu_position[EDIT_SOUND], 0, NUM_EDIT_SOUND_MENUS - 1); } -void callback_store_function() { - Serial.println(F("callback_store_function")); +void goto_effects_menu(void) +{ + menu_system.change_menu(effects_menu); + menu_system.set_focusPosition(Position::LEFT); + encoder_value[RIGHT_ENCODER] = menu_position[EFFECTS]; + enc[RIGHT_ENCODER].write(menu_position[EFFECTS], 0, NUM_EFFECTS_MENUS - 1); } -void callback_info_function() { - Serial.println(F("callback_info_function")); +void goto_system_menu(void) +{ + menu_system.change_menu(system_menu); + menu_system.set_focusPosition(Position::LEFT); + encoder_value[RIGHT_ENCODER] = menu_position[SYSTEM]; + enc[RIGHT_ENCODER].write(menu_position[SYSTEM], 0, NUM_SYSTEM_MENUS - 1); } -void menu_init(void) +void init_menus(void) { uint8_t i; @@ -98,31 +1160,372 @@ void menu_init(void) lcd.backlight(); //lcd.noAutoscroll(); + // setup main menu main_screen.add_line(main_line1); main_screen.add_line(main_line2); main_screen.add_line(main_line3); main_screen.add_line(main_line4); - - main_line1.attach_function(1, callback_favorites_function); - main_line2.attach_function(2, callback_sound_function); - main_line3.attach_function(3, callback_store_function); - main_line4.attach_function(4, callback_info_function); - + main_screen.add_line(main_line5); + main_screen.add_line(main_line6); main_screen.set_displayLineCount(2); main_menu.add_screen(main_screen); + main_line1.attach_function(LOAD_SOUND, callback_load_sound_function); + main_line2.attach_function(EDIT_SOUND, callback_edit_sound_function); + main_line3.attach_function(EFFECTS, callback_effect_function); + main_line4.attach_function(SAVE_SOUND, callback_save_sound_function); + main_line5.attach_function(SYSTEM, callback_system_function); + main_line6.attach_function(INFO, callback_info_function); + + // setup load_sound menu + load_sound_screen.add_line(load_sound_line1); + load_sound_screen.add_line(load_sound_line2); + load_sound_screen.set_displayLineCount(2); + load_sound_menu.add_screen(load_sound_screen); + + // setup sound menu + edit_sound_screen.add_line(edit_sound_line1); + edit_sound_screen.add_line(edit_sound_line2); + edit_sound_screen.add_line(edit_sound_line3); + edit_sound_screen.add_line(edit_sound_line4); + edit_sound_screen.add_line(edit_sound_line5); + edit_sound_screen.add_line(edit_sound_line6); + edit_sound_screen.add_line(edit_sound_line7); + edit_sound_screen.add_line(edit_sound_line8); + edit_sound_screen.add_line(edit_sound_line9); + edit_sound_screen.set_displayLineCount(2); + edit_sound_menu.add_screen(edit_sound_screen); + + edit_sound_line1.attach_function(DECAY, callback_decay_function); + edit_sound_line2.attach_function(RELEASE, callback_release_function); + edit_sound_line3.attach_function(HARDNESS, callback_hardness_function); + edit_sound_line4.attach_function(TREBLE, callback_treble_function); + edit_sound_line5.attach_function(STEREO_LEVEL, callback_stereo_function); + edit_sound_line6.attach_function(TRANSPOSE, callback_transpose_function); + edit_sound_line7.attach_function(TUNE, callback_tune_function); + edit_sound_line8.attach_function(DETUNE, callback_detune_function); + edit_sound_line9.attach_function(VELOCITY_SENSE, callback_velocity_sense_function); + + // setup decay menu + decay_screen.add_line(decay_line1); + decay_screen.add_line(decay_line2); + decay_screen.set_displayLineCount(2); + decay_menu.add_screen(decay_screen); + + // setup release menu + release_screen.add_line(release_line1); + release_screen.add_line(release_line2); + release_screen.set_displayLineCount(2); + release_menu.add_screen(release_screen); + + // setup hardness menu + hardness_screen.add_line(hardness_line1); + hardness_screen.add_line(hardness_line2); + hardness_screen.set_displayLineCount(2); + hardness_menu.add_screen(hardness_screen); + + // setup treble menu + treble_screen.add_line(treble_line1); + treble_screen.add_line(treble_line2); + treble_screen.set_displayLineCount(2); + treble_menu.add_screen(treble_screen); + + // setup stereo menu + stereo_screen.add_line(stereo_line1); + stereo_screen.add_line(stereo_line2); + stereo_screen.set_displayLineCount(2); + stereo_menu.add_screen(stereo_screen); + + // setup transpose menu + transpose_screen.add_line(transpose_line1); + transpose_screen.add_line(transpose_line2); + transpose_screen.set_displayLineCount(2); + transpose_menu.add_screen(transpose_screen); + + // setup tune menu + tune_screen.add_line(tune_line1); + tune_screen.add_line(tune_line2); + tune_screen.set_displayLineCount(2); + tune_menu.add_screen(tune_screen); + + // setup detune menu + detune_screen.add_line(detune_line1); + detune_screen.add_line(detune_line2); + detune_screen.set_displayLineCount(2); + detune_menu.add_screen(detune_screen); + + // setup velocity_sense menu + velocity_sense_screen.add_line(velocity_sense_line1); + velocity_sense_screen.add_line(velocity_sense_line2); + velocity_sense_screen.set_displayLineCount(2); + velocity_sense_menu.add_screen(velocity_sense_screen); + + // setup effects menu + effects_screen.add_line(effects_line1); + effects_screen.add_line(effects_line2); + effects_screen.add_line(effects_line3); + effects_screen.add_line(effects_line4); + effects_screen.add_line(effects_line5); + effects_screen.add_line(effects_line6); + effects_screen.add_line(effects_line7); + effects_screen.add_line(effects_line8); + effects_screen.add_line(effects_line9); + effects_screen.add_line(effects_line10); + effects_screen.add_line(effects_line11); + effects_screen.add_line(effects_line12); + effects_screen.add_line(effects_line13); + effects_screen.add_line(effects_line14); + effects_screen.add_line(effects_line15); + effects_screen.add_line(effects_line16); + effects_screen.add_line(effects_line17); + effects_screen.add_line(effects_line18); + effects_screen.add_line(effects_line19); + effects_screen.set_displayLineCount(2); + effects_menu.add_screen(effects_screen); + + effects_line1.attach_function(PAN_TREM_FREQUENCY, callback_pan_trem_frequency_function); + effects_line2.attach_function(PAN_TREM_LEVEL, callback_pan_trem_level_function); + effects_line3.attach_function(OVERDRIVE, callback_overdrive_function); + effects_line4.attach_function(COMP_GAIN, callback_comp_gain_function); + effects_line5.attach_function(COMP_RESPONSE, callback_comp_response_function); + effects_line6.attach_function(COMP_LIMIT, callback_comp_limit_function); + effects_line7.attach_function(COMP_THRESHOLD, callback_comp_threshold_function); + effects_line8.attach_function(COMP_ATTACK, callback_comp_attack_function); + effects_line9.attach_function(COMP_DECAY, callback_comp_decay_function); + effects_line10.attach_function(REV_ROOMSIZE, callback_reverb_roomsize_function); + effects_line11.attach_function(REV_DAMPING, callback_reverb_damping_function); + effects_line12.attach_function(REV_LEVEL, callback_reverb_level_function); + effects_line13.attach_function(CHORUS_FREQ, callback_chorus_frequency_function); + effects_line14.attach_function(CHORUS_DELAY, callback_chorus_delay_function); + effects_line15.attach_function(CHORUS_LEVEL, callback_chorus_level_function); + effects_line16.attach_function(BASS_LR_LEVEL, callback_bass_lr_level_function); + effects_line17.attach_function(BASS_MONO_LEVEL, callback_bass_mono_level_function); + effects_line18.attach_function(EQ_BASS, callback_eq_bass_function); + effects_line19.attach_function(EQ_TREBLE, callback_eq_treble_function); + + // setup pan_trem_frequency menu + pan_trem_frequency_screen.add_line(pan_trem_frequency_line1); + pan_trem_frequency_screen.add_line(pan_trem_frequency_line2); + pan_trem_frequency_screen.set_displayLineCount(2); + pan_trem_frequency_menu.add_screen(pan_trem_frequency_screen); + + // setup pan_trem_level menu + pan_trem_level_screen.add_line(pan_trem_level_line1); + pan_trem_level_screen.add_line(pan_trem_level_line2); + pan_trem_level_screen.set_displayLineCount(2); + pan_trem_level_menu.add_screen(pan_trem_level_screen); + + // setup overdrive menu + overdrive_screen.add_line(overdrive_line1); + overdrive_screen.add_line(overdrive_line2); + overdrive_screen.set_displayLineCount(2); + overdrive_menu.add_screen(overdrive_screen); + + // setup comp_gain menu + comp_gain_screen.add_line(comp_gain_line1); + comp_gain_screen.add_line(comp_gain_line2); + comp_gain_screen.set_displayLineCount(2); + comp_gain_menu.add_screen(comp_gain_screen); + + // setup comp_response menu + comp_response_screen.add_line(comp_response_line1); + comp_response_screen.add_line(comp_response_line2); + comp_response_screen.set_displayLineCount(2); + comp_response_menu.add_screen(comp_response_screen); + + // setup comp_limit menu + comp_limit_screen.add_line(comp_limit_line1); + comp_limit_screen.add_line(comp_limit_line2); + comp_limit_screen.set_displayLineCount(2); + comp_limit_menu.add_screen(comp_limit_screen); + + // setup comp_threshold menu + comp_threshold_screen.add_line(comp_threshold_line1); + comp_threshold_screen.add_line(comp_threshold_line2); + comp_threshold_screen.set_displayLineCount(2); + comp_threshold_menu.add_screen(comp_threshold_screen); + + // setup comp_attack menu + comp_attack_screen.add_line(comp_attack_line1); + comp_attack_screen.add_line(comp_attack_line2); + comp_attack_screen.set_displayLineCount(2); + comp_attack_menu.add_screen(comp_attack_screen); + + // setup comp_decay menu + comp_decay_screen.add_line(comp_decay_line1); + comp_decay_screen.add_line(comp_decay_line2); + comp_decay_screen.set_displayLineCount(2); + comp_decay_menu.add_screen(comp_decay_screen); + + // setup reverb_roomsize menu + reverb_roomsize_screen.add_line(reverb_roomsize_line1); + reverb_roomsize_screen.add_line(reverb_roomsize_line2); + reverb_roomsize_screen.set_displayLineCount(2); + reverb_roomsize_menu.add_screen(reverb_roomsize_screen); + + // setup reverb_damping menu + reverb_damping_screen.add_line(reverb_damping_line1); + reverb_damping_screen.add_line(reverb_damping_line2); + reverb_damping_screen.set_displayLineCount(2); + reverb_damping_menu.add_screen(reverb_damping_screen); + + // setup reverb_level menu + reverb_level_screen.add_line(reverb_level_line1); + reverb_level_screen.add_line(reverb_level_line2); + reverb_level_screen.set_displayLineCount(2); + reverb_level_menu.add_screen(reverb_level_screen); + + // setup bass_lr_level menu + bass_lr_level_screen.add_line(bass_lr_level_line1); + bass_lr_level_screen.add_line(bass_lr_level_line2); + bass_lr_level_screen.set_displayLineCount(2); + bass_lr_level_menu.add_screen(bass_lr_level_screen); + + // setup bass_mono_level menu + bass_mono_level_screen.add_line(bass_mono_level_line1); + bass_mono_level_screen.add_line(bass_mono_level_line2); + bass_mono_level_screen.set_displayLineCount(2); + bass_mono_level_menu.add_screen(bass_mono_level_screen); + + // setup eq_bass menu + eq_bass_screen.add_line(eq_bass_line1); + eq_bass_screen.add_line(eq_bass_line2); + eq_bass_screen.set_displayLineCount(2); + eq_bass_menu.add_screen(eq_bass_screen); + + // setup eq_treble menu + eq_treble_screen.add_line(eq_treble_line1); + eq_treble_screen.add_line(eq_treble_line2); + eq_treble_screen.set_displayLineCount(2); + eq_treble_menu.add_screen(eq_treble_screen); + + // setup save_sound menu + save_sound_screen.add_line(save_sound_line1); + save_sound_screen.add_line(save_sound_line2); + save_sound_screen.set_displayLineCount(2); + save_sound_menu.add_screen(save_sound_screen); + + // setup effects menu + system_screen.add_line(system_line1); + system_screen.add_line(system_line2); + system_screen.add_line(system_line3); + system_screen.add_line(system_line4); + system_screen.set_displayLineCount(2); + system_menu.add_screen(system_screen); + + system_line1.attach_function(LOUDNESS, callback_loudness_function); + system_line2.attach_function(MIDI_CHANNEL, callback_midi_channel_function); + system_line3.attach_function(MIDI_SOFT_THRU, callback_midi_soft_thru_function); + system_line4.attach_function(MAX_POLY, callback_max_poly_function); + + // setup loudness + loudness_screen.add_line(loudness_line1); + loudness_screen.add_line(loudness_line2); + loudness_screen.set_displayLineCount(2); + loudness_menu.add_screen(loudness_screen); + + // setup midi_channel + midi_channel_screen.add_line(midi_channel_line1); + midi_channel_screen.add_line(midi_channel_line2); + midi_channel_screen.set_displayLineCount(2); + midi_channel_menu.add_screen(midi_channel_screen); + + // setup midi_soft_thru + midi_soft_thru_screen.add_line(midi_soft_thru_line1); + midi_soft_thru_screen.add_line(midi_soft_thru_line2); + midi_soft_thru_screen.set_displayLineCount(2); + midi_soft_thru_menu.add_screen(midi_soft_thru_screen); + + // setup max_poly + max_poly_screen.add_line(max_poly_line1); + max_poly_screen.add_line(max_poly_line2); + max_poly_screen.set_displayLineCount(2); + max_poly_menu.add_screen(max_poly_screen); + + // setup info menu + info_screen.add_line(info_line1); + info_screen.add_line(info_line2); + info_screen.set_displayLineCount(2); + info_menu.add_screen(info_screen); + + // setup master_volume display + master_volume_screen.add_line(master_volume_line1); + master_volume_screen.add_line(master_volume_line2); + master_volume_screen.set_displayLineCount(2); + master_volume_menu.add_screen(master_volume_screen); + + // setup global system menu + menu_system.add_menu(main_menu); + menu_system.add_menu(load_sound_menu); + menu_system.add_menu(edit_sound_menu); + menu_system.add_menu(effects_menu); + menu_system.add_menu(decay_menu); + menu_system.add_menu(release_menu); + menu_system.add_menu(hardness_menu); + menu_system.add_menu(treble_menu); + menu_system.add_menu(stereo_menu); + menu_system.add_menu(transpose_menu); + menu_system.add_menu(tune_menu); + menu_system.add_menu(detune_menu); + menu_system.add_menu(velocity_sense_menu); + menu_system.add_menu(effects_menu); + menu_system.add_menu(pan_trem_frequency_menu); + menu_system.add_menu(pan_trem_level_menu); + menu_system.add_menu(overdrive_menu); + menu_system.add_menu(comp_gain_menu); + menu_system.add_menu(comp_response_menu); + menu_system.add_menu(comp_limit_menu); + menu_system.add_menu(comp_threshold_menu); + menu_system.add_menu(comp_attack_menu); + menu_system.add_menu(comp_decay_menu); + menu_system.add_menu(reverb_roomsize_menu); + menu_system.add_menu(reverb_damping_menu); + menu_system.add_menu(reverb_level_menu); + menu_system.add_menu(chorus_frequency_menu); + menu_system.add_menu(chorus_delay_menu); + menu_system.add_menu(chorus_level_menu); + menu_system.add_menu(bass_lr_level_menu); + menu_system.add_menu(bass_mono_level_menu); + menu_system.add_menu(eq_bass_menu); + menu_system.add_menu(eq_treble_menu); + menu_system.add_menu(save_sound_menu); + menu_system.add_menu(system_menu); + menu_system.add_menu(loudness_menu); + menu_system.add_menu(midi_channel_menu); + menu_system.add_menu(midi_soft_thru_menu); + menu_system.add_menu(max_poly_menu); + menu_system.add_menu(info_menu); + menu_system.add_menu(master_volume_menu); + menu_system.set_focusPosition(Position::LEFT); + menu_system.switch_focus(); menu_system.update(); + for ( i = 0; i < NUM_MENUS; i++) + menu_position[i] = -1; + menu_position[MAIN] = 0; + // setup encoder for (i = 0; i < NUM_ENCODER; i++) but[i].update(); - - enc[1].write(0, 0, 99); - enc[1].write(1, 0, 4); + enc[LEFT_ENCODER].write(master_volume, 0, 99); + encoder_value[LEFT_ENCODER] = master_volume; + enc[RIGHT_ENCODER].write(0, 0, NUM_MAIN_MENUS - 1); + encoder_value[RIGHT_ENCODER] = 0; } void handle_ui(void) { uint8_t i; + int32_t encoder_tmp; + + if (back_to_main > BACK_TO_MAIN_MS && menu_system.get_currentScreen() == &master_volume_screen) + { + { +#ifdef DEBUG + Serial.println(F("from master_volume to main")); +#endif + goto_main_menu(); + } + } for (i = 0; i < NUM_ENCODER; i++) { @@ -130,15 +1533,718 @@ void handle_ui(void) switch (i) { - case BUT_R: // SELECT - if (but[i].fallingEdge()) + case RIGHT_ENCODER: + // Encoder handling + encoder_tmp = enc[RIGHT_ENCODER].read(); + + if (menu_system.get_currentScreen() == &load_sound_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + sound = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &decay_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + decay = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &release_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + release = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &hardness_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + hardness = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &treble_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + treble = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &stereo_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + stereo = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &transpose_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + transpose = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &tune_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + tune = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &detune_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + detune = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &velocity_sense_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + velocity_sense = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &pan_trem_frequency_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + pan_trem_frequency = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &pan_trem_level_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + pan_trem_level = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &overdrive_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + overdrive = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &comp_gain_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + comp_gain = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &comp_response_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + comp_response = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &comp_limit_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + comp_limit = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &comp_threshold_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + comp_threshold = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &comp_attack_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + comp_attack = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &comp_decay_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + comp_decay = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &reverb_roomsize_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + reverb_roomsize = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &reverb_damping_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + reverb_damping = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &reverb_level_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + reverb_level = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &chorus_frequency_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + chorus_frequency = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &chorus_delay_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + chorus_delay = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &chorus_level_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + chorus_level = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &bass_lr_level_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + bass_lr_level = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &bass_mono_level_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + bass_mono_level = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &eq_bass_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + eq_bass = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &eq_treble_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + eq_treble = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &save_sound_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + sound = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &loudness_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + loudness = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &midi_channel_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + midi_channel = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &midi_soft_thru_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + midi_soft_thru = encoder_tmp; + menu_system.update(); + } + } + else if (menu_system.get_currentScreen() == &max_poly_screen) + { + if (encoder_tmp != encoder_value[RIGHT_ENCODER]) + { + // value up/down + max_poly = encoder_tmp; + menu_system.update(); + } + } + else + { + // Move menu focus + if (encoder_tmp > encoder_value[RIGHT_ENCODER]) + { + // move down +#ifdef DEBUG + Serial.print(F("ENC-R-DOWN: ")); + Serial.println(encoder_tmp); +#endif + encoder_switch_focus(encoder_tmp, encoder_value[RIGHT_ENCODER]); + menu_system.softUpdate(); + } + else if (encoder_tmp < encoder_value[RIGHT_ENCODER]) + { + // move up +#ifdef DEBUG + Serial.print(F("ENC-R-UP: ")); + Serial.println(encoder_tmp); +#endif + encoder_switch_focus(encoder_tmp, encoder_value[RIGHT_ENCODER]); + menu_system.softUpdate(); + } + } + encoder_value[RIGHT_ENCODER] = encoder_tmp; + + // button handling + if (but[i].fallingEdge()) // SELECT { #ifdef DEBUG Serial.println(F("SELECT-R")); #endif - menu_system.next_screen(); + + if (menu_system.get_currentScreen() == &load_sound_screen) + { + // load sound +#ifdef DEBUG + Serial.print("Load sound "); + Serial.println(sound); +#endif + ; // TODO + } + else if (menu_system.get_currentScreen() == &save_sound_screen) + { + // save sound +#ifdef DEBUG + Serial.print("Save sound "); + Serial.println(sound); +#endif + ; // TODO + } + else + { + uint8_t menu_callback_offset = 0; + + if (menu_system.get_currentScreen() == &edit_sound_screen) + menu_callback_offset = NUM_MAIN_MENUS; + else if (menu_system.get_currentScreen() == &effects_screen) + menu_callback_offset = NUM_MAIN_MENUS + NUM_LOAD_SOUNDS_MENUS + NUM_EDIT_SOUND_MENUS; + else if (menu_system.get_currentScreen() == &system_screen) + menu_callback_offset = NUM_MAIN_MENUS + NUM_LOAD_SOUNDS_MENUS + NUM_EDIT_SOUND_MENUS + NUM_EFFECTS_MENUS; // + NUM_SAVE_SOUNDS_MENUS; +#ifdef DEBUG + Serial.print(F("Starting callback number ")); + Serial.println(encoder_value[RIGHT_ENCODER] + 1 + menu_callback_offset, DEC); + Serial.print(F("encoder_value[RIGHT_ENCODER]=")); + Serial.print(encoder_value[RIGHT_ENCODER], DEC); + Serial.print(F(" menu_callback_offset=")); + Serial.println(menu_callback_offset, DEC); +#endif + + if (menu_system.is_callable(encoder_value[RIGHT_ENCODER] + 1 + menu_callback_offset)) + { + // change menu + menu_system.call_function(encoder_value[RIGHT_ENCODER] + 1 + menu_callback_offset); + //menu_system.update(); + } +#ifdef DEBUG + else + { + Serial.print(F("No callback for ")); + Serial.println(encoder_value[RIGHT_ENCODER] + 1 + menu_callback_offset, DEC); + } +#endif + } } break; + case LEFT_ENCODER: + // Encoder handling + encoder_tmp = enc[LEFT_ENCODER].read(); + + // Change volume + if (encoder_tmp > encoder_value[LEFT_ENCODER]) + { + // move down +#ifdef DEBUG + Serial.print(F("ENC-L-DOWN: ")); + Serial.println(encoder_tmp); +#endif + } + else if (encoder_tmp < encoder_value[LEFT_ENCODER]) + { + // move up +#ifdef DEBUG + Serial.print(F("ENC-L-UP: ")); + Serial.println(encoder_tmp); +#endif + } + if (encoder_tmp != encoder_value[LEFT_ENCODER]) + { + master_volume = encoder_tmp; + old_screen = menu_system.get_currentScreen(); +#ifdef DEBUG + Serial.print(F("master_volume: ")); + Serial.println(master_volume); +#endif + menu_system.change_menu(master_volume_menu); + menu_system.update(); + back_to_main = 0; + } + encoder_value[LEFT_ENCODER] = encoder_tmp; + + // button handling + if (but[i].fallingEdge()) // BACK + { +#ifdef DEBUG + Serial.print("Back press detected: "); +#endif + if (menu_system.get_currentScreen() == &load_sound_screen) // load_sound menu + { +#ifdef DEBUG + Serial.println(F("from load_sound to main")); +#endif + goto_main_menu(); + } + else if (menu_system.get_currentScreen() == &edit_sound_screen) // sound menu + { +#ifdef DEBUG + Serial.println(F("from load_sound to main")); +#endif + goto_main_menu(); + + } + else if (menu_system.get_currentScreen() == &decay_screen) // decay menu + { +#ifdef DEBUG + Serial.println(F("from decay to edit_sound")); +#endif + goto_edit_sound_menu(); + } + else if (menu_system.get_currentScreen() == &release_screen) // release menu + { +#ifdef DEBUG + Serial.println(F("from release to edit_sound")); +#endif + goto_edit_sound_menu(); + } + else if (menu_system.get_currentScreen() == &hardness_screen) // hardness menu + { +#ifdef DEBUG + Serial.println(F("from hardness to edit_sound")); +#endif + goto_edit_sound_menu(); + } + else if (menu_system.get_currentScreen() == &treble_screen) // treble menu + { +#ifdef DEBUG + Serial.println(F("from treble to edit_sound")); +#endif + goto_edit_sound_menu(); + } + else if (menu_system.get_currentScreen() == &stereo_screen) // stereo menu + { +#ifdef DEBUG + Serial.println(F("from stereo to edit_sound")); +#endif + goto_edit_sound_menu(); + } + else if (menu_system.get_currentScreen() == &transpose_screen) // transpose menu + { +#ifdef DEBUG + Serial.println(F("from transpose to edit_sound")); +#endif + goto_edit_sound_menu(); + } + else if (menu_system.get_currentScreen() == &tune_screen) // tune menu + { +#ifdef DEBUG + Serial.println(F("from tune to edit_sound")); +#endif + goto_edit_sound_menu(); + } + else if (menu_system.get_currentScreen() == &detune_screen) // detune menu + { +#ifdef DEBUG + Serial.println(F("from detune to edit_sound")); +#endif + goto_edit_sound_menu(); + } + else if (menu_system.get_currentScreen() == &velocity_sense_screen) // velocity_sense menu + { +#ifdef DEBUG + Serial.println(F("from velocity_sense to edit_sound")); +#endif + goto_edit_sound_menu(); + } + else if (menu_system.get_currentScreen() == &effects_screen) // effect menu + { +#ifdef DEBUG + Serial.println(F("from effect to main")); +#endif + goto_main_menu(); + } + else if (menu_system.get_currentScreen() == &pan_trem_frequency_screen) //pan_trem_frequency menu + { +#ifdef DEBUG + Serial.println(F("from pan_trem_frequency to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &pan_trem_level_screen) // pan_trem_level menu + { +#ifdef DEBUG + Serial.println(F("from pan_trem_level to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &overdrive_screen) // overdrive menu + { +#ifdef DEBUG + Serial.println(F("from overdrive to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &comp_gain_screen) // comp_gain menu + { +#ifdef DEBUG + Serial.println(F("from comp_gain to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &comp_response_screen) // comp_response menu + { +#ifdef DEBUG + Serial.println(F("from comp_response to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &comp_limit_screen) // comp_limit menu + { +#ifdef DEBUG + Serial.println(F("from comp_limit to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &comp_threshold_screen) // comp_threshold menu + { +#ifdef DEBUG + Serial.println(F("from comp_threshold to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &comp_attack_screen) // comp_attack menu + { +#ifdef DEBUG + Serial.println(F("from comp_attack to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &comp_decay_screen) // comp_decay menu + { +#ifdef DEBUG + Serial.println(F("from comp_decay to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &reverb_roomsize_screen) // reverb_roomsize menu + { +#ifdef DEBUG + Serial.println(F("from reverb_roomsize to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &reverb_damping_screen) // reverb_damping menu + { +#ifdef DEBUG + Serial.println(F("from reverb_damping to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &reverb_level_screen) // reverb_level menu + { +#ifdef DEBUG + Serial.println(F("from reverb_level to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &chorus_frequency_screen) // chorus_frequency menu + { +#ifdef DEBUG + Serial.println(F("from chorus_frequency to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &chorus_delay_screen) // chorus_delay menu + { +#ifdef DEBUG + Serial.println(F("from chorus_delay to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &chorus_level_screen) // chorus_level menu + { +#ifdef DEBUG + Serial.println(F("from chorus_level to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &bass_lr_level_screen) // bass_lr_level menu + { +#ifdef DEBUG + Serial.println(F("from bass_lr_level to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &effects_screen) // effects menu + { +#ifdef DEBUG + Serial.println(F("from pan_trem_frequency to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &bass_mono_level_screen) // bass_mono_level menu + { +#ifdef DEBUG + Serial.println(F("from bass_mono_level to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &eq_bass_screen) // eq_bass menu + { +#ifdef DEBUG + Serial.println(F("from eq_bass to effects")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &eq_treble_screen) // eq_treble menu + { +#ifdef DEBUG + Serial.println(F("from eq_treble to main")); +#endif + goto_effects_menu(); + } + else if (menu_system.get_currentScreen() == &save_sound_screen) // save_sound menu + { +#ifdef DEBUG + Serial.println(F("from save_sound to main")); +#endif + goto_main_menu(); + } + else if (menu_system.get_currentScreen() == &system_screen) // system menu + { +#ifdef DEBUG + Serial.println(F("from system to main")); +#endif + goto_main_menu(); + } + else if (menu_system.get_currentScreen() == &loudness_screen) // loudness menu + { +#ifdef DEBUG + Serial.println(F("from loudness to system")); +#endif + goto_system_menu(); + } + else if (menu_system.get_currentScreen() == &midi_channel_screen) // midi_channel menu + { +#ifdef DEBUG + Serial.println(F("from midi_channel to system")); +#endif + goto_system_menu(); + } + else if (menu_system.get_currentScreen() == &midi_soft_thru_screen) // midi_soft_thru menu + { +#ifdef DEBUG + Serial.println(F("from midi_soft_thru to system")); +#endif + goto_system_menu(); + } + else if (menu_system.get_currentScreen() == &max_poly_screen) // max_poly menu + { +#ifdef DEBUG + Serial.println(F("from max_poly to system")); +#endif + goto_system_menu(); + } + else if (menu_system.get_currentScreen() == &info_screen) // info menu + { +#ifdef DEBUG + Serial.println(F("from info to main")); +#endif + goto_main_menu(); + } + } } } } diff --git a/config.h b/config.h index 9126c4a..e214640 100644 --- a/config.h +++ b/config.h @@ -112,6 +112,7 @@ //************************************************************************************************* #define CONTROL_RATE_MS 100 +#define BACK_TO_MAIN_MS 500 // MIDI #ifdef MIDI_DEVICE_USB diff --git a/fast_log.h b/fast_log.h deleted file mode 100644 index 3e2c24b..0000000 --- a/fast_log.h +++ /dev/null @@ -1,50 +0,0 @@ -/* ---------------------------------------------------------------------- -* https://community.arm.com/tools/f/discussions/4292/cmsis-dsp-new-functionality-proposal/22621#22621 -* Fast approximation to the log2() function. It uses a two step -* process. First, it decomposes the floating-point number into -* a fractional component F and an exponent E. The fraction component -* is used in a polynomial approximation and then the exponent added -* to the result. A 3rd order polynomial is used and the result -* when computing db20() is accurate to 7.984884e-003 dB. -** ------------------------------------------------------------------- */ - -float log2f_approx_coeff[4] = {1.23149591368684f, -4.11852516267426f, 6.02197014179219f, -3.13396450166353f}; - -float log2f_approx(float X) -{ - float *C = &log2f_approx_coeff[0]; - float Y; - float F; - int E; - - // This is the approximation to log2() - F = frexpf(fabsf(X), &E); - - // Y = C[0]*F*F*F + C[1]*F*F + C[2]*F + C[3] + E; - Y = *C++; - Y *= F; - Y += (*C++); - Y *= F; - Y += (*C++); - Y *= F; - Y += (*C++); - Y += E; - return(Y); -} - -// https://codingforspeed.com/using-faster-exponential-approximation/ -inline float expf_approx(float x) { - x = 1.0f + x / 1024; - x *= x; x *= x; x *= x; x *= x; - x *= x; x *= x; x *= x; x *= x; - x *= x; x *= x; - return x; -} - -inline float unitToDb(float unit) { - return 6.02f * log2f_approx(unit); -} - -inline float dbToUnit(float db) { - return expf_approx(db * 2.302585092994046f * 0.05f); -} \ No newline at end of file