From e2700409b2d825ef564e895ff9a69666bb750f05 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 7 Oct 2017 01:46:45 -0400 Subject: [PATCH 1/3] Added onSampleRateChange() to Module --- Makefile | 1 + include/engine.hpp | 2 ++ src/app/Toolbar.cpp | 2 +- src/engine.cpp | 12 +++++++++++- src/settings.cpp | 6 ++++-- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 2ee90fc3..32e8cd81 100644 --- a/Makefile +++ b/Makefile @@ -74,6 +74,7 @@ include compile.mk dist: all + rm -rf dist $(MAKE) -C plugins/Fundamental dist ifeq ($(ARCH), mac) diff --git a/include/engine.hpp b/include/engine.hpp index 6df8b664..4d7b3419 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -49,6 +49,7 @@ struct Module { /** Advances the module by 1 audio frame with duration 1.0 / gSampleRate */ virtual void step() {} + virtual void onSampleRateChange() {} /** Override these to store extra internal data in the "data" property */ virtual json_t *toJson() { return NULL; } @@ -80,6 +81,7 @@ void engineAddWire(Wire *wire); void engineRemoveWire(Wire *wire); void engineSetParam(Module *module, int paramId, float value); void engineSetParamSmooth(Module *module, int paramId, float value); +void engineSetSampleRate(float sampleRate); extern float gSampleRate; extern bool gPaused; diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index a40758a8..4f3eb299 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -70,7 +70,7 @@ struct PauseItem : MenuItem { struct SampleRateItem : MenuItem { float sampleRate; void onAction() { - gSampleRate = sampleRate; + engineSetSampleRate(sampleRate); gPaused = false; } }; diff --git a/src/engine.cpp b/src/engine.cpp index 5ee7e1cb..df7f77d0 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -39,7 +39,7 @@ void Wire::step() { } void engineInit() { - gSampleRate = 44100.0; + engineSetSampleRate(44100.0); } void engineDestroy() { @@ -218,5 +218,15 @@ void engineSetParamSmooth(Module *module, int paramId, float value) { smoothValue = value; } +void engineSetSampleRate(float newSampleRate) { + VIPLock vipLock(vipMutex); + std::lock_guard lock(mutex); + gSampleRate = newSampleRate; + // onSampleRateChange + for (Module *module : modules) { + module->onSampleRateChange(); + } +} + } // namespace rack diff --git a/src/settings.cpp b/src/settings.cpp index f762d778..c2e5153e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -62,8 +62,10 @@ static void settingsFromJson(json_t *rootJ) { // sampleRate json_t *sampleRateJ = json_object_get(rootJ, "sampleRate"); - if (sampleRateJ) - gSampleRate = json_number_value(sampleRateJ); + if (sampleRateJ) { + float sampleRate = json_number_value(sampleRateJ); + engineSetSampleRate(sampleRate); + } } From a80eb15b372ac8c0d7000aa7f8fbd65a65477fcd Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 7 Oct 2017 02:52:44 -0400 Subject: [PATCH 2/3] Add SchmittTrigger::isHigh() --- include/dsp/digital.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/dsp/digital.hpp b/include/dsp/digital.hpp index 67b729d9..599f626a 100644 --- a/include/dsp/digital.hpp +++ b/include/dsp/digital.hpp @@ -41,6 +41,9 @@ struct SchmittTrigger { } return false; } + bool isHigh() { + return state == HIGH; + } void reset() { state = UNKNOWN; } From 3d044ab411eef8b157554aa02e009bc8ecf17480 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 7 Oct 2017 06:29:24 -0400 Subject: [PATCH 3/3] Add RoundBlackKnob --- include/components.hpp | 139 +++++++++++++++++----------- include/math.hpp | 6 ++ res/ComponentLibrary/RoundBlack.svg | 123 ++++++++++++++++++++++++ src/app/SVGKnob.cpp | 2 + 4 files changed, 218 insertions(+), 52 deletions(-) create mode 100644 res/ComponentLibrary/RoundBlack.svg diff --git a/include/components.hpp b/include/components.hpp index ffd5a169..ef078c33 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -25,6 +25,93 @@ namespace rack { // Knobs //////////////////// +struct RoundKnob : SVGKnob { + RoundKnob() { + minAngle = -0.83*M_PI; + maxAngle = 0.83*M_PI; + } +}; + +struct RoundBlackKnob : RoundKnob { + RoundBlackKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/RoundBlack.svg"))); + box.size = Vec(38, 38); + } +}; + +struct RoundSmallBlackKnob : RoundBlackKnob { + RoundSmallBlackKnob() { + box.size = Vec(28, 28); + } +}; + +struct RoundLargeBlackKnob : RoundBlackKnob { + RoundLargeBlackKnob() { + box.size = Vec(46, 46); + } +}; + +struct RoundHugeBlackKnob : RoundBlackKnob { + RoundHugeBlackKnob() { + box.size = Vec(56, 56); + } +}; + +struct RoundSmallBlackSnapKnob : RoundSmallBlackKnob, SnapKnob {}; + + +struct Davies1900hKnob : SVGKnob { + Davies1900hKnob() { + minAngle = -0.83*M_PI; + maxAngle = 0.83*M_PI; + } +}; + +struct Davies1900hWhiteKnob : Davies1900hKnob { + Davies1900hWhiteKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hWhite.svg"))); + } +}; + +struct Davies1900hBlackKnob : Davies1900hKnob { + Davies1900hBlackKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hBlack.svg"))); + } +}; + +struct Davies1900hRedKnob : Davies1900hKnob { + Davies1900hRedKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hRed.svg"))); + } +}; + +struct Davies1900hLargeWhiteKnob : Davies1900hKnob { + Davies1900hLargeWhiteKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeWhite.svg"))); + } +}; + +struct Davies1900hLargeBlackKnob : Davies1900hKnob { + Davies1900hLargeBlackKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeBlack.svg"))); + } +}; + +struct Davies1900hLargeRedKnob : Davies1900hKnob { + Davies1900hLargeRedKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeRed.svg"))); + } +}; + +struct Davies1900hSmallBlackKnob : Davies1900hKnob { + Davies1900hSmallBlackKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hSmallBlack.svg"))); + } +}; + +struct Davies1900hSmallBlackSnapKnob : Davies1900hSmallBlackKnob, SnapKnob {}; + + struct Rogan : SVGKnob { Rogan() { minAngle = -0.83*M_PI; @@ -261,58 +348,6 @@ struct SynthTechAlco : SVGKnob { } }; -struct Davies1900hKnob : SVGKnob { - Davies1900hKnob() { - box.size = Vec(36, 36); - minAngle = -0.83*M_PI; - maxAngle = 0.83*M_PI; - } -}; - -struct Davies1900hWhiteKnob : Davies1900hKnob { - Davies1900hWhiteKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hWhite.svg"))); - } -}; - -struct Davies1900hBlackKnob : Davies1900hKnob { - Davies1900hBlackKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hBlack.svg"))); - } -}; - -struct Davies1900hRedKnob : Davies1900hKnob { - Davies1900hRedKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hRed.svg"))); - } -}; - -struct Davies1900hLargeWhiteKnob : Davies1900hKnob { - Davies1900hLargeWhiteKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeWhite.svg"))); - } -}; - -struct Davies1900hLargeBlackKnob : Davies1900hKnob { - Davies1900hLargeBlackKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeBlack.svg"))); - } -}; - -struct Davies1900hLargeRedKnob : Davies1900hKnob { - Davies1900hLargeRedKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeRed.svg"))); - } -}; - -struct Davies1900hSmallBlackKnob : Davies1900hKnob { - Davies1900hSmallBlackKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hSmallBlack.svg"))); - } -}; - -struct Davies1900hSmallBlackSnapKnob : Davies1900hSmallBlackKnob, SnapKnob {}; - struct Trimpot : SVGKnob { Trimpot() { box.size = Vec(17, 17); diff --git a/include/math.hpp b/include/math.hpp index c01135b1..af8b67b4 100644 --- a/include/math.hpp +++ b/include/math.hpp @@ -167,9 +167,15 @@ struct Vec { Vec mult(float s) { return Vec(x * s, y * s); } + Vec mult(Vec b) { + return Vec(x * b.x, y * b.y); + } Vec div(float s) { return Vec(x / s, y / s); } + Vec div(Vec b) { + return Vec(x / b.x, y / b.y); + } float dot(Vec b) { return x * b.x + y * b.y; } diff --git a/res/ComponentLibrary/RoundBlack.svg b/res/ComponentLibrary/RoundBlack.svg new file mode 100644 index 00000000..92969944 --- /dev/null +++ b/res/ComponentLibrary/RoundBlack.svg @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/app/SVGKnob.cpp b/src/app/SVGKnob.cpp index 181766e4..256e6917 100644 --- a/src/app/SVGKnob.cpp +++ b/src/app/SVGKnob.cpp @@ -24,6 +24,8 @@ void SVGKnob::step() { if (dirty) { float angle = rescalef(value, minValue, maxValue, minAngle, maxAngle); tw->identity(); + // Scale SVG to box + tw->scale(box.size.div(sw->box.size)); // Rotate SVG Vec center = sw->box.getCenter(); tw->translate(center);