computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit 01237b1660c5a3cdc8c3ec9462792443af52583a
parent 1b7ade5ffed339f56bb2511b708306f0f0f8e0e9
Author: Adam Malone <1319733+freddyz@users.noreply.github.com>
Date:   Wed, 21 Aug 2019 15:29:05 -0500

laundry soup formula can calculate power by caret symbol.  be careful

Diffstat:
Msrc/dtpulse.cpp | 16++++++++++++++--
Msrc/dtpulse.hpp | 1+
2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp @@ -394,7 +394,7 @@ LaundryPoly::LaundryPoly(std::string formula) { std::string newFormula = ""; for (int i = 0; i < 16; i++ ) { newFormula = formula; - replaceAll(newFormula, "2^#", "<" + std::to_string(static_cast<long long>(1 << i)) + ">"); + //replaceAll(newFormula, "2^#", "<" + std::to_string(static_cast<long long>(1 << i)) + ">"); replaceAll(newFormula, "#", "<" + std::to_string(static_cast<long long>(i + 1)) + ">"); lss[i] = LaundrySoupSequence(newFormula); } @@ -630,7 +630,7 @@ Token::Token(std::string t, int val) { type=t; value = std::to_string(static_cast<long long>(val)); index=-1; - duration=val; + duration=std::max(val,1); } Token::Token(const Token& source) { type=source.type; @@ -924,6 +924,9 @@ void Parser::ParseFormula(Token t,std::vector<std::string> operatorWhitelist, bo else if(op=="Backslash") { result = lhs/rhs; } + else if(op=="Caret") { + result= myPow(lhs,rhs); + } terminalStack.push_back(Token("Integer",result)); } else { @@ -1389,3 +1392,12 @@ int mapVoltageToChannelCount(float vv) { } return (int) round(v * 1.6f); } +int myPow(int x, int p) +{ + if (p == 0) return 1; + if (p == 1) return x; + + int tmp = myPow(x, p/2); + if (p%2 == 0) return tmp * tmp; + else return x * tmp * tmp; +} diff --git a/src/dtpulse.hpp b/src/dtpulse.hpp @@ -192,3 +192,4 @@ std::string getByteString(float f); void replaceAll(std::string& str, const std::string& from, const std::string& to); float mapChannelCountToVoltage(int ch); int mapVoltageToChannelCount(float vv); +int myPow(int x, int p);