computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit a9925352ad075125618cf00c4d127e3ae68699d7
parent a68304c4ee41eda98eb45953980828e03e814025
Author: Adam Malone <[email protected]>
Date:   Mon,  5 Aug 2019 14:55:11 -0500

LaundryPoly class to hold 16 LaundrySoupSequences

Diffstat:
Msrc/dtpulse.cpp | 40+++++++++++++++++++++++++++++++++++++---
Msrc/dtpulse.hpp | 18++++++------------
Msrc/test.cpp | 7+++++--
3 files changed, 48 insertions(+), 17 deletions(-)

diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp @@ -382,15 +382,34 @@ void whoKnows(std::string input) { printVector(abs.workingIndexSequence); }*/ } +void whoKnowsLaundryPoly(std::string input) { + LaundryPoly lp = LaundryPoly(input); + lp.print(); +} + LaundryPoly::LaundryPoly(std::string formula) { + std::string newFormula = ""; + for(int i = 0; i < 16; i++ ) { + newFormula = formula; + replaceAll(newFormula,"#","<"+std::to_string(static_cast<long long>(i+1))+">"); + lss[i] = LaundrySoupSequence(newFormula); + } + } + void LaundryPoly::print() { + for(int i = 0; i < 16; i++) { + printf("channel %i:",i+1); + lss[i].print(); + } + } + void whoKnowsLaundry(std::string input) { - //LaundrySoupSequence laundry = LaundrySoupSequence(input); + LaundrySoupSequence laundry = LaundrySoupSequence(input); - /*laundry.print(); + laundry.print(); printf(" iteration:\n"); for(int j = 0; j < 13; j++) { laundry.incrementAndCheck(); printVector(laundry.workingPulseSequence); - }*/ + } } LaundrySoupSequence::LaundrySoupSequence() { @@ -420,6 +439,9 @@ LaundrySoupSequence::LaundrySoupSequence(std::string expr) { numSteps = (int) pulseSequence.size(); readHead = -1; } +LaundrySoupSequence::LaundrySoupSequence(std::vector<Token> tokens) { + +} void LaundrySoupSequence::print() { printf(" Laundry tokenStack:\n"); printTokenVector(tokenStack); @@ -595,6 +617,9 @@ Parser::Parser(std::string expr) { Parser::Parser() { Parser(""); } +void Parser::setForPolyLaundry() { + +} void Parser::setForLaundry() { //whitelists std::vector<std::string> laundryInterleaveAny = {"Letter", "Integer", "ChanceOfInteger", "Digit", "LeftParen", "RightParen","Channel"}; @@ -1251,3 +1276,12 @@ std::string getByteString(float f) { } return "horse"; } +void replaceAll(std::string& str, const std::string& from, const std::string& to) { + if(from.empty()) + return; + size_t start_pos = 0; + while((start_pos = str.find(from, start_pos)) != std::string::npos) { + str.replace(start_pos, from.length(), to); + start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx' + } +} diff --git a/src/dtpulse.hpp b/src/dtpulse.hpp @@ -43,6 +43,7 @@ class Parser { Token skipAndPeekToken(); void setForCookies(); void setForLaundry(); + void setForPolyLaundry(); void skipToken(); void setExactValue(Token t); void setForExactIntegers(Token t); @@ -101,6 +102,7 @@ class AbsoluteSequence { class LaundrySoupSequence { public: LaundrySoupSequence(std::string expr); + LaundrySoupSequence(std::vector<Token> tokens); LaundrySoupSequence(); std::vector<Token> tokenStack; std::vector<int> pulseSequence; @@ -142,19 +144,9 @@ class Quantizer { }; class LaundryPoly { public: - int index; LaundrySoupSequence lss[16]; - LaundryPoly(int n,std::string formula) { - index=n; - for(int i = 0; i < 16; i++ ) { - lss[i] = LaundrySoupSequence(formula); - } - } - void update(int dex,std::string formula) { - for(int i = 0; i < 16; i++ ) { - lss[i] = LaundrySoupSequence(formula); - } - } + LaundryPoly(std::string formula); + void print(); }; bool matchesAny(std::string val, std::vector<std::string> whitelist); bool is_digits(const std::string &str); @@ -183,7 +175,9 @@ bool matchParens(std::string value); std::string evalToken(std::string input, std::string type,std::vector<Token> tStack); void whoKnows(std::string input); void whoKnowsLaundry(std::string input); +void whoKnowsLaundryPoly(std::string input); void whoKnowsQuantize(std::string input); std::vector<int> getIndicesFromTokenStack(std::vector<Token> tokens); std::vector<int> duplicateIntVector(std::vector<int> input); std::string getByteString(float f); +void replaceAll(std::string& str, const std::string& from, const std::string& to); diff --git a/src/test.cpp b/src/test.cpp @@ -42,11 +42,14 @@ int main(int argc, char** argv) else if(type==7) { whoKnowsQuantize(argv[1]); } +else if(type==8) { + whoKnowsLaundryPoly(argv[1]); + } return 0; } -void printVector(std::vector <int> intVector) { +/*void printVector(std::vector <int> intVector) { for (std::vector<int>::const_iterator i = intVector.begin(); i != intVector.end(); ++i){ std::cout << *i << ' '; } std::cout << std::endl; -} +}*/