computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit 3c55da2eaaae2a9d0e4e56a723b346148bb5678c
parent d9f2fcd21eda66d4b440ede182c4b78327e731ab
Author: Adam M <[email protected]>
Date:   Fri, 21 Dec 2018 13:02:08 -0600

Fix the dangling parens problem

Diffstat:
MREADME.MD | 2+-
Msrc/ComputerscareILoveCookies.cpp | 48+++---------------------------------------------
Msrc/dtpulse.cpp | 40+++++++++++++++++++++++++---------------
3 files changed, 29 insertions(+), 61 deletions(-)

diff --git a/README.MD b/README.MD @@ -18,7 +18,7 @@ YLX LY5 2X5 Y2L 2LY X25 YLX YLL # I Love Cookies Signal & CV Sequencer. Uses Text as input. Because after all, don't we all love cookies? -Knobs are labeled with lowercase letters: a-z. Inputs are labeled with uppercase letters A-Z. Programming in the sequence: ~abcd~ will sequentially output the values of knobs a, b, c, and finally d. It will then loop back to step 0: knob a again. An exact voltage can be programmed by enclosing the value in square brackets. For example: ~<4.20>~. Surrounding +Knobs are labeled with lowercase letters: a-z. Inputs are labeled with uppercase letters A-Z. Programming in the sequence: ~abcd~ will sequentially output the values of knobs a, b, c, and finally d. It will then loop back to step 0: knob a again. An exact voltage can be programmed by enclosing the value in square brackets. For example: `<4.20>`. Surrounding All of the following are valid ILC programs: ~~~~ diff --git a/src/ComputerscareILoveCookies.cpp b/src/ComputerscareILoveCookies.cpp @@ -46,14 +46,14 @@ struct SmallLetterDisplay : TransparentWidget { if(doubleblink) { nvgBeginPath(vg); - nvgRoundedRect(vg, -1.0, -1.0, box.size.x-3, box.size.y-3, 8.0); + nvgRoundedRect(vg, 1.0, -1.0, box.size.x-3, box.size.y-3, 8.0); nvgFillColor(vg, doubleblinkColor); nvgFill(vg); } else { if(blink) { nvgBeginPath(vg); - nvgRoundedRect(vg, -1.0, -1.0, box.size.x-3, box.size.y-3, 8.0); + nvgRoundedRect(vg, 1.0, -1.0, box.size.x-3, box.size.y-3, 8.0); nvgFillColor(vg, backgroundColor); nvgFill(vg); } @@ -284,7 +284,7 @@ void onCreate () override this->smallLetterDisplays[i]->doubleblink = value; } std::string getDisplayString(int index) { - std::string lhs = std::to_string(this->newABS[index].readHead); + std::string lhs = std::to_string(this->newABS[index].readHead + 1); std::string rhs = std::to_string(this->newABS[index].numTokens); std::string thisVal = this->newABS[index].getWorkingStepDisplay(); @@ -416,48 +416,6 @@ void ComputerscareILoveCookies::step() { } } -///////////////////////////////////////////////// -struct NumberDisplayWidget3cookie : TransparentWidget { - - int *value; - std::shared_ptr<Font> font; - NVGcolor outlineColor; - //NVGcolor circleColor; - - NumberDisplayWidget3cookie() { - font = Font::load(assetPlugin(plugin, "res/digital-7.ttf")); - }; - - void draw(NVGcontext *vg) override - { - // Background - NVGcolor backgroundColor = nvgRGB(0x00, 0x00, 0x00); - - nvgBeginPath(vg); - nvgRoundedRect(vg, -2, -4, box.size.x+4, box.size.y+8, 4.0); - nvgFillColor(vg, outlineColor); - nvgFill(vg); - - nvgBeginPath(vg); - nvgRoundedRect(vg, 0.0, 0.0, box.size.x, box.size.y, 8.0); - nvgFillColor(vg, backgroundColor); - nvgFill(vg); - - // text - nvgFontSize(vg, 13); - nvgFontFaceId(vg, font->handle); - nvgTextLetterSpacing(vg, 2.5); - - std::stringstream to_display; - to_display << std::setw(3) << *value; - - Vec textPos = Vec(6.0f, 17.0f); - NVGcolor textColor = nvgRGB(0xC0, 0xE7, 0xDE); - nvgFillColor(vg, textColor); - nvgText(vg, textPos.x, textPos.y, to_display.str().c_str(), NULL); - } -}; - void MyTextFieldCookie::onTextChange() { module->checkLength(this->rowIndex); std::string value = module->textFields[this->rowIndex]->text; diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp @@ -434,7 +434,7 @@ void AbsoluteSequence::incrementAndCheck() { std::string AbsoluteSequence::getWorkingStepDisplay() { int stepIndex = peekWorkingStep(); if(stepIndex < 0) { - return "error"; + return "?"; } else if(stepIndex < 52) { std::string str(1,knobandinputlookup[stepIndex]); @@ -651,23 +651,32 @@ void Parser::ParseInterleave(Token t) { std::vector<Token> tempStack; std::vector<Token> output; stackVec.push_back({}); + int parenCount = 0; while(t.type=="Letter"||t.type=="ExactValue"||t.type=="RandomSequence"||t.type=="LeftParen"||t.type=="RightParen") { if(t.type=="LeftParen") { stackVec.push_back({}); + parenCount++; } else if(t.type=="RightParen") { //evaluate top of stack - tempStack = interleaveExpand(stackVec.back()); - printTokenVector(tempStack); - //pop top of stack - stackVec.pop_back(); - if(stackVec.size() > 0) { - //push this evaluated vector<Token> to new top - stackVec.back().push_back(tempStack); - } - else { - inError=true; - } + + if(parenCount > 0) { + parenCount--; + tempStack = interleaveExpand(stackVec.back()); + printTokenVector(tempStack); + //pop top of stack + stackVec.pop_back(); + if(stackVec.size() > 0) { + //push this evaluated vector<Token> to new top + stackVec.back().push_back(tempStack); + } + else { + inError=true; + } + } + else { + inError=true; + } } //Letter, ExactValue, or RandomSequence else { @@ -675,9 +684,10 @@ void Parser::ParseInterleave(Token t) { } t=skipAndPeekToken(); } - - output = interleaveExpand(stackVec.back()); - tokenStack.insert(tokenStack.end(),output.begin(),output.end()); + if(parenCount == 0) { + output = interleaveExpand(stackVec.back()); + tokenStack.insert(tokenStack.end(),output.begin(),output.end()); + } } void Parser::ParseAtExpand(Token t) { // for letter,{},<> followed by an optional "@" and an integer