computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit 9fa9dcdbd89cf8a0756364f06255abf8e9b676ce
parent ec495e7a38af194d746466a353e022a19f45ef94
Author: Adam M <[email protected]>
Date:   Wed, 28 Nov 2018 00:30:16 -0600

Tokens have index too

Diffstat:
Msrc/ComputerscareILoveCookies.cpp | 2+-
Msrc/dtpulse.cpp | 42+++++++++++++++---------------------------
Msrc/dtpulse.hpp | 1+
3 files changed, 17 insertions(+), 28 deletions(-)

diff --git a/src/ComputerscareILoveCookies.cpp b/src/ComputerscareILoveCookies.cpp @@ -480,7 +480,7 @@ void MyTextFieldCookie::onTextChange() { module->checkLength(this->rowIndex); std::string value = module->textFields[this->rowIndex]->text; if(matchParens(value)) { - whoKnows(module->textFields[this->rowIndex]->text); + whoKnows(value); printf("row: %i\n",this->rowIndex); module->setNextAbsoluteSequence(this->rowIndex); } diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp @@ -110,7 +110,7 @@ std::vector<int> parseLookup(std::string input, int offset, std::string lookup) int length = input.length(); absoluteSequence.resize(0); - for(unsigned int i = 0; i < length; i++) { + for(int i = 0; i < length; i++) { mappedIndex = (i + offset) % length; currentVal = lookup.find(input[mappedIndex]); absoluteSequence.push_back(currentVal); @@ -266,21 +266,21 @@ std::string hashExpand(std::string input, int hashnum) { std::string concatVectorFromLookup(std::vector<int> vector, std::string lookup) { std::string output=""; - for (int i = 0; i < vector.size(); i++){ + for (unsigned int i = 0; i < vector.size(); i++){ output+=lookup[vector[i]]; } return output; } void printFloatVector(std::vector<float> floatVector) { - for(int i = 0; i < floatVector.size(); i++) { + for(unsigned int i = 0; i < floatVector.size(); i++) { printf("floatVector[%i]: %f\n",i,floatVector[i]); } } void printTokenVector(std::vector<std::vector<Token>> tokenVector) { - for(int i = 0; i < tokenVector.size(); i++) { + for(unsigned int i = 0; i < tokenVector.size(); i++) { printf("tokenVector[%i]: ",i); - for(int j = 0; j < tokenVector[i].size(); j++) { - printf("%s ",tokenVector[i][j].value.c_str()); + for(unsigned int j = 0; j < tokenVector[i].size(); j++) { + printf("%i",tokenVector[i][j].index); } printf("\n"); @@ -333,13 +333,15 @@ AbsoluteSequence::AbsoluteSequence(std::string expr, std::string lookup) { Parser p = Parser(expr); exactFloats = p.exactFloats; randomTokens=p.randomVector; - + tokenStack = p.tokenStack; indexSequence = parseEntireString(expr,lookup,1); - } void AbsoluteSequence::print() { printFloatVector(exactFloats); printTokenVector(randomTokens); + for(int i = 0; i < tokenStack.size(); i++) { + tokenStack[i].print(); + } } Token::Token(std::string t, std::string v) { type = t; @@ -354,26 +356,11 @@ Parser::Parser(std::string expr) { currentIndex=0; tokens = tokenizeString(expr); expression=expr; - - - printf("\n\nafter setExpression:\n"); setExpression(tokens[0]); - for(int i = 0; i < tokenStack.size(); i++) { - tokenStack[i].print(); - } - currentIndex=0; tokens=tokenStack; tokenStack = {}; - printf("\n\nafter setForRandoms:\n"); setForRandoms(tokens[0]); - for(int i = 0; i < tokenStack.size(); i++) { - tokenStack[i].print(); - } - - - - printf("\n\n\n"); } void Parser::setExpression(Token t) { while (t.type!="NULL") { @@ -425,11 +412,11 @@ void Parser::ParseRandomSequence(Token t) { std::string num=""; while(t.type=="Letter" || t.type=="ExactValue") { if(t.type=="Letter") { - proposedRandomVector.push_back(Token("LetterIndex",std::to_string(knobandinputlookup.find(t.value)))); + proposedRandomVector.push_back(Token(t.type,t.value,knobandinputlookup.find(t.value))); t=skipAndPeekToken(); } if(t.type=="ExactValue") { - proposedRandomVector.push_back(Token("ExactValueIndex",std::to_string(t.index + 52))); + proposedRandomVector.push_back(Token("ExactValue",t.value,t.index + 52)); t=skipAndPeekToken(); } t=peekToken(); @@ -437,7 +424,8 @@ void Parser::ParseRandomSequence(Token t) { if(t.type=="RightCurly") { skipToken(); randomVector.push_back(proposedRandomVector); - tokenStack.push_back(Token("RandomSequence",std::to_string(randomVector.size()-1 + 52 + 26))); + int myIndex = myIndex + 52 + 26 + randomVector.size(); + tokenStack.push_back(Token("RandomSequence",std::to_string(myIndex),myIndex)); } else { printf("ERROR: no closing RightCurly. it was \"%s\" (%s)\n",t.value.c_str(),t.type.c_str()); @@ -495,7 +483,7 @@ std::string Parser::parseNumber(Token t) return number; } void Token::print() { - printf("type:%s, val:%s\n",type.c_str(),value.c_str()); + printf("type:%s, value:%s, index:%i\n",type.c_str(),value.c_str(),index); } std::vector<Token> tokenizeString(std::string input) { std::vector<Token> stack; diff --git a/src/dtpulse.hpp b/src/dtpulse.hpp @@ -54,6 +54,7 @@ class AbsoluteSequence { std::vector<float> exactFloats; std::vector<std::vector<int>> randomIndexes; std::vector<std::vector<Token>> randomTokens; + std::vector<Token> tokenStack; void print(); }; bool is_digits(const std::string &str);