computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit 447c2b47fb649678292d87a3dc389f4e11ace06d
parent 445fbdcf9bb25cdd2408a49990041e54b64ba109
Author: Adam M <[email protected]>
Date:   Thu, 31 Dec 2020 21:16:51 -0600

sync works with constant frame delay

Diffstat:
Msrc/ComputerscareBlank.cpp | 14+++++++++++---
Msrc/animatedGif.hpp | 10+++++-----
2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/ComputerscareBlank.cpp b/src/ComputerscareBlank.cpp @@ -132,7 +132,9 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { if (clockTriggered) { syncTimer.reset(); setSyncTime(currentSyncTime); - goToFrame(0); + if(params[ANIMATION_ENABLED].getValue()) { + goToFrame(0); + } } } @@ -245,7 +247,13 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { imageStatus = status; } void setSyncTime(float syncDuration) { - speedFactor = totalGifDuration / syncDuration; + if (params[CONSTANT_FRAME_DELAY].getValue() == 0) { + speedFactor = totalGifDuration / syncDuration; + } + else { + speedFactor = numFrames * defaultFrameDelayCentiseconds / syncDuration / 100; + } + } void setFrameDelay(float frameDelaySeconds) { float speedKnob = abs(params[ANIMATION_SPEED].getValue()); @@ -261,7 +269,7 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { if (params[CONSTANT_FRAME_DELAY].getValue()) { - frameDelay = .04 / appliedSpeedDivisor; + frameDelay = defaultFrameDelayCentiseconds / appliedSpeedDivisor / 100; } else { frameDelay = base / appliedSpeedDivisor; diff --git a/src/animatedGif.hpp b/src/animatedGif.hpp @@ -15,6 +15,7 @@ credit goes to urraka for this code: https://gist.github.com/urraka/685d9a6340b26b830d49 */ +const int defaultFrameDelayCentiseconds = 4; typedef struct gif_result_t { int delay; @@ -29,7 +30,7 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra FILE *f; stbi__context s; unsigned char *result = 0; - int frameDelay = 4; + int frameDelay = defaultFrameDelayCentiseconds; if (!(f = stbi__fopen(filename, "rb"))) { imageStatus = 3; @@ -65,11 +66,10 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra if (g.delay) { gr->delay = g.delay; frameDelay = g.delay; - } else { - gr->delay = 4; - frameDelay = 4; + gr->delay = defaultFrameDelayCentiseconds; + frameDelay = defaultFrameDelayCentiseconds; } //printf("frame %i delay:%i\n", *frames, frameDelay); frameDelays.push_back(frameDelay); @@ -205,7 +205,7 @@ struct AnimatedGifBuddy { return imageStatus; } float getSecondsDelay(int frameNumber) { - float secondsDelay = 0.05; + float secondsDelay = defaultFrameDelayCentiseconds / 100; if (frameDelays.size()) { secondsDelay = ((float) frameDelays[frameNumber]) / 100; }