computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit 6fce28134780a79f2690c8158c6cff05deddfb26
parent b4adc2c430c5ece1cdaac6dfc6b99f2a235339b3
Author: Adam M <[email protected]>
Date:   Sat, 16 Jan 2021 08:49:39 -0600

pause animation while zooming

Diffstat:
Msrc/ComputerscareBlank.cpp | 27++++++++++++++++++++++-----
Msrc/animatedGif.hpp | 4++--
2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/src/ComputerscareBlank.cpp b/src/ComputerscareBlank.cpp @@ -11,6 +11,7 @@ #include <dirent.h> #include <algorithm> #include <random> +#include <settings.hpp> #define FONT_SIZE 13 @@ -60,6 +61,11 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { bool tick = false; float lastShuffle = 2.f; + float lastZoom = -100; + int zoomCheckInterval = 5000; + int zoomCheckCounter = 0; + bool pauseAnimation = true; + /* uninitialized: 0 gif: 1 @@ -139,6 +145,17 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { void process(const ProcessArgs &args) override { if (imageStatus == 1) { sampleCounter++; + zoomCheckCounter++; + if (zoomCheckCounter > zoomCheckInterval) { + if (settings::zoom != lastZoom) { + pauseAnimation = true; + } + else { + pauseAnimation = false; + } + lastZoom = settings::zoom; + zoomCheckCounter = 0; + } } samplesDelay = frameDelay * args.sampleRate; @@ -258,7 +275,6 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { rep = opendir(dir.c_str()); - int i = 0; catalog.clear(); //fichier.clear(); while ((dirp = readdir(rep)) != NULL) { @@ -454,6 +470,7 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { //DEBUG("current:%i, samplesDelay:%i", currentFrame, samplesDelay); } + } void setCurrentFrameDelayFromTable() { if (ready) { @@ -479,7 +496,7 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { currentFrame += numFrames; currentFrame %= numFrames; setCurrentFrameDelayFromTable(); - DEBUG("currentFrame:%i, mappedFrame:%i, scrubFrame:%i", currentFrame, mappedFrame, scrubFrame); + //DEBUG("currentFrame:%i, mappedFrame:%i, scrubFrame:%i", currentFrame, mappedFrame, scrubFrame); } } void goToRandomFrame() { @@ -753,9 +770,9 @@ struct PNGDisplay : TransparentWidget { nvgFill(args.vg); nvgClosePath(args.vg); } - //if (blankModule->currentFrame != currentFrame) { - gifBuddy.displayGifFrame(args.vg, currentFrame); - //} + if (!blankModule->pauseAnimation) { + gifBuddy.displayGifFrame(args.vg, currentFrame); + } } } void step() override { diff --git a/src/animatedGif.hpp b/src/animatedGif.hpp @@ -165,7 +165,7 @@ struct AnimatedGifBuddy { return imageHandle; } int animatedGifCreateImage(NVGcontext* ctx, const char* filename, int imageFlags) { - int w, h, n, image; + int w, h, image; unsigned char* img; int frame = 0; stbi_set_unpremultiply_on_load(1); @@ -231,7 +231,7 @@ struct AnimatedGifBuddy { //2* total duration - frame0 - frameN-1 totalPingPongDurations.resize(0); - for (unsigned int i = 0; i < numFrames; i++) { + for (int i = 0; i < numFrames; i++) { float endpointDurations = frameDelaysSeconds[i] + frameDelaysSeconds[(i - 1 + numFrames) % numFrames]; totalPingPongDurations.push_back(2 * totalGifDuration - endpointDurations); }