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.

105 lines
4.6KB

  1. #include "plugin.hpp"
  2. struct Sum : Module {
  3. enum ParamIds {
  4. LEVEL_PARAM,
  5. NUM_PARAMS
  6. };
  7. enum InputIds {
  8. POLY_INPUT,
  9. NUM_INPUTS
  10. };
  11. enum OutputIds {
  12. MONO_OUTPUT,
  13. NUM_OUTPUTS
  14. };
  15. enum LightIds {
  16. ENUMS(CHANNEL_LIGHTS, 16),
  17. ENUMS(VU_LIGHTS, 6),
  18. NUM_LIGHTS
  19. };
  20. dsp::VuMeter2 vuMeter;
  21. dsp::ClockDivider vuDivider;
  22. dsp::ClockDivider lightDivider;
  23. Sum() {
  24. config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
  25. configParam(LEVEL_PARAM, 0.f, 1.f, 1.f, "Level", "%", 0.f, 100.f);
  26. vuMeter.lambda = 1 / 0.1f;
  27. vuDivider.setDivision(16);
  28. lightDivider.setDivision(256);
  29. }
  30. void process(const ProcessArgs &args) override {
  31. float sum = inputs[POLY_INPUT].getVoltageSum();
  32. sum *= params[LEVEL_PARAM].getValue();
  33. outputs[MONO_OUTPUT].setVoltage(sum);
  34. if (vuDivider.process()) {
  35. vuMeter.process(args.sampleTime * vuDivider.getDivision(), sum / 10.f);
  36. }
  37. // Set channel lights infrequently
  38. if (lightDivider.process()) {
  39. for (int c = 0; c < 16; c++) {
  40. bool active = (c < inputs[POLY_INPUT].getChannels());
  41. lights[CHANNEL_LIGHTS + c].setBrightness(active);
  42. }
  43. lights[VU_LIGHTS + 0].setBrightness(vuMeter.getBrightness(0.f, 0.f));
  44. for (int i = 1; i < 6; i++) {
  45. lights[VU_LIGHTS + i].setBrightness(vuMeter.getBrightness(-3.f * i, -3.f * (i - 1)));
  46. }
  47. }
  48. }
  49. };
  50. struct SumWidget : ModuleWidget {
  51. SumWidget(Sum *module) {
  52. setModule(module);
  53. setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Sum.svg")));
  54. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  55. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  56. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  57. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  58. addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec(7.62, 53.519)), module, Sum::LEVEL_PARAM));
  59. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.619, 21.347)), module, Sum::POLY_INPUT));
  60. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(7.62, 112.021)), module, Sum::MONO_OUTPUT));
  61. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(4.619, 33.595)), module, Sum::CHANNEL_LIGHTS + 0));
  62. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(6.619, 33.595)), module, Sum::CHANNEL_LIGHTS + 1));
  63. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(8.619, 33.595)), module, Sum::CHANNEL_LIGHTS + 2));
  64. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(10.619, 33.595)), module, Sum::CHANNEL_LIGHTS + 3));
  65. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(4.619, 35.595)), module, Sum::CHANNEL_LIGHTS + 4));
  66. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(6.619, 35.595)), module, Sum::CHANNEL_LIGHTS + 5));
  67. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(8.619, 35.595)), module, Sum::CHANNEL_LIGHTS + 6));
  68. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(10.619, 35.595)), module, Sum::CHANNEL_LIGHTS + 7));
  69. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(4.619, 37.595)), module, Sum::CHANNEL_LIGHTS + 8));
  70. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(6.619, 37.595)), module, Sum::CHANNEL_LIGHTS + 9));
  71. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(8.619, 37.595)), module, Sum::CHANNEL_LIGHTS + 10));
  72. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(10.619, 37.595)), module, Sum::CHANNEL_LIGHTS + 11));
  73. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(4.619, 39.595)), module, Sum::CHANNEL_LIGHTS + 12));
  74. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(6.619, 39.595)), module, Sum::CHANNEL_LIGHTS + 13));
  75. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(8.619, 39.595)), module, Sum::CHANNEL_LIGHTS + 14));
  76. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(10.619, 39.595)), module, Sum::CHANNEL_LIGHTS + 15));
  77. addChild(createLightCentered<MediumLight<RedLight>>(mm2px(Vec(7.619, 70.792)), module, Sum::VU_LIGHTS + 0));
  78. addChild(createLightCentered<MediumLight<YellowLight>>(mm2px(Vec(7.619, 75.917)), module, Sum::VU_LIGHTS + 1));
  79. addChild(createLightCentered<MediumLight<YellowLight>>(mm2px(Vec(7.619, 81.042)), module, Sum::VU_LIGHTS + 2));
  80. addChild(createLightCentered<MediumLight<GreenLight>>(mm2px(Vec(7.619, 86.167)), module, Sum::VU_LIGHTS + 3));
  81. addChild(createLightCentered<MediumLight<GreenLight>>(mm2px(Vec(7.619, 91.292)), module, Sum::VU_LIGHTS + 4));
  82. addChild(createLightCentered<MediumLight<GreenLight>>(mm2px(Vec(7.619, 96.417)), module, Sum::VU_LIGHTS + 5));
  83. }
  84. };
  85. Model *modelSum = createModel<Sum, SumWidget>("Sum");