commit f8db61747d205b740579e20c0a7f7a587ba1541a
parent 6fde74b41b11076698d161060036af93d2bf1e77
Author: Adam M <[email protected]>
Date: Wed, 2 Jan 2019 22:22:59 -0600
Implement LaundrySoupSequence in LaundrySoup module
Diffstat:
2 files changed, 41 insertions(+), 16 deletions(-)
diff --git a/src/ComputerscareLaundrySoup.cpp b/src/ComputerscareLaundrySoup.cpp
@@ -107,6 +107,8 @@ struct ComputerscareLaundrySoup : Module {
int absoluteStep[numFields] = {0};
int numSteps[numFields] = {0};
+ LaundrySoupSequence laundrySequences[numFields];
+
bool shouldChange[numFields] = {false};
ComputerscareLaundrySoup() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
@@ -172,6 +174,8 @@ void setAbsoluteSequenceFromQueue(int index) {
absoluteSequences[index].resize(0);
absoluteSequences[index] = nextAbsoluteSequences[index];
numSteps[index] = nextAbsoluteSequences[index].size() > 0 ? nextAbsoluteSequences[index].size() : 1;
+ laundrySequences[index] = LaundrySoupSequence(textFields[index]->text);
+ laundrySequences[index].print();
}
void checkIfShouldChange(int index) {
if(shouldChange[index]) {
@@ -204,17 +208,32 @@ void onCreate () override
*/
void incrementInternalStep(int i) {
+ laundrySequences[i].incrementAndCheck();
+
+ if(laundrySequences[i].readHead == 0) {
+ this->setChangeImminent(i,false);
+ }
this->absoluteStep[i] += 1;
this->absoluteStep[i] %= this->numSteps[i];
this->smallLetterDisplays[i]->value = this->getDisplayString(i);
}
- std::string getDisplayString(int i) {
- std::string out = std::to_string(this->absoluteStep[i]+1);
- out += "\n" + std::to_string(this->numSteps[i]);
- return out;
+ std::string getDisplayString(int index) {
+ std::string lhs = std::to_string(this->laundrySequences[index].readHead + 1);
+ std::string rhs = std::to_string(this->laundrySequences[index].numSteps);
+
+ padTo(lhs, 3,' ');
+ padTo(rhs, 3,' ');
+
+ std::string val = lhs + "\n" + rhs;
+
+ return val;
+ }
+ void setChangeImminent(int i,bool value) {
+ this->smallLetterDisplays[i]->doubleblink = value;
}
void resetOneOfThem(int i) {
+ this->laundrySequences[i].readHead = -1;
this->absoluteStep[i] = -1;
}
};
@@ -254,11 +273,12 @@ void ComputerscareLaundrySoup::step() {
}
else {
if ((inputs[GLOBAL_CLOCK_INPUT].active && clocked) || globalManualClockClicked) {
- incrementInternalStep(i);
+ incrementInternalStep(i);
}
}
- atFirstStep = (this->absoluteStep[i] == 0);
+ //atFirstStep = (this->absoluteStep[i] == 0);
+ atFirstStep = (this->laundrySequences[i].readHead == 0);
if((currentResetActive && currentResetTriggered) || (!currentResetActive && globalResetTriggered) || globalManualResetClicked || currentManualResetClicked) {
checkIfShouldChange(i);
@@ -269,8 +289,8 @@ void ComputerscareLaundrySoup::step() {
checkIfShouldChange(i);
}
}
- activeStep = absoluteSequences[i][this->absoluteStep[i]]==1;
-
+ //activeStep = absoluteSequences[i][this->absoluteStep[i]]==1;
+ activeStep = (this->laundrySequences[i].peekWorkingStep() == 1);
}
if(inputs[CLOCK_INPUT + i].active) {
outputs[TRG_OUTPUT + i].value = (currentTriggerIsHigh && activeStep) ? 10.0f : 0.0f;
@@ -284,9 +304,11 @@ void ComputerscareLaundrySoup::step() {
}
void MyTextField::onTextChange() {
- module->setNextAbsoluteSequence(this->rowIndex);
std::string value = module->textFields[this->rowIndex]->text;
- whoKnowsLaundry(value);
+ if(matchParens(value)) {
+ module->setNextAbsoluteSequence(this->rowIndex);
+ whoKnowsLaundry(value);
+ }
}
struct ComputerscareLaundrySoupWidget : ModuleWidget {
diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp
@@ -381,12 +381,8 @@ void whoKnows(std::string input) {
}
void whoKnowsLaundry(std::string input) {
LaundrySoupSequence laundry = LaundrySoupSequence(input);
- srand (time(NULL));
- printf(" Laundry tokenStack:\n");
- printTokenVector(laundry.tokenStack);
- printf(" Laundry pulseSequence:\n");
- printVector(laundry.pulseSequence);
-
+
+ laundry.print();
printf(" iteration:\n");
for(int j = 0; j < 13; j++) {
laundry.incrementAndCheck();
@@ -418,6 +414,12 @@ LaundrySoupSequence::LaundrySoupSequence(std::string expr) {
numSteps = (int) pulseSequence.size();
readHead = -1;
}
+void LaundrySoupSequence::print() {
+ printf(" Laundry tokenStack:\n");
+ printTokenVector(tokenStack);
+ printf(" Laundry pulseSequence:\n");
+ printVector(pulseSequence);
+}
std::vector<int> LaundrySoupSequence::makePulseSequence(std::vector<Token> tokens) {
std::vector<int> output = {};
int thisVal;
@@ -460,6 +462,7 @@ AbsoluteSequence::AbsoluteSequence() {
AbsoluteSequence::AbsoluteSequence(std::string expr, std::string lookup) {
std::vector<Token> defaultStack;
defaultStack.push_back(Token("Error", "error",-1));
+ srand (time(NULL));
//expr = expr=="" ? "a" : expr;
if(expr != "") {
Parser p = Parser(expr);