From 13a16aea60acd3fc546ef9feddf92f86d3fc1d0a Mon Sep 17 00:00:00 2001 From: Jim Tupper Date: Mon, 1 Oct 2018 23:30:47 +0100 Subject: [PATCH 1/9] Essential working Stages --- src/AudibleInstruments.cpp | 2 +- src/Stages.cpp | 188 ++++++++++++++++++++++++++++++++++--- 2 files changed, 174 insertions(+), 16 deletions(-) diff --git a/src/AudibleInstruments.cpp b/src/AudibleInstruments.cpp index b6f9ccb..1eabd8d 100644 --- a/src/AudibleInstruments.cpp +++ b/src/AudibleInstruments.cpp @@ -23,5 +23,5 @@ void init(rack::Plugin *p) { p->addModel(modelVeils); p->addModel(modelFrames); // p->addModel(modelPeaks); - // p->addModel(modelStages); + p->addModel(modelStages); } diff --git a/src/Stages.cpp b/src/Stages.cpp index b7ca955..3c8f2b5 100644 --- a/src/Stages.cpp +++ b/src/Stages.cpp @@ -9,6 +9,58 @@ static const int NUM_CHANNELS = 6; static const int BLOCK_SIZE = 8; +struct GroupBuilder { + + GroupBuilder() { + for (size_t i = 0; i < NUM_CHANNELS; i += 1) { + groupSize[i] = 0; + } + } + + size_t groupSize[NUM_CHANNELS]; + bool isPatched = false; + + bool buildGroups(std::vector *inputs, size_t first, size_t count) { + bool changed = false; + isPatched = false; + size_t activeGroup = 0; + + for (int i = count-1; i >= 0; i -= 1) { + auto patched = (*inputs)[first + i].active; + + activeGroup += 1; + if (!patched) { + changed = changed || groupSize[i] != 0; + groupSize[i] = 0; + } else if (patched) { + isPatched = true; + changed = changed || groupSize[i] != activeGroup; + groupSize[i] = activeGroup; + activeGroup = 0; + } + } + + return changed; + } + + int groupForSegment(int segment) { + int group = 0; + int currentGroupSize = 0; + + for (int i = 0; i < NUM_CHANNELS; i += 1) { + if (currentGroupSize <= 0) { + currentGroupSize = max(1, groupSize[i]); + group = i; + } + + if (segment == i) { + return group; + } + + currentGroupSize -= 1; + } + } +}; struct Stages : Module { enum ParamIds { @@ -33,8 +85,10 @@ struct Stages : Module { }; stages::segment::Configuration configurations[NUM_CHANNELS]; + bool configuration_changed[NUM_CHANNELS]; stages::SegmentGenerator segment_generator[NUM_CHANNELS]; stages::Oscillator oscillator[NUM_CHANNELS]; + bool abloop; // stages::ChainState chain_state; // stages::Settings settings; @@ -44,9 +98,11 @@ struct Stages : Module { // Buffers float envelopeBuffer[NUM_CHANNELS][BLOCK_SIZE] = {}; + float typeLightsBuffer[NUM_CHANNELS][BLOCK_SIZE] = {}; stmlib::GateFlags last_gate_flags[NUM_CHANNELS] = {}; stmlib::GateFlags gate_flags[NUM_CHANNELS][BLOCK_SIZE] = {}; int blockIndex = 0; + GroupBuilder groupBuilder; Stages() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { // chain_state.Init(NULL, NULL); @@ -54,12 +110,14 @@ struct Stages : Module { } void onReset() override { + abloop = false; for (size_t i = 0; i < NUM_CHANNELS; ++i) { segment_generator[i].Init(); oscillator[i].Init(); configurations[i].type = stages::segment::TYPE_RAMP; configurations[i].loop = false; + configuration_changed[i] = true; } } @@ -103,21 +161,52 @@ struct Stages : Module { secondaries[i] = params[SHAPE_PARAMS + i].value; } - // // Get patched state - // for (int i = 0; i < NUM_CHANNELS; i++) { - // bool p = inputs[GATE_INPUTS + i].active; - // if (p != patched[i]) - // dirty_configurations[i] = true; - // patched[i] = p; - // } + // See if the group associations have changed since the last group + auto groups_changed = groupBuilder.buildGroups(&inputs, GATE_INPUTS, NUM_CHANNELS); // Process block stages::SegmentGenerator::Output out[BLOCK_SIZE] = {}; - for (int i = 0; i < NUM_CHANNELS; i++) { + for (int i = 0; i < NUM_CHANNELS;) { + + // Check if the config needs applying to the segment generator for this group + bool segment_changed = groups_changed; + int numberOfLoops = 0; + for (size_t j = 0; j < max(1, groupBuilder.groupSize[i]); j += 1) { + numberOfLoops += configurations[i + j].loop ? 1 : 0; + segment_changed |= configuration_changed[i + j]; + configuration_changed[i + j] = false; + } + + if (segment_changed) { + if (numberOfLoops > 2) { + for (size_t j = 0; j < max(1, groupBuilder.groupSize[i]); j += 1) { + configurations[i + j].loop = false; + } + } + segment_generator[i].Configure(groupBuilder.groupSize[i] > 0, &configurations[i], max(1, groupBuilder.groupSize[i])); + } + + // Set the segment parameters on the generator we're about to process + for (size_t j = 0; j < segment_generator[i].num_segments(); j += 1) { + segment_generator[i].set_segment_parameters(j, primaries[i + j], secondaries[i + j]); + + oscillator[i + j].Render( + 0.00001f, 0.5f, typeLightsBuffer[i + j], BLOCK_SIZE + ); + } + bool led_state = segment_generator[i].Process(gate_flags[i], out, BLOCK_SIZE); + + // Set the outputs for the active segment in each output sample + // All outputs also go to the first segment for (int j = 0; j < BLOCK_SIZE; j++) { + for (int k = 1; k < segment_generator[i].num_segments(); k += 1) { + envelopeBuffer[i + k][j] = k == out[j].segment ? out[j].value : 0.f; + } envelopeBuffer[i][j] = out[j].value; } + + i += segment_generator[i].num_segments(); } } @@ -125,16 +214,50 @@ struct Stages : Module { // Buttons for (int i = 0; i < NUM_CHANNELS; i++) { bool pressed = params[TYPE_PARAMS + i].value > 0.f; - if (pressed) { + if (pressed && pressedTime >= 0.f) { pressedTime += engineGetSampleTime(); - } - // Check if released - if (typeTriggers[i].process(!pressed)) { if (pressedTime >= 1.f) { + pressedTime = -1.f; + configuration_changed[i] = true; configurations[i].loop = !configurations[i].loop; + + // ensure that we're the only loop item in the group + if (configurations[i].loop) { + int group = groupBuilder.groupForSegment(i); + + if (abloop) { + // See how many loop items we have + int loopitems = 0; + + for (int j = 0; j < groupBuilder.groupSize[group]; j += 1) { + loopitems += configurations[group + j].loop ? 1 : 0; + } + + // Turn abloop off if we've got 2 or more loops + if (loopitems >= 2) { + abloop = false; + } + + // If we've got >2 loops, clear down to the one loop + if (loopitems > 2) { + for (int j = 0; j < groupBuilder.groupSize[group]; j += 1) { + configurations[group + j].loop = (group + j) == i; + } + } + } else { + for (int j = 0; j < groupBuilder.groupSize[group]; j += 1) { + configurations[group + j].loop = (group + j) == i; + } + } + } } - else { + } + + // Check if released + if (typeTriggers[i].process(!pressed)) { + if (pressedTime >= 0.f) { configurations[i].type = (stages::segment::Type) ((configurations[i].type + 1) % 3); + configuration_changed[i] = true; } pressedTime = 0.f; } @@ -154,13 +277,32 @@ struct Stages : Module { } // Output + int group = 0; + int currentGroupSize = 0; + int loopcount = 0; for (int i = 0; i < NUM_CHANNELS; i++) { float envelope = envelopeBuffer[i][blockIndex]; outputs[ENVELOPE_OUTPUTS + i].value = envelope * 10.f; lights[ENVELOPE_LIGHTS + i].setBrightnessSmooth(envelope); - lights[TYPE_LIGHTS + i*2 + 0].setBrightness(configurations[i].type == 0 || configurations[i].type == 1); - lights[TYPE_LIGHTS + i*2 + 1].setBrightness(configurations[i].type == 1 || configurations[i].type == 2); + if (currentGroupSize <= 0) { + currentGroupSize = max(1, groupBuilder.groupSize[i]); + group = i; + loopcount = 0; + } + currentGroupSize -= 1; + + loopcount += configurations[i].loop ? 1 : 0; + if (!configurations[i].loop) { + lights[TYPE_LIGHTS + i*2 + 0].setBrightness(configurations[i].type == 0 || configurations[i].type == 1); + lights[TYPE_LIGHTS + i*2 + 1].setBrightness(configurations[i].type == 1 || configurations[i].type == 2); + } else if (configurations[i].loop && loopcount == 1) { + lights[TYPE_LIGHTS + i*2 + 0].setBrightness((configurations[i].type == 0 || configurations[i].type == 1) * abs(typeLightsBuffer[i][blockIndex])); + lights[TYPE_LIGHTS + i*2 + 1].setBrightness((configurations[i].type == 1 || configurations[i].type == 2) * abs(typeLightsBuffer[i][blockIndex])); + } else { + lights[TYPE_LIGHTS + i*2 + 0].setBrightness((configurations[i].type == 0 || configurations[i].type == 1) * (1.f - abs(typeLightsBuffer[i][blockIndex]))); + lights[TYPE_LIGHTS + i*2 + 1].setBrightness((configurations[i].type == 1 || configurations[i].type == 2) * (1.f - abs(typeLightsBuffer[i][blockIndex]))); + } } } }; @@ -227,6 +369,22 @@ struct StagesWidget : ModuleWidget { addChild(ModuleLightWidget::create>(mm2px(Vec(48.07649, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 4)); addChild(ModuleLightWidget::create>(mm2px(Vec(59.51696, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 5)); } + + void appendContextMenu(Menu *menu) override { + Stages *module = dynamic_cast(this->module); + + struct ABLoopItem : MenuItem { + Stages *module; + void onAction(EventAction &e) override { + module->abloop = true; + } + }; + + menu->addChild(MenuEntry::create()); + ABLoopItem *abloopItem = MenuItem::create("Set A/B Loop", CHECKMARK(module->abloop)); + abloopItem->module = module; + menu->addChild(abloopItem); + } }; From 32aa9a15eb8fa40242018353c3c3e5114b00f4aa Mon Sep 17 00:00:00 2001 From: Jim Tupper Date: Tue, 2 Oct 2018 00:48:46 +0100 Subject: [PATCH 2/9] Allow varying sample rate --- eurorack | 2 +- src/Stages.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/eurorack b/eurorack index e9aac2a..041b005 160000 --- a/eurorack +++ b/eurorack @@ -1 +1 @@ -Subproject commit e9aac2ab705e7b7e902b43a1bbd9e01d25cd42a2 +Subproject commit 041b00526bbffd8fa59d4b08f8a43238e8437b16 diff --git a/src/Stages.cpp b/src/Stages.cpp index 3c8f2b5..e653fbc 100644 --- a/src/Stages.cpp +++ b/src/Stages.cpp @@ -110,7 +110,10 @@ struct Stages : Module { } void onReset() override { + stages::kSampleRate = engineGetSampleRate(); + abloop = false; + for (size_t i = 0; i < NUM_CHANNELS; ++i) { segment_generator[i].Init(); oscillator[i].Init(); @@ -152,6 +155,13 @@ struct Stages : Module { } } + void onSampleRateChange() override { + stages::kSampleRate = engineGetSampleRate(); + for (int i = 0; i < NUM_CHANNELS; i++) { + // segment_generator[i].InitRamps(); + } + } + void stepBlock() { // Get parameters float primaries[NUM_CHANNELS]; @@ -282,7 +292,7 @@ struct Stages : Module { int loopcount = 0; for (int i = 0; i < NUM_CHANNELS; i++) { float envelope = envelopeBuffer[i][blockIndex]; - outputs[ENVELOPE_OUTPUTS + i].value = envelope * 10.f; + outputs[ENVELOPE_OUTPUTS + i].value = envelope * 8.f; lights[ENVELOPE_LIGHTS + i].setBrightnessSmooth(envelope); if (currentGroupSize <= 0) { From d9434e41c97ead49a58a54799a8c69d8a72401de Mon Sep 17 00:00:00 2001 From: Jim Tupper Date: Tue, 2 Oct 2018 00:51:11 +0100 Subject: [PATCH 3/9] Sending input CV to the correct segments --- src/Stages.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stages.cpp b/src/Stages.cpp index e653fbc..71910c2 100644 --- a/src/Stages.cpp +++ b/src/Stages.cpp @@ -167,7 +167,7 @@ struct Stages : Module { float primaries[NUM_CHANNELS]; float secondaries[NUM_CHANNELS]; for (int i = 0; i < NUM_CHANNELS; i++) { - primaries[i] = clamp(params[LEVEL_PARAMS + i].value + inputs[LEVEL_INPUTS].value / 8.f, 0.f, 1.f); + primaries[i] = clamp(params[LEVEL_PARAMS + i].value + inputs[LEVEL_INPUTS + i].value / 8.f, 0.f, 1.f); secondaries[i] = params[SHAPE_PARAMS + i].value; } From f29754229deadd311ac6987248f707dd6f44d951 Mon Sep 17 00:00:00 2001 From: Jim Tupper Date: Tue, 2 Oct 2018 22:25:29 +0100 Subject: [PATCH 4/9] Breaking long press button functionality out Using simpler sine oscillators for flashing lights that can render with a phase offset. Cleaning up warnings. --- src/Stages.cpp | 182 ++++++++++++++++++++++++++++++------------------- 1 file changed, 113 insertions(+), 69 deletions(-) diff --git a/src/Stages.cpp b/src/Stages.cpp index 71910c2..d20094e 100644 --- a/src/Stages.cpp +++ b/src/Stages.cpp @@ -4,11 +4,66 @@ #include "stages/segment_generator.h" #include "stages/oscillator.h" - // Must match io_buffer.h static const int NUM_CHANNELS = 6; static const int BLOCK_SIZE = 8; +struct SineOscillator { + float phase = 0.f; + + float step(float offset) { + + // Implement a simple sine oscillator + float deltaTime = engineGetSampleTime(); + + float freq = 0.5f; + + // Accumulate the phase + phase += freq * deltaTime; + if (phase >= 1.0f) + phase -= 1.0f; + + // Compute the sine output + float sine = sinf(2.0f * M_PI * (phase + offset)); + return sine; + } +}; + +struct LongPressButton { + + enum Events { + NO_PRESS, + SHORT_PRESS, + LONG_PRESS + }; + + float pressedTime = 0.f; + BooleanTrigger trigger; + + Events step(Param& param) { + auto result = NO_PRESS; + + bool pressed = param.value > 0.f; + if (pressed && pressedTime >= 0.f) { + pressedTime += engineGetSampleTime(); + if (pressedTime >= 1.f) { + pressedTime = -1.f; + result = LONG_PRESS; + } + } + + // Check if released + if (trigger.process(!pressed)) { + if (pressedTime >= 0.f) { + result = SHORT_PRESS; + } + pressedTime = 0.f; + } + + return result; + } +}; + struct GroupBuilder { GroupBuilder() { @@ -59,6 +114,8 @@ struct GroupBuilder { currentGroupSize -= 1; } + + return segment; } }; @@ -87,18 +144,16 @@ struct Stages : Module { stages::segment::Configuration configurations[NUM_CHANNELS]; bool configuration_changed[NUM_CHANNELS]; stages::SegmentGenerator segment_generator[NUM_CHANNELS]; - stages::Oscillator oscillator[NUM_CHANNELS]; + SineOscillator oscillator[NUM_CHANNELS]; bool abloop; // stages::ChainState chain_state; // stages::Settings settings; // Buttons - BooleanTrigger typeTriggers[NUM_CHANNELS]; - float pressedTime = 0.f; + LongPressButton typeButtons[NUM_CHANNELS]; // Buffers float envelopeBuffer[NUM_CHANNELS][BLOCK_SIZE] = {}; - float typeLightsBuffer[NUM_CHANNELS][BLOCK_SIZE] = {}; stmlib::GateFlags last_gate_flags[NUM_CHANNELS] = {}; stmlib::GateFlags gate_flags[NUM_CHANNELS][BLOCK_SIZE] = {}; int blockIndex = 0; @@ -116,7 +171,6 @@ struct Stages : Module { for (size_t i = 0; i < NUM_CHANNELS; ++i) { segment_generator[i].Init(); - oscillator[i].Init(); configurations[i].type = stages::segment::TYPE_RAMP; configurations[i].loop = false; @@ -181,7 +235,7 @@ struct Stages : Module { // Check if the config needs applying to the segment generator for this group bool segment_changed = groups_changed; int numberOfLoops = 0; - for (size_t j = 0; j < max(1, groupBuilder.groupSize[i]); j += 1) { + for (int j = 0; j < max(1, groupBuilder.groupSize[i]); j += 1) { numberOfLoops += configurations[i + j].loop ? 1 : 0; segment_changed |= configuration_changed[i + j]; configuration_changed[i + j] = false; @@ -189,7 +243,7 @@ struct Stages : Module { if (segment_changed) { if (numberOfLoops > 2) { - for (size_t j = 0; j < max(1, groupBuilder.groupSize[i]); j += 1) { + for (int j = 0; j < max(1, groupBuilder.groupSize[i]); j += 1) { configurations[i + j].loop = false; } } @@ -197,15 +251,11 @@ struct Stages : Module { } // Set the segment parameters on the generator we're about to process - for (size_t j = 0; j < segment_generator[i].num_segments(); j += 1) { + for (int j = 0; j < segment_generator[i].num_segments(); j += 1) { segment_generator[i].set_segment_parameters(j, primaries[i + j], secondaries[i + j]); - - oscillator[i + j].Render( - 0.00001f, 0.5f, typeLightsBuffer[i + j], BLOCK_SIZE - ); } - bool led_state = segment_generator[i].Process(gate_flags[i], out, BLOCK_SIZE); + segment_generator[i].Process(gate_flags[i], out, BLOCK_SIZE); // Set the outputs for the active segment in each output sample // All outputs also go to the first segment @@ -220,56 +270,49 @@ struct Stages : Module { } } - void step() override { - // Buttons - for (int i = 0; i < NUM_CHANNELS; i++) { - bool pressed = params[TYPE_PARAMS + i].value > 0.f; - if (pressed && pressedTime >= 0.f) { - pressedTime += engineGetSampleTime(); - if (pressedTime >= 1.f) { - pressedTime = -1.f; - configuration_changed[i] = true; - configurations[i].loop = !configurations[i].loop; - - // ensure that we're the only loop item in the group - if (configurations[i].loop) { - int group = groupBuilder.groupForSegment(i); - - if (abloop) { - // See how many loop items we have - int loopitems = 0; - - for (int j = 0; j < groupBuilder.groupSize[group]; j += 1) { - loopitems += configurations[group + j].loop ? 1 : 0; - } - - // Turn abloop off if we've got 2 or more loops - if (loopitems >= 2) { - abloop = false; - } - - // If we've got >2 loops, clear down to the one loop - if (loopitems > 2) { - for (int j = 0; j < groupBuilder.groupSize[group]; j += 1) { - configurations[group + j].loop = (group + j) == i; - } - } - } else { - for (int j = 0; j < groupBuilder.groupSize[group]; j += 1) { - configurations[group + j].loop = (group + j) == i; - } - } - } - } + void toggleMode(int i) { + configurations[i].type = (stages::segment::Type) ((configurations[i].type + 1) % 3); + configuration_changed[i] = true; + } + + void toggleLoop(int i) { + configuration_changed[i] = true; + configurations[i].loop = !configurations[i].loop; + + // ensure that we're the only loop item in the group + if (configurations[i].loop) { + int group = groupBuilder.groupForSegment(i); + + // See how many loop items we have + int loopitems = 0; + + for (size_t j = 0; j < groupBuilder.groupSize[group]; j += 1) { + loopitems += configurations[group + j].loop ? 1 : 0; } - // Check if released - if (typeTriggers[i].process(!pressed)) { - if (pressedTime >= 0.f) { - configurations[i].type = (stages::segment::Type) ((configurations[i].type + 1) % 3); - configuration_changed[i] = true; + // If we've got too many loop items, clear down to the one loop + if ((abloop && loopitems > 2) || (!abloop && loopitems > 1)) { + for (size_t j = 0; j < groupBuilder.groupSize[group]; j += 1) { + configurations[group + j].loop = (group + (int)j) == i; } - pressedTime = 0.f; + loopitems = 1; + } + + // Turn abloop off if we've got 2 or more loops + if (loopitems >= 2) { + abloop = false; + } + } + } + + void step() override { + // Buttons + for (int i = 0; i < NUM_CHANNELS; i++) { + switch (typeButtons[i].step(params[TYPE_PARAMS + i])) { + default: + case LongPressButton::NO_PRESS: break; + case LongPressButton::SHORT_PRESS: toggleMode(i); break; + case LongPressButton::LONG_PRESS: toggleLoop(i); break; } } @@ -287,7 +330,6 @@ struct Stages : Module { } // Output - int group = 0; int currentGroupSize = 0; int loopcount = 0; for (int i = 0; i < NUM_CHANNELS; i++) { @@ -297,22 +339,24 @@ struct Stages : Module { if (currentGroupSize <= 0) { currentGroupSize = max(1, groupBuilder.groupSize[i]); - group = i; loopcount = 0; } currentGroupSize -= 1; loopcount += configurations[i].loop ? 1 : 0; + auto flashlevel = 1.f; + if (!configurations[i].loop) { - lights[TYPE_LIGHTS + i*2 + 0].setBrightness(configurations[i].type == 0 || configurations[i].type == 1); - lights[TYPE_LIGHTS + i*2 + 1].setBrightness(configurations[i].type == 1 || configurations[i].type == 2); + oscillator[i].step(0.f); // move the oscillator on to keep the lights in sync } else if (configurations[i].loop && loopcount == 1) { - lights[TYPE_LIGHTS + i*2 + 0].setBrightness((configurations[i].type == 0 || configurations[i].type == 1) * abs(typeLightsBuffer[i][blockIndex])); - lights[TYPE_LIGHTS + i*2 + 1].setBrightness((configurations[i].type == 1 || configurations[i].type == 2) * abs(typeLightsBuffer[i][blockIndex])); + flashlevel = abs(oscillator[i].step(0.f)); } else { - lights[TYPE_LIGHTS + i*2 + 0].setBrightness((configurations[i].type == 0 || configurations[i].type == 1) * (1.f - abs(typeLightsBuffer[i][blockIndex]))); - lights[TYPE_LIGHTS + i*2 + 1].setBrightness((configurations[i].type == 1 || configurations[i].type == 2) * (1.f - abs(typeLightsBuffer[i][blockIndex]))); + flashlevel = 1 - abs(oscillator[i].step(0.0625f)); } + + lights[TYPE_LIGHTS + i*2 + 0].setBrightness((configurations[i].type == 0 || configurations[i].type == 1) * flashlevel); + lights[TYPE_LIGHTS + i*2 + 1].setBrightness((configurations[i].type == 1 || configurations[i].type == 2) * flashlevel); + } } }; From 55d7087daaa321262f15fd9e9f67cdb873835ff8 Mon Sep 17 00:00:00 2001 From: Jim Tupper Date: Tue, 2 Oct 2018 22:26:32 +0100 Subject: [PATCH 5/9] Fixing panel size to 14hp or 71.12mm --- res/Stages.svg | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/res/Stages.svg b/res/Stages.svg index 8e40025..4518a1a 100644 --- a/res/Stages.svg +++ b/res/Stages.svg @@ -10,9 +10,9 @@ xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="70.887665mm" + width="71.120003mm" height="128.5889mm" - viewBox="0 0 70.887665 128.5889" + viewBox="0 0 71.120003 128.5889" version="1.1" id="svg1428" inkscape:version="0.92.2 2405546, 2018-03-11" @@ -1173,11 +1173,11 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="0.98994949" - inkscape:cx="191.99827" - inkscape:cy="232.47187" + inkscape:zoom="5.6" + inkscape:cx="149.63939" + inkscape:cy="511.43702" inkscape:document-units="mm" - inkscape:current-layer="layer2" + inkscape:current-layer="layer1" showgrid="false" fit-margin-top="0" fit-margin-left="0" @@ -1186,7 +1186,7 @@ inkscape:window-width="1600" inkscape:window-height="882" inkscape:window-x="0" - inkscape:window-y="18" + inkscape:window-y="27" inkscape:window-maximized="0" inkscape:snap-bbox="true" inkscape:snap-bbox-midpoints="false" @@ -1194,7 +1194,8 @@ inkscape:snap-page="true" inkscape:bbox-nodes="true" inkscape:snap-bbox-edge-midpoints="true" - inkscape:bbox-paths="true" /> + inkscape:bbox-paths="true" + units="mm" /> @@ -1213,11 +1214,11 @@ id="layer1" transform="translate(0.04409722,-168.45588)"> Date: Tue, 2 Oct 2018 22:52:44 +0100 Subject: [PATCH 6/9] Re-initializing ramp generators when sample rate changes --- eurorack | 2 +- src/Stages.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eurorack b/eurorack index 041b005..f8d34c2 160000 --- a/eurorack +++ b/eurorack @@ -1 +1 @@ -Subproject commit 041b00526bbffd8fa59d4b08f8a43238e8437b16 +Subproject commit f8d34c206da458e4d8708df2cc94064826d975ff diff --git a/src/Stages.cpp b/src/Stages.cpp index d20094e..a1545a6 100644 --- a/src/Stages.cpp +++ b/src/Stages.cpp @@ -212,7 +212,7 @@ struct Stages : Module { void onSampleRateChange() override { stages::kSampleRate = engineGetSampleRate(); for (int i = 0; i < NUM_CHANNELS; i++) { - // segment_generator[i].InitRamps(); + segment_generator[i].InitRamps(); } } From 7279f7391dbdb7eb7bffc16c8b0d66d20ca2dbee Mon Sep 17 00:00:00 2001 From: Jim Tupper Date: Tue, 2 Oct 2018 23:07:41 +0100 Subject: [PATCH 7/9] Fixing up alternate light flashing lights Was abusing legacy match from when using a triangle oscillator for the light levels --- src/Stages.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stages.cpp b/src/Stages.cpp index a1545a6..d30751e 100644 --- a/src/Stages.cpp +++ b/src/Stages.cpp @@ -351,7 +351,7 @@ struct Stages : Module { } else if (configurations[i].loop && loopcount == 1) { flashlevel = abs(oscillator[i].step(0.f)); } else { - flashlevel = 1 - abs(oscillator[i].step(0.0625f)); + flashlevel = abs(oscillator[i].step(0.25f)); } lights[TYPE_LIGHTS + i*2 + 0].setBrightness((configurations[i].type == 0 || configurations[i].type == 1) * flashlevel); From bcc460848a55a401ccc2709c484b04afaecad4b3 Mon Sep 17 00:00:00 2001 From: Jim Tupper Date: Wed, 3 Oct 2018 19:49:24 +0100 Subject: [PATCH 8/9] Changing individual segment output to be the inverse of the phase, which seems to match up more with the Stages manual --- src/Stages.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stages.cpp b/src/Stages.cpp index d30751e..9f86ded 100644 --- a/src/Stages.cpp +++ b/src/Stages.cpp @@ -261,7 +261,7 @@ struct Stages : Module { // All outputs also go to the first segment for (int j = 0; j < BLOCK_SIZE; j++) { for (int k = 1; k < segment_generator[i].num_segments(); k += 1) { - envelopeBuffer[i + k][j] = k == out[j].segment ? out[j].value : 0.f; + envelopeBuffer[i + k][j] = k == out[j].segment ? 1- out[j].phase : 0.f; } envelopeBuffer[i][j] = out[j].value; } From c575b8abeb9d28758cddc1af14ade1dd7fc5df90 Mon Sep 17 00:00:00 2001 From: Jim Tupper Date: Thu, 4 Oct 2018 23:20:53 +0100 Subject: [PATCH 9/9] Adding multi-width capability to segment generator --- res/Stages.svg | 11968 ++++++++++++++++++++++++++++++++++++++++++++--- src/Stages.cpp | 268 +- 2 files changed, 11589 insertions(+), 647 deletions(-) diff --git a/res/Stages.svg b/res/Stages.svg index 4518a1a..2bcb9e9 100644 --- a/res/Stages.svg +++ b/res/Stages.svg @@ -10,9 +10,9 @@ xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="71.120003mm" + width="426.72mm" height="128.5889mm" - viewBox="0 0 71.120003 128.5889" + viewBox="0 0 426.72 128.5889" version="1.1" id="svg1428" inkscape:version="0.92.2 2405546, 2018-03-11" @@ -1165,6 +1165,3444 @@ width="179.20599" y="23.478001" id="rect11797" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id="background-0" /> + id="g8152-3" + transform="matrix(0.33866667,0,0,0.33866667,436.95688,169.57609)"> + id="defs7957-8"> + id="rect5791" /> + id="clipPath10802-5"> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> + clip-path="url(#SVGID_2_-4)" /> *inputs, size_t first, size_t count) { @@ -102,7 +103,7 @@ struct GroupBuilder { int group = 0; int currentGroupSize = 0; - for (int i = 0; i < NUM_CHANNELS; i += 1) { + for (int i = 0; i < NUM_CHANNELS * MAX_MODULES; i += 1) { if (currentGroupSize <= 0) { currentGroupSize = max(1, groupSize[i]); group = i; @@ -121,41 +122,43 @@ struct GroupBuilder { struct Stages : Module { enum ParamIds { - ENUMS(SHAPE_PARAMS, NUM_CHANNELS), - ENUMS(TYPE_PARAMS, NUM_CHANNELS), - ENUMS(LEVEL_PARAMS, NUM_CHANNELS), + ENUMS(SHAPE_PARAMS, NUM_CHANNELS*MAX_MODULES), + ENUMS(TYPE_PARAMS, NUM_CHANNELS*MAX_MODULES), + ENUMS(LEVEL_PARAMS, NUM_CHANNELS*MAX_MODULES), NUM_PARAMS }; enum InputIds { - ENUMS(LEVEL_INPUTS, NUM_CHANNELS), - ENUMS(GATE_INPUTS, NUM_CHANNELS), + ENUMS(LEVEL_INPUTS, NUM_CHANNELS*MAX_MODULES), + ENUMS(GATE_INPUTS, NUM_CHANNELS*MAX_MODULES), NUM_INPUTS }; enum OutputIds { - ENUMS(ENVELOPE_OUTPUTS, NUM_CHANNELS), + ENUMS(ENVELOPE_OUTPUTS, NUM_CHANNELS*MAX_MODULES), NUM_OUTPUTS }; enum LightIds { - ENUMS(TYPE_LIGHTS, NUM_CHANNELS*2), - ENUMS(ENVELOPE_LIGHTS, NUM_CHANNELS), + ENUMS(TYPE_LIGHTS, NUM_CHANNELS*2*MAX_MODULES), + ENUMS(ENVELOPE_LIGHTS, NUM_CHANNELS*MAX_MODULES), NUM_LIGHTS }; - stages::segment::Configuration configurations[NUM_CHANNELS]; - bool configuration_changed[NUM_CHANNELS]; - stages::SegmentGenerator segment_generator[NUM_CHANNELS]; - SineOscillator oscillator[NUM_CHANNELS]; + int numModules = 1; + + stages::segment::Configuration configurations[NUM_CHANNELS*MAX_MODULES]; + bool configuration_changed[NUM_CHANNELS*MAX_MODULES]; + stages::SegmentGenerator segment_generator[NUM_CHANNELS*MAX_MODULES]; + SineOscillator oscillator[NUM_CHANNELS*MAX_MODULES]; bool abloop; // stages::ChainState chain_state; // stages::Settings settings; // Buttons - LongPressButton typeButtons[NUM_CHANNELS]; + LongPressButton typeButtons[NUM_CHANNELS*MAX_MODULES]; // Buffers - float envelopeBuffer[NUM_CHANNELS][BLOCK_SIZE] = {}; - stmlib::GateFlags last_gate_flags[NUM_CHANNELS] = {}; - stmlib::GateFlags gate_flags[NUM_CHANNELS][BLOCK_SIZE] = {}; + float envelopeBuffer[NUM_CHANNELS*MAX_MODULES][BLOCK_SIZE] = {}; + stmlib::GateFlags last_gate_flags[NUM_CHANNELS*MAX_MODULES] = {}; + stmlib::GateFlags gate_flags[NUM_CHANNELS*MAX_MODULES][BLOCK_SIZE] = {}; int blockIndex = 0; GroupBuilder groupBuilder; @@ -169,7 +172,7 @@ struct Stages : Module { abloop = false; - for (size_t i = 0; i < NUM_CHANNELS; ++i) { + for (size_t i = 0; i < NUM_CHANNELS*MAX_MODULES; ++i) { segment_generator[i].Init(); configurations[i].type = stages::segment::TYPE_RAMP; @@ -181,8 +184,10 @@ struct Stages : Module { json_t *toJson() override { json_t *rootJ = json_object(); + json_object_set_new(rootJ, "numModules", json_integer(numModules)); + json_t *configurationsJ = json_array(); - for (int i = 0; i < NUM_CHANNELS; i++) { + for (int i = 0; i < NUM_CHANNELS*MAX_MODULES; i++) { json_t *configurationJ = json_object(); json_object_set_new(configurationJ, "type", json_integer(configurations[i].type)); json_object_set_new(configurationJ, "loop", json_boolean(configurations[i].loop)); @@ -194,8 +199,12 @@ struct Stages : Module { } void fromJson(json_t *rootJ) override { + json_t *numModulesJ = json_object_get(rootJ, "numModules"); + if (numModulesJ) + numModules = json_integer_value(numModulesJ); + json_t *configurationsJ = json_object_get(rootJ, "configurations"); - for (int i = 0; i < NUM_CHANNELS; i++) { + for (int i = 0; i < NUM_CHANNELS*MAX_MODULES; i++) { json_t *configurationJ = json_array_get(configurationsJ, i); if (configurationJ) { json_t *typeJ = json_object_get(configurationJ, "type"); @@ -211,26 +220,26 @@ struct Stages : Module { void onSampleRateChange() override { stages::kSampleRate = engineGetSampleRate(); - for (int i = 0; i < NUM_CHANNELS; i++) { + for (int i = 0; i < NUM_CHANNELS*MAX_MODULES; i++) { segment_generator[i].InitRamps(); } } void stepBlock() { // Get parameters - float primaries[NUM_CHANNELS]; - float secondaries[NUM_CHANNELS]; - for (int i = 0; i < NUM_CHANNELS; i++) { + float primaries[NUM_CHANNELS*numModules]; + float secondaries[NUM_CHANNELS*numModules]; + for (int i = 0; i < NUM_CHANNELS*numModules; i++) { primaries[i] = clamp(params[LEVEL_PARAMS + i].value + inputs[LEVEL_INPUTS + i].value / 8.f, 0.f, 1.f); secondaries[i] = params[SHAPE_PARAMS + i].value; } // See if the group associations have changed since the last group - auto groups_changed = groupBuilder.buildGroups(&inputs, GATE_INPUTS, NUM_CHANNELS); + auto groups_changed = groupBuilder.buildGroups(&inputs, GATE_INPUTS, NUM_CHANNELS * numModules); // Process block stages::SegmentGenerator::Output out[BLOCK_SIZE] = {}; - for (int i = 0; i < NUM_CHANNELS;) { + for (int i = 0; i < NUM_CHANNELS*numModules;) { // Check if the config needs applying to the segment generator for this group bool segment_changed = groups_changed; @@ -307,7 +316,7 @@ struct Stages : Module { void step() override { // Buttons - for (int i = 0; i < NUM_CHANNELS; i++) { + for (int i = 0; i < NUM_CHANNELS * numModules; i++) { switch (typeButtons[i].step(params[TYPE_PARAMS + i])) { default: case LongPressButton::NO_PRESS: break; @@ -317,7 +326,7 @@ struct Stages : Module { } // Input - for (int i = 0; i < NUM_CHANNELS; i++) { + for (int i = 0; i < NUM_CHANNELS * numModules; i++) { bool gate = (inputs[GATE_INPUTS + i].value >= 1.7f); last_gate_flags[i] = stmlib::ExtractGateFlags(last_gate_flags[i], gate); gate_flags[i][blockIndex] = last_gate_flags[i]; @@ -332,7 +341,7 @@ struct Stages : Module { // Output int currentGroupSize = 0; int loopcount = 0; - for (int i = 0; i < NUM_CHANNELS; i++) { + for (int i = 0; i < NUM_CHANNELS * numModules; i++) { float envelope = envelopeBuffer[i][blockIndex]; outputs[ENVELOPE_OUTPUTS + i].value = envelope * 8.f; lights[ENVELOPE_LIGHTS + i].setBrightnessSmooth(envelope); @@ -363,65 +372,118 @@ struct Stages : Module { struct StagesWidget : ModuleWidget { + + Stages* module; + int lastNumModules = 1; + + Widget* topLeftScrew; + Widget* topRightScrew; + Widget* bottomLeftScrew; + Widget* bottomRightScrew; + StagesWidget(Stages *module) : ModuleWidget(module) { + this->module = module; setPanel(SVG::load(assetPlugin(plugin, "res/Stages.svg"))); - addChild(Widget::create(Vec(RACK_GRID_WIDTH, 0))); - addChild(Widget::create(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); - addChild(Widget::create(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); - addChild(Widget::create(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); - - addParam(ParamWidget::create(mm2px(Vec(3.72965, 13.98158)), module, Stages::SHAPE_PARAMS + 0, 0.0, 1.0, 0.5)); - addParam(ParamWidget::create(mm2px(Vec(15.17012, 13.98158)), module, Stages::SHAPE_PARAMS + 1, 0.0, 1.0, 0.5)); - addParam(ParamWidget::create(mm2px(Vec(26.6099, 13.98158)), module, Stages::SHAPE_PARAMS + 2, 0.0, 1.0, 0.5)); - addParam(ParamWidget::create(mm2px(Vec(38.07174, 13.98158)), module, Stages::SHAPE_PARAMS + 3, 0.0, 1.0, 0.5)); - addParam(ParamWidget::create(mm2px(Vec(49.51152, 13.98158)), module, Stages::SHAPE_PARAMS + 4, 0.0, 1.0, 0.5)); - addParam(ParamWidget::create(mm2px(Vec(60.95199, 13.98158)), module, Stages::SHAPE_PARAMS + 5, 0.0, 1.0, 0.5)); - addParam(ParamWidget::create(mm2px(Vec(4.17259, 32.37248)), module, Stages::TYPE_PARAMS + 0, 0.0, 1.0, 0.0)); - addParam(ParamWidget::create(mm2px(Vec(15.61237, 32.37248)), module, Stages::TYPE_PARAMS + 1, 0.0, 1.0, 0.0)); - addParam(ParamWidget::create(mm2px(Vec(27.05284, 32.37248)), module, Stages::TYPE_PARAMS + 2, 0.0, 1.0, 0.0)); - addParam(ParamWidget::create(mm2px(Vec(38.51399, 32.37248)), module, Stages::TYPE_PARAMS + 3, 0.0, 1.0, 0.0)); - addParam(ParamWidget::create(mm2px(Vec(49.95446, 32.37248)), module, Stages::TYPE_PARAMS + 4, 0.0, 1.0, 0.0)); - addParam(ParamWidget::create(mm2px(Vec(61.39424, 32.37248)), module, Stages::TYPE_PARAMS + 5, 0.0, 1.0, 0.0)); - addParam(ParamWidget::create(mm2px(Vec(3.36193, 43.06508)), module, Stages::LEVEL_PARAMS + 0, 0.0, 1.0, 1.0)); - addParam(ParamWidget::create(mm2px(Vec(14.81619, 43.06508)), module, Stages::LEVEL_PARAMS + 1, 0.0, 1.0, 1.0)); - addParam(ParamWidget::create(mm2px(Vec(26.26975, 43.06508)), module, Stages::LEVEL_PARAMS + 2, 0.0, 1.0, 1.0)); - addParam(ParamWidget::create(mm2px(Vec(37.70265, 43.06508)), module, Stages::LEVEL_PARAMS + 3, 0.0, 1.0, 1.0)); - addParam(ParamWidget::create(mm2px(Vec(49.15759, 43.06508)), module, Stages::LEVEL_PARAMS + 4, 0.0, 1.0, 1.0)); - addParam(ParamWidget::create(mm2px(Vec(60.61184, 43.06508)), module, Stages::LEVEL_PARAMS + 5, 0.0, 1.0, 1.0)); - - addInput(Port::create(mm2px(Vec(2.70756, 77.75277)), Port::INPUT, module, Stages::LEVEL_INPUTS + 0)); - addInput(Port::create(mm2px(Vec(14.14734, 77.75277)), Port::INPUT, module, Stages::LEVEL_INPUTS + 1)); - addInput(Port::create(mm2px(Vec(25.58781, 77.75277)), Port::INPUT, module, Stages::LEVEL_INPUTS + 2)); - addInput(Port::create(mm2px(Vec(37.04896, 77.75277)), Port::INPUT, module, Stages::LEVEL_INPUTS + 3)); - addInput(Port::create(mm2px(Vec(48.48943, 77.75277)), Port::INPUT, module, Stages::LEVEL_INPUTS + 4)); - addInput(Port::create(mm2px(Vec(59.92921, 77.75277)), Port::INPUT, module, Stages::LEVEL_INPUTS + 5)); - addInput(Port::create(mm2px(Vec(2.70756, 92.35239)), Port::INPUT, module, Stages::GATE_INPUTS + 0)); - addInput(Port::create(mm2px(Vec(14.14734, 92.35239)), Port::INPUT, module, Stages::GATE_INPUTS + 1)); - addInput(Port::create(mm2px(Vec(25.58781, 92.35239)), Port::INPUT, module, Stages::GATE_INPUTS + 2)); - addInput(Port::create(mm2px(Vec(37.04896, 92.35239)), Port::INPUT, module, Stages::GATE_INPUTS + 3)); - addInput(Port::create(mm2px(Vec(48.48943, 92.35239)), Port::INPUT, module, Stages::GATE_INPUTS + 4)); - addInput(Port::create(mm2px(Vec(59.92921, 92.35239)), Port::INPUT, module, Stages::GATE_INPUTS + 5)); - - addOutput(Port::create(mm2px(Vec(2.70756, 106.95203)), Port::OUTPUT, module, Stages::ENVELOPE_OUTPUTS + 0)); - addOutput(Port::create(mm2px(Vec(14.14734, 106.95203)), Port::OUTPUT, module, Stages::ENVELOPE_OUTPUTS + 1)); - addOutput(Port::create(mm2px(Vec(25.58781, 106.95203)), Port::OUTPUT, module, Stages::ENVELOPE_OUTPUTS + 2)); - addOutput(Port::create(mm2px(Vec(37.04896, 106.95203)), Port::OUTPUT, module, Stages::ENVELOPE_OUTPUTS + 3)); - addOutput(Port::create(mm2px(Vec(48.48943, 106.95203)), Port::OUTPUT, module, Stages::ENVELOPE_OUTPUTS + 4)); - addOutput(Port::create(mm2px(Vec(59.92921, 106.95203)), Port::OUTPUT, module, Stages::ENVELOPE_OUTPUTS + 5)); - - addChild(ModuleLightWidget::create>(mm2px(Vec(5.27737, 26.74447)), module, Stages::TYPE_LIGHTS + 0*2)); - addChild(ModuleLightWidget::create>(mm2px(Vec(16.73784, 26.74447)), module, Stages::TYPE_LIGHTS + 1*2)); - addChild(ModuleLightWidget::create>(mm2px(Vec(28.1783, 26.74447)), module, Stages::TYPE_LIGHTS + 2*2)); - addChild(ModuleLightWidget::create>(mm2px(Vec(39.61877, 26.74447)), module, Stages::TYPE_LIGHTS + 3*2)); - addChild(ModuleLightWidget::create>(mm2px(Vec(51.07923, 26.74447)), module, Stages::TYPE_LIGHTS + 4*2)); - addChild(ModuleLightWidget::create>(mm2px(Vec(62.51971, 26.74447)), module, Stages::TYPE_LIGHTS + 5*2)); - addChild(ModuleLightWidget::create>(mm2px(Vec(2.29462, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 0)); - addChild(ModuleLightWidget::create>(mm2px(Vec(13.73509, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 1)); - addChild(ModuleLightWidget::create>(mm2px(Vec(25.17556, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 2)); - addChild(ModuleLightWidget::create>(mm2px(Vec(36.63671, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 3)); - addChild(ModuleLightWidget::create>(mm2px(Vec(48.07649, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 4)); - addChild(ModuleLightWidget::create>(mm2px(Vec(59.51696, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 5)); + this->box.size.x = 210 * module->numModules; + this->panel->box.size = this->box.size; + + topLeftScrew = Widget::create(Vec(RACK_GRID_WIDTH, 0)); + topRightScrew = Widget::create(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)); + bottomLeftScrew = Widget::create(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)); + bottomRightScrew = Widget::create(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)); + addChild(topLeftScrew); + addChild(topRightScrew); + addChild(bottomLeftScrew); + addChild(bottomRightScrew); + + for(auto i = 0; i < MAX_MODULES; i += 1) { + float offset = 71.12 * i; + addParam(ParamWidget::create(mm2px(Vec(offset + 3.72965, 13.98158)), module, Stages::SHAPE_PARAMS + 0 + (NUM_CHANNELS*i), 0.0, 1.0, 0.5)); + addParam(ParamWidget::create(mm2px(Vec(offset + 15.17012, 13.98158)), module, Stages::SHAPE_PARAMS + 1 + (NUM_CHANNELS*i), 0.0, 1.0, 0.5)); + addParam(ParamWidget::create(mm2px(Vec(offset + 26.6099, 13.98158)), module, Stages::SHAPE_PARAMS + 2 + (NUM_CHANNELS*i), 0.0, 1.0, 0.5)); + addParam(ParamWidget::create(mm2px(Vec(offset + 38.07174, 13.98158)), module, Stages::SHAPE_PARAMS + 3 + (NUM_CHANNELS*i), 0.0, 1.0, 0.5)); + addParam(ParamWidget::create(mm2px(Vec(offset + 49.51152, 13.98158)), module, Stages::SHAPE_PARAMS + 4 + (NUM_CHANNELS*i), 0.0, 1.0, 0.5)); + addParam(ParamWidget::create(mm2px(Vec(offset + 60.95199, 13.98158)), module, Stages::SHAPE_PARAMS + 5 + (NUM_CHANNELS*i), 0.0, 1.0, 0.5)); + addParam(ParamWidget::create(mm2px(Vec(offset + 4.17259, 32.37248)), module, Stages::TYPE_PARAMS + 0 + (NUM_CHANNELS*i), 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(mm2px(Vec(offset + 15.61237, 32.37248)), module, Stages::TYPE_PARAMS + 1 + (NUM_CHANNELS*i), 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(mm2px(Vec(offset + 27.05284, 32.37248)), module, Stages::TYPE_PARAMS + 2 + (NUM_CHANNELS*i), 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(mm2px(Vec(offset + 38.51399, 32.37248)), module, Stages::TYPE_PARAMS + 3 + (NUM_CHANNELS*i), 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(mm2px(Vec(offset + 49.95446, 32.37248)), module, Stages::TYPE_PARAMS + 4 + (NUM_CHANNELS*i), 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(mm2px(Vec(offset + 61.39424, 32.37248)), module, Stages::TYPE_PARAMS + 5 + (NUM_CHANNELS*i), 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(mm2px(Vec(offset + 3.36193, 43.06508)), module, Stages::LEVEL_PARAMS + 0 + (NUM_CHANNELS*i), 0.0, 1.0, 1.0)); + addParam(ParamWidget::create(mm2px(Vec(offset + 14.81619, 43.06508)), module, Stages::LEVEL_PARAMS + 1 + (NUM_CHANNELS*i), 0.0, 1.0, 1.0)); + addParam(ParamWidget::create(mm2px(Vec(offset + 26.26975, 43.06508)), module, Stages::LEVEL_PARAMS + 2 + (NUM_CHANNELS*i), 0.0, 1.0, 1.0)); + addParam(ParamWidget::create(mm2px(Vec(offset + 37.70265, 43.06508)), module, Stages::LEVEL_PARAMS + 3 + (NUM_CHANNELS*i), 0.0, 1.0, 1.0)); + addParam(ParamWidget::create(mm2px(Vec(offset + 49.15759, 43.06508)), module, Stages::LEVEL_PARAMS + 4 + (NUM_CHANNELS*i), 0.0, 1.0, 1.0)); + addParam(ParamWidget::create(mm2px(Vec(offset + 60.61184, 43.06508)), module, Stages::LEVEL_PARAMS + 5 + (NUM_CHANNELS*i), 0.0, 1.0, 1.0)); + + addInput(Port::create(mm2px(Vec(offset + 2.70756, 77.75277)), Port::INPUT, module, Stages::LEVEL_INPUTS + 0 + (NUM_CHANNELS*i))); + addInput(Port::create(mm2px(Vec(offset + 14.14734, 77.75277)), Port::INPUT, module, Stages::LEVEL_INPUTS + 1 + (NUM_CHANNELS*i))); + addInput(Port::create(mm2px(Vec(offset + 25.58781, 77.75277)), Port::INPUT, module, Stages::LEVEL_INPUTS + 2 + (NUM_CHANNELS*i))); + addInput(Port::create(mm2px(Vec(offset + 37.04896, 77.75277)), Port::INPUT, module, Stages::LEVEL_INPUTS + 3 + (NUM_CHANNELS*i))); + addInput(Port::create(mm2px(Vec(offset + 48.48943, 77.75277)), Port::INPUT, module, Stages::LEVEL_INPUTS + 4 + (NUM_CHANNELS*i))); + addInput(Port::create(mm2px(Vec(offset + 59.92921, 77.75277)), Port::INPUT, module, Stages::LEVEL_INPUTS + 5 + (NUM_CHANNELS*i))); + + addInput(Port::create(mm2px(Vec(offset + 2.70756, 92.35239)), Port::INPUT, module, Stages::GATE_INPUTS + 0 + (NUM_CHANNELS*i))); + addInput(Port::create(mm2px(Vec(offset + 14.14734, 92.35239)), Port::INPUT, module, Stages::GATE_INPUTS + 1 + (NUM_CHANNELS*i))); + addInput(Port::create(mm2px(Vec(offset + 25.58781, 92.35239)), Port::INPUT, module, Stages::GATE_INPUTS + 2 + (NUM_CHANNELS*i))); + addInput(Port::create(mm2px(Vec(offset + 37.04896, 92.35239)), Port::INPUT, module, Stages::GATE_INPUTS + 3 + (NUM_CHANNELS*i))); + addInput(Port::create(mm2px(Vec(offset + 48.48943, 92.35239)), Port::INPUT, module, Stages::GATE_INPUTS + 4 + (NUM_CHANNELS*i))); + addInput(Port::create(mm2px(Vec(offset + 59.92921, 92.35239)), Port::INPUT, module, Stages::GATE_INPUTS + 5 + (NUM_CHANNELS*i))); + + addOutput(Port::create(mm2px(Vec(offset + 2.70756, 106.95203)), Port::OUTPUT, module, Stages::ENVELOPE_OUTPUTS + 0 + (NUM_CHANNELS*i))); + addOutput(Port::create(mm2px(Vec(offset + 14.14734, 106.95203)), Port::OUTPUT, module, Stages::ENVELOPE_OUTPUTS + 1 + (NUM_CHANNELS*i))); + addOutput(Port::create(mm2px(Vec(offset + 25.58781, 106.95203)), Port::OUTPUT, module, Stages::ENVELOPE_OUTPUTS + 2 + (NUM_CHANNELS*i))); + addOutput(Port::create(mm2px(Vec(offset + 37.04896, 106.95203)), Port::OUTPUT, module, Stages::ENVELOPE_OUTPUTS + 3 + (NUM_CHANNELS*i))); + addOutput(Port::create(mm2px(Vec(offset + 48.48943, 106.95203)), Port::OUTPUT, module, Stages::ENVELOPE_OUTPUTS + 4 + (NUM_CHANNELS*i))); + addOutput(Port::create(mm2px(Vec(offset + 59.92921, 106.95203)), Port::OUTPUT, module, Stages::ENVELOPE_OUTPUTS + 5 + (NUM_CHANNELS*i))); + + addChild(ModuleLightWidget::create>(mm2px(Vec(offset + 5.27737, 26.74447)), module, Stages::TYPE_LIGHTS + (0*2) + (NUM_CHANNELS*2*i))); + addChild(ModuleLightWidget::create>(mm2px(Vec(offset + 16.73784, 26.74447)), module, Stages::TYPE_LIGHTS + (1*2) + (NUM_CHANNELS*2*i))); + addChild(ModuleLightWidget::create>(mm2px(Vec(offset + 28.1783, 26.74447)), module, Stages::TYPE_LIGHTS + (2*2) + (NUM_CHANNELS*2*i))); + addChild(ModuleLightWidget::create>(mm2px(Vec(offset + 39.61877, 26.74447)), module, Stages::TYPE_LIGHTS + (3*2) + (NUM_CHANNELS*2*i))); + addChild(ModuleLightWidget::create>(mm2px(Vec(offset + 51.07923, 26.74447)), module, Stages::TYPE_LIGHTS + (4*2) + (NUM_CHANNELS*2*i))); + addChild(ModuleLightWidget::create>(mm2px(Vec(offset + 62.51971, 26.74447)), module, Stages::TYPE_LIGHTS + (5*2) + (NUM_CHANNELS*2*i))); + addChild(ModuleLightWidget::create>(mm2px(Vec(offset + 2.29462, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 0 + (NUM_CHANNELS*i))); + addChild(ModuleLightWidget::create>(mm2px(Vec(offset + 13.73509, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 1 + (NUM_CHANNELS*i))); + addChild(ModuleLightWidget::create>(mm2px(Vec(offset + 25.17556, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 2 + (NUM_CHANNELS*i))); + addChild(ModuleLightWidget::create>(mm2px(Vec(offset + 36.63671, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 3 + (NUM_CHANNELS*i))); + addChild(ModuleLightWidget::create>(mm2px(Vec(offset + 48.07649, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 4 + (NUM_CHANNELS*i))); + addChild(ModuleLightWidget::create>(mm2px(Vec(offset + 59.51696, 103.19253)), module, Stages::ENVELOPE_LIGHTS + 5 + (NUM_CHANNELS*i))); + } + } + + void step() override { + if (module->numModules != lastNumModules) { + resize(module->numModules); + + // Remove wires which no longer have a port + for (int i = 0; i < inputs.size(); i++) { + if (inputs[i]->portId >= Stages::LEVEL_INPUTS + (module->numModules * NUM_CHANNELS) && inputs[i]->portId < Stages::LEVEL_INPUTS + (NUM_CHANNELS * MAX_MODULES)) { + gRackWidget->wireContainer->removeAllWires(inputs[i]); + } + if (inputs[i]->portId >= Stages::GATE_INPUTS + (module->numModules * NUM_CHANNELS) && inputs[i]->portId < Stages::GATE_INPUTS + (NUM_CHANNELS * MAX_MODULES)) { + gRackWidget->wireContainer->removeAllWires(inputs[i]); + } + } + for (int i = 0; i < outputs.size(); i++) { + if (outputs[i]->portId >= Stages::ENVELOPE_OUTPUTS + (module->numModules * NUM_CHANNELS) && outputs[i]->portId < Stages::ENVELOPE_OUTPUTS + (NUM_CHANNELS * MAX_MODULES)) { + gRackWidget->wireContainer->removeAllWires(outputs[i]); + } + } + } + + ModuleWidget::step(); + } + + void resize(int width) { + lastNumModules = width; + this->box.size.x = width * 210; + this->panel->box.size = this->box.size; + + topRightScrew->box.pos.x = box.size.x - 2 * RACK_GRID_WIDTH; + bottomRightScrew->box.pos.x = box.size.x - 2 * RACK_GRID_WIDTH; } void appendContextMenu(Menu *menu) override { @@ -438,7 +500,39 @@ struct StagesWidget : ModuleWidget { ABLoopItem *abloopItem = MenuItem::create("Set A/B Loop", CHECKMARK(module->abloop)); abloopItem->module = module; menu->addChild(abloopItem); + + struct ExpandoItem : MenuItem { + Stages *module; + int width = 1; + void onAction(EventAction &e) override { + module->numModules = width; + } + }; + + struct ModuleLinkingItem : MenuItem { + Stages* module; + + Menu *createChildMenu() override { + Menu *menu = new Menu(); + for (auto i = 1; i <= MAX_MODULES; i += 1) { + ExpandoItem *expandoItem = MenuItem::create(stringf("%dx", i), CHECKMARK(module->numModules == i)); + expandoItem->module = module; + expandoItem->width = i; + menu->addChild(expandoItem); + } + return menu; + } + }; + + menu->addChild(MenuEntry::create()); + ModuleLinkingItem *moduleLinkingItem = MenuItem::create("Linked Modules"); + moduleLinkingItem->module = module; + menu->addChild(moduleLinkingItem); + } + + + };