commit 8a17f25ed4c788ed4dc24f6197649f8cda888af1
parent bd8dddb6f2e3bc0a38ab90469d42d580f01edb6b
Author: Adam M <aemalone@gmail.com>
Date: Sun, 25 Nov 2018 17:23:30 -0600
move parens matching function to dtpulse, tokenize
Diffstat:
4 files changed, 147 insertions(+), 59 deletions(-)
diff --git a/src/ComputerscareILoveCookies.cpp b/src/ComputerscareILoveCookies.cpp
@@ -213,11 +213,14 @@ ComputerscareILoveCookies() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LI
void onRandomize() override {
randomizeAllFields();
}
+ void randomizeShuffle() {
+ }
void randomizeAllFields() {
- std::string mainlookup = knoblookup;
+ std::string mainlookup = knobandinputlookup;
std::string string = "";
std::string randchar = "";
+ float ru;
int length = 0;
for (int i = 0; i < numFields; i++) {
@@ -226,6 +229,10 @@ ComputerscareILoveCookies() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LI
for(int j = 0; j < length; j++) {
randchar = mainlookup[rand() % mainlookup.size()];
string = string + randchar;
+ ru = randomUniform();
+ if(ru < 0.2) {
+ string = "(" + string + ")";
+ }
}
textFields[i]->text = string;
setNextAbsoluteSequence(i);
@@ -236,44 +243,6 @@ ComputerscareILoveCookies() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LI
int length = value.length();
textFields[index]->fontSize = length > 17 ? (length > 30 ? SM_FONT_SIZE : MED_FONT_SIZE) : LG_FONT_SIZE;
}
- bool matchParens(int index) {
- std::string value=textFields[index]->text;
- std::string c="";
- int parensCount=0;
- int squareCount=0;
- int curlyCount=0;
- int angleCount=0;
- bool theyMatch=true;
- for(unsigned int i = 0; i < value.length(); i++) {
- c = value[i];
- if(c=="(") {
- parensCount+=1;
- }
- else if(c==")") {
- parensCount-=1;
- }
- if(c=="[") {
- squareCount+=1;
- }
- else if(c=="]") {
- squareCount-=1;
- }
- if(c=="{") {
- curlyCount+=1;
- }
- else if(c=="}") {
- curlyCount-=1;
- }
- if(c=="<") {
- angleCount+=1;
- }
- else if(c==">") {
- angleCount-=1;
- }
- }
- theyMatch = (parensCount==0) && (squareCount ==0) && (curlyCount==0) && (angleCount==0);
- return theyMatch;
- }
void setNextAbsoluteSequence(int index) {
shouldChange[index] = true;
nextAbsoluteSequences[index].resize(0);
@@ -290,7 +259,6 @@ ComputerscareILoveCookies() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LI
if(shouldChange[index]) {
setAbsoluteSequenceFromQueue(index);
shouldChange[index] = false;
- //changeImminent[index] = false;
}
}
int getAbsoluteStep(int index) {
@@ -328,7 +296,9 @@ void onCreate () override
this->displayString[i] = this->getDisplayString(i);
this->smallLetterDisplays[i]->value = this->displayString[i];
this->smallLetterDisplays[i]->blink = this->shouldChange[i];
-
+ if(i==0) {
+ printf("%i\n",this->absoluteStep[i]);
+ }
if(this->absoluteStep[i] == 0) {
this->setChangeImminent(i,false);
}
@@ -352,25 +322,36 @@ void onCreate () override
return val;
}
float mapKnobValue(float rawValue, int rowIndex) {
- // raw value is between -10 and +10
+ // raw value is between 0 and +10
/*
0: -10,10
1: -5,5
2: 0,10
3: 0,5
4: 0,1
+ 5: -1,1
+ 6: 0,2
+ 7: 0,3
+ 8: -2,2
*/
float mappedValue = 0.f;
- int mapEnum = 0;
+ int mapEnum = 4;
switch(mapEnum) {
- case 0: mappedValue = rawValue; break;
- case 1: mappedValue = rawValue / 2.f; break;
- case 2: mappedValue = (rawValue + 10.f) / 2.f; break;
- case 3: mappedValue = (rawValue + 10.f) / 4.f; break;
- case 4: mappedValue = (rawValue + 10.f) / 20.f; break;
+ case 0: mappedValue = mapValue(rawValue,-5.f,2.f); break;
+ case 1: mappedValue = mapValue(rawValue,-5.f,1.f); break;
+ case 2: mappedValue = rawValue; break;
+ case 3: mappedValue = mapValue(rawValue,0.f,0.5); break;
+ case 4: mappedValue = mapValue(rawValue,0.f,0.1); break;
+ case 5: mappedValue = mapValue(rawValue,-5,0.2); break;
+ case 6: mappedValue = mapValue(rawValue,0.f,0.2); break;
+ case 7: mappedValue = mapValue(rawValue,0.f,1/3); break;
+ case 8: mappedValue = mapValue(rawValue,-5.f,0.4); break;
}
return mappedValue;
}
+ float mapValue(float input, float offset, float multiplier) {
+ return (input + offset) * multiplier;
+ }
};
@@ -415,9 +396,11 @@ void ComputerscareILoveCookies::step() {
atFirstStep = (this->absoluteStep[i] == 0);
if(globalManualResetClicked || currentManualResetClicked) {
setChangeImminent(i,true);
+ resetOneOfThem(i);
}
- if(globalManualResetClicked || currentManualResetClicked || (currentResetActive && currentResetTriggered) || (!currentResetActive && globalResetTriggered)) {
- //resetOneOfThem(i);
+ if( (currentResetActive && currentResetTriggered) || (!currentResetActive && globalResetTriggered)) {
+ resetOneOfThem(i);
+ setChangeImminent(i,false);
}
else {
if(atFirstStep && !currentResetActive && !inputs[GLOBAL_RESET_INPUT].active) {
@@ -437,10 +420,13 @@ void ComputerscareILoveCookies::step() {
//outputs[TRG_OUTPUT + i].value = params[KNOB_PARAM + activeKnob].value;
// how to handle a randomization input here?
// negative integers?
+ // values greater than 52 for randomization
+ // then must keep a separate dictionary
+ // dict[52] = [1,2,24] and then it must look this up and randomize
if(activeKnobIndex[i] < 26) {
knobRawValue = params[activeKnobIndex[i]].value;
}
- else {
+ else if(activeKnobIndex[i] < 52) {
knobRawValue = inputs[SIGNAL_INPUT + activeKnobIndex[i] - 26].value;
}
outputs[TRG_OUTPUT + i].value = mapKnobValue(knobRawValue,i);
@@ -497,7 +483,8 @@ struct NumberDisplayWidget3cookie : TransparentWidget {
void MyTextFieldCookie::onTextChange() {
module->checkLength(this->rowIndex);
- if(module->matchParens(this->rowIndex)) {
+ std::string value = module->textFields[this->rowIndex]->text;
+ if(matchParens(value)) {
printf("row: %i\n",this->rowIndex);
module->setNextAbsoluteSequence(this->rowIndex);
}
diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp
@@ -263,6 +263,7 @@ std::string hashExpand(std::string input, int hashnum) {
}
return output;
}
+
std::string concatVectorFromLookup(std::vector<int> vector, std::string lookup) {
std::string output="";
for (int i = 0; i < vector.size(); i++){
@@ -270,18 +271,114 @@ std::string concatVectorFromLookup(std::vector<int> vector, std::string lookup)
}
return output;
}
-Token::Token(int i, std::string v) {
- type = i;
+
+bool matchParens(std::string value) {
+ std::string c="";
+ int parensCount=0;
+ int squareCount=0;
+ int curlyCount=0;
+ int angleCount=0;
+ bool theyMatch=true;
+ for(unsigned int i = 0; i < value.length(); i++) {
+ c = value[i];
+ if(c=="(") {
+ parensCount+=1;
+ }
+ else if(c==")") {
+ parensCount-=1;
+ }
+ if(c=="[") {
+ squareCount+=1;
+ }
+ else if(c=="]") {
+ squareCount-=1;
+ }
+ if(c=="{") {
+ curlyCount+=1;
+ }
+ else if(c=="}") {
+ curlyCount-=1;
+ }
+ if(c=="<") {
+ angleCount+=1;
+ }
+ else if(c==">") {
+ angleCount-=1;
+ }
+ }
+ theyMatch = (parensCount==0) && (squareCount ==0) && (curlyCount==0) && (angleCount==0);
+ return theyMatch;
+ }
+
+
+Token::Token(std::string t, std::string v) {
+ type = t;
val = v;
}
void Token::print() {
- printf("type:%i, val:%s\n",type,val.c_str());
+ printf("type:%s, val:%s\n",type.c_str(),val.c_str());
}
std::vector<Token> tokenizeString(std::string input) {
std::vector<Token> stack;
for(unsigned int i = 0; i < input.length(); i++) {
std::string token(1,input[i]);
- stack.push_back(Token(0,token));
+ if(token=="(") stack.push_back(Token("LeftParen",token));
+ else if(token== ")") stack.push_back(Token("RightParen",token));
+ else if(token== "[") stack.push_back(Token("LeftSquare",token));
+ else if(token== "]") stack.push_back(Token("RightSquare",token));
+ else if(token== "{") stack.push_back(Token("LeftCurly",token));
+ else if(token== "}") stack.push_back(Token("RightCurly",token));
+ else if(token== "<") stack.push_back(Token("LeftAngle",token));
+ else if(token== ">") stack.push_back(Token("RightAngle",token));
+ else if(token== "@") stack.push_back(Token("At",token));
+ else if(token== ",") stack.push_back(Token("Comma",token));
+ else if(token== "+") stack.push_back(Token("Plus",token));
+ else if(token== "-") stack.push_back(Token("Minus",token));
+ else if(token== "*") stack.push_back(Token("Asterix",token));
+ else if(token== "/") stack.push_back(Token("Backslash",token));
+ else if(token== " ") stack.push_back(Token("Whitespace",token));
+ else if(token== ".") stack.push_back(Token("Period",token));
+ else if(token== "!") stack.push_back(Token("Bang",token));
+ else if(token== "?") stack.push_back(Token("Question",token));
+ else if(token== "#") stack.push_back(Token("Hash",token));
+ else if(token== "^") stack.push_back(Token("Caret",token));
+ else if(token== ":") stack.push_back(Token("Colon",token));
+ else if(token== ";") stack.push_back(Token("Semicolon",token));
+ else if(token== "|") stack.push_back(Token("Pipe",token));
+ else if(knobandinputlookup.find(token) != -1) stack.push_back(Token("Letter",token));
+ else if(integerlookup.find(token) != -1) stack.push_back(Token("Integer",token));
+ else stack.push_back(Token("Unknown",token));
}
return stack;
}
+std::string whoKnows(std::string input) {
+ std::vector<Token> tStack = tokenizeString(input);
+ return evalToken("","Integer",tStack);
+}
+
+std::string evalToken(std::string input,std::string type, std::vector<Token> tStack) {
+ std::string output = input;
+ Token peek = Token("Unknown","~");
+ if(tStack.size()) {
+ peek = tStack.front();
+ if(type=="Integer") {
+ tStack.erase(tStack.begin());
+ if(peek.type=="Integer") output = evalToken(output+peek.val,"Integer",tStack);
+ }
+ else if(type=="Letter") {
+ tStack.erase(tStack.begin());
+ if(peek.type=="Letter") output = evalToken(output+peek.val,"Letter",tStack);
+ }
+ else if(type=="LeftCurly") {
+ tStack.erase(tStack.begin());
+ if(peek.type=="Letter") output = output + evalToken(output+peek.val,"rLetter",tStack);
+ else if(peek.type=="Integer") output = output+evalToken(peek.val,"rInt",tStack);
+ }
+ else if(type=="rLetter") {
+ //if(peek.type=="Letter") output =
+ }
+
+ }
+ return output;
+}
+
diff --git a/src/dtpulse.hpp b/src/dtpulse.hpp
@@ -16,9 +16,9 @@ extern std::string knobandinputlookup;
#endif
class Token {
public:
- int type;
+ std::string type;
std::string val;
- Token(int t, std::string v);
+ Token(std::string t, std::string v);
void print();
};
bool is_digits(const std::string &str);
@@ -37,4 +37,6 @@ std::string atExpand(std::string input, int atnum, std::string lookup);
std::string countExpand(std::string input, int atnum);
std::string concatVectorFromLookup(std::vector<int> vector, std::string lookup);
std::vector<Token> tokenizeString(std::string input);
-
+bool matchParens(std::string value);
+std::string evalToken(std::string input, std::string type,std::vector<Token> tStack);
+std::string whoKnows(std::string input);
diff --git a/src/test.cpp b/src/test.cpp
@@ -35,9 +35,11 @@ int main(int argc, char** argv)
}
else if(type==5) {
std::vector<Token> stack = tokenizeString(argv[1]);
+
for(int i = 0; i < stack.size(); i++) {
stack[i].print();
}
+ printf("whoKnows:%s\n",whoKnows(argv[1]).c_str());
}
return 0;
}