diff --git a/MicroDexed.ino b/MicroDexed.ino index 86dfbc0..746ea66 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -821,25 +821,56 @@ void set_volume(float v, float p) configuration.vol = v; configuration.pan = p; -#ifdef DEBUG + /* + #ifdef DEBUG + Serial.print(F("Setting volume: VOL=")); + Serial.print(v, DEC); + Serial.print(F("[")); + Serial.print(configuration.vol, DEC); + Serial.print(F("] PAN=")); + Serial.print(F("[")); + Serial.print(configuration.pan, DEC); + Serial.print(F("] ")); + Serial.print(pow(configuration.vol * sinf(configuration.pan * PI / 2), VOLUME_CURVE), 3); + Serial.print(F("/")); + Serial.println(pow(configuration.vol * cosf( configuration.pan * PI / 2), VOLUME_CURVE), 3); + #endif + + dexed->fx.Gain = v; + + // http://files.csound-tutorial.net/floss_manual/Release03/Cs_FM_03_ScrapBook/b-panning-and-spatialization.html + volume_r.gain(sinf(p * PI / 2)); + volume_l.gain(cosf(p * PI / 2)); + */ + + dexed->fx.Gain = v; + + uint16_t tmp = v * 1023.0 + 0.5; + float tmp2 = configuration.pan; + float tmp3 = (float)(tmp * (tmp + 2)) / (float)(1 << 20); +#ifdef SHOW_DEBUG Serial.print(F("Setting volume: VOL=")); - Serial.print(v, DEC); + Serial.print(value, DEC); Serial.print(F("[")); - Serial.print(configuration.vol, 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.vol * sinf(configuration.pan * PI / 2), VOLUME_CURVE), 3); + Serial.print(tmp3 * sinf(tmp2 * PI / 2), 3); Serial.print(F("/")); - Serial.println(pow(configuration.vol * cosf( configuration.pan * PI / 2), VOLUME_CURVE), 3); + Serial.println(tmp3 * cosf(tmp2 * PI / 2), 3); #endif - dexed->fx.Gain = v; - + // 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 - volume_r.gain(sinf(p * PI / 2)); - volume_l.gain(cosf(p * PI / 2)); + volume_r.gain(tmp3 * sinf(tmp2 * PI / 2)); + volume_l.gain(tmp3 * cosf(tmp2 * PI / 2)); + /* if (configuration.mono == 2) + volume_l.gain(0.0); + else if (configuration.mono == 3) + volume_r.gain(0.0); */ } // https://www.dr-lex.be/info-stuff/volumecontrols.html#table1 @@ -883,6 +914,11 @@ void initial_values_from_eeprom(void) #ifdef DEBUG Serial.println(); #endif + + if (configuration.vol > 1.0) + configuration.vol = 1.0; + else if (configuration.vol < 0.0) + configuration.vol = 0.0; } void eeprom_write(void) diff --git a/UI.hpp b/UI.hpp index 05e5e21..638a43a 100644 --- a/UI.hpp +++ b/UI.hpp @@ -38,12 +38,18 @@ #define _LCDML_DISP_cfg_scrollbar 1 // enable a scrollbar extern config_t configuration; -void set_volume(float v, float p); +//void set_volume(float v, float p); extern char bank_names[MAX_BANKS][BANK_NAME_LEN]; extern char bank_name[BANK_NAME_LEN]; extern char voice_name[VOICE_NAME_LEN]; extern char voice_names[MAX_VOICES][VOICE_NAME_LEN]; extern void strip_extension(char* s, char *target); +extern void eeprom_write(void); +extern bool get_voice_names_from_bank(uint8_t b); +extern bool load_sysex(uint8_t b, uint8_t v); +extern value_change_t soften_volume; +extern value_change_t soften_filter_res; +extern value_change_t soften_filter_cut; /*********************************************************************** GLOBAL @@ -62,7 +68,9 @@ const uint8_t scroll_bar[5][8] = { enum { ENC_R, ENC_L }; enum { MENU_START, MENU_VOICE, MENU_EDIT, MENU_VOLUME }; +enum {MENU_VOICE_BANK, MENU_VOICE_SOUND}; uint8_t menu_state = MENU_START; +uint8_t menu_voice = MENU_VOICE_SOUND; void lcdml_menu_display(void); void lcdml_voice_menu_display(void); @@ -184,8 +192,34 @@ void lcdml_menu_control(void) case MENU_VOICE: #ifdef DEBUG Serial.println(F("State: MENU_VOICE, Encoder left down")); - break; #endif + switch (menu_voice) + { + case MENU_VOICE_BANK: + if (configuration.bank < MAX_BANKS) + { + configuration.bank++; + load_sysex(configuration.bank, configuration.voice); + get_voice_names_from_bank(configuration.bank); + } + break; + case MENU_VOICE_SOUND: + if (configuration.voice < 31) + configuration.voice++; + else + { + if (configuration.bank < MAX_BANKS) + { + configuration.bank++; + configuration.voice = 0; + load_sysex(configuration.bank, configuration.voice); + get_voice_names_from_bank(configuration.bank); + } + } + eeprom_write(); + } + UI_func_voice_selection(0); + break; } } ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position[ENC_R] + 4); @@ -211,8 +245,34 @@ void lcdml_menu_control(void) case MENU_VOICE: #ifdef DEBUG Serial.println(F("State: MENU_VOICE, Encoder left up")); - break; #endif + switch (menu_voice) + { + case MENU_VOICE_BANK: + if (configuration.bank > 0) + { + configuration.bank--; + load_sysex(configuration.bank, configuration.voice); + get_voice_names_from_bank(configuration.bank); + } + break; + case MENU_VOICE_SOUND: + if (configuration.voice > 0) + configuration.voice--; + else + { + if (configuration.bank > 0) + { + configuration.bank--; + configuration.voice = 31; + load_sysex(configuration.bank, configuration.voice); + get_voice_names_from_bank(configuration.bank); + } + } + eeprom_write(); + } + UI_func_voice_selection(0); + break; } } ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position[ENC_R] - 4); @@ -258,6 +318,11 @@ void lcdml_menu_control(void) #ifdef DEBUG Serial.println(F("State: MENU_VOICE, button short press")); #endif + if (menu_voice == MENU_VOICE_BANK) + menu_voice = MENU_VOICE_SOUND; + else + menu_voice = MENU_VOICE_BANK; + UI_func_voice_selection(0); } } } @@ -279,11 +344,14 @@ void lcdml_menu_control(void) #ifdef DEBUG Serial.println(F("Volume +")); #endif - if (configuration.vol < 1.0) + if (configuration.vol < 0.95) { - set_volume(configuration.vol + 0.05, configuration.pan); - UI_func_volume(0); + //set_volume(configuration.vol + 0.05, configuration.pan); + soften_volume.diff = 0.05 / SOFTEN_VALUE_CHANGE_STEPS; + soften_volume.steps = SOFTEN_VALUE_CHANGE_STEPS; + eeprom_write(); } + UI_func_volume(0); } ENCODER[ENC_L].write(g_LCDML_CONTROL_Encoder_position[ENC_L] + 4); } @@ -301,11 +369,14 @@ void lcdml_menu_control(void) #ifdef DEBUG Serial.println(F("Volume -")); #endif - if (configuration.vol > 0.0) + if (configuration.vol > 0.05) { - set_volume(configuration.vol - 0.05, configuration.pan); - UI_func_volume(0); + //set_volume(configuration.vol - 0.05, configuration.pan); + soften_volume.diff = -0.05 / SOFTEN_VALUE_CHANGE_STEPS; + soften_volume.steps = SOFTEN_VALUE_CHANGE_STEPS; + eeprom_write(); } + UI_func_volume(0); } ENCODER[ENC_L].write(g_LCDML_CONTROL_Encoder_position[ENC_L] - 4); } @@ -619,23 +690,34 @@ void UI_func_voice_selection(uint8_t param) menu_state = MENU_VOICE; - // update LCD content - LCDML.DISP_clear(); - - lcd.show(0, 0, 2, configuration.bank); - lcd.show(0, 2, 1, " "); strip_extension(bank_names[configuration.bank], bank_name); - lcd.show(0, 2, 1, " "); - lcd.show(0, 3, 8, bank_name); - lcd.show(0, 11, 1, " "); + //LCDML.DISP_clear(); + // display bank and voice number + lcd.show(0, 0, 2, configuration.bank); lcd.show(1, 0, 2, configuration.voice + 1); - lcd.show(1, 2, 1, " "); - lcd.show(1, 2, 1, "["); - lcd.show(1, 3, 10, voice_names[configuration.voice]); - lcd.show(1, 14, 1, "]"); + // display names + lcd.show(0, 4, 10, bank_name); + lcd.show(1, 4, 10, voice_names[configuration.voice]); + + // display selections + switch (menu_voice) + { + case MENU_VOICE_BANK: + lcd.show(0, 2, 2, " ["); + lcd.show(0, 14, 2, "] "); + lcd.show(1, 2, 2, " "); + lcd.show(1, 14, 2, " "); + break; + case MENU_VOICE_SOUND: + lcd.show(0, 2, 2, " "); + lcd.show(0, 14, 2, " "); + lcd.show(1, 2, 2, " ["); + lcd.show(1, 14, 2, "] "); + break; + } } void UI_func_volume(uint8_t param) diff --git a/config.h b/config.h index 68410a4..78a562c 100644 --- a/config.h +++ b/config.h @@ -38,7 +38,7 @@ // $ aplaymidi -p 20:0 # e.g. test.mid // $ arecord -f cd -Dhw:1,0 /tmp/bla.wav -#define VERSION "0.9.6" +#define VERSION "0.9.7" //************************************************************************************************* //* DEVICE SETTINGS @@ -96,7 +96,7 @@ #define REDUCE_LOUDNESS 1 #endif #define SAMPLE_RATE 44100 -#define SOFTEN_VALUE_CHANGE_STEPS 20 +#define SOFTEN_VALUE_CHANGE_STEPS 5 //************************************************************************************************* //* UI @@ -138,6 +138,7 @@ #define ENC_DELAY_TIME_STEPS 50 #define ENC_DELAY_FB_STEPS 35 #define ENC_DELAY_VOLUME_STEPS 50 +#define ENC_VOLUME_STEPS 20 #define NUM_ENCODER 2 #define ENC_L_PIN_A 3 #define ENC_L_PIN_B 2