diff --git a/MicroMDAEPiano.ino b/MicroMDAEPiano.ino index d5c31dd..252fca9 100644 --- a/MicroMDAEPiano.ino +++ b/MicroMDAEPiano.ino @@ -127,10 +127,13 @@ config_t configuration = { ENC_EQ_TREBLE_DEFAULT, // eq_treble ENC_LOUDNESS_DEFAULT, // loudness ENC_MIDI_CHANNEL_DEFAULT, // midi_channel - ENC_MIDI_CHANNEL_DEFAULT, // midi_soft_thru - ENC_MAX_POLY_DEFAULT // max_poly + ENC_MIDI_SOFT_THRU_DEFAULT, // midi_soft_thru + ENC_MAX_POLY_DEFAULT, // max_poly + 0 // pan }; +float _loudness=mapfloat(float(ENC_LOUDNESS_DEFAULT), ENC_LOUDNESS_MIN, ENC_LOUDNESS_MAX, 0.0, 1.0); + bool eeprom_update_flag = false; #ifdef SHOW_CPU_LOAD_MSEC elapsedMillis cpu_mem_millis; @@ -450,11 +453,11 @@ bool checkMidiChannel(byte inChannel) void set_master_volume(uint8_t value) { + configuration.pan=0; // BAD HACK! 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(value, DEC); Serial.print(F("[")); diff --git a/UI.hpp b/UI.hpp index 4376456..715fad3 100644 --- a/UI.hpp +++ b/UI.hpp @@ -101,6 +101,7 @@ extern AudioMixer4 mixer_r; extern AudioMixer4 mixer_l; extern AudioAmplifier volume_r; extern AudioAmplifier volume_l; +extern float _loudness; /****************************************** TEXT GETTER FUCTIONS @@ -158,10 +159,10 @@ char* get_comp_limit_value_text(void) { switch (configuration.comp_limit) { - case 0: + case false: return (comp_limit_value_text1); break; - case 1: + case true: return (comp_limit_value_text2); break; } @@ -1937,7 +1938,7 @@ void set_loudness(uint8_t value) Serial.print(F("Set LOUDNESS ")); Serial.println(value); #endif - configuration._loudness = mapfloat(float(value), ENC_LOUDNESS_MIN, ENC_LOUDNESS_MAX, 0.0, 1.0); + _loudness = mapfloat(float(value), ENC_LOUDNESS_MIN, ENC_LOUDNESS_MAX, 0.0, 1.0); //volume_r.gain(tmp); //volume_l.gain(tmp); configuration.loudness = value; @@ -1968,6 +1969,7 @@ void set_max_poly(uint8_t value) Serial.println(value); #endif configuration.max_poly = value; + ep->reset_voices(); } void set_complete_configuration(void) diff --git a/config.h b/config.h index 5976e48..e20e4b3 100644 --- a/config.h +++ b/config.h @@ -261,8 +261,8 @@ #define ENC_MIDI_SOFT_THRU_DEFAULT 1 // #define ENC_MAX_POLY_MIN 1 -#define ENC_MAX_POLY_MAX 32 -#define ENC_MAX_POLY_DEFAULT 32 +#define ENC_MAX_POLY_MAX NVOICES +#define ENC_MAX_POLY_DEFAULT NVOICES // #define ENC_MASTER_VOLUME_MIN 0 #define ENC_MASTER_VOLUME_MAX 99 @@ -323,7 +323,7 @@ struct config_t { uint8_t overdrive; uint8_t comp_gain; uint8_t comp_response; - uint8_t comp_limit; + bool comp_limit; uint8_t comp_threshold; uint8_t comp_attack; uint8_t comp_decay; @@ -338,9 +338,8 @@ struct config_t { uint8_t eq_bass; uint8_t eq_treble; uint8_t loudness; - float _loudness; uint8_t midi_channel; - uint8_t midi_soft_thru; + bool midi_soft_thru; uint8_t max_poly; int8_t pan; }; diff --git a/mdaEPiano.cpp b/mdaEPiano.cpp index d4a565c..686ef40 100644 --- a/mdaEPiano.cpp +++ b/mdaEPiano.cpp @@ -29,6 +29,8 @@ #include #include +extern float _loudness; + mdaEPiano::mdaEPiano() // mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, NPROGS, NPARAMS) { Fs = SAMPLE_RATE; iFs = 1.0f / Fs; //just in case... @@ -98,6 +100,12 @@ mdaEPiano::mdaEPiano() // mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) kgrp[31].pos = 406046; kgrp[31].end = 414486; kgrp[31].loop = 2306; //ghost kgrp[32].pos = 414487; kgrp[32].end = 422408; kgrp[32].loop = 2169; + //initialise... + reset_voices(); +} + +void mdaEPiano::reset_voices(void) // reset all voices +{ //initialise... for (int32_t v = 0; v < NVOICES; v++) { @@ -116,7 +124,6 @@ mdaEPiano::mdaEPiano() // mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) update(); // suspend(); } - void mdaEPiano::update() //parameter change { float * param = programs[curProgram].param; @@ -240,8 +247,8 @@ void mdaEPiano::process(int16_t* outputs_r, int16_t* outputs_l) l = 1.0; else if (l < -1.0) l = -1.0; - outputs_l[frame] = static_cast(l * configuration._loudness * 0x7fff) >> REDUCE_LOUDNESS; - outputs_r[frame] = static_cast(r * configuration._loudness * 0x7fff) >> REDUCE_LOUDNESS; + outputs_l[frame] = static_cast(l * _loudness * 0x7fff) >> REDUCE_LOUDNESS; + outputs_r[frame] = static_cast(r * _loudness * 0x7fff) >> REDUCE_LOUDNESS; } if (fabs(tl) < 1.0e-10) tl = 0.0f; //anti-denormal @@ -260,7 +267,7 @@ void mdaEPiano::noteOn(int32_t note, int32_t velocity) if (velocity > 0) { - if (activevoices < NVOICES) //add a note + if (activevoices < configuration.max_poly) //add a note { vl = activevoices; activevoices++; @@ -268,7 +275,7 @@ void mdaEPiano::noteOn(int32_t note, int32_t velocity) } else //steal a note { - for (v = 0; v < NVOICES; v++) //find quietest voice + for (v = 0; v < configuration.max_poly; v++) //find quietest voice { if (voice[v].env < l) { l = voice[v].env; @@ -318,7 +325,7 @@ void mdaEPiano::noteOn(int32_t note, int32_t velocity) } else //note off { - for (v = 0; v < NVOICES; v++) if (voice[v].note == note) //any voices playing that note? + for (v = 0; v < configuration.max_poly; v++) if (voice[v].note == note) //any voices playing that note? { if (sustain == 0) { @@ -360,7 +367,7 @@ bool mdaEPiano::processMidiController(uint8_t data1, uint8_t data2) default: //all notes off if (data1 > 0x7A) { - for (int32_t v = 0; v < NVOICES; v++) voice[v].dec = 0.99f; + for (int32_t v = 0; v < configuration.max_poly; v++) voice[v].dec = 0.99f; sustain = 0; muff = 160.0f; } diff --git a/mdaEPiano.h b/mdaEPiano.h index b593301..f4a5b2a 100644 --- a/mdaEPiano.h +++ b/mdaEPiano.h @@ -87,6 +87,7 @@ class mdaEPiano virtual void setParameter(int32_t index, float value); virtual float getParameter(int32_t index); virtual void resume(); + void reset_voices(void); int32_t guiUpdate; void guiGetDisplay(int32_t index, char *label);