You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.7KB

  1. #include "Sums.hpp"
  2. void Sums::step() {
  3. float a = inputs[A_INPUT].value;
  4. float b = inputs[B_INPUT].value;
  5. if (_disableOutputLimit) {
  6. outputs[SUM_OUTPUT].value = a + b,
  7. outputs[DIFFERENCE_OUTPUT].value = a - b;
  8. outputs[MAX_OUTPUT].value = std::max(a, b);
  9. outputs[MIN_OUTPUT].value = std::min(a, b);
  10. if (inputs[NEGATE_INPUT].active) {
  11. outputs[NEGATE_OUTPUT].value = -inputs[NEGATE_INPUT].value;
  12. }
  13. else {
  14. outputs[NEGATE_OUTPUT].value = 0.0f;
  15. }
  16. }
  17. else {
  18. outputs[SUM_OUTPUT].value = clamp(a + b, -12.0f, 12.0f);
  19. outputs[DIFFERENCE_OUTPUT].value = clamp(a - b, -12.0f, 12.0f);
  20. outputs[MAX_OUTPUT].value = clamp(std::max(a, b), -12.0f, 12.0f);
  21. outputs[MIN_OUTPUT].value = clamp(std::min(a, b), -12.0f, 12.0f);
  22. if (inputs[NEGATE_INPUT].active) {
  23. outputs[NEGATE_OUTPUT].value = clamp(-inputs[NEGATE_INPUT].value, -12.0f, 12.0f);
  24. }
  25. else {
  26. outputs[NEGATE_OUTPUT].value = 0.0f;
  27. }
  28. }
  29. }
  30. struct SumsWidget : DisableOutputLimitModuleWidget {
  31. static constexpr int hp = 3;
  32. SumsWidget(Sums* module) : DisableOutputLimitModuleWidget(module) {
  33. box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
  34. {
  35. SVGPanel *panel = new SVGPanel();
  36. panel->box.size = box.size;
  37. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Sums.svg")));
  38. addChild(panel);
  39. }
  40. addChild(Widget::create<ScrewSilver>(Vec(0, 0)));
  41. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365)));
  42. // generated by svg_widgets.rb
  43. auto aInputPosition = Vec(10.5, 23.0);
  44. auto bInputPosition = Vec(10.5, 53.0);
  45. auto negateInputPosition = Vec(10.5, 262.0);
  46. auto sumOutputPosition = Vec(10.5, 86.0);
  47. auto differenceOutputPosition = Vec(10.5, 126.0);
  48. auto maxOutputPosition = Vec(10.5, 166.0);
  49. auto minOutputPosition = Vec(10.5, 206.0);
  50. auto negateOutputPosition = Vec(10.5, 295.0);
  51. // end generated by svg_widgets.rb
  52. addInput(Port::create<Port24>(aInputPosition, Port::INPUT, module, Sums::A_INPUT));
  53. addInput(Port::create<Port24>(bInputPosition, Port::INPUT, module, Sums::B_INPUT));
  54. addInput(Port::create<Port24>(negateInputPosition, Port::INPUT, module, Sums::NEGATE_INPUT));
  55. addOutput(Port::create<Port24>(sumOutputPosition, Port::OUTPUT, module, Sums::SUM_OUTPUT));
  56. addOutput(Port::create<Port24>(differenceOutputPosition, Port::OUTPUT, module, Sums::DIFFERENCE_OUTPUT));
  57. addOutput(Port::create<Port24>(maxOutputPosition, Port::OUTPUT, module, Sums::MAX_OUTPUT));
  58. addOutput(Port::create<Port24>(minOutputPosition, Port::OUTPUT, module, Sums::MIN_OUTPUT));
  59. addOutput(Port::create<Port24>(negateOutputPosition, Port::OUTPUT, module, Sums::NEGATE_OUTPUT));
  60. }
  61. };
  62. RACK_PLUGIN_MODEL_INIT(Bogaudio, Sums) {
  63. Model *modelSums = createModel<Sums, SumsWidget>("Bogaudio-Sums", "Sums", "arithmetic logic", LOGIC_TAG);
  64. return modelSums;
  65. }