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.

121 lines
3.3KB

  1. //============================================================================================================
  2. //!
  3. //! \file VU-G1.cpp
  4. //!
  5. //! \brief VU-G1 is a simple six input volume monitoring module.
  6. //!
  7. //============================================================================================================
  8. #include "Gratrix.hpp"
  9. namespace rack_plugin_Gratrix {
  10. //============================================================================================================
  11. //! \brief The module.
  12. struct GtxModule_VU_G1 : Module
  13. {
  14. enum ParamIds {
  15. NUM_PARAMS
  16. };
  17. enum InputIds {
  18. IN1_INPUT, // N+1
  19. NUM_INPUTS
  20. };
  21. enum OutputIds {
  22. NUM_OUTPUTS,
  23. };
  24. enum LightIds {
  25. NUM_LIGHTS = 10 // N
  26. };
  27. GtxModule_VU_G1()
  28. :
  29. Module(NUM_PARAMS, (GTX__N+1) * NUM_INPUTS, NUM_OUTPUTS, GTX__N * NUM_LIGHTS)
  30. {
  31. }
  32. static constexpr std::size_t imap(std::size_t port, std::size_t bank)
  33. {
  34. return port + bank * NUM_INPUTS;
  35. }
  36. void step() override
  37. {
  38. for (std::size_t i=0; i<GTX__N; ++i)
  39. {
  40. float input = inputs[imap(IN1_INPUT, i)].active ? inputs[imap(IN1_INPUT, i)].value : inputs[imap(IN1_INPUT, GTX__N)].value;
  41. float dB = logf(fabsf(input * 0.1f)) * (10.0f / logf(20.0f));
  42. float dB2 = dB * (1.0f / 3.0f);
  43. for (int j = 0; j < NUM_LIGHTS; j++)
  44. {
  45. float b = clamp(dB2 + (j+1), 0.0f, 1.0f);
  46. lights[NUM_LIGHTS * i + j].setBrightnessSmooth(b * 0.9f);
  47. }
  48. }
  49. }
  50. };
  51. //============================================================================================================
  52. //! \brief The widget.
  53. struct GtxWidget_VU_G1 : ModuleWidget
  54. {
  55. GtxWidget_VU_G1(GtxModule_VU_G1 *module) : ModuleWidget(module)
  56. {
  57. GTX__WIDGET();
  58. box.size = Vec(6*15, 380);
  59. #if GTX__SAVE_SVG
  60. {
  61. PanelGen pg(assetPlugin(plugin, "build/res/VU-G1.svg"), box.size, "VU-G1");
  62. pg.nob_big(0, 0, "VOLUME");
  63. pg.bus_in (0, 2, "IN");
  64. }
  65. #endif
  66. setPanel(SVG::load(assetPlugin(plugin, "res/VU-G1.svg")));
  67. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  68. addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 0)));
  69. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  70. addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 365)));
  71. for (std::size_t i=0; i<GTX__N; ++i)
  72. {
  73. addInput(createInputGTX<PortInMed>(Vec(px(0, i), py(2, i)), module, GtxModule_VU_G1::imap(GtxModule_VU_G1::IN1_INPUT, i)));
  74. }
  75. addInput(createInputGTX<PortInMed>(Vec(gx(0), gy(2)), module, GtxModule_VU_G1::imap(GtxModule_VU_G1::IN1_INPUT, GTX__N)));
  76. for (std::size_t i=0, k=0; i<GTX__N; ++i)
  77. {
  78. for (std::size_t j=0; j<GtxModule_VU_G1::NUM_LIGHTS; ++j, ++k)
  79. {
  80. switch (j)
  81. {
  82. case 0 : addChild(ModuleLightWidget::create<SmallLight< RedLight>>(l_s(gx(0)+(i-2.5f)*13.0f, gy(0.5)+(j-4.5f)*11.0f), module, k)); break;
  83. case 1 :
  84. case 2 : addChild(ModuleLightWidget::create<SmallLight<YellowLight>>(l_s(gx(0)+(i-2.5f)*13.0f, gy(0.5)+(j-4.5f)*11.0f), module, k)); break;
  85. default : addChild(ModuleLightWidget::create<SmallLight< GreenLight>>(l_s(gx(0)+(i-2.5f)*13.0f, gy(0.5)+(j-4.5f)*11.0f), module, k)); break;
  86. }
  87. }
  88. }
  89. }
  90. };
  91. } // namespace rack_plugin_Gratrix
  92. using namespace rack_plugin_Gratrix;
  93. RACK_PLUGIN_MODEL_INIT(Gratrix, VU_G1) {
  94. Model *model = Model::create<GtxModule_VU_G1, GtxWidget_VU_G1>("Gratrix", "VU-G1", "VU-G1", VISUAL_TAG);
  95. return model;
  96. }