diff --git a/src/effect_base.cpp b/src/effect_base.cpp index f74eb29..ab424ce 100644 --- a/src/effect_base.cpp +++ b/src/effect_base.cpp @@ -1,5 +1,8 @@ +#include #include "effect_base.h" +LOGMODULE ("AudioEffect"); + AudioEffect::AudioEffect(float32_t samplerate) { this->samplerate = samplerate; @@ -24,6 +27,30 @@ unsigned AudioEffect::getId() return EFFECT_NONE; } +void AudioEffect::setParameters(std::vector params) +{ + LOGNOTE("setParameters size: %d", params.size()); + for (size_t i = 0; i < params.size(); i++) + { + this->setParameter(i, params[i]); + LOGNOTE("Param %d: %d", i, params[i]); + } +} + +std::vector AudioEffect::getParameters() +{ + LOGNOTE("getParameters"); + size_t len = getParametersSize(); + LOGNOTE("sizeof: %d", len); + std::vector params; + for (size_t i = 0; i < len; i++) + { + params.push_back(getParameter(i)); + LOGNOTE("Param %d: %d", i, params[i]); + } + return params; +} + void AudioEffect::process(const float32_t* inblock, float32_t* outblock, uint16_t len) { // Mono process @@ -35,17 +62,20 @@ void AudioEffect::process(const float32_t* inblock, float32_t* outblock, uint16_ void AudioEffect::process(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len) { if (bypass) { + if (inblockL != outblockL || inblockR != outblockR) { + // if input and output buffers are different we should copy the content + for (uint16_t i=0; i < len; i++) + { + outblockL[i] = inblockL[i]; + outblockR[i] = inblockR[i]; + } + } return; } doProcess(inblockL, inblockR, outblockL, outblockR, len); } void AudioEffect::doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len) { - for (uint16_t i=0; i < len; i++) - { - outblockL[i] = inblockL[i]; - outblockR[i] = inblockR[i]; - } } AudioEffectNone::AudioEffectNone(float32_t samplerate) : AudioEffect(samplerate) @@ -58,11 +88,6 @@ AudioEffectNone::~AudioEffectNone() void AudioEffectNone::doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len) { - for (uint16_t i=0; i < len; i++) - { - outblockL[i] = inblockL[i]; - outblockR[i] = inblockR[i]; - } } unsigned AudioEffectNone::getId() diff --git a/src/effect_base.h b/src/effect_base.h index 2bc30f3..b2a1320 100644 --- a/src/effect_base.h +++ b/src/effect_base.h @@ -3,6 +3,7 @@ //#include #include +#include #define EFFECT_NONE 0 #define EFFECT_CHORUS 1 @@ -19,20 +20,28 @@ public: bool getBypass(); virtual unsigned getId(); + virtual void setParameter(unsigned param, unsigned value) { } + virtual unsigned getParameter(unsigned param) { return 0; } + void setParameters(std::vector params); + std::vector getParameters(); void process(const float32_t* inblockL, float32_t* outblockL, uint16_t len); void process(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len); protected: bool bypass = false; float32_t samplerate; + virtual size_t getParametersSize() + { + return 0; + } virtual void doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len); }; diff --git a/src/effect_chorus.h b/src/effect_chorus.h index c1f221f..9368dca 100644 --- a/src/effect_chorus.h +++ b/src/effect_chorus.h @@ -36,6 +36,10 @@ public: unsigned getChorusIIRate(); void setChorusIIRate(unsigned int rate); protected: + virtual size_t getParametersSize() + { + return sizeof(AudioEffectChorus::Param); + } virtual void doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len); private: diff --git a/src/effect_delay.cpp b/src/effect_delay.cpp index 906ae0b..215804f 100644 --- a/src/effect_delay.cpp +++ b/src/effect_delay.cpp @@ -19,7 +19,7 @@ AudioEffectDelay::AudioEffectDelay(float32_t samplerate) : AudioEffect(samplerat this->timeL = 0.36f; this->timeR = 0.36f; - this->feedback = 0.3f; + this->feedback = 0.5f; } AudioEffectDelay::~AudioEffectDelay() diff --git a/src/effect_delay.h b/src/effect_delay.h index 34e9917..1e2ec03 100644 --- a/src/effect_delay.h +++ b/src/effect_delay.h @@ -25,6 +25,10 @@ public: virtual void setParameter(unsigned param, unsigned value); virtual unsigned getParameter(unsigned param); protected: + virtual size_t getParametersSize() + { + return sizeof(AudioEffectDelay::Param); + } virtual void doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len); private: size_t bufferSize; diff --git a/src/effect_lpf.h b/src/effect_lpf.h index 9ce0e6d..d93b610 100644 --- a/src/effect_lpf.h +++ b/src/effect_lpf.h @@ -88,6 +88,11 @@ public: } protected: + virtual size_t getParametersSize() + { + return sizeof(AudioEffectLPF::Param); + } + virtual void doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len) { for (int i = 0; i < len; i++) { diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 7ac073f..b69ffa6 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -1308,6 +1308,14 @@ bool CMiniDexed::DoSavePerformance (void) m_PerformanceConfig.SetMIDIChannel (m_nMIDIChannel[nTG], nTG); m_PerformanceConfig.SetVolume (m_nVolume[nTG], nTG); m_PerformanceConfig.SetPan (m_nPan[nTG], nTG); + + m_PerformanceConfig.SetInsertFX (m_InsertFX[nTG]->getId(), nTG); + LOGNOTE("Saving Insert FX Paramas"); + std::vector pParams = m_InsertFX[nTG]->getParameters(); + m_PerformanceConfig.SetInsertFXParams (pParams, nTG); + pParams.clear(); + pParams.shrink_to_fit(); + m_PerformanceConfig.SetDetune (m_nMasterTune[nTG], nTG); m_PerformanceConfig.SetCutoff (m_nCutoff[nTG], nTG); m_PerformanceConfig.SetResonance (m_nResonance[nTG], nTG); @@ -1751,6 +1759,12 @@ void CMiniDexed::LoadPerformanceParameters(void) setPortamentoGlissando (m_PerformanceConfig.GetPortamentoGlissando (nTG), nTG); setPortamentoTime (m_PerformanceConfig.GetPortamentoTime (nTG), nTG); + setInsertFXType(m_PerformanceConfig.GetInsertFX (nTG), nTG); + std::vector pParams = m_PerformanceConfig.GetInsertFXParams(nTG); + m_InsertFX[nTG]->setParameters(pParams); + pParams.clear(); + pParams.shrink_to_fit(); + m_nNoteLimitLow[nTG] = m_PerformanceConfig.GetNoteLimitLow (nTG); m_nNoteLimitHigh[nTG] = m_PerformanceConfig.GetNoteLimitHigh (nTG); m_nNoteShift[nTG] = m_PerformanceConfig.GetNoteShift (nTG); diff --git a/src/performanceconfig.cpp b/src/performanceconfig.cpp index 8cd6275..7166990 100644 --- a/src/performanceconfig.cpp +++ b/src/performanceconfig.cpp @@ -23,8 +23,9 @@ #include #include "performanceconfig.h" #include "mididevice.h" -#include +#include #include +#include LOGMODULE ("Performance"); @@ -132,6 +133,12 @@ bool CPerformanceConfig::Load (void) PropertyName.Format ("Pan%u", nTG+1); m_nPan[nTG] = m_Properties.GetNumber (PropertyName, 64); + PropertyName.Format ("InsertFX%u", nTG+1); + m_nInsertFX[nTG] = m_Properties.GetNumber (PropertyName, 0); + + PropertyName.Format ("InsertFXParams%u", nTG+1); + m_nInsertFXParams[nTG] = m_Properties.GetString (PropertyName, ""); + PropertyName.Format ("Detune%u", nTG+1); m_nDetune[nTG] = m_Properties.GetSignedNumber (PropertyName, 0); @@ -249,6 +256,12 @@ bool CPerformanceConfig::Save (void) PropertyName.Format ("Pan%u", nTG+1); m_Properties.SetNumber (PropertyName, m_nPan[nTG]); + PropertyName.Format ("InsertFX%u", nTG+1); + m_Properties.SetNumber (PropertyName, m_nInsertFX[nTG]); + + PropertyName.Format ("InsertFXParams%u", nTG+1); + m_Properties.SetString (PropertyName, m_nInsertFXParams[nTG].c_str()); + PropertyName.Format ("Detune%u", nTG+1); m_Properties.SetSignedNumber (PropertyName, m_nDetune[nTG]); @@ -361,6 +374,39 @@ unsigned CPerformanceConfig::GetPan (unsigned nTG) const return m_nPan[nTG]; } +unsigned CPerformanceConfig::GetInsertFX (unsigned nTG) const +{ + assert (nTG < CConfig::ToneGenerators); + return m_nInsertFX[nTG]; +} + +std::vector CPerformanceConfig::GetInsertFXParams (unsigned nTG) const +{ + assert (nTG < CConfig::ToneGenerators); + + LOGNOTE("Loading Insert FX Params"); + + std::string params = m_nInsertFXParams[nTG]; + if (params.empty()) { + LOGNOTE("Empty Insert FX Params"); + std::vector empty; + return empty; + } + + char delimiter = ','; + std::stringstream ss(params); + std::string temp; + std::vector tokens; + while (getline(ss, temp, delimiter)) + { + LOGNOTE("Insert FX Params token: %s", temp.c_str()); + tokens.push_back(stoi(temp)); + } + LOGNOTE("Insert FX Params tokens size: %d\n", tokens.size()); + LOGNOTE("Loaded Insert FX Params\n"); + return tokens; +} + int CPerformanceConfig::GetDetune (unsigned nTG) const { assert (nTG < CConfig::ToneGenerators); @@ -433,6 +479,30 @@ void CPerformanceConfig::SetPan (unsigned nValue, unsigned nTG) m_nPan[nTG] = nValue; } +void CPerformanceConfig::SetInsertFX (unsigned nValue, unsigned nTG) +{ + assert (nTG < CConfig::ToneGenerators); + m_nInsertFX[nTG] = nValue; +} + +void CPerformanceConfig::SetInsertFXParams (std::vector pParams, unsigned nTG) +{ + LOGNOTE("SetInsertFXParams"); + assert (nTG < CConfig::ToneGenerators); + + LOGNOTE("SetInsertFXParams sizeof %d", pParams.size()); + std::string params = ""; + for (size_t i = 0; i < pParams.size(); i++) + { + if (i != 0) { + params += ","; + } + params += std::to_string(pParams[i]); + } + LOGNOTE("SetInsertFXParams %s", params.c_str()); + m_nInsertFXParams[nTG] = params; +} + void CPerformanceConfig::SetDetune (int nValue, unsigned nTG) { assert (nTG < CConfig::ToneGenerators); diff --git a/src/performanceconfig.h b/src/performanceconfig.h index 0d50daa..ccea378 100644 --- a/src/performanceconfig.h +++ b/src/performanceconfig.h @@ -26,6 +26,7 @@ #include "config.h" #include #include +#include #define NUM_VOICE_PARAM 156 #define NUM_PERFORMANCES 128 #define NUM_PERFORMANCE_BANKS 128 @@ -48,6 +49,8 @@ public: unsigned GetMIDIChannel (unsigned nTG) const; // 0 .. 15, omni, off unsigned GetVolume (unsigned nTG) const; // 0 .. 127 unsigned GetPan (unsigned nTG) const; // 0 .. 127 + unsigned GetInsertFX (unsigned nTG) const; // 0 .. X + std::vector GetInsertFXParams (unsigned nTG) const; int GetDetune (unsigned nTG) const; // -99 .. 99 unsigned GetCutoff (unsigned nTG) const; // 0 .. 99 unsigned GetResonance (unsigned nTG) const; // 0 .. 99 @@ -76,6 +79,8 @@ public: void SetMIDIChannel (unsigned nValue, unsigned nTG); void SetVolume (unsigned nValue, unsigned nTG); void SetPan (unsigned nValue, unsigned nTG); + void SetInsertFX (unsigned nValue, unsigned nTG); + void SetInsertFXParams (std::vector pParams, unsigned nTG); void SetDetune (int nValue, unsigned nTG); void SetCutoff (unsigned nValue, unsigned nTG); void SetResonance (unsigned nValue, unsigned nTG); @@ -157,6 +162,8 @@ private: unsigned m_nMIDIChannel[CConfig::ToneGenerators]; unsigned m_nVolume[CConfig::ToneGenerators]; unsigned m_nPan[CConfig::ToneGenerators]; + unsigned m_nInsertFX[CConfig::ToneGenerators]; + std::string m_nInsertFXParams[CConfig::ToneGenerators]; int m_nDetune[CConfig::ToneGenerators]; unsigned m_nCutoff[CConfig::ToneGenerators]; unsigned m_nResonance[CConfig::ToneGenerators];