Browse Source

Use block pointer instead of value in Module. Clamp `block->bufferSize` in Module instead of each script engine.

tags/v1.1.1
Andrew Belt 5 years ago
parent
commit
fda2350055
3 changed files with 20 additions and 18 deletions
  1. +1
    -2
      src/DuktapeEngine.cpp
  2. +18
    -15
      src/Prototype.cpp
  3. +1
    -1
      src/QuickJSEngine.cpp

+ 1
- 2
src/DuktapeEngine.cpp View File

@@ -91,8 +91,7 @@ struct DuktapeEngine : ScriptEngine {
duk_pop(ctx); duk_pop(ctx);
// bufferSize // bufferSize
duk_get_prop_string(ctx, -1, "bufferSize"); duk_get_prop_string(ctx, -1, "bufferSize");
int bufferSize = duk_get_int(ctx, -1);
block->bufferSize = rack::clamp(bufferSize, 1, MAX_BUFFER_SIZE);
block->bufferSize = duk_get_int(ctx, -1);
duk_pop(ctx); duk_pop(ctx);
} }
duk_pop(ctx); duk_pop(ctx);


+ 18
- 15
src/Prototype.cpp View File

@@ -41,7 +41,7 @@ struct Prototype : Module {
ScriptEngine* scriptEngine = NULL; ScriptEngine* scriptEngine = NULL;
int frame = 0; int frame = 0;
int frameDivider; int frameDivider;
ScriptEngine::ProcessBlock block;
ScriptEngine::ProcessBlock* block;
int bufferIndex = 0; int bufferIndex = 0;


FSW_SESSION* fsw = NULL; FSW_SESSION* fsw = NULL;
@@ -54,11 +54,13 @@ struct Prototype : Module {
for (int i = 0; i < NUM_ROWS; i++) for (int i = 0; i < NUM_ROWS; i++)
configParam(SWITCH_PARAMS + i, 0.f, 1.f, 0.f, string::f("Switch %d", i + 1)); configParam(SWITCH_PARAMS + i, 0.f, 1.f, 0.f, string::f("Switch %d", i + 1));


block = new ScriptEngine::ProcessBlock;
setPath(""); setPath("");
} }


~Prototype() { ~Prototype() {
setPath(""); setPath("");
delete block;
} }


void onReset() override { void onReset() override {
@@ -73,23 +75,23 @@ struct Prototype : Module {


// Inputs // Inputs
for (int i = 0; i < NUM_ROWS; i++) for (int i = 0; i < NUM_ROWS; i++)
block.inputs[i][bufferIndex] = inputs[IN_INPUTS + i].getVoltage();
block->inputs[i][bufferIndex] = inputs[IN_INPUTS + i].getVoltage();


// Process block // Process block
if (++bufferIndex >= block.bufferSize) {
if (++bufferIndex >= block->bufferSize) {
bufferIndex = 0; bufferIndex = 0;


// Block settings // Block settings
block.sampleRate = args.sampleRate;
block.sampleTime = args.sampleTime;
block->sampleRate = args.sampleRate;
block->sampleTime = args.sampleTime;


// Params // Params
for (int i = 0; i < NUM_ROWS; i++) for (int i = 0; i < NUM_ROWS; i++)
block.knobs[i] = params[KNOB_PARAMS + i].getValue();
block->knobs[i] = params[KNOB_PARAMS + i].getValue();
for (int i = 0; i < NUM_ROWS; i++) for (int i = 0; i < NUM_ROWS; i++)
block.switches[i] = params[SWITCH_PARAMS + i].getValue() > 0.f;
block->switches[i] = params[SWITCH_PARAMS + i].getValue() > 0.f;
float oldKnobs[NUM_ROWS]; float oldKnobs[NUM_ROWS];
std::memcpy(oldKnobs, block.knobs, sizeof(block.knobs));
std::memcpy(oldKnobs, block->knobs, sizeof(block->knobs));


// Run ScriptEngine's process function // Run ScriptEngine's process function
{ {
@@ -107,21 +109,21 @@ struct Prototype : Module {


// Params // Params
for (int i = 0; i < NUM_ROWS; i++) { for (int i = 0; i < NUM_ROWS; i++) {
if (block.knobs[i] != oldKnobs[i])
params[KNOB_PARAMS + i].setValue(block.knobs[i]);
if (block->knobs[i] != oldKnobs[i])
params[KNOB_PARAMS + i].setValue(block->knobs[i]);
} }
// Lights // Lights
for (int i = 0; i < NUM_ROWS; i++) for (int i = 0; i < NUM_ROWS; i++)
for (int c = 0; c < 3; c++) for (int c = 0; c < 3; c++)
lights[LIGHT_LIGHTS + i * 3 + c].setBrightness(block.lights[i][c]);
lights[LIGHT_LIGHTS + i * 3 + c].setBrightness(block->lights[i][c]);
for (int i = 0; i < NUM_ROWS; i++) for (int i = 0; i < NUM_ROWS; i++)
for (int c = 0; c < 3; c++) for (int c = 0; c < 3; c++)
lights[SWITCH_LIGHTS + i * 3 + c].setBrightness(block.switchLights[i][c]);
lights[SWITCH_LIGHTS + i * 3 + c].setBrightness(block->switchLights[i][c]);
} }


// Outputs // Outputs
for (int i = 0; i < NUM_ROWS; i++) for (int i = 0; i < NUM_ROWS; i++)
outputs[OUT_OUTPUTS + i].setVoltage(block.outputs[i][bufferIndex]);
outputs[OUT_OUTPUTS + i].setVoltage(block->outputs[i][bufferIndex]);
} }


void setPath(std::string path) { void setPath(std::string path) {
@@ -192,7 +194,7 @@ struct Prototype : Module {
// Reset process state // Reset process state
frameDivider = 32; frameDivider = 32;
frame = 0; frame = 0;
block = ScriptEngine::ProcessBlock();
*block = ScriptEngine::ProcessBlock();
bufferIndex = 0; bufferIndex = 0;
// Reset outputs and lights because they might hold old values // Reset outputs and lights because they might hold old values
for (int i = 0; i < NUM_ROWS; i++) for (int i = 0; i < NUM_ROWS; i++)
@@ -215,7 +217,7 @@ struct Prototype : Module {
return; return;
} }
scriptEngine->module = this; scriptEngine->module = this;
scriptEngine->block = &block;
scriptEngine->block = block;


// Run script // Run script
if (scriptEngine->run(path, script)) { if (scriptEngine->run(path, script)) {
@@ -224,6 +226,7 @@ struct Prototype : Module {
scriptEngine = NULL; scriptEngine = NULL;
return; return;
} }
block->bufferSize = clamp(block->bufferSize, 1, MAX_BUFFER_SIZE);
this->script = script; this->script = script;
this->engineName = scriptEngine->getEngineName(); this->engineName = scriptEngine->getEngineName();
} }


+ 1
- 1
src/QuickJSEngine.cpp View File

@@ -128,7 +128,7 @@ struct QuickJSEngine : ScriptEngine {
JSValue buffer = JS_GetPropertyStr(ctx, config, "bufferSize"); JSValue buffer = JS_GetPropertyStr(ctx, config, "bufferSize");
int32_t bufferValue; int32_t bufferValue;
if (JS_ToInt32(ctx, &bufferValue, buffer) == 0) { if (JS_ToInt32(ctx, &bufferValue, buffer) == 0) {
block->bufferSize = rack::clamp(bufferValue, 1, MAX_BUFFER_SIZE);
block->bufferSize = bufferValue;
} }


JS_FreeValue(ctx, config); JS_FreeValue(ctx, config);


Loading…
Cancel
Save