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.

DualAtenuverter.cpp 2.5KB

5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "Befaco.hpp"
  2. struct DualAtenuverter : Module {
  3. enum ParamIds {
  4. ATEN1_PARAM,
  5. OFFSET1_PARAM,
  6. ATEN2_PARAM,
  7. OFFSET2_PARAM,
  8. NUM_PARAMS
  9. };
  10. enum InputIds {
  11. IN1_INPUT,
  12. IN2_INPUT,
  13. NUM_INPUTS
  14. };
  15. enum OutputIds {
  16. OUT1_OUTPUT,
  17. OUT2_OUTPUT,
  18. NUM_OUTPUTS
  19. };
  20. enum LightIds {
  21. OUT1_POS_LIGHT,
  22. OUT1_NEG_LIGHT,
  23. OUT2_POS_LIGHT,
  24. OUT2_NEG_LIGHT,
  25. NUM_LIGHTS
  26. };
  27. DualAtenuverter() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  28. void step() override;
  29. };
  30. void DualAtenuverter::step() {
  31. float out1 = inputs[IN1_INPUT].value * params[ATEN1_PARAM].value + params[OFFSET1_PARAM].value;
  32. float out2 = inputs[IN2_INPUT].value * params[ATEN2_PARAM].value + params[OFFSET2_PARAM].value;
  33. out1 = clamp(out1, -10.0f, 10.0f);
  34. out2 = clamp(out2, -10.0f, 10.0f);
  35. outputs[OUT1_OUTPUT].value = out1;
  36. outputs[OUT2_OUTPUT].value = out2;
  37. lights[OUT1_POS_LIGHT].value = fmaxf(0.0, out1 / 5.0);
  38. lights[OUT1_NEG_LIGHT].value = fmaxf(0.0, -out1 / 5.0);
  39. lights[OUT2_POS_LIGHT].value = fmaxf(0.0, out2 / 5.0);
  40. lights[OUT2_NEG_LIGHT].value = fmaxf(0.0, -out2 / 5.0);
  41. }
  42. struct DualAtenuverterWidget : ModuleWidget {
  43. DualAtenuverterWidget(DualAtenuverter *module) : ModuleWidget(module) {
  44. setPanel(SVG::load(assetPlugin(plugin, "res/DualAtenuverter.svg")));
  45. addChild(createWidget<Knurlie>(Vec(15, 0)));
  46. addChild(createWidget<Knurlie>(Vec(15, 365)));
  47. addParam(createParam<Davies1900hWhiteKnob>(Vec(20, 33), module, DualAtenuverter::ATEN1_PARAM, -1.0, 1.0, 0.0));
  48. addParam(createParam<Davies1900hRedKnob>(Vec(20, 91), module, DualAtenuverter::OFFSET1_PARAM, -10.0, 10.0, 0.0));
  49. addParam(createParam<Davies1900hWhiteKnob>(Vec(20, 201), module, DualAtenuverter::ATEN2_PARAM, -1.0, 1.0, 0.0));
  50. addParam(createParam<Davies1900hRedKnob>(Vec(20, 260), module, DualAtenuverter::OFFSET2_PARAM, -10.0, 10.0, 0.0));
  51. addInput(createPort<PJ301MPort>(Vec(7, 152), PortWidget::INPUT, module, DualAtenuverter::IN1_INPUT));
  52. addOutput(createPort<PJ301MPort>(Vec(43, 152), PortWidget::OUTPUT, module, DualAtenuverter::OUT1_OUTPUT));
  53. addInput(createPort<PJ301MPort>(Vec(7, 319), PortWidget::INPUT, module, DualAtenuverter::IN2_INPUT));
  54. addOutput(createPort<PJ301MPort>(Vec(43, 319), PortWidget::OUTPUT, module, DualAtenuverter::OUT2_OUTPUT));
  55. addChild(createLight<MediumLight<GreenRedLight>>(Vec(33, 143), module, DualAtenuverter::OUT1_POS_LIGHT));
  56. addChild(createLight<MediumLight<GreenRedLight>>(Vec(33, 311), module, DualAtenuverter::OUT2_POS_LIGHT));
  57. }
  58. };
  59. Model *modelDualAtenuverter = createModel<DualAtenuverter, DualAtenuverterWidget>("DualAtenuverter");