diff --git a/README.md b/README.md index 51db31d..4428086 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,8 @@ Follow the build instructions for [VCV Rack](https://github.com/VCVRack/Rack). ## License -Source code licensed under [BSD-3-Clause](LICENSE.txt) by [Andrew Belt](https://andrewbelt.name/) +All **source code** is copyright © 2019 Andrew Belt and licensed under the [BSD-3-Clause License](https://opensource.org/licenses/BSD-3-Clause). -VCV logo is © 2017. Derivative works may not use the VCV logo. +The **VCV logo and icon** are copyright © 2017 Andrew Belt and may not be used in derivative works. -The panel graphics in the `res` directory are copyright © 2017-2019 [Grayscale](http://grayscale.info/) and licensed under [CC BY-NC-ND 4.0](https://creativecommons.org/licenses/by-nc-nd/4.0/). -You may not create derivative works of these graphics. +The **panel graphics** in the `res` directory are copyright © 2019 [Grayscale](http://grayscale.info/) and licensed under [CC BY-NC-ND 4.0](https://creativecommons.org/licenses/by-nc-nd/4.0/). diff --git a/plugin.json b/plugin.json index dd10df7..5472015 100644 --- a/plugin.json +++ b/plugin.json @@ -76,6 +76,26 @@ "SequentialSwitch2": { "name": "Sequential Switch 1", "tags": ["Utility"] + }, + "Split": { + "name": "Split", + "description": "Splits a polyphonic cable into multiple monophonic cables", + "tags": ["Poly", "Utility"] + }, + "Merge": { + "name": "Merge", + "description": "Combines multiple monophonic cables into a polyphonic cable", + "tags": ["Poly", "Utility"] + }, + "Sum": { + "name": "Sum", + "description": "Sums all channels in a polyphonic cable", + "tags": ["Poly", "Utility"] + }, + "Viz": { + "name": "Viz", + "description": "Visualizes all channels of a polyphonic cable", + "tags": ["Poly", "Visual"] } } } \ No newline at end of file diff --git a/res/Merge.svg b/res/Merge.svg new file mode 100644 index 0000000..861ac8f --- /dev/null +++ b/res/Merge.svg @@ -0,0 +1,415 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/Split.svg b/res/Split.svg new file mode 100644 index 0000000..51c88ce --- /dev/null +++ b/res/Split.svg @@ -0,0 +1,408 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/Sum.svg b/res/Sum.svg new file mode 100644 index 0000000..06433f0 --- /dev/null +++ b/res/Sum.svg @@ -0,0 +1,451 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/Viz.svg b/res/Viz.svg new file mode 100644 index 0000000..97ecf4f --- /dev/null +++ b/res/Viz.svg @@ -0,0 +1,251 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/nunito/Nunito-Bold.ttf b/res/nunito/Nunito-Bold.ttf new file mode 100644 index 0000000..4ce517a Binary files /dev/null and b/res/nunito/Nunito-Bold.ttf differ diff --git a/res/nunito/SIL Open Font License.txt b/res/nunito/SIL Open Font License.txt new file mode 100644 index 0000000..a9d0ccd --- /dev/null +++ b/res/nunito/SIL Open Font License.txt @@ -0,0 +1,44 @@ +Copyright (c) 2011, Vernon Adams (vern@newtypography.co.uk), +with Reserved Font Name Nunito. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others. + +The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the copyright statement(s). + +"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment. + +"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission. + +5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. \ No newline at end of file diff --git a/res/fonts/OFL.txt b/res/sudo/OFL.txt similarity index 100% rename from res/fonts/OFL.txt rename to res/sudo/OFL.txt diff --git a/res/fonts/Sudo.ttf b/res/sudo/Sudo.ttf similarity index 100% rename from res/fonts/Sudo.ttf rename to res/sudo/Sudo.ttf diff --git a/src/8vert.cpp b/src/8vert.cpp index 790a266..8284c39 100644 --- a/src/8vert.cpp +++ b/src/8vert.cpp @@ -1,4 +1,4 @@ -#include "Fundamental.hpp" +#include "plugin.hpp" struct _8vert : Module { diff --git a/src/ADSR.cpp b/src/ADSR.cpp index f9fad49..1d6b1ff 100644 --- a/src/ADSR.cpp +++ b/src/ADSR.cpp @@ -1,4 +1,4 @@ -#include "Fundamental.hpp" +#include "plugin.hpp" struct ADSR : Module { diff --git a/src/Delay.cpp b/src/Delay.cpp index 205aeb3..3ca1bf7 100644 --- a/src/Delay.cpp +++ b/src/Delay.cpp @@ -1,4 +1,4 @@ -#include "Fundamental.hpp" +#include "plugin.hpp" #include "samplerate.h" diff --git a/src/LFO.cpp b/src/LFO.cpp index 45a34bd..93bb71b 100644 --- a/src/LFO.cpp +++ b/src/LFO.cpp @@ -1,4 +1,4 @@ -#include "Fundamental.hpp" +#include "plugin.hpp" struct LowFrequencyOscillator { diff --git a/src/Merge.cpp b/src/Merge.cpp new file mode 100644 index 0000000..ea09c3d --- /dev/null +++ b/src/Merge.cpp @@ -0,0 +1,103 @@ +#include "plugin.hpp" + + +struct Merge : Module { + enum ParamIds { + NUM_PARAMS + }; + enum InputIds { + ENUMS(MONO_INPUTS, 16), + NUM_INPUTS + }; + enum OutputIds { + POLY_OUTPUT, + NUM_OUTPUTS + }; + enum LightIds { + ENUMS(CHANNEL_LIGHTS, 16), + NUM_LIGHTS + }; + + int lightFrame = 0; + + Merge() { + config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + } + + void step() override { + int lastChannel = -1; + for (int c = 0; c < 16; c++) { + if (inputs[MONO_INPUTS + c].isConnected()) { + lastChannel = c; + float v = inputs[MONO_INPUTS + c].getVoltage(); + outputs[POLY_OUTPUT].setVoltage(v, c); + } + else { + outputs[POLY_OUTPUT].setVoltage(0.f, c); + } + } + + outputs[POLY_OUTPUT].setChannels(lastChannel + 1); + + // Set channel lights infrequently + if (++lightFrame >= 512) { + lightFrame = 0; + for (int c = 0; c < 16; c++) { + bool active = (c < outputs[POLY_OUTPUT].getChannels()); + lights[CHANNEL_LIGHTS + c].setBrightness(active); + } + } + } +}; + + +struct MergeWidget : ModuleWidget { + MergeWidget(Merge *module) { + setModule(module); + setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Merge.svg"))); + + addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); + addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); + addChild(createWidget(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + + addInput(createInputCentered(mm2px(Vec(6.771, 37.02)), module, Merge::MONO_INPUTS + 0)); + addInput(createInputCentered(mm2px(Vec(6.771, 48.02)), module, Merge::MONO_INPUTS + 1)); + addInput(createInputCentered(mm2px(Vec(6.77, 59.02)), module, Merge::MONO_INPUTS + 2)); + addInput(createInputCentered(mm2px(Vec(6.77, 70.02)), module, Merge::MONO_INPUTS + 3)); + addInput(createInputCentered(mm2px(Vec(6.77, 81.02)), module, Merge::MONO_INPUTS + 4)); + addInput(createInputCentered(mm2px(Vec(6.77, 92.02)), module, Merge::MONO_INPUTS + 5)); + addInput(createInputCentered(mm2px(Vec(6.771, 103.02)), module, Merge::MONO_INPUTS + 6)); + addInput(createInputCentered(mm2px(Vec(6.771, 114.02)), module, Merge::MONO_INPUTS + 7)); + addInput(createInputCentered(mm2px(Vec(18.275, 37.02)), module, Merge::MONO_INPUTS + 8)); + addInput(createInputCentered(mm2px(Vec(18.275, 48.02)), module, Merge::MONO_INPUTS + 9)); + addInput(createInputCentered(mm2px(Vec(18.274, 59.02)), module, Merge::MONO_INPUTS + 10)); + addInput(createInputCentered(mm2px(Vec(18.274, 70.02)), module, Merge::MONO_INPUTS + 11)); + addInput(createInputCentered(mm2px(Vec(18.274, 81.02)), module, Merge::MONO_INPUTS + 12)); + addInput(createInputCentered(mm2px(Vec(18.274, 92.02)), module, Merge::MONO_INPUTS + 13)); + addInput(createInputCentered(mm2px(Vec(18.275, 103.02)), module, Merge::MONO_INPUTS + 14)); + addInput(createInputCentered(mm2px(Vec(18.275, 114.02)), module, Merge::MONO_INPUTS + 15)); + + addOutput(createOutputCentered(mm2px(Vec(6.77, 21.347)), module, Merge::POLY_OUTPUT)); + + addChild(createLightCentered>(mm2px(Vec(15.276, 17.775)), module, Merge::CHANNEL_LIGHTS + 0)); + addChild(createLightCentered>(mm2px(Vec(17.275, 17.775)), module, Merge::CHANNEL_LIGHTS + 1)); + addChild(createLightCentered>(mm2px(Vec(19.275, 17.775)), module, Merge::CHANNEL_LIGHTS + 2)); + addChild(createLightCentered>(mm2px(Vec(21.275, 17.775)), module, Merge::CHANNEL_LIGHTS + 3)); + addChild(createLightCentered>(mm2px(Vec(15.276, 19.775)), module, Merge::CHANNEL_LIGHTS + 4)); + addChild(createLightCentered>(mm2px(Vec(17.275, 19.775)), module, Merge::CHANNEL_LIGHTS + 5)); + addChild(createLightCentered>(mm2px(Vec(19.275, 19.775)), module, Merge::CHANNEL_LIGHTS + 6)); + addChild(createLightCentered>(mm2px(Vec(21.275, 19.775)), module, Merge::CHANNEL_LIGHTS + 7)); + addChild(createLightCentered>(mm2px(Vec(15.276, 21.775)), module, Merge::CHANNEL_LIGHTS + 8)); + addChild(createLightCentered>(mm2px(Vec(17.275, 21.775)), module, Merge::CHANNEL_LIGHTS + 9)); + addChild(createLightCentered>(mm2px(Vec(19.275, 21.775)), module, Merge::CHANNEL_LIGHTS + 10)); + addChild(createLightCentered>(mm2px(Vec(21.276, 21.775)), module, Merge::CHANNEL_LIGHTS + 11)); + addChild(createLightCentered>(mm2px(Vec(15.276, 23.775)), module, Merge::CHANNEL_LIGHTS + 12)); + addChild(createLightCentered>(mm2px(Vec(17.275, 23.775)), module, Merge::CHANNEL_LIGHTS + 13)); + addChild(createLightCentered>(mm2px(Vec(19.275, 23.775)), module, Merge::CHANNEL_LIGHTS + 14)); + addChild(createLightCentered>(mm2px(Vec(21.276, 23.775)), module, Merge::CHANNEL_LIGHTS + 15)); + } +}; + + +Model *modelMerge = createModel("Merge"); diff --git a/src/Mutes.cpp b/src/Mutes.cpp index abb4475..6cd3214 100644 --- a/src/Mutes.cpp +++ b/src/Mutes.cpp @@ -1,4 +1,4 @@ -#include "Fundamental.hpp" +#include "plugin.hpp" #define NUM_CHANNELS 10 diff --git a/src/SEQ3.cpp b/src/SEQ3.cpp index b4c2bc1..246f0c0 100644 --- a/src/SEQ3.cpp +++ b/src/SEQ3.cpp @@ -1,4 +1,4 @@ -#include "Fundamental.hpp" +#include "plugin.hpp" struct SEQ3 : Module { diff --git a/src/Scope.cpp b/src/Scope.cpp index 719cae8..5e2db7a 100644 --- a/src/Scope.cpp +++ b/src/Scope.cpp @@ -1,5 +1,5 @@ #include -#include "Fundamental.hpp" +#include "plugin.hpp" static const int BUFFER_SIZE = 512; @@ -146,7 +146,10 @@ struct ScopeDisplay : TransparentWidget { std::shared_ptr font; struct Stats { - float vrms, vpp, vmin, vmax; + float vrms = 0.f; + float vpp = 0.f; + float vmin = 0.f; + float vmax = 0.f; void calculate(float *values) { vrms = 0.0f; vmax = -INFINITY; @@ -164,7 +167,7 @@ struct ScopeDisplay : TransparentWidget { Stats statsX, statsY; ScopeDisplay() { - font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/Sudo.ttf")); + font = APP->window->loadFont(asset::plugin(pluginInstance, "res/Sudo/Sudo.ttf")); } void drawWaveform(const DrawContext &ctx, float *valuesX, float *valuesY) { diff --git a/src/SequentialSwitch.cpp b/src/SequentialSwitch.cpp index 926b830..c063ea6 100644 --- a/src/SequentialSwitch.cpp +++ b/src/SequentialSwitch.cpp @@ -1,4 +1,4 @@ -#include "Fundamental.hpp" +#include "plugin.hpp" template diff --git a/src/Split.cpp b/src/Split.cpp new file mode 100644 index 0000000..1197404 --- /dev/null +++ b/src/Split.cpp @@ -0,0 +1,94 @@ +#include "plugin.hpp" + + +struct Split : Module { + enum ParamIds { + NUM_PARAMS + }; + enum InputIds { + POLY_INPUT, + NUM_INPUTS + }; + enum OutputIds { + ENUMS(MONO_OUTPUTS, 16), + NUM_OUTPUTS + }; + enum LightIds { + ENUMS(CHANNEL_LIGHTS, 16), + NUM_LIGHTS + }; + + Split() { + config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + } + + int lightFrame = 0; + + void step() override { + for (int c = 0; c < 16; c++) { + float v = inputs[POLY_INPUT].getVoltage(c); + outputs[MONO_OUTPUTS + c].setVoltage(v); + } + + // Set channel lights infrequently + if (++lightFrame >= 512) { + lightFrame = 0; + for (int c = 0; c < 16; c++) { + bool active = (c < inputs[POLY_INPUT].getChannels()); + lights[CHANNEL_LIGHTS + c].setBrightness(active); + } + } + } +}; + + +struct SplitWidget : ModuleWidget { + SplitWidget(Split *module) { + setModule(module); + setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Split.svg"))); + + addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); + addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); + addChild(createWidget(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + + addInput(createInputCentered(mm2px(Vec(6.77, 21.347)), module, Split::POLY_INPUT)); + + addOutput(createOutputCentered(mm2px(Vec(6.771, 37.02)), module, Split::MONO_OUTPUTS + 0)); + addOutput(createOutputCentered(mm2px(Vec(6.771, 48.02)), module, Split::MONO_OUTPUTS + 1)); + addOutput(createOutputCentered(mm2px(Vec(6.77, 59.02)), module, Split::MONO_OUTPUTS + 2)); + addOutput(createOutputCentered(mm2px(Vec(6.77, 70.02)), module, Split::MONO_OUTPUTS + 3)); + addOutput(createOutputCentered(mm2px(Vec(6.77, 81.02)), module, Split::MONO_OUTPUTS + 4)); + addOutput(createOutputCentered(mm2px(Vec(6.77, 92.02)), module, Split::MONO_OUTPUTS + 5)); + addOutput(createOutputCentered(mm2px(Vec(6.771, 103.02)), module, Split::MONO_OUTPUTS + 6)); + addOutput(createOutputCentered(mm2px(Vec(6.771, 114.02)), module, Split::MONO_OUTPUTS + 7)); + addOutput(createOutputCentered(mm2px(Vec(18.275, 37.02)), module, Split::MONO_OUTPUTS + 8)); + addOutput(createOutputCentered(mm2px(Vec(18.275, 48.02)), module, Split::MONO_OUTPUTS + 9)); + addOutput(createOutputCentered(mm2px(Vec(18.274, 59.02)), module, Split::MONO_OUTPUTS + 10)); + addOutput(createOutputCentered(mm2px(Vec(18.274, 70.02)), module, Split::MONO_OUTPUTS + 11)); + addOutput(createOutputCentered(mm2px(Vec(18.274, 81.02)), module, Split::MONO_OUTPUTS + 12)); + addOutput(createOutputCentered(mm2px(Vec(18.274, 92.02)), module, Split::MONO_OUTPUTS + 13)); + addOutput(createOutputCentered(mm2px(Vec(18.275, 103.02)), module, Split::MONO_OUTPUTS + 14)); + addOutput(createOutputCentered(mm2px(Vec(18.275, 114.02)), module, Split::MONO_OUTPUTS + 15)); + + addChild(createLightCentered>(mm2px(Vec(15.276, 17.775)), module, Split::CHANNEL_LIGHTS + 0)); + addChild(createLightCentered>(mm2px(Vec(17.275, 17.775)), module, Split::CHANNEL_LIGHTS + 1)); + addChild(createLightCentered>(mm2px(Vec(19.275, 17.775)), module, Split::CHANNEL_LIGHTS + 2)); + addChild(createLightCentered>(mm2px(Vec(21.275, 17.775)), module, Split::CHANNEL_LIGHTS + 3)); + addChild(createLightCentered>(mm2px(Vec(15.276, 19.775)), module, Split::CHANNEL_LIGHTS + 4)); + addChild(createLightCentered>(mm2px(Vec(17.275, 19.775)), module, Split::CHANNEL_LIGHTS + 5)); + addChild(createLightCentered>(mm2px(Vec(19.275, 19.775)), module, Split::CHANNEL_LIGHTS + 6)); + addChild(createLightCentered>(mm2px(Vec(21.275, 19.775)), module, Split::CHANNEL_LIGHTS + 7)); + addChild(createLightCentered>(mm2px(Vec(15.276, 21.775)), module, Split::CHANNEL_LIGHTS + 8)); + addChild(createLightCentered>(mm2px(Vec(17.275, 21.775)), module, Split::CHANNEL_LIGHTS + 9)); + addChild(createLightCentered>(mm2px(Vec(19.275, 21.775)), module, Split::CHANNEL_LIGHTS + 10)); + addChild(createLightCentered>(mm2px(Vec(21.276, 21.775)), module, Split::CHANNEL_LIGHTS + 11)); + addChild(createLightCentered>(mm2px(Vec(15.276, 23.775)), module, Split::CHANNEL_LIGHTS + 12)); + addChild(createLightCentered>(mm2px(Vec(17.275, 23.775)), module, Split::CHANNEL_LIGHTS + 13)); + addChild(createLightCentered>(mm2px(Vec(19.275, 23.775)), module, Split::CHANNEL_LIGHTS + 14)); + addChild(createLightCentered>(mm2px(Vec(21.276, 23.775)), module, Split::CHANNEL_LIGHTS + 15)); + } +}; + + +Model *modelSplit = createModel("Split"); diff --git a/src/Sum.cpp b/src/Sum.cpp new file mode 100644 index 0000000..74f8200 --- /dev/null +++ b/src/Sum.cpp @@ -0,0 +1,108 @@ +#include "plugin.hpp" + + +struct Sum : Module { + enum ParamIds { + LEVEL_PARAM, + NUM_PARAMS + }; + enum InputIds { + POLY_INPUT, + NUM_INPUTS + }; + enum OutputIds { + MONO_OUTPUT, + NUM_OUTPUTS + }; + enum LightIds { + ENUMS(CHANNEL_LIGHTS, 16), + ENUMS(VU_LIGHTS, 6), + NUM_LIGHTS + }; + + int frame = 0; + dsp::VUMeter2 vuMeter; + + Sum() { + config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + params[LEVEL_PARAM].config(0.f, 1.f, 1.f, "Level", "%", 0.f, 100.f); + + vuMeter.lambda = 1 / 0.1f; + } + + void step() override { + int channels = inputs[POLY_INPUT].getChannels(); + float sum = 0.f; + for (int c = 0; c < channels; c++) { + sum += inputs[POLY_INPUT].getVoltage(c); + } + + sum *= params[LEVEL_PARAM].getValue(); + outputs[MONO_OUTPUT].setVoltage(sum); + + if (frame % 16 == 0) { + vuMeter.process(APP->engine->getSampleTime() * 16, sum / 10.f); + } + + // Set channel lights infrequently + if (frame % 256 == 0) { + for (int c = 0; c < 16; c++) { + bool active = (c < inputs[POLY_INPUT].getChannels()); + lights[CHANNEL_LIGHTS + c].setBrightness(active); + } + + lights[VU_LIGHTS + 0].setBrightness(vuMeter.getBrightness(0.f, 0.f)); + for (int i = 1; i < 6; i++) { + lights[VU_LIGHTS + i].setBrightness(vuMeter.getBrightness(-3.f * i, -3.f * (i - 1))); + } + } + + frame++; + } +}; + + +struct SumWidget : ModuleWidget { + SumWidget(Sum *module) { + setModule(module); + setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Sum.svg"))); + + addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); + addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); + addChild(createWidget(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + + addParam(createParamCentered(mm2px(Vec(7.62, 53.519)), module, Sum::LEVEL_PARAM)); + + addInput(createInputCentered(mm2px(Vec(7.619, 21.347)), module, Sum::POLY_INPUT)); + + addOutput(createOutputCentered(mm2px(Vec(7.62, 112.021)), module, Sum::MONO_OUTPUT)); + + addChild(createLightCentered>(mm2px(Vec(4.619, 33.595)), module, Sum::CHANNEL_LIGHTS + 0)); + addChild(createLightCentered>(mm2px(Vec(6.619, 33.595)), module, Sum::CHANNEL_LIGHTS + 1)); + addChild(createLightCentered>(mm2px(Vec(8.619, 33.595)), module, Sum::CHANNEL_LIGHTS + 2)); + addChild(createLightCentered>(mm2px(Vec(10.619, 33.595)), module, Sum::CHANNEL_LIGHTS + 3)); + addChild(createLightCentered>(mm2px(Vec(4.619, 35.595)), module, Sum::CHANNEL_LIGHTS + 4)); + addChild(createLightCentered>(mm2px(Vec(6.619, 35.595)), module, Sum::CHANNEL_LIGHTS + 5)); + addChild(createLightCentered>(mm2px(Vec(8.619, 35.595)), module, Sum::CHANNEL_LIGHTS + 6)); + addChild(createLightCentered>(mm2px(Vec(10.619, 35.595)), module, Sum::CHANNEL_LIGHTS + 7)); + addChild(createLightCentered>(mm2px(Vec(4.619, 37.595)), module, Sum::CHANNEL_LIGHTS + 8)); + addChild(createLightCentered>(mm2px(Vec(6.619, 37.595)), module, Sum::CHANNEL_LIGHTS + 9)); + addChild(createLightCentered>(mm2px(Vec(8.619, 37.595)), module, Sum::CHANNEL_LIGHTS + 10)); + addChild(createLightCentered>(mm2px(Vec(10.619, 37.595)), module, Sum::CHANNEL_LIGHTS + 11)); + addChild(createLightCentered>(mm2px(Vec(4.619, 39.595)), module, Sum::CHANNEL_LIGHTS + 12)); + addChild(createLightCentered>(mm2px(Vec(6.619, 39.595)), module, Sum::CHANNEL_LIGHTS + 13)); + addChild(createLightCentered>(mm2px(Vec(8.619, 39.595)), module, Sum::CHANNEL_LIGHTS + 14)); + addChild(createLightCentered>(mm2px(Vec(10.619, 39.595)), module, Sum::CHANNEL_LIGHTS + 15)); + + addChild(createLightCentered>(mm2px(Vec(7.619, 70.792)), module, Sum::VU_LIGHTS + 0)); + addChild(createLightCentered>(mm2px(Vec(7.619, 75.917)), module, Sum::VU_LIGHTS + 1)); + addChild(createLightCentered>(mm2px(Vec(7.619, 81.042)), module, Sum::VU_LIGHTS + 2)); + addChild(createLightCentered>(mm2px(Vec(7.619, 86.167)), module, Sum::VU_LIGHTS + 3)); + addChild(createLightCentered>(mm2px(Vec(7.619, 91.292)), module, Sum::VU_LIGHTS + 4)); + addChild(createLightCentered>(mm2px(Vec(7.619, 96.417)), module, Sum::VU_LIGHTS + 5)); + } +}; + + +Model *modelSum = createModel("Sum"); diff --git a/src/Unity.cpp b/src/Unity.cpp index 74eaa22..af8c990 100644 --- a/src/Unity.cpp +++ b/src/Unity.cpp @@ -1,4 +1,4 @@ -#include "Fundamental.hpp" +#include "plugin.hpp" struct Unity : Module { diff --git a/src/VCA.cpp b/src/VCA.cpp index d77660b..e6e6d5b 100644 --- a/src/VCA.cpp +++ b/src/VCA.cpp @@ -1,4 +1,4 @@ -#include "Fundamental.hpp" +#include "plugin.hpp" struct VCA : Module { diff --git a/src/VCF.cpp b/src/VCF.cpp index 7a327f8..53ad6a6 100644 --- a/src/VCF.cpp +++ b/src/VCF.cpp @@ -1,4 +1,4 @@ -#include "Fundamental.hpp" +#include "plugin.hpp" static float clip(float x) { diff --git a/src/VCMixer.cpp b/src/VCMixer.cpp index 5771ddf..e16b1da 100644 --- a/src/VCMixer.cpp +++ b/src/VCMixer.cpp @@ -1,4 +1,4 @@ -#include "Fundamental.hpp" +#include "plugin.hpp" struct VCMixer : Module { diff --git a/src/VCO.cpp b/src/VCO.cpp index 8c93d75..19a1786 100644 --- a/src/VCO.cpp +++ b/src/VCO.cpp @@ -1,4 +1,4 @@ -#include "Fundamental.hpp" +#include "plugin.hpp" extern float sawTable[2048]; diff --git a/src/Viz.cpp b/src/Viz.cpp new file mode 100644 index 0000000..6ed9f1c --- /dev/null +++ b/src/Viz.cpp @@ -0,0 +1,126 @@ +#include "plugin.hpp" + + +struct Viz : Module { + enum ParamIds { + NUM_PARAMS + }; + enum InputIds { + POLY_INPUT, + NUM_INPUTS + }; + enum OutputIds { + NUM_OUTPUTS + }; + enum LightIds { + ENUMS(VU_LIGHTS, 16*2), + NUM_LIGHTS + }; + + int channels = 0; + dsp::VUMeter2 vuMeter[16]; + int frame = 0; + + Viz() { + config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + + for (int c = 0; c < 16; c++) { + vuMeter[c].lambda = 1 / 0.1f; + } + } + + void step() override { + if (frame % 16 == 0) { + channels = inputs[POLY_INPUT].getChannels(); + float deltaTime = APP->engine->getSampleTime() * 16; + + // Process VU meters + for (int c = 0; c < channels; c++) { + float value = inputs[POLY_INPUT].getVoltage(c) / 10.f; + vuMeter[c].process(deltaTime, value); + } + for (int c = channels; c < 16; c++) { + vuMeter[c].reset(); + } + } + + if (frame % 256 == 0) { + // Set lights + for (int c = 0; c < 16; c++) { + float green = vuMeter[c].getBrightness(-24.f, -6.f); + float red = vuMeter[c].getBrightness(-6.f, 0.f); + lights[VU_LIGHTS + c*2 + 0].setBrightness(green - red); + lights[VU_LIGHTS + c*2 + 1].setBrightness(red); + } + } + + frame++; + } +}; + + +struct VizDisplay : Widget { + Viz *module; + std::shared_ptr font; + + VizDisplay() { + box.size = mm2px(Vec(15.24, 88.126)); + font = APP->window->loadFont(asset::plugin(pluginInstance, "res/nunito/Nunito-Bold.ttf")); + } + + void draw(const widget::DrawContext &ctx) override { + for (int c = 0; c < 16; c++) { + Vec p = Vec(15, 16 + (float) c / 16 * (box.size.y - 10)); + std::string text = string::f("%d", c + 1); + + nvgFontFaceId(ctx.vg, font->handle); + nvgFontSize(ctx.vg, 11); + nvgTextLetterSpacing(ctx.vg, 0.0); + nvgTextAlign(ctx.vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE); + if (module && c < module->channels) + nvgFillColor(ctx.vg, nvgRGB(255, 255, 255)); + else + nvgFillColor(ctx.vg, nvgRGB(99, 99, 99)); + nvgText(ctx.vg, p.x, p.y, text.c_str(), NULL); + } + } +}; + + +struct VizWidget : ModuleWidget { + VizWidget(Viz *module) { + setModule(module); + setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Viz.svg"))); + + addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); + addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); + addChild(createWidget(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + + addInput(createInputCentered(mm2px(Vec(7.619, 21.346)), module, Viz::POLY_INPUT)); + + addChild(createLightCentered>(mm2px(Vec(10.854, 33.626)), module, Viz::VU_LIGHTS + 0*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 38.916)), module, Viz::VU_LIGHTS + 1*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 44.205)), module, Viz::VU_LIGHTS + 2*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 49.496)), module, Viz::VU_LIGHTS + 3*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 54.785)), module, Viz::VU_LIGHTS + 4*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 60.075)), module, Viz::VU_LIGHTS + 5*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 65.364)), module, Viz::VU_LIGHTS + 6*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 70.654)), module, Viz::VU_LIGHTS + 7*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 75.943)), module, Viz::VU_LIGHTS + 8*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 81.233)), module, Viz::VU_LIGHTS + 9*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 86.522)), module, Viz::VU_LIGHTS + 10*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 91.812)), module, Viz::VU_LIGHTS + 11*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 97.101)), module, Viz::VU_LIGHTS + 12*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 102.392)), module, Viz::VU_LIGHTS + 13*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 107.681)), module, Viz::VU_LIGHTS + 14*2)); + addChild(createLightCentered>(mm2px(Vec(10.854, 112.971)), module, Viz::VU_LIGHTS + 15*2)); + + VizDisplay *vizDisplay = createWidget(mm2px(Vec(0.0, 29.235))); + vizDisplay->module = module; + addChild(vizDisplay); + } +}; + + +Model *modelViz = createModel("Viz"); diff --git a/src/Fundamental.cpp b/src/plugin.cpp similarity index 81% rename from src/Fundamental.cpp rename to src/plugin.cpp index 505cb2d..92d5198 100644 --- a/src/Fundamental.cpp +++ b/src/plugin.cpp @@ -1,4 +1,4 @@ -#include "Fundamental.hpp" +#include "plugin.hpp" Plugin *pluginInstance; @@ -23,4 +23,8 @@ void init(rack::Plugin *p) { p->addModel(modelSEQ3); p->addModel(modelSequentialSwitch1); p->addModel(modelSequentialSwitch2); + p->addModel(modelSplit); + p->addModel(modelMerge); + p->addModel(modelSum); + p->addModel(modelViz); } diff --git a/src/Fundamental.hpp b/src/plugin.hpp similarity index 84% rename from src/Fundamental.hpp rename to src/plugin.hpp index d874b21..8c68585 100644 --- a/src/Fundamental.hpp +++ b/src/plugin.hpp @@ -24,5 +24,9 @@ extern Model *modelScope; extern Model *modelSEQ3; extern Model *modelSequentialSwitch1; extern Model *modelSequentialSwitch2; +extern Model *modelSplit; +extern Model *modelMerge; +extern Model *modelSum; +extern Model *modelViz;