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.

108 lines
4.3KB

  1. #include "plugin.hpp"
  2. struct Viz : Module {
  3. enum ParamIds {
  4. NUM_PARAMS
  5. };
  6. enum InputIds {
  7. POLY_INPUT,
  8. NUM_INPUTS
  9. };
  10. enum OutputIds {
  11. NUM_OUTPUTS
  12. };
  13. enum LightIds {
  14. ENUMS(VU_LIGHTS, 16 * 2),
  15. NUM_LIGHTS
  16. };
  17. int lastChannels = 0;
  18. dsp::ClockDivider lightDivider;
  19. Viz() {
  20. config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
  21. lightDivider.setDivision(16);
  22. }
  23. void process(const ProcessArgs &args) override {
  24. if (lightDivider.process()) {
  25. lastChannels = inputs[POLY_INPUT].getChannels();
  26. float deltaTime = args.sampleTime * lightDivider.getDivision();
  27. for (int c = 0; c < 16; c++) {
  28. float v = inputs[POLY_INPUT].getVoltage(c) / 10.f;
  29. lights[VU_LIGHTS + c * 2 + 0].setSmoothBrightness(v, deltaTime);
  30. lights[VU_LIGHTS + c * 2 + 1].setSmoothBrightness(-v, deltaTime);
  31. }
  32. }
  33. }
  34. };
  35. struct VizDisplay : Widget {
  36. Viz *module;
  37. std::shared_ptr<Font> font;
  38. VizDisplay() {
  39. box.size = mm2px(Vec(15.24, 88.126));
  40. font = APP->window->loadFont(asset::plugin(pluginInstance, "res/nunito/Nunito-Bold.ttf"));
  41. }
  42. void draw(const DrawArgs &args) override {
  43. for (int c = 0; c < 16; c++) {
  44. Vec p = Vec(15, 16 + (float) c / 16 * (box.size.y - 10));
  45. std::string text = string::f("%d", c + 1);
  46. nvgFontFaceId(args.vg, font->handle);
  47. nvgFontSize(args.vg, 11);
  48. nvgTextLetterSpacing(args.vg, 0.0);
  49. nvgTextAlign(args.vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE);
  50. if (module && c < module->lastChannels)
  51. nvgFillColor(args.vg, nvgRGB(255, 255, 255));
  52. else
  53. nvgFillColor(args.vg, nvgRGB(99, 99, 99));
  54. nvgText(args.vg, p.x, p.y, text.c_str(), NULL);
  55. }
  56. }
  57. };
  58. struct VizWidget : ModuleWidget {
  59. VizWidget(Viz *module) {
  60. setModule(module);
  61. setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Viz.svg")));
  62. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  63. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  64. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  65. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  66. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.619, 21.346)), module, Viz::POLY_INPUT));
  67. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 33.626)), module, Viz::VU_LIGHTS + 0 * 2));
  68. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 38.916)), module, Viz::VU_LIGHTS + 1 * 2));
  69. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 44.205)), module, Viz::VU_LIGHTS + 2 * 2));
  70. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 49.496)), module, Viz::VU_LIGHTS + 3 * 2));
  71. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 54.785)), module, Viz::VU_LIGHTS + 4 * 2));
  72. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 60.075)), module, Viz::VU_LIGHTS + 5 * 2));
  73. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 65.364)), module, Viz::VU_LIGHTS + 6 * 2));
  74. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 70.654)), module, Viz::VU_LIGHTS + 7 * 2));
  75. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 75.943)), module, Viz::VU_LIGHTS + 8 * 2));
  76. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 81.233)), module, Viz::VU_LIGHTS + 9 * 2));
  77. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 86.522)), module, Viz::VU_LIGHTS + 10 * 2));
  78. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 91.812)), module, Viz::VU_LIGHTS + 11 * 2));
  79. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 97.101)), module, Viz::VU_LIGHTS + 12 * 2));
  80. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 102.392)), module, Viz::VU_LIGHTS + 13 * 2));
  81. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 107.681)), module, Viz::VU_LIGHTS + 14 * 2));
  82. addChild(createLightCentered<SmallLight<GreenRedLight>>(mm2px(Vec(10.854, 112.971)), module, Viz::VU_LIGHTS + 15 * 2));
  83. VizDisplay *vizDisplay = createWidget<VizDisplay>(mm2px(Vec(0.0, 29.235)));
  84. vizDisplay->module = module;
  85. addChild(vizDisplay);
  86. }
  87. };
  88. Model *modelViz = createModel<Viz, VizWidget>("Viz");