diff options
author | falkTX <falktx@gmail.com> | 2018-09-30 23:07:25 +0200 |
---|---|---|
committer | Damien Zammit <damien@zamaudio.com> | 2018-12-18 19:57:48 +1100 |
commit | fcce190f4e64b4e478792a701dfd7b10ecb04c70 (patch) | |
tree | 4f863a53a10cba217eb006124cb5fad308d233a9 | |
parent | 5257b0113d6bb7462380086a7e8e4e2fe89302e8 (diff) |
ZamSynth general fix up
-rw-r--r-- | plugins/ZamSynth/DistrhoPluginInfo.h | 2 | ||||
-rw-r--r-- | plugins/ZamSynth/ZamSynthPlugin.cpp | 76 | ||||
-rw-r--r-- | plugins/ZamSynth/ZamSynthPlugin.hpp | 5 | ||||
-rw-r--r-- | plugins/ZamSynth/ZamSynthUI.cpp | 88 | ||||
-rw-r--r-- | plugins/ZamSynth/ZamSynthUI.hpp | 8 |
5 files changed, 88 insertions, 91 deletions
diff --git a/plugins/ZamSynth/DistrhoPluginInfo.h b/plugins/ZamSynth/DistrhoPluginInfo.h index 710242e..17e8570 100644 --- a/plugins/ZamSynth/DistrhoPluginInfo.h +++ b/plugins/ZamSynth/DistrhoPluginInfo.h @@ -28,7 +28,7 @@ #define DISTRHO_PLUGIN_NUM_OUTPUTS 2 #define DISTRHO_PLUGIN_WANT_LATENCY 0 -#define DISTRHO_PLUGIN_WANT_PROGRAMS 1 +#define DISTRHO_PLUGIN_WANT_PROGRAMS 0 #define DISTRHO_PLUGIN_WANT_STATE 1 #define DISTRHO_PLUGIN_WANT_TIMEPOS 0 diff --git a/plugins/ZamSynth/ZamSynthPlugin.cpp b/plugins/ZamSynth/ZamSynthPlugin.cpp index e81ae72..14a33a9 100644 --- a/plugins/ZamSynth/ZamSynthPlugin.cpp +++ b/plugins/ZamSynth/ZamSynthPlugin.cpp @@ -22,10 +22,33 @@ START_NAMESPACE_DISTRHO // ----------------------------------------------------------------------- ZamSynthPlugin::ZamSynthPlugin() - : Plugin(paramCount, 1, 1) // 1 program, 1 state + : Plugin(paramCount, 0, 2) // 0 programs, 2 states { - // set default values - loadProgram(0); + /* Default parameter values */ + gain = 0.0f; + graph = 0.0f; + speed = 10.0f; + + /* Default variable values */ + for (int i = 0; i < MAX_VOICES; i++) { + voice[i].playing = false; + voice[i].notenum = -1; + voice[i].envpos = 0; + voice[i].slowcount = 0; + voice[i].curamp = 0.f; + voice[i].vi = 0.f; + voice[i].rampstate = 0.f; + } + + curvoice = voice; //ptr to first voice + + for (int i = 0; i < AREAHEIGHT; i++) { + wave_y[i] = sin(i*2.*M_PI/getSampleRate());//*1000 + } + + for (int i = 0; i < MAX_ENV; i++) { + env_y[i] = (sin(i*2.*M_PI/getSampleRate()*1000./2.)) > 0.f ? sin(i*2.*M_PI/getSampleRate()*1000./2.) : 0.f; + } } // ----------------------------------------------------------------------- @@ -65,14 +88,6 @@ void ZamSynthPlugin::initParameter(uint32_t index, Parameter& parameter) } } -void ZamSynthPlugin::initProgramName(uint32_t index, String& programName) -{ - if (index != 0) - return; - - programName = "Default"; -} - // ----------------------------------------------------------------------- // Internal data @@ -110,45 +125,6 @@ void ZamSynthPlugin::setParameterValue(uint32_t index, float value) } } -void ZamSynthPlugin::loadProgram(uint32_t index) -{ - if (index != 0) - return; - - /* Default parameter values */ - gain = 0.0f; - graph = 0.0f; - speed = 10.0f; - - /* Default variable values */ - for (int i = 0; i < MAX_VOICES; i++) { - voice[i].playing = false; - voice[i].notenum = -1; - voice[i].envpos = 0; - voice[i].slowcount = 0; - voice[i].curamp = 0.f; - voice[i].vi = 0.f; - voice[i].rampstate = 0.f; - } - - curvoice = voice; //ptr to first voice - - for (int i = 0; i < AREAHEIGHT; i++) { - wave_y[i] = sin(i*2.*M_PI/getSampleRate());//*1000 - } - - for (int i = 0; i < MAX_ENV; i++) { - env_y[i] = (sin(i*2.*M_PI/getSampleRate()*1000./2.)) > 0.f ? sin(i*2.*M_PI/getSampleRate()*1000./2.) : 0.f; - } - /* reset filter values */ - activate(); -} - -String ZamSynthPlugin::getState(const char*) const -{ - return String(""); -} - void ZamSynthPlugin::setState(const char* key, const char* value) { if (strcmp(key, "waveform") == 0) { diff --git a/plugins/ZamSynth/ZamSynthPlugin.hpp b/plugins/ZamSynth/ZamSynthPlugin.hpp index e4ae27c..3c95b98 100644 --- a/plugins/ZamSynth/ZamSynthPlugin.hpp +++ b/plugins/ZamSynth/ZamSynthPlugin.hpp @@ -83,15 +83,13 @@ protected: // ------------------------------------------------------------------- // Init - void initParameter(uint32_t index, Parameter& parameter) ; - void initProgramName(uint32_t index, String& programName) ; + void initParameter(uint32_t index, Parameter& parameter) override; // ------------------------------------------------------------------- // Internal data float getParameterValue(uint32_t index) const override; void setParameterValue(uint32_t index, float value) override; - void loadProgram(uint32_t index) override; // ------------------------------------------------------------------- // Process @@ -118,7 +116,6 @@ protected: void run(const float** inputs, float** outputs, uint32_t frames, const MidiEvent* midievent, uint32_t midicount) override; void setState(const char* key, const char* value) override; - String getState(const char* key) const override; void initState(unsigned int index, String& key, String& defval) override; // ------------------------------------------------------------------- diff --git a/plugins/ZamSynth/ZamSynthUI.cpp b/plugins/ZamSynth/ZamSynthUI.cpp index 702ef1f..a52df0f 100644 --- a/plugins/ZamSynth/ZamSynthUI.cpp +++ b/plugins/ZamSynth/ZamSynthUI.cpp @@ -23,10 +23,12 @@ START_NAMESPACE_DISTRHO // ----------------------------------------------------------------------- ZamSynthUI::ZamSynthUI() - : UI() + : UI(), + fWaveUpdated(false), + fEnvUpdated(false) { setSize(ZamSynthArtwork::zamsynthWidth, ZamSynthArtwork::zamsynthHeight); - + // background fImgBackground = Image(ZamSynthArtwork::zamsynthData, ZamSynthArtwork::zamsynthWidth, ZamSynthArtwork::zamsynthHeight, GL_BGR); @@ -81,7 +83,8 @@ ZamSynthUI::ZamSynthUI() fToggleGraph->setDown(false); // set default values - programLoaded(0); + fKnobGain->setValue(0.0f); + fKnobSpeed->setValue(10.0f); } void ZamSynthUI::stateChanged(const char* key, const char* value) @@ -111,6 +114,7 @@ void ZamSynthUI::stateChanged(const char* key, const char* value) tmp = strtok(NULL, " "); } } + repaint(); } // ----------------------------------------------------------------------- @@ -132,15 +136,6 @@ void ZamSynthUI::parameterChanged(uint32_t index, float value) } } -void ZamSynthUI::programLoaded(uint32_t index) -{ - if (index != 0) - return; - - fKnobGain->setValue(0.0f); - fKnobSpeed->setValue(10.0f); -} - // ----------------------------------------------------------------------- // Widget Callbacks @@ -170,6 +165,8 @@ void ZamSynthUI::imageKnobValueChanged(ImageKnob* knob, float value) void ZamSynthUI::imageButtonClicked(ImageButton*, int) { + const bool isEnvelope = fToggleGraph->isDown(); + float wavesmooth[AREAHEIGHT]; float xs[AREAHEIGHT]; int i; @@ -183,17 +180,18 @@ void ZamSynthUI::imageButtonClicked(ImageButton*, int) gaussiansmooth(wavesmooth, xs, gr, AREAHEIGHT, 4); memcpy(gr, wavesmooth, AREAHEIGHT*sizeof(float)); - char tmp[4*AREAHEIGHT+1] = {0}; + char* tmp = isEnvelope ? fEnvState : fWaveState; + memset(tmp, 0, sizeof(fWaveState)); for(i = 0; i < AREAHEIGHT; i++) { char wavestr[5] = {0}; snprintf(wavestr, sizeof(wavestr), "%03d ", (int) (fCanvasArea.getHeight()-gr[i])); strcat(tmp, wavestr); } - if (fToggleGraph->isDown()) - setState("envelope", tmp); + if (isEnvelope) + fEnvUpdated = true; else - setState("waveform", tmp); + fWaveUpdated = true; } void ZamSynthUI::imageSwitchClicked(ImageSwitch* tog, bool down) @@ -253,6 +251,8 @@ bool ZamSynthUI::onMotion(const MotionEvent& ev) fDragValid = true; } + const bool isEnvelope = fToggleGraph->isDown(); + int x = ev.pos.getX(); int y = ev.pos.getY(); @@ -262,33 +262,35 @@ bool ZamSynthUI::onMotion(const MotionEvent& ev) if (y < 10) y = 10; float *gr; - if (!fToggleGraph->isDown()) { - gr = wave_y; - if (y > fCanvasArea.getHeight()+10) - y = fCanvasArea.getHeight()+10; + if (isEnvelope) { + gr = env_y; + if (y > fCanvasArea.getHeight() / 2. + 10) + y = fCanvasArea.getHeight() / 2. + 10; } else { - gr = env_y; - if (y > fCanvasArea.getHeight() / 2. + 10) - y = fCanvasArea.getHeight() / 2. + 10; + gr = wave_y; + if (y > fCanvasArea.getHeight()+10) + y = fCanvasArea.getHeight()+10; } if (gr[x-10] != (y-10)) { - char tmp[4*AREAHEIGHT+1] = {0}; - int i; - for(i = 0; i < AREAHEIGHT; i++) { - char wavestr[5] = {0}; - snprintf(wavestr, sizeof(wavestr), "%03d ", (int) (fCanvasArea.getHeight()-gr[i])); - strcat(tmp, wavestr); - } + char* tmp = isEnvelope ? fEnvState : fWaveState; + memset(tmp, 0, sizeof(fWaveState)); + + int i; + for(i = 0; i < AREAHEIGHT; i++) { + char wavestr[5] = {0}; + snprintf(wavestr, sizeof(wavestr), "%03d ", (int) (fCanvasArea.getHeight()-gr[i])); + strcat(tmp, wavestr); + } gr[x-10] = y-10; - if (gr == env_y) - setState("envelope",tmp); - else - setState("waveform",tmp); + if (isEnvelope) + fEnvUpdated = true; + else + fWaveUpdated = true; - repaint(); + repaint(); } return true; @@ -319,6 +321,22 @@ void ZamSynthUI::onDisplay() // reset color glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } + +void ZamSynthUI::uiIdle() +{ + if (fWaveUpdated) + { + fWaveUpdated = false; + setState("waveform", fWaveState); + } + + if (fEnvUpdated) + { + fEnvUpdated = false; + setState("envelope", fEnvState); + } +} + // ----------------------------------------------------------------------- UI* createUI() diff --git a/plugins/ZamSynth/ZamSynthUI.hpp b/plugins/ZamSynth/ZamSynthUI.hpp index 5c2368e..a881404 100644 --- a/plugins/ZamSynth/ZamSynthUI.hpp +++ b/plugins/ZamSynth/ZamSynthUI.hpp @@ -52,7 +52,6 @@ protected: // DSP Callbacks void parameterChanged(uint32_t index, float value) override; - void programLoaded(uint32_t index) override; void stateChanged(const char*, const char*) override; // ------------------------------------------------------------------- @@ -66,6 +65,7 @@ protected: void imageSwitchClicked(ImageSwitch* tog, bool down) override; void onDisplay() override; + void uiIdle() override; bool onMouse(const MouseEvent&) override; bool onMotion(const MotionEvent&) override; @@ -81,6 +81,12 @@ private: bool fDragging; bool fDragValid; DGL::Rectangle<int> fCanvasArea; + + bool fWaveUpdated; + char fWaveState[4*AREAHEIGHT+1]; + + bool fEnvUpdated; + char fEnvState[4*AREAHEIGHT+1]; }; // ----------------------------------------------------------------------- |