computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit ae0f2b4cdb90a3195553d20df977a0ee6529b33e
parent 3037b2c6c643bb187868c8e11420e84ee43d7fdb
Author: Adam M <[email protected]>
Date:   Wed, 28 Nov 2018 23:04:30 -0600

parse-ish functionality for iterating through AbsoluteSequence

Diffstat:
Msrc/ComputerscareILoveCookies.cpp | 17+++++++++++++----
Msrc/dtpulse.cpp | 63++++++++++++++++++++++++++++++++++++++++++++++++---------------
Msrc/dtpulse.hpp | 9++++++++-
3 files changed, 69 insertions(+), 20 deletions(-)

diff --git a/src/ComputerscareILoveCookies.cpp b/src/ComputerscareILoveCookies.cpp @@ -168,9 +168,11 @@ struct ComputerscareILoveCookies : Module { std::vector<int> absoluteSequences[numFields]; std::vector<int> nextAbsoluteSequences[numFields]; std::vector<float> otherOutputValues = {2.02}; + + AbsoluteSequence newABS[numFields]; - bool shouldChange[numFields] = {false}; - bool changeImminent[numFields] = {false}; + bool shouldChange[numFields] = {true}; + bool changeImminent[numFields] = {true}; int absoluteStep[numFields] = {0}; int currentVal[numFields] = {0}; @@ -231,7 +233,7 @@ ComputerscareILoveCookies() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LI randchar = mainlookup[rand() % mainlookup.size()]; string = string + randchar; ru = randomUniform(); - if(ru < 0.2) { + if(ru < 0.1) { string = "(" + string + ")"; } } @@ -351,6 +353,7 @@ void onCreate () override float mapValue(float input, float offset, float multiplier) { return (input + offset) * multiplier; } + }; @@ -422,8 +425,14 @@ void ComputerscareILoveCookies::step() { knobRawValue = inputs[SIGNAL_INPUT + activeKnobIndex[i] - 26].value; outputs[TRG_OUTPUT + i].value = knobRawValue; } + else if(activeKnobIndex[i] < 78) { + outputs[TRG_OUTPUT + i].value = 1.11; + } + else if(activeKnobIndex[i] <104) { + outputs[TRG_OUTPUT + i].value = 2.22; + } else { - outputs[TRG_OUTPUT+i].value = otherOutputValues[activeKnobIndex[i]-52]; + outputs[TRG_OUTPUT+i].value = otherOutputValues[activeKnobIndex[i]-104]; } if(inputs[CLOCK_INPUT + i].active) { outputs[FIRST_STEP_OUTPUT + i].value = (currentTriggerIsHigh && atFirstStep) ? 10.f : 0.0f; diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp @@ -327,21 +327,61 @@ bool matchParens(std::string value) { void whoKnows(std::string input) { AbsoluteSequence abs = AbsoluteSequence(input,knobandinputlookup); abs.print(); + printf(" indexSequence:\n"); + printVector(abs.indexSequence); + printf(" workingIndexSequence:\n"); + printVector(abs.workingIndexSequence); + srand (time(NULL)); + for(int j = 0; j < 13; j++) { + //randomizeIndex(2); + abs.incrementAndCheck(); + printVector(abs.workingIndexSequence); + } } +AbsoluteSequence::AbsoluteSequence() { + AbsoluteSequence("",knobandinputlookup); +} AbsoluteSequence::AbsoluteSequence(std::string expr, std::string lookup) { Parser p = Parser(expr); exactFloats = p.exactFloats; randomTokens=p.randomVector; tokenStack = p.tokenStack; + readHead = 0; indexSequence = getIndicesFromTokenStack(tokenStack); workingIndexSequence = duplicateIntVector(indexSequence);; } void AbsoluteSequence::randomizeIndex(int index) { int randomTokenIndex = indexSequence[index] - 78; std::vector<int> myRandomTokens = getIndicesFromTokenStack(randomTokens[randomTokenIndex]); - workingIndexSequence[index] = myRandomTokens[rand() % (1+myRandomTokens.size())]; + int size = myRandomTokens.size(); + if(size) { + //random one from those enclosed by the {} + workingIndexSequence[index] = myRandomTokens[rand() % (myRandomTokens.size())]; + } + else { + //random address ie: a-z,A-Z + workingIndexSequence[index] = rand() % 52; + } +} +void AbsoluteSequence::skipStep() { + readHead++; + readHead %= indexSequence.size(); +} +int AbsoluteSequence::skipAndPeek() { + skipStep(); + return peekStep(); } +int AbsoluteSequence::peekStep() { + return indexSequence[readHead]; +} +void AbsoluteSequence::incrementAndCheck() { + //printf("readHead:%i, peek:%i\n",readHead,peekStep()); + if(skipAndPeek()>=78) { + randomizeIndex(readHead); + } +} + std::vector<int> getIndicesFromTokenStack(std::vector<Token> tokens) { std::vector<int> output; for(unsigned int i = 0; i < tokens.size(); i++) { @@ -364,15 +404,6 @@ void AbsoluteSequence::print() { for(int i = 0; i < tokenStack.size(); i++) { tokenStack[i].print(); } - printf(" indexSequence:\n"); - printVector(indexSequence); - printf(" workingIndexSequence:\n"); - printVector(workingIndexSequence); - srand (time(NULL)); - for(int j = 0; j < 3; j++) { - randomizeIndex(2); - printVector(workingIndexSequence); - } } Token::Token(std::string t, std::string v) { type = t; @@ -387,11 +418,13 @@ Parser::Parser(std::string expr) { currentIndex=0; tokens = tokenizeString(expr); expression=expr; - setExpression(tokens[0]); - currentIndex=0; - tokens=tokenStack; - tokenStack = {}; - setForRandoms(tokens[0]); + if(tokens.size() > 0) { + setExpression(tokens[0]); + currentIndex=0; + tokens=tokenStack; + tokenStack = {}; + setForRandoms(tokens[0]); + } } void Parser::setExpression(Token t) { while (t.type!="NULL") { diff --git a/src/dtpulse.hpp b/src/dtpulse.hpp @@ -51,7 +51,7 @@ class Parser { class AbsoluteSequence { public: AbsoluteSequence(std::string expr, std::string lookup); - + AbsoluteSequence(); void randomizeIndex(int index); std::vector<int> indexSequence; std::vector<int> workingIndexSequence; @@ -59,7 +59,14 @@ class AbsoluteSequence { std::vector<std::vector<int>> randomIndexes; std::vector<std::vector<Token>> randomTokens; std::vector<Token> tokenStack; + int readHead; void print(); + void skipStep(); + int peekStep(); + int skipAndPeek(); + void incrementAndCheck(); + int getReadHead(); + int getCurrentAddressAtReadHead(); }; bool is_digits(const std::string &str); void padTo(std::string &str, const size_t num, const char paddingChar );