commit ef27e0c1d05aed230a707b0633da275c43b33675
parent a15fcdb3fbfb86fde2be5f0c7ba365efcc3fd5bf
Author: Adam Malone <1319733+freddyz@users.noreply.github.com>
Date: Wed, 9 Jan 2019 12:18:05 -0600
Merge remote branch 'origin/master' into ohpeas
Diffstat:
4 files changed, 88 insertions(+), 4 deletions(-)
diff --git a/src/ComputerscareLaundrySoup.cpp b/src/ComputerscareLaundrySoup.cpp
@@ -249,6 +249,7 @@ void ComputerscareLaundrySoup::step() {
bool globalGateIn = globalClockTrigger.isHigh();
bool atFirstStep = false;
+ bool atLastStepAfterIncrement = false;
bool clocked = globalClockTrigger.process(inputs[GLOBAL_CLOCK_INPUT].value);
bool currentTriggerIsHigh = false;
bool currentTriggerClocked = false;
@@ -274,14 +275,16 @@ void ComputerscareLaundrySoup::step() {
if(currentTriggerClocked || globalManualClockClicked) {
incrementInternalStep(i);
activeStep[i] = (this->laundrySequences[i].peekWorkingStep() == 1);
-
+ atLastStepAfterIncrement = this->laundrySequences[i].atLastStep();
+ if(atLastStepAfterIncrement) checkIfShouldChange(i);
}
}
else {
if ((inputs[GLOBAL_CLOCK_INPUT].active && clocked) || globalManualClockClicked) {
incrementInternalStep(i);
activeStep[i] = (this->laundrySequences[i].peekWorkingStep() == 1);
-
+ atLastStepAfterIncrement = this->laundrySequences[i].atLastStep();
+ if(atLastStepAfterIncrement) checkIfShouldChange(i);
}
}
@@ -300,7 +303,7 @@ void ComputerscareLaundrySoup::step() {
}
else {
if(atFirstStep && !currentResetActive && !inputs[GLOBAL_RESET_INPUT].active) {
- checkIfShouldChange(i);
+ //checkIfShouldChange(i);
}
}
}
@@ -319,12 +322,13 @@ void ComputerscareLaundrySoup::step() {
void MyTextField::onTextChange() {
std::string value = module->textFields[this->rowIndex]->text;
LaundrySoupSequence lss = LaundrySoupSequence(value);
+
if(!lss.inError && matchParens(value)) {
module->textFields[this->rowIndex]->inError=false;
module->setNextAbsoluteSequence(this->rowIndex);
module->updateDisplayBlink(this->rowIndex);
- whoKnowsLaundry(value);
+ //whoKnowsLaundry(value);
}
else {
module->textFields[this->rowIndex]->inError=true;
diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp
@@ -456,6 +456,9 @@ void LaundrySoupSequence::incrementAndCheck() {
randomizePulseValue(readHead);
}
}
+bool LaundrySoupSequence::atLastStep() {
+ return (readHead == (numSteps -1 ));
+}
void LaundrySoupSequence::randomizePulseValue(int index) {
workingPulseSequence[index] = (rand() % 2);
}
@@ -586,6 +589,9 @@ Parser::Parser(std::string expr) {
expression=expr;
inError = false;
}
+Parser::Parser() {
+ Parser("");
+}
void Parser::setForLaundry() {
//whitelists
std::vector<std::string> laundryInterleaveAny = {"Letter","Integer","ChanceOfInteger","Digit","LeftParen","RightParen"};
@@ -1138,3 +1144,55 @@ std::vector<Token> tokenizeString(std::string input) {
}
return stack;
}
+void whoKnowsQuantize(std::string input) {
+ Quantizer q = Quantizer("2212221",12,0);
+ float in = std::stof(input);
+ printf("%f\n",q.quantize(in));
+}
+Quantizer::Quantizer(std::string intervals, int divisions, int trans) {
+ scaleParser = Parser(intervals);
+ //printTokenVector(scaleParser.tokens);
+ numDivisions = divisions;
+ transpose=trans;
+ fTranspose = (float)transpose/(float)numDivisions;
+ mappedValues = generateMappedValues();
+ numSteps = (int) mappedValues.size();
+ printFloatVector(mappedValues);
+}
+std::vector<float> Quantizer::generateMappedValues() {
+ std::vector<float> output;
+ float sum = 0.f;
+ float fNumDivisions = (float)numDivisions;
+ float currentVal = 0.f;
+ std::vector<Token> stack = scaleParser.tokens;
+ output.push_back(0.f);
+ for(unsigned int i = 0; i < stack.size(); i++) {
+ if(stack[i].type=="Digit") {
+ sum += std::stof(stack[i].value);
+ currentVal = sum/fNumDivisions;
+ output.push_back(currentVal);
+ }
+ }
+ return output;
+}
+float Quantizer::findClosestValue(float input) {
+ float closestValue = 10.f;
+ float smallestDiff = 10.f;
+ float thisDiff = 0.f;
+ for(int i = 0; i < numSteps; i++) {
+ thisDiff = fabs(input - mappedValues[i]);
+ if(thisDiff < smallestDiff) {
+ closestValue = mappedValues[i];
+ smallestDiff = thisDiff;
+ }
+ }
+ return closestValue;
+}
+float Quantizer::quantize(float input) {
+ float octavePart = floor(input);
+ float fractionalPart = input-octavePart;
+ float quantizedFractional = findClosestValue(fractionalPart);
+ float quantizedPreTranspose = octavePart + quantizedFractional;
+ float quantizedVal = quantizedPreTranspose + fTranspose;
+ return quantizedVal;
+}
diff --git a/src/dtpulse.hpp b/src/dtpulse.hpp
@@ -7,6 +7,7 @@
#include <algorithm>
#include <typeinfo>
#include <stdexcept>
+#include <math.h>
#ifndef MY_GLOBALS_H
#define MY_GLOBALS_H
@@ -30,6 +31,7 @@ class Token {
};
class Parser {
public:
+ Parser();
Parser(std::string expr);
std::string expression;
std::vector<Token> tokens;
@@ -110,8 +112,24 @@ class LaundrySoupSequence {
int skipAndPeek();
int peekWorkingStep();
void incrementAndCheck();
+ bool atLastStep();
void randomizePulseValue(int index);
};
+class Quantizer {
+ public:
+ Quantizer(std::string intervals, int divisions, int trans);
+ float quantize(float val);
+ int numDivisions;
+ int transpose;
+ bool parseError;
+ int numSteps;
+ float fTranspose;
+ private:
+ Parser scaleParser;
+ float findClosestValue(float input);
+ std::vector<float> mappedValues;
+ std::vector<float> generateMappedValues();
+};
bool matchesAny(std::string val, std::vector<std::string> whitelist);
bool is_digits(const std::string &str);
void padTo(std::string &str, const size_t num, const char paddingChar );
@@ -138,5 +156,6 @@ 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 whoKnowsQuantize(std::string input);
std::vector<int> getIndicesFromTokenStack(std::vector<Token> tokens);
std::vector<int> duplicateIntVector(std::vector<int> input);
diff --git a/src/test.cpp b/src/test.cpp
@@ -39,6 +39,9 @@ int main(int argc, char** argv)
else if(type==6) {
whoKnowsLaundry(argv[1]);
}
+ else if(type==7) {
+ whoKnowsQuantize(argv[1]);
+ }
return 0;
}
void printVector(std::vector <int> intVector) {