Skip to content

Commit

Permalink
Migration to V1 - Phase 2
Browse files Browse the repository at this point in the history
  • Loading branch information
netboy3 committed Sep 26, 2019
1 parent 5c9272f commit 8ae064c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 116 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
SLUG = mtsch-plugins
VERSION = 0.6.0

RACK_DIR ?= ../..
# FLAGS will be passed to both the C and C++ compiler
FLAGS +=
Expand Down
57 changes: 23 additions & 34 deletions src/Rationals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,24 @@ struct Rationals : Module {
};

Rationals() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
for (int i = 0; i < NUM_CHANNELS; i++) {
configParam(Rationals::PARAMS + 2*i, 1, MAX_VALUE, 1);
configParam(Rationals::PARAMS + 1 + 2*i, 1, MAX_VALUE, 1);
}
}
void step() override;
void process(const ProcessArgs& args) override;

char display[4*NUM_CHANNELS];
};

void Rationals::step() {
void Rationals::process(const ProcessArgs& args) {

for (int i = 0; i < NUM_CHANNELS; i++) {
float num_cv = std::round(inputs[INPUTS + 1 + 3*i].value);
float num_par = std::round(params[PARAMS + 2*i].value);
float den_cv = std::round(inputs[INPUTS + 2 + 3*i].value);
float den_par = std::round(params[PARAMS + 1 + 2*i].value);
float num_cv = std::round(inputs[INPUTS + 1 + 3*i].getVoltage());
float num_par = std::round(params[PARAMS + 2*i].getValue());
float den_cv = std::round(inputs[INPUTS + 2 + 3*i].getVoltage());
float den_par = std::round(params[PARAMS + 1 + 2*i].getValue());

float num = num_cv + num_par;
float den = den_cv + den_par;
Expand All @@ -84,7 +88,7 @@ void Rationals::step() {
}
display[3 + digit_offset] = dig2 + '0';

outputs[OUTPUTS + i].value = inputs[INPUTS + 3*i].value + log2f(num/den);
outputs[OUTPUTS + i].setVoltage(inputs[INPUTS + 3*i].getVoltage() + log2f(num/den));
}
}

Expand All @@ -98,12 +102,7 @@ RationalsWidget::RationalsWidget(Rationals *module) {

box.size = Vec(10 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);

{
SVGPanel *panel = new SVGPanel();
panel->box.size = box.size;
panel->setBackground(SVG::load(assetPlugin(pluginInstance, "res/Rationals.svg")));
addChild(panel);
}
setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Rationals.svg")));

addChild(createWidget<ScrewSilver>(Vec(0, 0)));
addChild(createWidget<ScrewSilver>(Vec(0, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
Expand All @@ -116,37 +115,27 @@ RationalsWidget::RationalsWidget(Rationals *module) {

if (module) {
// Numerator digits.
addChild(new DigitDisplay(Vec(digit_x, y_pos + DIGIT_Y_OFFSET),
5.f, &module->display[0+offset]));
addChild(new DigitDisplay(Vec(digit_x + DIGIT_SPACING, y_pos + DIGIT_Y_OFFSET),
5.f, &module->display[1+offset]));
addChild(new DigitDisplay(Vec(digit_x, y_pos + DIGIT_Y_OFFSET), 5.f, &module->display[0+offset]));
addChild(new DigitDisplay(Vec(digit_x + DIGIT_SPACING, y_pos + DIGIT_Y_OFFSET), 5.f, &module->display[1+offset]));
// Denominator digits.
addChild(new DigitDisplay(Vec(digit_x, y_pos + DIGIT_Y_OFFSET + NUMDEN_SPACING),
5.f, &module->display[2+offset]));
addChild(new DigitDisplay(Vec(digit_x + DIGIT_SPACING, y_pos + DIGIT_Y_OFFSET + NUMDEN_SPACING),
5.f, &module->display[3+offset]));
addChild(new DigitDisplay(Vec(digit_x, y_pos + DIGIT_Y_OFFSET + NUMDEN_SPACING), 5.f, &module->display[2+offset]));
addChild(new DigitDisplay(Vec(digit_x + DIGIT_SPACING, y_pos + DIGIT_Y_OFFSET + NUMDEN_SPACING), 5.f, &module->display[3+offset]));
}

// Numerator knob.
addParam(createParam<RoundSmallBlackKnob>(Vec(X_POS + KNOB_X_OFFSET, y_pos),
module, Rationals::PARAMS + 2*i, 1, MAX_VALUE, 1));
addParam(createParam<RoundSmallBlackKnob>(Vec(X_POS + KNOB_X_OFFSET, y_pos), module, Rationals::PARAMS + 2*i));
// Denominator knob.
addParam(createParam<RoundSmallBlackKnob>(Vec(X_POS + KNOB_X_OFFSET, y_pos + NUMDEN_SPACING),
module, Rationals::PARAMS + 1 + 2*i, 1, MAX_VALUE, 1));
addParam(createParam<RoundSmallBlackKnob>(Vec(X_POS + KNOB_X_OFFSET, y_pos + NUMDEN_SPACING), module, Rationals::PARAMS + 1 + 2*i));

// IO.
addInput(createPort<PJ301MPort>(Vec(X_POS, y_pos + IO_Y_OFFSET),
PortWidget::INPUT, module, Rationals::INPUTS + i*3));
addOutput(createPort<PJ301MPort>(Vec(X_POS + OUT_X_OFFSET, y_pos + IO_Y_OFFSET),
PortWidget::OUTPUT, module, Rationals::OUTPUTS + i));
addInput(createInput<PJ301MPort>(Vec(X_POS, y_pos + IO_Y_OFFSET), module, Rationals::INPUTS + i*3));
addOutput(createOutput<PJ301MPort>(Vec(X_POS + OUT_X_OFFSET, y_pos + IO_Y_OFFSET), module, Rationals::OUTPUTS + i));
}

// CV mod grid.
for (int i = 0; i < NUM_CHANNELS; i++) {
addInput(createPort<PJ301MPort>(Vec(GRID_X_POS + i*GRID_SPACING, GRID_Y_POS),
PortWidget::INPUT, module, Rationals::INPUTS + 1 + i*3));
addInput(createPort<PJ301MPort>(Vec(GRID_X_POS + i*GRID_SPACING, GRID_Y_POS + GRID_SPACING),
PortWidget::INPUT, module, Rationals::INPUTS + 2 + i*3));
addInput(createInput<PJ301MPort>(Vec(GRID_X_POS + i*GRID_SPACING, GRID_Y_POS), module, Rationals::INPUTS + 1 + i*3));
addInput(createInput<PJ301MPort>(Vec(GRID_X_POS + i*GRID_SPACING, GRID_Y_POS + GRID_SPACING), module, Rationals::INPUTS + 2 + i*3));
}
}

Expand Down
28 changes: 12 additions & 16 deletions src/Sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,22 @@ struct Sum : Module {
};

Sum() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
for (int i = 0; i < NUM_CHANNELS; i++) {
configParam(Sum::PARAMS + i, -1, 1, 1);
}
}
void step() override;
void process(const ProcessArgs& args) override;
};

void Sum::step() {
void Sum::process(const ProcessArgs& args) {
float acc = 0;

for (int i = 0; i < NUM_CHANNELS; i++) {
acc += inputs[INPUTS + i].value * params[PARAMS + i].value;
acc += inputs[INPUTS + i].getVoltage() * params[PARAMS + i].getValue();
}

outputs[OUTPUT].value = acc;
outputs[OUTPUT].setVoltage(acc);
}

struct SumWidget : ModuleWidget {
Expand All @@ -50,24 +53,17 @@ SumWidget::SumWidget(Sum *module) {
setModule(module);
box.size = Vec(4 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);

{
SVGPanel *panel = new SVGPanel();
panel->box.size = box.size;
panel->setBackground(SVG::load(assetPlugin(pluginInstance, "res/Sum.svg")));
addChild(panel);
}
setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Sum.svg")));

addChild(createWidget<ScrewSilver>(Vec(0, 0)));
addChild(createWidget<ScrewSilver>(Vec(0, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));

for (int i = 0; i < NUM_CHANNELS; i++) {
addInput(createPort<PJ301MPort>(Vec(X_POSITION, Y_INPUT_POSITION + i * SPACING),
PortWidget::INPUT, module, Sum::INPUTS + i));
addParam(createParam<CKSSThree>(Vec(X_POSITION + 30, Y_INPUT_POSITION + i * SPACING),
module, Sum::PARAMS + i, -1, 1, 1));
addInput(createInput<PJ301MPort>(Vec(X_POSITION, Y_INPUT_POSITION + i * SPACING), module, Sum::INPUTS + i));
addParam(createParam<CKSSThree>(Vec(X_POSITION + 30, Y_INPUT_POSITION + i * SPACING), module, Sum::PARAMS + i));
}

addOutput(createPort<PJ301MPort>(Vec(X_POSITION, Y_OUTPUT_POSITION), PortWidget::OUTPUT, module, Sum::OUTPUT));
addOutput(createOutput<PJ301MPort>(Vec(X_POSITION, Y_OUTPUT_POSITION), module, Sum::OUTPUT));
}


Expand Down
110 changes: 48 additions & 62 deletions src/TriggerPanic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,43 +82,48 @@ struct TriggerPanic : Module {
NUM_LIGHTS
};

SchmittTrigger trigger;
SchmittTrigger panic;
SchmittTrigger clear;
dsp::SchmittTrigger trigger;
dsp::SchmittTrigger panic;
dsp::SchmittTrigger clear;
float *buff;
int current_i;
int buff_len;

TriggerPanic() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
buff_len = BUFFER_LENGTH * engineGetSampleRate();
buff = new float[buff_len];
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
configParam(TriggerPanic::PANIC_BUTTON, 0, 1, 0);
configParam(TriggerPanic::MIX_KNOB, 0, 1, 0.5);
configParam(TriggerPanic::MIX_CV_AMT, -1, 1, 0);
configParam(TriggerPanic::FEEDBACK_KNOB, 0, 1, 0.5);
configParam(TriggerPanic::FEEDBACK_CV_AMT, -1, 1, 0);
buff_len = BUFFER_LENGTH * APP->engine->getSampleRate();
buff = new float[buff_len];
}

void onReset() { // override
void onReset() override {
for (int i = 0; i < buff_len; i++) {
buff[i] = 0;
}
current_i = 0;
}

void step() override;
void process(const ProcessArgs& args) override;
};

void TriggerPanic::step() {
void TriggerPanic::process(const ProcessArgs& args) {
// TODO: cv control
// panic button
// gui

// Reset on trigger.
if (trigger.process(inputs[TRIGGER_IN].value)) {
if (trigger.process(inputs[TRIGGER_IN].getVoltage())) {
current_i = 0;
}
// Panic button.
if (panic.process(params[PANIC_BUTTON].value)) {
if (panic.process(params[PANIC_BUTTON].getValue())) {
onReset();
outputs[AUDIO_OUT].value = 0;
outputs[AUX_OUT].value = 0;
outputs[AUDIO_OUT].setVoltage(0);
outputs[AUX_OUT].setVoltage(0);
return;
}

Expand All @@ -127,33 +132,33 @@ void TriggerPanic::step() {

// Get feedback amount value.
float feedback_amt =
clamp(params[FEEDBACK_KNOB].value +
inputs[FEEDBACK_CV].value/5 * params[FEEDBACK_CV_AMT].value,
clamp(params[FEEDBACK_KNOB].getValue() +
inputs[FEEDBACK_CV].getVoltage()/5 * params[FEEDBACK_CV_AMT].getValue(),
0.0f, 1.0f);

// Direct feedback when AUX_IN or AUX_OUT are disconnected.
float feedback;
if (inputs[AUX_IN].active && outputs[AUX_OUT].active) {
if (inputs[AUX_IN].isConnected() && outputs[AUX_OUT].isConnected()) {
lights[AUX_ACTIVE_LIGHT].value = 0;
outputs[AUX_OUT].value = buff[current_i];
feedback = inputs[AUX_IN].value * feedback_amt;
outputs[AUX_OUT].setVoltage(buff[current_i]);
feedback = inputs[AUX_IN].getVoltage() * feedback_amt;
} else {
lights[AUX_ACTIVE_LIGHT].value = 1;
outputs[AUX_OUT].value = buff[current_i];
feedback = (inputs[AUX_IN].value + buff[current_i]) * feedback_amt;
outputs[AUX_OUT].setVoltage(buff[current_i]);
feedback = (inputs[AUX_IN].getVoltage() + buff[current_i]) * feedback_amt;
}
float mix =
clamp(params[MIX_KNOB].value +
(params[MIX_CV_AMT].value * inputs[MIX_CV].value/5),
clamp(params[MIX_KNOB].getValue() +
(params[MIX_CV_AMT].getValue() * inputs[MIX_CV].getVoltage()/5),
0.0f, 1.0f);
outputs[AUDIO_OUT].value = (1-mix)*inputs[AUDIO_IN].value + mix*buff[current_i];
outputs[AUDIO_OUT].setVoltage((1-mix)*inputs[AUDIO_IN].getVoltage() + mix*buff[current_i]);

buff[current_i] = clamp(inputs[AUDIO_IN].value + feedback, -5.0f, 5.0f);
buff[current_i] = clamp(inputs[AUDIO_IN].getVoltage() + feedback, -5.0f, 5.0f);

current_i++;
} else {
lights[BUFF_FULL_LIGHT].value = 1;
outputs[AUDIO_OUT].value = 0;
outputs[AUDIO_OUT].setVoltage(0);
}
}

Expand All @@ -165,57 +170,38 @@ TriggerPanicWidget::TriggerPanicWidget(TriggerPanic *module) {
setModule(module);
box.size = Vec(10 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);

{
SVGPanel *panel = new SVGPanel();
panel->box.size = box.size;
panel->setBackground(SVG::load(assetPlugin(pluginInstance, "res/TriggerPanic.svg")));
addChild(panel);
}
setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/TriggerPanic.svg")));

addChild(createWidget<ScrewBlack>(Vec(15, 0)));
addChild(createWidget<ScrewBlack>(Vec(box.size.x-30, 0)));
addChild(createWidget<ScrewBlack>(Vec(15, 365)));
addChild(createWidget<ScrewBlack>(Vec(box.size.x-30, 365)));
addChild(createWidget<ScrewBlack>(Vec(box.size.x-30, 0)));
addChild(createWidget<ScrewBlack>(Vec(15, 365)));
addChild(createWidget<ScrewBlack>(Vec(box.size.x-30, 365)));

// Trigger in.
addInput(createPort<PJ301MPort>(Vec(TRIGGER_X, TRIGGER_Y),
PortWidget::INPUT, module, TriggerPanic::TRIGGER_IN));
addInput(createInput<PJ301MPort>(Vec(TRIGGER_X, TRIGGER_Y), module, TriggerPanic::TRIGGER_IN));

// Panic.
addParam(createParam<BefacoPush>(Vec(PANIC_X, PANIC_Y),
module, TriggerPanic::PANIC_BUTTON, 0, 1, 0));
addChild(createLight<SmallLight<RedLight>>(Vec(BUFF_X, BUFF_Y),
module, TriggerPanic::BUFF_FULL_LIGHT));
addParam(createParam<BefacoPush>(Vec(PANIC_X, PANIC_Y), module, TriggerPanic::PANIC_BUTTON));
addChild(createLight<SmallLight<RedLight>>(Vec(BUFF_X, BUFF_Y), module, TriggerPanic::BUFF_FULL_LIGHT));

// Mix.
addParam(createParam<Davies1900hBlackKnob>(Vec(MIX_GROUP_X, MIX_GROUP_Y),
module, TriggerPanic::MIX_KNOB, 0, 1, 0.5));
addParam(createParam<Trimpot>(Vec(MIX_GROUP_X + MF_GROUP_CV_AMT_X, MIX_GROUP_Y + MF_GROUP_CV_AMT_Y),
module, TriggerPanic::MIX_CV_AMT, -1, 1, 0));
addInput(createPort<PJ301MPort>(Vec(MIX_GROUP_X + MF_GROUP_CV_IN_X, MIX_GROUP_Y + MF_GROUP_CV_IN_Y),
PortWidget::INPUT, module, TriggerPanic::MIX_CV));
addParam(createParam<Davies1900hBlackKnob>(Vec(MIX_GROUP_X, MIX_GROUP_Y), module, TriggerPanic::MIX_KNOB));
addParam(createParam<Trimpot>(Vec(MIX_GROUP_X + MF_GROUP_CV_AMT_X, MIX_GROUP_Y + MF_GROUP_CV_AMT_Y), module, TriggerPanic::MIX_CV_AMT));
addInput(createInput<PJ301MPort>(Vec(MIX_GROUP_X + MF_GROUP_CV_IN_X, MIX_GROUP_Y + MF_GROUP_CV_IN_Y), module, TriggerPanic::MIX_CV));

// Feedback.
addParam(createParam<Davies1900hBlackKnob>(Vec(FB_GROUP_X, FB_GROUP_Y),
module, TriggerPanic::FEEDBACK_KNOB, 0, 1, 0.5));
addParam(createParam<Trimpot>(Vec(FB_GROUP_X + MF_GROUP_CV_AMT_X, FB_GROUP_Y + MF_GROUP_CV_AMT_Y),
module, TriggerPanic::FEEDBACK_CV_AMT, -1, 1, 0));
addInput(createPort<PJ301MPort>(Vec(FB_GROUP_X + MF_GROUP_CV_IN_X, FB_GROUP_Y + MF_GROUP_CV_IN_Y),
PortWidget::INPUT, module, TriggerPanic::FEEDBACK_CV));
addParam(createParam<Davies1900hBlackKnob>(Vec(FB_GROUP_X, FB_GROUP_Y), module, TriggerPanic::FEEDBACK_KNOB));
addParam(createParam<Trimpot>(Vec(FB_GROUP_X + MF_GROUP_CV_AMT_X, FB_GROUP_Y + MF_GROUP_CV_AMT_Y), module, TriggerPanic::FEEDBACK_CV_AMT));
addInput(createInput<PJ301MPort>(Vec(FB_GROUP_X + MF_GROUP_CV_IN_X, FB_GROUP_Y + MF_GROUP_CV_IN_Y), module, TriggerPanic::FEEDBACK_CV));

// Aux IO.
addInput(createPort<PJ301MPort>(Vec(AUX_X, AUX_Y),
PortWidget::INPUT, module, TriggerPanic::AUX_IN));
addChild(createLight<SmallLight<GreenLight>>(Vec(AUX_LIGHT_X, AUX_LIGHT_Y),
module, TriggerPanic::AUX_ACTIVE_LIGHT));
addOutput(createPort<PJ301MPort>(Vec(AUX_OUT_X, AUX_Y),
PortWidget::OUTPUT, module, TriggerPanic::AUX_OUT));
addInput(createInput<PJ301MPort>(Vec(AUX_X, AUX_Y), module, TriggerPanic::AUX_IN));
addChild(createLight<SmallLight<GreenLight>>(Vec(AUX_LIGHT_X, AUX_LIGHT_Y), module, TriggerPanic::AUX_ACTIVE_LIGHT));
addOutput(createOutput<PJ301MPort>(Vec(AUX_OUT_X, AUX_Y), module, TriggerPanic::AUX_OUT));

// Audio IO.
addInput(createPort<PJ301MPort>(Vec(AUDIO_IN_X, AUDIO_IO_Y),
PortWidget::INPUT, module, TriggerPanic::AUDIO_IN));
addOutput(createPort<PJ301MPort>(Vec(AUDIO_OUT_X, AUDIO_IO_Y),
PortWidget::OUTPUT, module, TriggerPanic::AUDIO_OUT));
addInput(createInput<PJ301MPort>(Vec(AUDIO_IN_X, AUDIO_IO_Y), module, TriggerPanic::AUDIO_IN));
addOutput(createOutput<PJ301MPort>(Vec(AUDIO_OUT_X, AUDIO_IO_Y), module, TriggerPanic::AUDIO_OUT));

}

Expand Down
2 changes: 1 addition & 1 deletion src/mtsch.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "rack0.hpp"
#include "rack.hpp"

using namespace rack;

Expand Down

0 comments on commit 8ae064c

Please sign in to comment.