diff --git a/third-party/Synth_Dexed/src/synth_dexed.cpp b/third-party/Synth_Dexed/src/synth_dexed.cpp index 95b5de0..ab3a534 100644 --- a/third-party/Synth_Dexed/src/synth_dexed.cpp +++ b/third-party/Synth_Dexed/src/synth_dexed.cpp @@ -283,8 +283,6 @@ float PluginFx::getGain(void) Dexed::Dexed(uint8_t maxnotes, int rate) { - uint8_t i; - Exp2::init(); Tanh::init(); Sin::init(); @@ -297,19 +295,7 @@ Dexed::Dexed(uint8_t maxnotes, int rate) fx.init(rate); engineMsfa = new FmCore; - max_notes=maxnotes; - voices=new ProcessorVoice[max_notes]; - - for (i = 0; i < max_notes; i++) - { - voices[i].dx7_note = new Dx7Note; - voices[i].keydown = false; - voices[i].sustained = false; - voices[i].live = false; - voices[i].key_pressed_timer = 0; - } - currentNote = 0; resetControllers(); controllers.masterTune = 0; @@ -317,13 +303,12 @@ Dexed::Dexed(uint8_t maxnotes, int rate) lastKeyDown = -1; vuSignal = 0.0; controllers.core = engineMsfa; - lfo.reset(data + 137); - - setMonoMode(false); - sustain = false; + voices=NULL; + setMaxNotes(max_notes); + setMonoMode(false); loadInitVoice(); xrun = 0; @@ -343,6 +328,47 @@ Dexed::~Dexed() delete(engineMsfa); } +void Dexed::setMaxNotes(uint8_t new_max_notes) +{ + uint8_t i=0; + + max_notes=constrain(max_notes,0,_MAX_NOTES); + +#ifdef DEBUG + Serial.print("Allocating memory for "); + Serial.print(max_notes,DEC); + Serial.println(" notes."); +#endif + + if(voices) + { + panic(); + for (i = 0; i < max_notes; i++) + { + if(voices[i].dx7_note) + delete voices[i].dx7_note; + } + delete voices; + } + + max_notes=new_max_notes; + + if(max_notes>0) + { + voices=new ProcessorVoice[max_notes]; + for (i = 0; i < max_notes; i++) + { + voices[i].dx7_note = new Dx7Note; + voices[i].keydown = false; + voices[i].sustained = false; + voices[i].live = false; + voices[i].key_pressed_timer = 0; + } + } + else + voices=NULL; +} + void Dexed::activate(void) { panic(); @@ -596,7 +622,7 @@ void Dexed::setOPAll(uint8_t ops) controllers.opSwitch = ops; } -bool Dexed::isMonoMode(void) { +bool Dexed::getMonoMode(void) { return monoMode; } @@ -604,7 +630,6 @@ void Dexed::setMonoMode(bool mode) { if (monoMode == mode) return; - //panic(); notesOff(); monoMode = mode; } @@ -668,16 +693,6 @@ void Dexed::notesOff(void) { } } -void Dexed::setMaxNotes(uint8_t n) { - if (n <= max_notes) - { - notesOff(); - max_notes = n; - //panic(); - controllers.refresh(); - } -} - uint8_t Dexed::getMaxNotes(void) { return max_notes; @@ -885,9 +900,8 @@ void Dexed::loadVoiceParameters(uint8_t* new_data) panic(); memcpy(&data, new_data, 155); doRefreshVoice(); - strncpy(dexed_voice_name, (char *)&new_data[145], sizeof(dexed_voice_name) - 1); - #ifdef DEBUG + strncpy(dexed_voice_name, (char *)&new_data[145], sizeof(dexed_voice_name) - 1); dexed_voice_name[10] = '\0'; Serial.print(F("Voice [")); diff --git a/third-party/Synth_Dexed/src/synth_dexed.h b/third-party/Synth_Dexed/src/synth_dexed.h index 6a799d3..0610038 100644 --- a/third-party/Synth_Dexed/src/synth_dexed.h +++ b/third-party/Synth_Dexed/src/synth_dexed.h @@ -30,47 +30,14 @@ #include "teensy_board_detection.h" #define SYNTH_DEXED_VERSION "1.0.0" -#define DEBUG 1 +//#define DEBUG 1 #define SAMPLE_RATE 44100 #define MIDI_CONTROLLER_MODE_MAX 2 #define TRANSPOSE_FIX 24 #define VOICE_SILENCE_LEVEL 1100 -// Teensy-4.x settings -#ifdef TEENSY4 -#define MAX_NOTES 32 -#endif - -// Teensy-3.6 settings -#if defined(TEENSY3_6) -# if defined(USE_FX) -# if F_CPU == 256000000 -# define MAX_NOTES 20 -# elif F_CPU == 240000000 -# define MAX_NOTES 18 -# elif F_CPU == 216000000 -# define MAX_NOTES 16 -# else -# warning >>> You should consider to use 216MHz overclocking to get polyphony of 16 instead 12 voices <<< -# define MAX_NOTES 12 -# endif -# else -# if F_CPU == 256000000 -# define MAX_NOTES 20 -# elif F_CPU == 216000000 -# define MAX_NOTES 20 -# else -# define MAX_NOTES 16 -# endif -# endif -#endif - -#ifdef TEENSY3_5 -#undef MIDI_DEVICE_USB_HOST -#define MAX_NOTES 11 -#undef USE_FX -#endif +#define _MAX_NOTES 32 #define NUM_VOICE_PARAMETERS 156 @@ -1150,7 +1117,7 @@ class Dexed // Global methods void activate(void); void deactivate(void); - bool isMonoMode(void); + bool getMonoMode(void); void setMonoMode(bool mode); void setRefreshMode(bool mode); void setMaxNotes(uint8_t n);