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.

129 lines
4.9KB

  1. #include "plugin.hpp"
  2. struct _8vert : Module {
  3. enum ParamIds {
  4. ENUMS(GAIN_PARAMS, 8),
  5. NUM_PARAMS
  6. };
  7. enum InputIds {
  8. ENUMS(IN_INPUTS, 8),
  9. NUM_INPUTS
  10. };
  11. enum OutputIds {
  12. ENUMS(OUT_OUTPUTS, 8),
  13. NUM_OUTPUTS
  14. };
  15. enum LightIds {
  16. NUM_LIGHTS
  17. };
  18. dsp::ClockDivider paramDivider;
  19. _8vert() {
  20. config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
  21. for (int i = 0; i < 8; i++) {
  22. configParam(GAIN_PARAMS + i, -1.f, 1.f, 0.f, string::f("Row %d gain", i + 1), "%", 0, 100);
  23. configInput(IN_INPUTS + i, string::f("Row %d", i + 1));
  24. configOutput(OUT_OUTPUTS + i, string::f("Row %d", i + 1));
  25. }
  26. paramDivider.setDivision(2048);
  27. }
  28. void process(const ProcessArgs& args) override {
  29. float in[16] = {10.f};
  30. int channels = 1;
  31. for (int i = 0; i < 8; i++) {
  32. // Get input
  33. if (inputs[IN_INPUTS + i].isConnected()) {
  34. channels = inputs[IN_INPUTS + i].getChannels();
  35. inputs[IN_INPUTS + i].readVoltages(in);
  36. }
  37. if (outputs[OUT_OUTPUTS + i].isConnected()) {
  38. // Apply gain
  39. float out[16];
  40. float gain = params[GAIN_PARAMS + i].getValue();
  41. for (int c = 0; c < channels; c++) {
  42. out[c] = gain * in[c];
  43. }
  44. // Set output
  45. outputs[OUT_OUTPUTS + i].setChannels(channels);
  46. outputs[OUT_OUTPUTS + i].writeVoltages(out);
  47. }
  48. }
  49. if (paramDivider.process()) {
  50. refreshParamQuantities();
  51. }
  52. }
  53. /** Set the gain param units to either V or %, depending on whether a cable is connected. */
  54. void refreshParamQuantities() {
  55. bool normalized = true;
  56. for (int i = 0; i < 8; i++) {
  57. ParamQuantity* pq = paramQuantities[GAIN_PARAMS + i];
  58. if (!pq)
  59. continue;
  60. if (inputs[IN_INPUTS + i].isConnected())
  61. normalized = false;
  62. if (normalized) {
  63. pq->unit = "V";
  64. pq->displayMultiplier = 10.f;
  65. }
  66. else {
  67. pq->unit = "%";
  68. pq->displayMultiplier = 100.f;
  69. }
  70. }
  71. }
  72. };
  73. struct _8vertWidget : ModuleWidget {
  74. _8vertWidget(_8vert* module) {
  75. setModule(module);
  76. setPanel(createPanel(asset::plugin(pluginInstance, "res/8vert.svg")));
  77. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  78. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  79. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  80. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  81. addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec(20.351, 21.968)), module, _8vert::GAIN_PARAMS + 0));
  82. addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec(20.351, 34.982)), module, _8vert::GAIN_PARAMS + 1));
  83. addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec(20.351, 48.004)), module, _8vert::GAIN_PARAMS + 2));
  84. addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec(20.351, 61.026)), module, _8vert::GAIN_PARAMS + 3));
  85. addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec(20.351, 74.048)), module, _8vert::GAIN_PARAMS + 4));
  86. addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec(20.351, 87.07)), module, _8vert::GAIN_PARAMS + 5));
  87. addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec(20.351, 100.093)), module, _8vert::GAIN_PARAMS + 6));
  88. addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec(20.351, 113.115)), module, _8vert::GAIN_PARAMS + 7));
  89. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.331, 21.968)), module, _8vert::IN_INPUTS + 0));
  90. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.331, 34.982)), module, _8vert::IN_INPUTS + 1));
  91. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.331, 48.004)), module, _8vert::IN_INPUTS + 2));
  92. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.331, 61.026)), module, _8vert::IN_INPUTS + 3));
  93. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.331, 74.048)), module, _8vert::IN_INPUTS + 4));
  94. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.331, 87.07)), module, _8vert::IN_INPUTS + 5));
  95. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.331, 100.093)), module, _8vert::IN_INPUTS + 6));
  96. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.331, 113.115)), module, _8vert::IN_INPUTS + 7));
  97. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.371, 21.968)), module, _8vert::OUT_OUTPUTS + 0));
  98. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.371, 34.982)), module, _8vert::OUT_OUTPUTS + 1));
  99. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.371, 48.004)), module, _8vert::OUT_OUTPUTS + 2));
  100. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.371, 61.026)), module, _8vert::OUT_OUTPUTS + 3));
  101. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.371, 74.048)), module, _8vert::OUT_OUTPUTS + 4));
  102. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.371, 87.07)), module, _8vert::OUT_OUTPUTS + 5));
  103. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.371, 100.093)), module, _8vert::OUT_OUTPUTS + 6));
  104. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.371, 113.115)), module, _8vert::OUT_OUTPUTS + 7));
  105. }
  106. };
  107. Model* model_8vert = createModel<_8vert, _8vertWidget>("8vert");