Skip to content

Commit

Permalink
CVfunk 2.0.8 update
Browse files Browse the repository at this point in the history
Added new module StepWave
fixed reset bug in Collatz
added Range CV to HexMod
added Slew CV on Pentasequencer
added context menu option to Decima to output subsequence to Gate
added pass-through output to Morta
  • Loading branch information
codygeary authored Aug 23, 2024
1 parent b450f55 commit 903518d
Show file tree
Hide file tree
Showing 9 changed files with 1,022 additions and 173 deletions.
63 changes: 33 additions & 30 deletions src/Collatz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,43 +165,46 @@ struct Collatz : Module {
}
}

// Handle reset logic
if (resetTrigger.process(params[RESET_BUTTON_PARAM].getValue()) ||
resetTrigger.process(inputs[RESET_INPUT].getVoltage()-0.01f)) {
sequenceRunning = false;
rhythmStepIndex = 0;
currentNumber = 0;
lights[RUN_LIGHT].setBrightness(0);
outputs[GATE_OUTPUT].setVoltage(0.0f);
outputs[ACCENT_OUTPUT].setVoltage(0.0f);
lights[GATE_LIGHT].setBrightness(0);
lights[ACCENT_LIGHT].setBrightness(0);
}
if (resetTrigger.process(params[RESET_BUTTON_PARAM].getValue()) ||
resetTrigger.process(inputs[RESET_INPUT].getVoltage() - 0.01f)) {
sequenceRunning = false;
sequenceTriggered = false; // Clear the trigger flag on reset
rhythmStepIndex = 0;
currentNumber = 0;
lights[RUN_LIGHT].setBrightness(0);
outputs[GATE_OUTPUT].setVoltage(0.0f);
outputs[ACCENT_OUTPUT].setVoltage(0.0f);
lights[GATE_LIGHT].setBrightness(0);
lights[ACCENT_LIGHT].setBrightness(0);
}

// Handle trigger logic
if ( (sampleTrigger.process(inputs[START_INPUT].getVoltage()) || params[START_BUTTON_PARAM].getValue() > 0) && !sequenceRunning && !sequenceTriggered) {
sequenceTriggered = true; // Mark that a sequence start is pending
lights[RUN_LIGHT].setBrightness(1);
}

// Clock handling logic
bool externalClockConnected = inputs[CLOCK_INPUT].isConnected();
if (externalClockConnected && clockTrigger.process(inputs[CLOCK_INPUT].getVoltage()-0.01f)) {
if (sequenceTriggered) {
// Reset necessary variables for starting the sequence
currentNumber = startingNumber;
sequenceRunning = true;
sequenceTriggered = false; // Reset trigger flag after starting the sequence
rhythmStepIndex = 0; // Reset rhythm index if needed
} else if (sequenceRunning ) {
advanceSequence();
}

// Update lastClockTime for rate calculation
if (firstPulseReceived) {clockRate = 1.0f / lastClockTime;}
lastClockTime = 0.0f;
firstPulseReceived = true;
}
// Clock handling logic
bool externalClockConnected = inputs[CLOCK_INPUT].isConnected();
if (externalClockConnected && clockTrigger.process(inputs[CLOCK_INPUT].getVoltage() - 0.01f)) {
if (sequenceTriggered || !sequenceRunning) { // Check if either the sequence was triggered or it isn't running
// Reset necessary variables for starting the sequence
currentNumber = startingNumber;
sequenceRunning = true;
sequenceTriggered = false; // Reset trigger flag after starting the sequence
rhythmStepIndex = 0; // Reset rhythm index if needed
} else if (sequenceRunning) {
advanceSequence();
}

// Update lastClockTime for rate calculation
if (firstPulseReceived) {
clockRate = 1.0f / lastClockTime;
}
lastClockTime = 0.0f;
firstPulseReceived = true;
}


// Accumulate time since the last clock pulse for rate calculation
if (firstPulseReceived && externalClockConnected) {
Expand Down
58 changes: 52 additions & 6 deletions src/Decima.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct Decima : Module {
float PulseLength = 1.0f;
bool trigger = true;
bool manualStageSelect = false;
bool probGateEnabled = false;

json_t* dataToJson() override {
json_t* rootJ = json_object();
Expand All @@ -64,6 +65,8 @@ struct Decima : Module {
json_array_append_new(stepActiveJ, json_boolean(stepActive[i]));
}
json_object_set_new(rootJ, "stepActive", stepActiveJ);
json_object_set_new(rootJ, "probGateEnabled", json_boolean(probGateEnabled));


return rootJ;
}
Expand All @@ -79,6 +82,10 @@ struct Decima : Module {
}
}
}

json_t* probGateEnabledJ = json_object_get(rootJ, "probGateEnabled");
if (probGateEnabledJ) probGateEnabled = json_is_true(probGateEnabledJ);

}

Decima() {
Expand Down Expand Up @@ -186,14 +193,24 @@ struct Decima : Module {
lights[BUTTON_LIGHT_1 + i].setBrightness(active ? 1.0f : 0.0f);
lights[STAGE_LIGHT_1 + i].setBrightness(step == i ? 1.0f : 0.0f);

if (step == i) {
outputs[GATE_1 + i].setVoltage(10.0f);
} else {
outputs[GATE_1 + i].setVoltage(0.0f);
}
if (probGateEnabled) {
if (step == i && stepActive[i] && trigger) {
outputs[GATE_1 + i].setVoltage(10.0f);
} else {
outputs[GATE_1 + i].setVoltage(0.0f);
}

} else {
if (step == i) {
outputs[GATE_1 + i].setVoltage(10.0f);
} else {
outputs[GATE_1 + i].setVoltage(0.0f);
}
}

}

if (!manualStageSelect) { // Add this condition
if (!manualStageSelect) {
if (stepActive[step] && (SyncTimer.time < PulseLength)) {
if (trigger) { // Only output if the step is triggered by probability setting
outputs[OUTPUT].setVoltage(10.0f);
Expand Down Expand Up @@ -260,6 +277,35 @@ struct DecimaWidget : ModuleWidget {
addOutput(createOutputCentered<ThemedPJ301MPort>(Vec(57, 338), module, Decima::OUTPUT));
addOutput(createOutputCentered<ThemedPJ301MPort>(Vec(92, 338), module, Decima::INV_OUTPUT));
}

void appendContextMenu(Menu* menu) override {
ModuleWidget::appendContextMenu(menu);

Decima* decimaModule = dynamic_cast<Decima*>(module);
assert(decimaModule); // Ensure the cast succeeds

// Separator for visual grouping in the context menu
menu->addChild(new MenuSeparator());

// Retriggering enabled/disabled menu item
struct ProbgateEnabledItem : MenuItem {
Decima* decimaModule;
void onAction(const event::Action& e) override {
decimaModule->probGateEnabled = !decimaModule->probGateEnabled;
}
void step() override {
rightText = decimaModule->probGateEnabled ? "" : "";
MenuItem::step();
}
};

ProbgateEnabledItem* probGateItem = new ProbgateEnabledItem();
probGateItem->text = "Active step outputs to Gate output";
probGateItem->decimaModule = decimaModule; // Ensure we're setting the module
menu->addChild(probGateItem);
}


};

Model* modelDecima = createModel<Decima, DecimaWidget>("Decima");
Loading

0 comments on commit 903518d

Please sign in to comment.