computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit 7c0c93150cbd18fe9e9bb05800654f47db863f20
parent 691fcb6479e071e4c3e78a11bf8af950ee0f3092
Author: Adam M <aemalone@gmail.com>
Date:   Wed,  7 Nov 2018 23:26:18 -0600

added the other parse options to cookies, and the quantization

Diffstat:
Msrc/ComputerscareILoveCookies.cpp | 67++++++++++++++++++++++++++++++++++++++++++++++---------------------
Msrc/ComputerscareLaundrySoup.cpp | 9+++------
Msrc/dtpulse.cpp | 57++++++++++++++++++++++++++++++++++++++++++++++++---------
Msrc/dtpulse.hpp | 5++++-
4 files changed, 101 insertions(+), 37 deletions(-)

diff --git a/src/ComputerscareILoveCookies.cpp b/src/ComputerscareILoveCookies.cpp @@ -19,7 +19,8 @@ const std::vector<NVGcolor> outlineColorMap = {COLOR_COMPUTERSCARE_RED,COLOR_COM class MyTextFieldCookie : public LedDisplayTextField { public: - int fontSize = 18; + int fontSize = 15; + int rowIndex=0; MyTextFieldCookie() : LedDisplayTextField() {} void setModule(ComputerscareILoveCookies* _module) { module = _module; @@ -97,6 +98,9 @@ struct ComputerscareILoveCookies : Module { MyTextFieldCookie* textFields[numFields]; std::vector<int> absoluteSequences[numFields]; + std::vector<int> nextAbsoluteSequences[numFields]; + + bool shouldChange[numFields] = {false}; int absoluteStep[numFields] = {0}; int numSteps[numFields] = {0}; @@ -136,7 +140,7 @@ ComputerscareILoveCookies() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LI } void randomizeAllFields() { - std::string mainlookup =knoblookup; + std::string mainlookup = knoblookup; std::string string = ""; std::string randchar = ""; int length = 0; @@ -149,24 +153,33 @@ ComputerscareILoveCookies() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LI string = string + randchar; } textFields[i]->text = string; + setNextAbsoluteSequence(i); } - onCreate(); - } void parseFormula(std::string input, int index) { std::vector<int> absoluteSequence; - int currentVal; absoluteSequence.resize(0); - - for(unsigned int i = 0; i < input.length(); i++) { - currentVal = knoblookup.find(input[i]); - absoluteSequence.push_back(currentVal); - } - + absoluteSequence = parseStringAsValues(input,knoblookup); numSteps[index] = absoluteSequence.size(); absoluteSequences[index] = absoluteSequence; } + void setNextAbsoluteSequence(int index) { + shouldChange[index] = true; + nextAbsoluteSequences[index].resize(0); + nextAbsoluteSequences[index] = parseStringAsValues(textFields[index]->text,knoblookup); + } + void setAbsoluteSequenceFromQueue(int index) { + absoluteSequences[index].resize(0); + absoluteSequences[index] = nextAbsoluteSequences[index]; + numSteps[index] = nextAbsoluteSequences[index].size() > 0 ? nextAbsoluteSequences[index].size() : 1; + } + void checkIfShouldChange(int index) { + if(shouldChange[index]) { + setAbsoluteSequenceFromQueue(index); + shouldChange[index] = false; + } + } int getAbsoluteStep(int index) { return this->absoluteStep[index]; } @@ -176,9 +189,8 @@ ComputerscareILoveCookies() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LI void onCreate () override { for(int i = 0; i < numFields; i++) { - if(textFields[i]->text.size() > 0) { - parseFormula(textFields[i]->text,i); - } + setNextAbsoluteSequence(i); + checkIfShouldChange(i); resetOneOfThem(i); } } @@ -212,7 +224,7 @@ void ComputerscareILoveCookies::step() { bool globalGateIn = globalClockTrigger.isHigh(); bool activeStep = 0; - int activeKnob; + int activeKnob = 0;; bool atFirstStep = false; bool clocked = globalClockTrigger.process(inputs[GLOBAL_CLOCK_INPUT].value); bool currentTriggerIsHigh; @@ -243,8 +255,19 @@ void ComputerscareILoveCookies::step() { resetOneOfThem(i); } + atFirstStep = (this->absoluteStep[i] == 0); + + if((currentResetActive && currentResetTriggered) || (!currentResetActive && globalResetTriggered)) { + checkIfShouldChange(i); + resetOneOfThem(i); + } + else { + if(atFirstStep && !currentResetActive && !inputs[GLOBAL_RESET_INPUT].active) { + checkIfShouldChange(i); + } + } + activeKnob = absoluteSequences[i][this->absoluteStep[i]]; - //printf("%i, %f",i,activeKnob); atFirstStep = (this->absoluteStep[i] == 0); for(int k = 0; k < numKnobRows * numKnobColumns; k++) { @@ -253,7 +276,6 @@ void ComputerscareILoveCookies::step() { } if(inputs[CLOCK_INPUT + i].active) { outputs[TRG_OUTPUT + i].value = params[KNOB_PARAM + activeKnob].value; - outputs[FIRST_STEP_OUTPUT + i].value = (currentTriggerIsHigh && atFirstStep) ? 10.f : 0.0f; } else { @@ -339,16 +361,16 @@ struct SmallLetterDisplay : TransparentWidget { } }; void MyTextFieldCookie::onTextChange() { - module->onCreate(); + module->setNextAbsoluteSequence(this->rowIndex); } struct ComputerscareILoveCookiesWidget : ModuleWidget { double verticalSpacing = 18.4; int verticalStart = 80; - int index; - double knobPosX; - double knobPosY; + int index=0; + double knobPosX=0.0; + double knobPosY=0.0; double knobXStart = 2; double knobYStart = 16; double knobRowWidth = 13; @@ -407,6 +429,7 @@ struct ComputerscareILoveCookiesWidget : ModuleWidget { textField->box.size = mm2px(Vec(63, 7)); textField->multiline = false; textField->color = nvgRGB(0xC0, 0xE7, 0xDE); + textField->rowIndex = i; addChild(textField); module->textFields[i] = textField; @@ -414,6 +437,7 @@ struct ComputerscareILoveCookiesWidget : ModuleWidget { NumberDisplayWidget3cookie *display = new NumberDisplayWidget3cookie(); display->box.pos = mm2px(Vec(23,verticalStart - 9.2 +verticalSpacing*i)); display->box.size = Vec(50, 20); + display->outlineColor = outlineColorMap[i]; if(&module->numSteps[i]) { display->value = &module->absoluteStep[i]; @@ -423,6 +447,7 @@ struct ComputerscareILoveCookiesWidget : ModuleWidget { } addChild(display); } + module->onCreate(); } MyTextFieldCookie* textField; }; diff --git a/src/ComputerscareLaundrySoup.cpp b/src/ComputerscareLaundrySoup.cpp @@ -156,11 +156,9 @@ ComputerscareLaundrySoup() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIG } void setNextAbsoluteSequence(int index) { - //if(textFields[index]->text.size() > 0) { - shouldChange[index] = true; - nextAbsoluteSequences[index].resize(0); - nextAbsoluteSequences[index] = parseEntireString(textFields[index]->text,b64lookup); - //} + shouldChange[index] = true; + nextAbsoluteSequences[index].resize(0); + nextAbsoluteSequences[index] = parseStringAsTimes(textFields[index]->text,b64lookup); } void setAbsoluteSequenceFromQueue(int index) { absoluteSequences[index].resize(0); @@ -184,7 +182,6 @@ void onCreate () override void onReset () override { - onCreate(); } diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp @@ -6,13 +6,18 @@ bool is_digits(const std::string &str) { return str.find_first_not_of(integerlookup) == std::string::npos; } -std::vector<int> parseStringAsValues(std::string input, std::string lookup) { + +std::vector<int> parseStringAsTimes(std::string input, std::string lookup) { // "113" -> {1,1,3} - std::vector<int> absoluteSequence; - absoluteSequence.resize(0); - return absoluteSequence; + return parseEntireString(input,lookup,0); } -std::vector<int> parseEntireString(std::string input,std::string lookup) { + +std::vector<int> parseStringAsValues(std::string input, std::string lookup) { + // "113" -> {1,1,3} + return parseEntireString(input,lookup,1); +} + +std::vector<int> parseEntireString(std::string input,std::string lookup,int type) { // "113" -> {1,1,1,0,0} std::vector<int> absoluteSequence; absoluteSequence.resize(0); @@ -34,8 +39,8 @@ std::vector<int> parseEntireString(std::string input,std::string lookup) { std::string atlhs; std::string commalhs; - int atnum; - int offsetnum; + int atnum=-1; + int offsetnum=0; std::stringstream inputstream(input); std::stringstream atstream(input); @@ -50,7 +55,6 @@ std::vector<int> parseEntireString(std::string input,std::string lookup) { while(std::getline(atstream,atseg,'@')) { atVec.push_back(atseg); } - atnum = (atVec.size() > 1 && is_digits(atVec[1]) )? std::stoi(atVec[1]) : -1; if(atVec[0].empty() && atnum > 0) { for(int i = 0; i < atnum; i++) { @@ -76,7 +80,13 @@ std::vector<int> parseEntireString(std::string input,std::string lookup) { offsetnum = (offsetVec.size() > 1 && is_digits(offsetVec[1]))? std::stoi(offsetVec[1]) : 0; commaVec.resize(0); // below may be the only line that has to change for a by value parse - commaVec = parseDt(atExpand(offsetVec[0],atnum,lookup),offsetnum,lookup); + if(type==0) { + commaVec = parseDt(atExpand(offsetVec[0],atnum,lookup),offsetnum,lookup); + } + else { + commaVec = parseLookup(countExpand(offsetVec[0],atnum),offsetnum,lookup); + } + absoluteSequence.insert(absoluteSequence.end(),commaVec.begin(),commaVec.end()); } } @@ -84,6 +94,17 @@ std::vector<int> parseEntireString(std::string input,std::string lookup) { } return absoluteSequence; } +std::vector<int> parseLookup(std::string input, int offset, std::string lookup) { + std::vector<int> absoluteSequence; + int currentVal; + absoluteSequence.resize(0); + + for(unsigned int i = 0; i < input.length(); i++) { + currentVal = lookup.find(input[i]); + absoluteSequence.push_back(currentVal); + } + return absoluteSequence; +} std::vector<int> parseDt(std::string input, int offset, std::string lookup) { std::vector <int> absoluteSequence; @@ -138,6 +159,24 @@ std::string atExpand(std::string input, int atnum, std::string lookup) { return output; } +std::string countExpand(std::string input, int atnum) { + std::string output=""; + int length = input.length(); + int total = 0; + int index = 0; + int lookupVal; + if(atnum == -1) { + return input; + } + else if(atnum == 0) { + return ""; + } + for(index = 0; index < atnum; index++) { + output += input[index % length]; + } + return output; +} + std::string hashExpand(std::string input, int hashnum) { std::string output=""; int length = input.length(); diff --git a/src/dtpulse.hpp b/src/dtpulse.hpp @@ -7,8 +7,11 @@ bool is_digits(const std::string &str); std::vector <int> parseString(std::string expr); std::vector <int> parseDt(std::string input, int offset, std::string lookup); -std::vector<int> parseEntireString(std::string input,std::string lookup); +std::vector <int> parseLookup(std::string input, int offset, std::string lookup); +std::vector<int> parseEntireString(std::string input,std::string lookup, int type); std::vector<int> parseStringAsValues(std::string input,std::string lookup); +std::vector<int> parseStringAsTimes(std::string input,std::string lookup); void printVector(std::vector <int> intVector); std::string hashExpand(std::string input, int hashnum); std::string atExpand(std::string input, int atnum, std::string lookup); +std::string countExpand(std::string input, int atnum);