computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit 3056ea7607f965b2f2e4acd2ebec2744aecde94a
parent 291956f3be8bec68e11af45d6300941c3bb3d146
Author: Adam M <aemalone@gmail.com>
Date:   Fri, 25 Dec 2020 17:38:41 -0600

Remove vestigial path member, show bad-gif animation if gif aint good

Diffstat:
Mres/ComputerscareGolyPeneratorPanel.svg | 17+++++++++--------
Ares/bad-gif.gif | 0
Msrc/ComputerscareBlank.cpp | 18+++++++++++++-----
Msrc/animatedGif.hpp | 33++++++++++++++++++++-------------
4 files changed, 42 insertions(+), 26 deletions(-)

diff --git a/res/ComputerscareGolyPeneratorPanel.svg b/res/ComputerscareGolyPeneratorPanel.svg @@ -24,11 +24,11 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="2.8284273" - inkscape:cx="21.143622" - inkscape:cy="101.4454" + inkscape:zoom="11.313709" + inkscape:cx="34.04832" + inkscape:cy="278.57564" inkscape:document-units="mm" - inkscape:current-layer="g1669" + inkscape:current-layer="text1023" showgrid="false" units="px" inkscape:snap-bbox="true" @@ -381,8 +381,8 @@ id="text1023" style="font-style:normal;font-weight:normal;font-size:2.98674px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.074669"> <path - d="m 11.774808,217.08568 q 0,0.2507 -0.19728,0.41128 -0.195726,0.16058 -0.535917,0.16058 -0.19262,0 -0.354172,-0.0475 -0.159998,-0.0492 -0.268735,-0.10651 v -0.34573 h 0.01553 q 0.138251,0.10977 0.30757,0.17532 0.169318,0.0639 0.324657,0.0639 0.192619,0 0.301356,-0.0655 0.108737,-0.0655 0.108737,-0.20646 0,-0.10808 -0.05903,-0.16386 -0.05903,-0.0557 -0.226794,-0.095 -0.06213,-0.0147 -0.163106,-0.0344 -0.09942,-0.0197 -0.181746,-0.0426 -0.228348,-0.0639 -0.324656,-0.18679 -0.09476,-0.12454 -0.09476,-0.30478 0,-0.11305 0.04349,-0.213 0.04504,-0.1 0.135145,-0.17862 0.08699,-0.077 0.22058,-0.12125 0.135144,-0.0458 0.301357,-0.0458 0.155337,0 0.313783,0.041 0.159998,0.0393 0.265628,0.0966 v 0.32935 h -0.01553 q -0.111844,-0.0868 -0.271842,-0.14582 -0.159999,-0.0607 -0.313784,-0.0607 -0.159999,0 -0.270289,0.0655 -0.11029,0.0639 -0.11029,0.1917 0,0.11306 0.0668,0.17041 0.06524,0.0574 0.21126,0.0934 0.08077,0.0197 0.180192,0.0393 0.100966,0.0197 0.167766,0.0361 0.203493,0.0491 0.313783,0.16877 0.110291,0.12125 0.110291,0.32115 z" - style="stroke-width:0.0816852" + d="m 10.367148,217.19757 q 0,0.2507 0.21228,0.41128 0.210608,0.16058 0.576666,0.16058 0.207266,0 0.381102,-0.0475 0.172163,-0.0492 0.289168,-0.10651 v -0.34573 h -0.01671 q -0.148763,0.10977 -0.330956,0.17532 -0.182192,0.0639 -0.349342,0.0639 -0.207265,0 -0.32427,-0.0655 -0.117005,-0.0655 -0.117005,-0.20646 0,-0.10808 0.06352,-0.16386 0.06352,-0.0557 0.244038,-0.095 0.06685,-0.0147 0.175508,-0.0344 0.10698,-0.0197 0.195565,-0.0426 0.245711,-0.0639 0.349342,-0.18679 0.101965,-0.12454 0.101965,-0.30478 0,-0.11305 -0.0468,-0.213 -0.04846,-0.1 -0.14542,-0.17862 -0.09361,-0.077 -0.237353,-0.12125 -0.145419,-0.0458 -0.324271,-0.0458 -0.167148,0 -0.337641,0.041 -0.172164,0.0393 -0.285825,0.0966 v 0.32935 h 0.01671 q 0.120348,-0.0868 0.292511,-0.14582 0.172165,-0.0607 0.337643,-0.0607 0.172165,0 0.290841,0.0655 0.118676,0.0639 0.118676,0.1917 0,0.11306 -0.07188,0.17041 -0.0702,0.0574 -0.227324,0.0934 -0.08691,0.0197 -0.193893,0.0393 -0.108643,0.0197 -0.180522,0.0361 -0.218966,0.0491 -0.337642,0.16877 -0.118677,0.12125 -0.118677,0.32115 z" + style="stroke-width:0.0847338" id="path1059" /> <path d="m 13.216187,217.5418 q -0.143483,0.0598 -0.2709,0.0911 -0.125965,0.0314 -0.264219,0.0257 -0.176092,-0.007 -0.317881,-0.0642 -0.141636,-0.0585 -0.23572,-0.16757 -0.09554,-0.10918 -0.137404,-0.27166 -0.04186,-0.16249 -0.02002,-0.37642 0.04072,-0.39875 0.282192,-0.61677 0.242932,-0.21794 0.602392,-0.2031 0.139708,0.006 0.269582,0.0506 0.131329,0.0449 0.23759,0.10632 l -0.03106,0.30416 -0.01455,-6.1e-4 q -0.115201,-0.10266 -0.243738,-0.1606 -0.127083,-0.0579 -0.253695,-0.0631 -0.232848,-0.01 -0.38424,0.14197 -0.149788,0.15019 -0.180696,0.45289 -0.03002,0.29397 0.08476,0.45802 0.116384,0.16263 0.355054,0.17249 0.08296,0.003 0.171047,-0.0149 0.08809,-0.0183 0.16006,-0.0504 0.06278,-0.0281 0.118599,-0.0594 0.05596,-0.0328 0.08905,-0.0563 l 0.01455,6e-4 z" @@ -393,9 +393,10 @@ style="stroke-width:0.074669" id="path1063" /> <path - d="m 15.71696,217.61816 h -0.523015 v -2.26922 h 0.523015 z" + d="m 15.71696,217.61816 h -0.523015 v -2.26922 l 0.288405,0.0746 z" style="stroke-width:0.10313" - id="path1065" /> + id="path1065" + sodipodi:nodetypes="ccccc" /> <path d="m 17.625965,216.73055 h -1.200238 q 0,0.16874 0.04521,0.29486 0.04521,0.1245 0.123962,0.20477 0.07583,0.0786 0.179379,0.11794 0.105003,0.0393 0.230423,0.0393 0.166254,0 0.333966,-0.0737 0.169171,-0.0754 0.240631,-0.14743 h 0.01458 v 0.3358 q -0.138545,0.0655 -0.282924,0.10974 -0.144378,0.0443 -0.303341,0.0443 -0.405426,0 -0.632932,-0.24571 -0.227505,-0.24736 -0.227505,-0.70111 0,-0.44883 0.217297,-0.71257 0.218755,-0.26372 0.574597,-0.26372 0.329591,0 0.507512,0.21622 0.17938,0.21624 0.17938,0.61429 z m -0.266882,-0.23588 q -0.0015,-0.24243 -0.109377,-0.37512 -0.106461,-0.13269 -0.325217,-0.13269 -0.220213,0 -0.351467,0.1458 -0.129795,0.14578 -0.147295,0.36201 z" style="stroke-width:0.0791362" diff --git a/res/bad-gif.gif b/res/bad-gif.gif Binary files differ. diff --git a/src/ComputerscareBlank.cpp b/src/ComputerscareBlank.cpp @@ -13,7 +13,6 @@ struct ComputerscareBlank : Module { bool loading = true; bool loadedJSON = false; std::string path; - std::string lastPath; std::vector<std::string> paths; float width = 120; @@ -31,6 +30,7 @@ struct ComputerscareBlank : Module { float frameDelay = .5; int samplesDelay = 10000; int speed = 100000; + int imageStatus=0; ComputerscareSVGPanel* panelRef; enum ParamIds { @@ -103,6 +103,9 @@ struct ComputerscareBlank : Module { DEBUG("setting frame count %i", frameCount); numFrames = frameCount; } + void setImageStatus(int status) { + imageStatus=status; + } void setFrameDelay(float frameDelaySeconds) { frameDelay = frameDelaySeconds; } @@ -134,9 +137,7 @@ struct ComputerscareBlank : Module { json_t *pathJ = json_object_get(rootJ, "path"); if (pathJ) { - //paths.push_back(path) - path = json_string_value(pathJ); - setPath(path); + setPath(json_string_value(pathJ)); } json_t *widthJ = json_object_get(rootJ, "width"); @@ -247,10 +248,17 @@ struct PNGDisplay : TransparentWidget { DEBUG("path not module path"); DEBUG("path: %s, modulePath:%s",path.c_str(),modulePath.c_str()); gifBuddy = AnimatedGifBuddy(args.vg, modulePath.c_str()); + if(gifBuddy.getImageStatus() == 3) { + std::string badGifPath = asset::plugin(pluginInstance, "res/bad-gif.gif"); + gifBuddy = AnimatedGifBuddy(args.vg, badGifPath.c_str()); + } img = gifBuddy.getHandle(); blankModule->setFrameCount(gifBuddy.getFrameCount()); blankModule->setFrameDelay(gifBuddy.getSecondsDelay(0)); + blankModule->setImageStatus(gifBuddy.getImageStatus()); + + nvgImageSize(args.vg, img, &imgWidth, &imgHeight); imgRatio = ((float)imgWidth / (float)imgHeight); @@ -347,7 +355,7 @@ struct ComputerscareBlankWidget : ModuleWidget { menu->addChild(loadImageItem); menu->addChild(construct<MenuLabel>(&MenuLabel::text, "Current Image Path:")); - menu->addChild(construct<MenuLabel>(&MenuLabel::text, blank->path)); + menu->addChild(construct<MenuLabel>(&MenuLabel::text, blank->getPath())); menu->addChild(construct<MenuLabel>(&MenuLabel::text, "")); diff --git a/src/animatedGif.hpp b/src/animatedGif.hpp @@ -24,15 +24,17 @@ typedef struct gif_result_t { -STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *frames, std::vector<unsigned char*> &framePointers, std::vector<int> &frameDelays,bool &isGif) +STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *frames, std::vector<unsigned char*> &framePointers, std::vector<int> &frameDelays, int &imageStatus) { FILE *f; stbi__context s; unsigned char *result = 0; int frameDelay = 4; - if (!(f = stbi__fopen(filename, "rb"))) + if (!(f = stbi__fopen(filename, "rb"))) { + imageStatus = 3; return stbi__errpuc("can't fopen", "Unable to open file"); + } stbi__start_file(&s, f); @@ -63,13 +65,13 @@ 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; } - printf("frame %i delay:%i\n",*frames,frameDelay); + //printf("frame %i delay:%i\n", *frames, frameDelay); frameDelays.push_back(frameDelay); prev = gr; gr = (gif_result*) stbi__malloc(sizeof(gif_result)); @@ -118,19 +120,19 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra if (prev != &head) STBI_FREE(prev); } } - printf("framePointers.size() %i\n",framePointers.size()); + printf("framePointers.size() %i\n", framePointers.size()); if (framePointers.size()) { printf("first frame address p:%i\n", framePointers[0]); printf("second frame address p:%i\n", framePointers[1]); } - isGif = true; + imageStatus = 1; } else { printf("NOT A GIF\n"); result = stbi__load_main(&s, x, y, frames, 4); *frames = !!result; - isGif = false; + imageStatus = 2; } fclose(f); @@ -148,7 +150,7 @@ struct AnimatedGifBuddy { bool initialized = false; int numFrames = -1; int frameDelay = 0; - bool isGif = false; + int imageStatus = 0; AnimatedGifBuddy() { } @@ -168,8 +170,8 @@ struct AnimatedGifBuddy { framePointers = {}; frameDelays = {}; - printf("framePointers.size BEFORE %i\n",framePointers.size()); - img = stbi_xload(filename, &w, &h, &frame, framePointers, frameDelays, isGif); + printf("framePointers.size BEFORE %i\n", framePointers.size()); + img = stbi_xload(filename, &w, &h, &frame, framePointers, frameDelays, imageStatus); printf(filename); printf("\nframe delay:%i\n", frameDelay); printf("loaded %i frames\n", framePointers.size()); @@ -177,6 +179,8 @@ struct AnimatedGifBuddy { //printVector(framePointers); if (img == NULL) { printf("Failed to load %s - %s\n", filename, stbi_failure_reason()); + imageStatus = 3; + printf("image status:%i\n", imageStatus); return 0; } image = nvgCreateImageRGBA(ctx, w, h, imageFlags, img); @@ -185,7 +189,7 @@ struct AnimatedGifBuddy { return image; } void displayGifFrame(NVGcontext* ctx, int frameNumber) { - if (initialized && frameNumber < numFrames && (isGif && numFrames > 0)) { + if (initialized && frameNumber < numFrames && (imageStatus == 1 && numFrames > 0)) { const unsigned char* dataAtFrame = framePointers[frameNumber]; nvgUpdateImage(ctx, imageHandle, dataAtFrame); } @@ -193,9 +197,12 @@ struct AnimatedGifBuddy { int getFrameCount() { return numFrames; } + int getImageStatus() { + return imageStatus; + } float getSecondsDelay(int frameNumber) { - float secondsDelay=0.05; - if(frameDelays.size()) { + float secondsDelay = 0.05; + if (frameDelays.size()) { secondsDelay = ((float) frameDelays[frameNumber]) / 100; } return secondsDelay;