computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit f3319cc196759b3ea7ded789df3f4660409ffadc
parent f54102d3e18152b5c99f89807da319e48720f63e
Author: Adam M <[email protected]>
Date:   Sat,  2 Jan 2021 12:31:47 -0600

Guards around attempting to animate non-gifs or while loading

Diffstat:
Msrc/ComputerscareBlank.cpp | 57+++++++++++++++++++++++++++++++++++----------------------
1 file changed, 35 insertions(+), 22 deletions(-)

diff --git a/src/ComputerscareBlank.cpp b/src/ComputerscareBlank.cpp @@ -40,6 +40,12 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { int samplesDelay = 10000; int speed = 100000; int imageStatus = 0; + /* + uninitialized: 0 + gif: 1 + not gif: 2 + error:3 + */ bool expanderConnected = false; @@ -110,7 +116,10 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { leftExpander.consumerMessage = leftMessages[1]; } void process(const ProcessArgs &args) override { - sampleCounter++; + if (imageStatus == 1) { + sampleCounter++; + } + samplesDelay = frameDelay * args.sampleRate; bool shouldAdvanceAnimation = false; @@ -224,9 +233,13 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { void loadRandomGif(int index = 0) { std::string dir = rack::string::directory(paths[index]); getContainingDirectory(); - int randomIndex = floor(random::uniform() * catalog.size()); - - setPath(dir + "/" + catalog[randomIndex]); + if (catalog.size()) { + int randomIndex = floor(random::uniform() * catalog.size()); + setPath(dir + "/" + catalog[randomIndex]); + } + else { + DEBUG("no gifs in this directory"); + } } @@ -339,9 +352,8 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { loadRandomGif(); } } - //setFrameDelay(frameDelays[currentFrame]); } - DEBUG("current:%i, samplesDelay:%i", currentFrame, samplesDelay); + //DEBUG("current:%i, samplesDelay:%i", currentFrame, samplesDelay); } void setCurrentFrameDelayFromTable() { if (ready) { @@ -349,26 +361,27 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { } } void nextFrame() { - currentFrame++; - currentFrame %= numFrames; - setCurrentFrameDelayFromTable(); + goToFrame(currentFrame + 1); + } void prevFrame() { - currentFrame--; - currentFrame += numFrames; - currentFrame %= numFrames; - setCurrentFrameDelayFromTable(); + goToFrame(currentFrame - 1); } void goToFrame(int frameNum) { - sampleCounter = 0; - currentFrame = frameNum; - currentFrame += numFrames; - currentFrame %= numFrames; - setCurrentFrameDelayFromTable(); + if (numFrames) { + sampleCounter = 0; + currentFrame = frameNum; + currentFrame += numFrames; + currentFrame %= numFrames; + setCurrentFrameDelayFromTable(); + } + else { + DEBUG("no frames lol"); + } } void goToRandomFrame() { - currentFrame = (int) std::floor(random::uniform() * numFrames); - setCurrentFrameDelayFromTable(); + int randFrame = (int) std::floor(random::uniform() * numFrames); + goToFrame(randFrame); } void scanToPosition(float scanVoltage) { /* 0v = frame 0 @@ -378,12 +391,12 @@ struct ComputerscareBlank : ComputerscareMenuParamModule { if (ready) { int frameNum; float vu = (scanVoltage) / 10.01f; - if(params[CONSTANT_FRAME_DELAY].getValue()) { + if (params[CONSTANT_FRAME_DELAY].getValue()) { frameNum = floor((vu) * numFrames); } else { //frameMapForScan - frameNum = frameMapForScan[floor(vu*frameMapForScan.size())]; + frameNum = frameMapForScan[floor(vu * frameMapForScan.size())]; } goToFrame(frameNum); }