Browse Source

Added onSampleRateChange() to Module

tags/v0.4.0
Andrew Belt 7 years ago
parent
commit
e2700409b2
5 changed files with 19 additions and 4 deletions
  1. +1
    -0
      Makefile
  2. +2
    -0
      include/engine.hpp
  3. +1
    -1
      src/app/Toolbar.cpp
  4. +11
    -1
      src/engine.cpp
  5. +4
    -2
      src/settings.cpp

+ 1
- 0
Makefile View File

@@ -74,6 +74,7 @@ include compile.mk


dist: all
rm -rf dist
$(MAKE) -C plugins/Fundamental dist

ifeq ($(ARCH), mac)


+ 2
- 0
include/engine.hpp View File

@@ -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;


+ 1
- 1
src/app/Toolbar.cpp View File

@@ -70,7 +70,7 @@ struct PauseItem : MenuItem {
struct SampleRateItem : MenuItem {
float sampleRate;
void onAction() {
gSampleRate = sampleRate;
engineSetSampleRate(sampleRate);
gPaused = false;
}
};


+ 11
- 1
src/engine.cpp View File

@@ -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<std::mutex> lock(mutex);
gSampleRate = newSampleRate;
// onSampleRateChange
for (Module *module : modules) {
module->onSampleRateChange();
}
}


} // namespace rack

+ 4
- 2
src/settings.cpp View File

@@ -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);
}
}




Loading…
Cancel
Save