| @@ -74,6 +74,7 @@ include compile.mk | |||||
| dist: all | dist: all | ||||
| rm -rf dist | |||||
| $(MAKE) -C plugins/Fundamental dist | $(MAKE) -C plugins/Fundamental dist | ||||
| ifeq ($(ARCH), mac) | ifeq ($(ARCH), mac) | ||||
| @@ -49,6 +49,7 @@ struct Module { | |||||
| /** Advances the module by 1 audio frame with duration 1.0 / gSampleRate */ | /** Advances the module by 1 audio frame with duration 1.0 / gSampleRate */ | ||||
| virtual void step() {} | virtual void step() {} | ||||
| virtual void onSampleRateChange() {} | |||||
| /** Override these to store extra internal data in the "data" property */ | /** Override these to store extra internal data in the "data" property */ | ||||
| virtual json_t *toJson() { return NULL; } | virtual json_t *toJson() { return NULL; } | ||||
| @@ -80,6 +81,7 @@ void engineAddWire(Wire *wire); | |||||
| void engineRemoveWire(Wire *wire); | void engineRemoveWire(Wire *wire); | ||||
| void engineSetParam(Module *module, int paramId, float value); | void engineSetParam(Module *module, int paramId, float value); | ||||
| void engineSetParamSmooth(Module *module, int paramId, float value); | void engineSetParamSmooth(Module *module, int paramId, float value); | ||||
| void engineSetSampleRate(float sampleRate); | |||||
| extern float gSampleRate; | extern float gSampleRate; | ||||
| extern bool gPaused; | extern bool gPaused; | ||||
| @@ -70,7 +70,7 @@ struct PauseItem : MenuItem { | |||||
| struct SampleRateItem : MenuItem { | struct SampleRateItem : MenuItem { | ||||
| float sampleRate; | float sampleRate; | ||||
| void onAction() { | void onAction() { | ||||
| gSampleRate = sampleRate; | |||||
| engineSetSampleRate(sampleRate); | |||||
| gPaused = false; | gPaused = false; | ||||
| } | } | ||||
| }; | }; | ||||
| @@ -39,7 +39,7 @@ void Wire::step() { | |||||
| } | } | ||||
| void engineInit() { | void engineInit() { | ||||
| gSampleRate = 44100.0; | |||||
| engineSetSampleRate(44100.0); | |||||
| } | } | ||||
| void engineDestroy() { | void engineDestroy() { | ||||
| @@ -218,5 +218,15 @@ void engineSetParamSmooth(Module *module, int paramId, float value) { | |||||
| smoothValue = value; | smoothValue = value; | ||||
| } | } | ||||
| void engineSetSampleRate(float newSampleRate) { | |||||
| VIPLock vipLock(vipMutex); | |||||
| std::lock_guard<std::mutex> lock(mutex); | |||||
| gSampleRate = newSampleRate; | |||||
| // onSampleRateChange | |||||
| for (Module *module : modules) { | |||||
| module->onSampleRateChange(); | |||||
| } | |||||
| } | |||||
| } // namespace rack | } // namespace rack | ||||
| @@ -62,8 +62,10 @@ static void settingsFromJson(json_t *rootJ) { | |||||
| // sampleRate | // sampleRate | ||||
| json_t *sampleRateJ = json_object_get(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); | |||||
| } | |||||
| } | } | ||||