From 2dd128532a89fb78fa6336e89dd9f550b23c234e Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 27 May 2019 15:16:33 +0200 Subject: [PATCH] Added midi controllers for some paramters. Fixes. --- MicroMDAEPiano.ino | 34 ++++++++++++++++++++++++++++---- UI.hpp | 2 +- config.h | 4 ++-- mdaEPiano.cpp | 49 ++++++++++++++++++++++++++++++++++------------ mdaEPiano.h | 7 +++++-- 5 files changed, 75 insertions(+), 21 deletions(-) diff --git a/MicroMDAEPiano.ino b/MicroMDAEPiano.ino index 86cb69c..35e3ac2 100644 --- a/MicroMDAEPiano.ino +++ b/MicroMDAEPiano.ino @@ -318,7 +318,27 @@ void handleControlChange(byte inChannel, byte inData1, byte inData2) { if (checkMidiChannel(inChannel)) { - ep->processMidiController(inData1, inData2); + switch (inData1) + { + case 10: // Panorama + configuration.pan = mapfloat(float(inData2), 0, 127, 0.0, 1.0); + break; + case 91: // Reverb level + set_reverb_level(map(inData2, 0, 127, ENC_REVERB_LEVEL_MIN, ENC_REVERB_LEVEL_MAX)); + break; + case 92: // Tremolo level (same as modwheel) + inData1 = 1; // now it's modwheel and can be processd by ep->processMidiController :-) + break; + case 93: // Chorus level + set_chorus_level(map(inData2, 0, 127, ENC_CHORUS_LEVEL_MIN, ENC_CHORUS_LEVEL_MAX)); + break; + case 94: // Detune level + ep->setDetune(mapfloat(float(inData2), 0, 127, 0.0, 1.0)); + break; + default: + ep->processMidiController(inData1, inData2); + break; + } } } @@ -334,15 +354,21 @@ void handlePitchBend(byte inChannel, int inPitch) void handleProgramChange(byte inChannel, byte inProgram) { - ; + if (checkMidiChannel(inChannel)) + { + sound = inProgram; + load_sound(); + if (menu_system.get_currentScreen() == &load_sound_screen) + menu_system.update(); + } } -void handleSystemExclusive(byte *data, uint len) +void handleSystemExclusive(byte * data, uint len) { ; } -void handleSystemExclusiveChunk(const byte *data, uint16_t len, bool last) +void handleSystemExclusiveChunk(const byte * data, uint16_t len, bool last) { ; } diff --git a/UI.hpp b/UI.hpp index 7e33576..3232ec5 100644 --- a/UI.hpp +++ b/UI.hpp @@ -1977,7 +1977,7 @@ void set_reverb_level(uint8_t value) Serial.print(F("Set REVERB_LEVEL ")); Serial.println(value); #endif - float tmp = mapfloat(float(value), ENC_REVERB_DAMPING_MIN, ENC_REVERB_DAMPING_MAX, 0.0, 1.0); + float tmp = mapfloat(float(value), ENC_REVERB_LEVEL_MIN, ENC_REVERB_LEVEL_MAX, 0.0, 1.0); //mixer_r.gain(0, 1.0 - tmp); //mixer_l.gain(0, 1.0 - tmp); mixer_r.gain(0, 1.0); diff --git a/config.h b/config.h index 40b284d..4d8bd77 100644 --- a/config.h +++ b/config.h @@ -97,7 +97,7 @@ 30: 1.22 Volts p-p 31: 1.16 Volts p-p */ -#define SGTL5000_LINEOUT_LEVEL 28 +#define SGTL5000_LINEOUT_LEVEL 22 //#define SDCARD_CS_PIN 10 //#define SDCARD_MOSI_PIN 7 //#define SDCARD_SCK_PIN 14 @@ -135,7 +135,7 @@ //* DO NO CHANGE ANYTHING BEYOND IF YOU DON'T KNOW WHAT YOU ARE DOING !!! //************************************************************************************************* -#define MICRO_MDAEPIANO_VERSION "0.9.0" +#define MICRO_MDAEPIANO_VERSION "0.9.1" #define MAX_SOUNDS min(99,int((4096-EEPROM_CONFIGURATIONS)/sizeof(config_t))) diff --git a/mdaEPiano.cpp b/mdaEPiano.cpp index 2aec6e5..ad2a339 100644 --- a/mdaEPiano.cpp +++ b/mdaEPiano.cpp @@ -30,6 +30,8 @@ #include extern float _loudness; +extern uint8_t master_volume; +extern config_t configuration; mdaEPiano::mdaEPiano() // mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, NPROGS, NPARAMS) { @@ -115,23 +117,39 @@ mdaEPiano::mdaEPiano() // mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) void mdaEPiano::reset_voices(void) // reset all voices { - //initialise... for (int32_t v = 0; v < NVOICES; v++) { voice[v].env = 0.0f; voice[v].dec = 0.99f; //all notes off } - volume = 0.2f; + //volume = // 0.00002f * 127; // Fixing this level and using CC#7 as master_volume muff = 160.0f; sustain = activevoices = 0; tl = tr = lfo0 = dlfo = 0.0f; lfo1 = 1.0f; - vol = VOLUME; update(); - // suspend(); } +void mdaEPiano::reset_controllers(void) // reset controllers +{ + tl = tr = lfo0 = dlfo = 0.0f; + lfo1 = 1.0f; + + update(); +} + +void mdaEPiano::stop_voices(void) // all keys off, but no reset for sustain +{ + for (int32_t v = 0; v < NVOICES; v++) + { + voice[v].env = 0.0f; + } + muff = 160.0f; + activevoices = 0; + + update(); +} void mdaEPiano::update() //parameter change { @@ -401,7 +419,7 @@ bool mdaEPiano::processMidiController(uint8_t data1, uint8_t data2) break; case 0x07: //volume - volume = 0.00002f * (float)(data2 * data2); + master_volume = map(data2, 0, 127, ENC_MASTER_VOLUME_MIN, ENC_MASTER_VOLUME_MAX); break; case 0x40: //sustain pedal @@ -413,13 +431,20 @@ bool mdaEPiano::processMidiController(uint8_t data1, uint8_t data2) } break; - default: //all notes off - if (data1 > 0x7A) - { - for (int32_t v = 0; v < max_polyphony; v++) voice[v].dec = 0.99f; - sustain = 0; - muff = 160.0f; - } + case 0x78: // All Sound Off: mutes all sounding notes. It does so regardless of release time or sustain. (See MIDI CC 123) + reset_voices(); + break; + case 0x79: // Reset All Controllers: it will reset all controllers to their default. + reset_controllers(); + break; + case 0x7b: // All Notes Off: mutes all sounding notes. Release time will still be maintained, and notes held by sustain will not turn off until sustain pedal is depressed. + stop_voices(); + break; + case 0x7e: // Mono Mode: sets device mode to Monophonic. + setMaxPolyphony(1); + break; + case 0x7f: // Poly Mode: sets device mode to Polyphonic. + setMaxPolyphony(configuration.max_poly); break; } return (true); diff --git a/mdaEPiano.h b/mdaEPiano.h index 0b60a36..d98ec74 100644 --- a/mdaEPiano.h +++ b/mdaEPiano.h @@ -98,6 +98,8 @@ class mdaEPiano //virtual float getParameter(int32_t index); virtual void resume(); void reset_voices(void); + void reset_controllers(void); + void stop_voices(void); void setDecay(float value); void setRelease(float value); void setHardness(float value); @@ -111,7 +113,7 @@ class mdaEPiano void setDetune(float value); void setOverdrive(float value); int32_t getActiveVoices(void); - + private: void update(); //my parameter update void fillpatch(int32_t p, char *name, float p0, float p1, float p2, float p3, float p4, @@ -132,7 +134,8 @@ class mdaEPiano float lfo0, lfo1, dlfo, lmod, rmod; float treb, tfrq, tl, tr; float tune, fine, random, stretch, overdrive; - float muff, muffvel, sizevel, velsens, volume, modwhl; + float muff, muffvel, sizevel, velsens, modwhl; + const float volume = 0.00002f * 127; float vol; //uint8_t curProgram; };