Sums.cpp (2771B)
1 2 #include "Sums.hpp" 3 4 void Sums::processAll(const ProcessArgs& args) { 5 for (int i = 0, cn = std::max(1, inputs[A_INPUT].getChannels()); i < cn; ++i) { 6 float a = inputs[A_INPUT].getPolyVoltage(i); 7 float b = inputs[B_INPUT].getPolyVoltage(i); 8 outputs[SUM_OUTPUT].setChannels(cn); 9 outputs[DIFFERENCE_OUTPUT].setChannels(cn); 10 outputs[MAX_OUTPUT].setChannels(cn); 11 outputs[MIN_OUTPUT].setChannels(cn); 12 if (_disableOutputLimit) { 13 outputs[SUM_OUTPUT].setVoltage(a + b, i); 14 outputs[DIFFERENCE_OUTPUT].setVoltage(a - b, i); 15 outputs[MAX_OUTPUT].setVoltage(std::max(a, b), i); 16 outputs[MIN_OUTPUT].setVoltage(std::min(a, b), i); 17 } 18 else { 19 outputs[SUM_OUTPUT].setVoltage(clamp(a + b, -12.0f, 12.0f), i); 20 outputs[DIFFERENCE_OUTPUT].setVoltage(clamp(a - b, -12.0f, 12.0f), i); 21 outputs[MAX_OUTPUT].setVoltage(clamp(std::max(a, b), -12.0f, 12.0f), i); 22 outputs[MIN_OUTPUT].setVoltage(clamp(std::min(a, b), -12.0f, 12.0f), i); 23 } 24 } 25 26 int cn = inputs[NEGATE_INPUT].getChannels(); 27 outputs[NEGATE_OUTPUT].setChannels(cn); 28 for (int i = 0; i < cn; ++i) { 29 if (_disableOutputLimit) { 30 outputs[NEGATE_OUTPUT].setVoltage(-inputs[NEGATE_INPUT].getPolyVoltage(i), i); 31 } 32 else { 33 outputs[NEGATE_OUTPUT].setVoltage(clamp(-inputs[NEGATE_INPUT].getPolyVoltage(i), -12.0f, 12.0f), i); 34 } 35 } 36 } 37 38 struct SumsWidget : DisableOutputLimitModuleWidget { 39 static constexpr int hp = 3; 40 41 SumsWidget(Sums* module) { 42 setModule(module); 43 box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT); 44 setPanel(box.size, "Sums"); 45 createScrews(); 46 47 // generated by svg_widgets.rb 48 auto aInputPosition = Vec(10.5, 23.0); 49 auto bInputPosition = Vec(10.5, 53.0); 50 auto negateInputPosition = Vec(10.5, 262.0); 51 52 auto sumOutputPosition = Vec(10.5, 86.0); 53 auto differenceOutputPosition = Vec(10.5, 126.0); 54 auto maxOutputPosition = Vec(10.5, 166.0); 55 auto minOutputPosition = Vec(10.5, 206.0); 56 auto negateOutputPosition = Vec(10.5, 295.0); 57 // end generated by svg_widgets.rb 58 59 addInput(createInput<Port24>(aInputPosition, module, Sums::A_INPUT)); 60 addInput(createInput<Port24>(bInputPosition, module, Sums::B_INPUT)); 61 addInput(createInput<Port24>(negateInputPosition, module, Sums::NEGATE_INPUT)); 62 63 addOutput(createOutput<Port24>(sumOutputPosition, module, Sums::SUM_OUTPUT)); 64 addOutput(createOutput<Port24>(differenceOutputPosition, module, Sums::DIFFERENCE_OUTPUT)); 65 addOutput(createOutput<Port24>(maxOutputPosition, module, Sums::MAX_OUTPUT)); 66 addOutput(createOutput<Port24>(minOutputPosition, module, Sums::MIN_OUTPUT)); 67 addOutput(createOutput<Port24>(negateOutputPosition, module, Sums::NEGATE_OUTPUT)); 68 } 69 }; 70 71 Model* modelSums = bogaudio::createModel<Sums, SumsWidget>("Bogaudio-Sums", "SUMS", "Arithmetic logic", "Logic", "Polyphonic");