diff options
author | Damien Zammit <damien@zamaudio.com> | 2014-04-25 23:16:54 +1000 |
---|---|---|
committer | Damien Zammit <damien@zamaudio.com> | 2014-04-25 23:16:54 +1000 |
commit | 013c381724758e54650d3b6d5d2c7081f3a40c51 (patch) | |
tree | b971f5850984c1f2bc07a66120dcd86c3dc6d962 | |
parent | e812cb0b8fa8d7722798b029961467335211e0bb (diff) |
Only set state when values require to be changed
Signed-off-by: Damien Zammit <damien@zamaudio.com>
-rw-r--r-- | plugins/ZamSynth/ZamSynthUI.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/plugins/ZamSynth/ZamSynthUI.cpp b/plugins/ZamSynth/ZamSynthUI.cpp index 808b000..a65f5aa 100644 --- a/plugins/ZamSynth/ZamSynthUI.cpp +++ b/plugins/ZamSynth/ZamSynthUI.cpp @@ -118,6 +118,15 @@ void ZamSynthUI::imageButtonClicked(ImageButton* button, int) } gaussiansmooth(wavesmooth, xs, wave_y, AREAHEIGHT, 4); memcpy(wave_y, 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])); + strcat(tmp, wavestr); + } + + d_setState("waveform", tmp); } void ZamSynthUI::gaussiansmooth(float* smoothed, float* xs, float* ys, int n, int radius) @@ -179,17 +188,7 @@ bool ZamSynthUI::onMotion(int x, int y) if (x < 10) x = 10; if (y < 10) y = 10; - wave_y[x-10] = (y-10); - repaint(); - - return true; -} - - -void ZamSynthUI::onDisplay() -{ - fImgBackground.draw(); - + if (wave_y[x-10] != (y-10)) { char tmp[4*AREAHEIGHT+1] = {0}; int i; for(i = 0; i < AREAHEIGHT; i++) { @@ -198,7 +197,18 @@ void ZamSynthUI::onDisplay() strcat(tmp, wavestr); } - d_setState("waveform",tmp); + wave_y[x-10] = y-10; + d_setState("waveform",tmp); + repaint(); + } + + return true; +} + + +void ZamSynthUI::onDisplay() +{ + fImgBackground.draw(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -206,6 +216,7 @@ void ZamSynthUI::onDisplay() glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glLineWidth(2); + int i; glColor4f(0.235f, 1.f, 0.235f, 1.0f); for (i = 2; i < AREAHEIGHT; ++i) { glBegin(GL_LINES); |