diff options
Diffstat (limited to 'plugins/ZamSynth/ZamSynthUI.cpp')
-rw-r--r-- | plugins/ZamSynth/ZamSynthUI.cpp | 103 |
1 files changed, 77 insertions, 26 deletions
diff --git a/plugins/ZamSynth/ZamSynthUI.cpp b/plugins/ZamSynth/ZamSynthUI.cpp index 47c7dcb..2afc28c 100644 --- a/plugins/ZamSynth/ZamSynthUI.cpp +++ b/plugins/ZamSynth/ZamSynthUI.cpp @@ -31,9 +31,15 @@ ZamSynthUI::ZamSynthUI() // knob Image knobImage(ZamSynthArtwork::knobData, ZamSynthArtwork::knobWidth, ZamSynthArtwork::knobHeight); + + // button Image smoothrImage(ZamSynthArtwork::smoothrData, ZamSynthArtwork::smoothrWidth, ZamSynthArtwork::smoothrHeight); Image smoothyImage(ZamSynthArtwork::smoothyData, ZamSynthArtwork::smoothyWidth, ZamSynthArtwork::smoothyHeight); + // toggle + Image toggleonImage(ZamSynthArtwork::toggleonData, ZamSynthArtwork::toggleonWidth, ZamSynthArtwork::toggleonHeight); + Image toggleoffImage(ZamSynthArtwork::toggleoffData, ZamSynthArtwork::toggleoffWidth, ZamSynthArtwork::toggleoffHeight); + // knob fKnobGain = new ImageKnob(this, knobImage); @@ -48,35 +54,56 @@ ZamSynthUI::ZamSynthUI() fButtonSmooth->setPos(265, 55); fButtonSmooth->setCallback(this); + // drawing area fCanvasArea.setPos(10,10); fCanvasArea.setSize(AREAHEIGHT,AREAHEIGHT); for (int i = 0; i < AREAHEIGHT; i++) { wave_y[i] = -(AREAHEIGHT*(sin(2.*i*M_PI/AREAHEIGHT)-1.0))/2.; + env_y[i] = -(2*AREAHEIGHT*(sin(2.*i*M_PI/AREAHEIGHT/2.)-1.0))/2.; } + + // toggle + fToggleGraph = new ImageToggle(this, toggleonImage, toggleoffImage, toggleoffImage); + fToggleGraph->setPos(290, 85); + fToggleGraph->setCallback(this); + + fGraph = false; } ZamSynthUI::~ZamSynthUI() { delete fKnobGain; delete fButtonSmooth; + delete fToggleGraph; } void ZamSynthUI::d_stateChanged(const char* key, const char* value) { - if (strcmp(key, "waveform") != 0) return; - - char* tmp; - char* saveptr; - int i = 0; - char tmpbuf[4*AREAHEIGHT+1] = {0}; - snprintf(tmpbuf, 4*AREAHEIGHT, "%s", value); - tmp = strtok(tmpbuf, " "); - while ((tmp != NULL) && (i < AREAHEIGHT)) { - wave_y[i] = AREAHEIGHT-((float)atoi(tmp)); - i++; - //printf("reload dsp wave_y[%d]=%.2f ", i, wave_y[i]); - tmp = strtok(NULL, " "); - } + if (strcmp(key, "waveform") == 0) { + char* tmp; + int i = 0; + char tmpbuf[4*AREAHEIGHT+1] = {0}; + snprintf(tmpbuf, 4*AREAHEIGHT, "%s", value); + tmp = strtok(tmpbuf, " "); + while ((tmp != NULL) && (i < AREAHEIGHT)) { + wave_y[i] = AREAHEIGHT-((float)atoi(tmp)); + i++; + //printf("reload dsp wave_y[%d]=%.2f ", i, wave_y[i]); + tmp = strtok(NULL, " "); + } + } else if (strcmp(key, "envelope") == 0) { + char* tmp; + int i = 0; + char tmpbuf[4*AREAHEIGHT+1] = {0}; + snprintf(tmpbuf, 4*AREAHEIGHT, "%s", value); + tmp = strtok(tmpbuf, " "); + while ((tmp != NULL) && (i < AREAHEIGHT)) { + env_y[i] = AREAHEIGHT-((float)atoi(tmp)); + i++; + //printf("reload dsp env_y[%d]=%.2f ", i, env_y[i]); + tmp = strtok(NULL, " "); + } + } } // ----------------------------------------------------------------------- @@ -121,7 +148,7 @@ void ZamSynthUI::imageKnobValueChanged(ImageKnob* knob, float value) d_setParameterValue(ZamSynthPlugin::paramGain, value); } -void ZamSynthUI::imageButtonClicked(ImageButton* button, int) +void ZamSynthUI::imageButtonClicked(ImageButton*, int) { float wavesmooth[AREAHEIGHT]; float xs[AREAHEIGHT]; @@ -129,17 +156,29 @@ void ZamSynthUI::imageButtonClicked(ImageButton* button, int) for (i = 0; i < AREAHEIGHT; i++) { xs[i] = i; } - gaussiansmooth(wavesmooth, xs, wave_y, AREAHEIGHT, 4); - memcpy(wave_y, wavesmooth, AREAHEIGHT*sizeof(float)); + + float *gr; + gr = (fGraph) ? env_y : wave_y; + + gaussiansmooth(wavesmooth, xs, gr, AREAHEIGHT, 4); + memcpy(gr, wavesmooth, AREAHEIGHT*sizeof(float)); char tmp[4*AREAHEIGHT+1] = {0}; for(i = 0; i < AREAHEIGHT; i++) { char wavestr[5] = {0}; - snprintf(wavestr, sizeof(wavestr), "%03d ", (int) (fCanvasArea.getHeight()-wave_y[i])); + snprintf(wavestr, sizeof(wavestr), "%03d ", (int) (fCanvasArea.getHeight()-gr[i])); strcat(tmp, wavestr); } - d_setState("waveform", tmp); + if (fGraph) + d_setState("envelope", tmp); + else + d_setState("waveform", tmp); +} + +void ZamSynthUI::imageToggleClicked(ImageToggle*, int) +{ + fGraph = !fGraph; } void ZamSynthUI::gaussiansmooth(float* smoothed, float* xs, float* ys, int n, int radius) @@ -201,18 +240,27 @@ bool ZamSynthUI::onMotion(int x, int y) if (x < 10) x = 10; if (y < 10) y = 10; - if (wave_y[x-10] != (y-10)) { + float *gr; + + gr = (fGraph) ? env_y : wave_y; + + 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()-wave_y[i])); + snprintf(wavestr, sizeof(wavestr), "%03d ", (int) (fCanvasArea.getHeight()-gr[i])); strcat(tmp, wavestr); } - wave_y[x-10] = y-10; - d_setState("waveform",tmp); - repaint(); + gr[x-10] = y-10; + + if (gr == env_y) + d_setState("envelope",tmp); + else + d_setState("waveform",tmp); + + repaint(); } return true; @@ -229,12 +277,15 @@ void ZamSynthUI::onDisplay() glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glLineWidth(2); + float *gr; + gr = (fGraph) ? env_y : wave_y; + int i; glColor4f(0.235f, 1.f, 0.235f, 1.0f); for (i = 2; i < AREAHEIGHT; ++i) { glBegin(GL_LINES); - glVertex2i(i-1+fCanvasArea.getX(), wave_y[i-1]+fCanvasArea.getY()); - glVertex2i(i+fCanvasArea.getX(), wave_y[i]+fCanvasArea.getY()); + glVertex2i(i-1+fCanvasArea.getX(), gr[i-1]+fCanvasArea.getY()); + glVertex2i(i+fCanvasArea.getX(), gr[i]+fCanvasArea.getY()); glEnd(); } // reset color |