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.

131 lines
4.1KB

  1. #include "plugin.hpp"
  2. using simd::float_4;
  3. struct Mixer : Module {
  4. enum ParamIds {
  5. CH1_PARAM,
  6. CH2_PARAM,
  7. CH3_PARAM,
  8. CH4_PARAM,
  9. NUM_PARAMS
  10. };
  11. enum InputIds {
  12. IN1_INPUT,
  13. IN2_INPUT,
  14. IN3_INPUT,
  15. IN4_INPUT,
  16. NUM_INPUTS
  17. };
  18. enum OutputIds {
  19. OUT1_OUTPUT,
  20. OUT2_OUTPUT,
  21. NUM_OUTPUTS
  22. };
  23. enum LightIds {
  24. OUT_POS_LIGHT,
  25. OUT_NEG_LIGHT,
  26. OUT_BLUE_LIGHT,
  27. NUM_LIGHTS
  28. };
  29. Mixer() {
  30. config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
  31. configParam(CH1_PARAM, 0.0, 1.0, 0.0, "Ch 1 level", "%", 0, 100);
  32. configParam(CH2_PARAM, 0.0, 1.0, 0.0, "Ch 2 level", "%", 0, 100);
  33. configParam(CH3_PARAM, 0.0, 1.0, 0.0, "Ch 3 level", "%", 0, 100);
  34. configParam(CH4_PARAM, 0.0, 1.0, 0.0, "Ch 4 level", "%", 0, 100);
  35. }
  36. void process(const ProcessArgs& args) override {
  37. int channels1 = inputs[IN1_INPUT].getChannels();
  38. int channels2 = inputs[IN2_INPUT].getChannels();
  39. int channels3 = inputs[IN3_INPUT].getChannels();
  40. int channels4 = inputs[IN4_INPUT].getChannels();
  41. int out_channels = 1;
  42. out_channels = std::max(out_channels, channels1);
  43. out_channels = std::max(out_channels, channels2);
  44. out_channels = std::max(out_channels, channels3);
  45. out_channels = std::max(out_channels, channels4);
  46. float_4 out[4] = {};
  47. if (inputs[IN1_INPUT].isConnected()) {
  48. for (int c = 0; c < channels1; c += 4)
  49. out[c / 4] += inputs[IN1_INPUT].getVoltageSimd<float_4>(c) * params[CH1_PARAM].getValue();
  50. }
  51. if (inputs[IN2_INPUT].isConnected()) {
  52. for (int c = 0; c < channels2; c += 4)
  53. out[c / 4] += inputs[IN2_INPUT].getVoltageSimd<float_4>(c) * params[CH2_PARAM].getValue();
  54. }
  55. if (inputs[IN3_INPUT].isConnected()) {
  56. for (int c = 0; c < channels3; c += 4)
  57. out[c / 4] += inputs[IN3_INPUT].getVoltageSimd<float_4>(c) * params[CH3_PARAM].getValue();
  58. }
  59. if (inputs[IN4_INPUT].isConnected()) {
  60. for (int c = 0; c < channels4; c += 4)
  61. out[c / 4] += inputs[IN4_INPUT].getVoltageSimd<float_4>(c) * params[CH4_PARAM].getValue();
  62. }
  63. outputs[OUT1_OUTPUT].setChannels(out_channels);
  64. outputs[OUT2_OUTPUT].setChannels(out_channels);
  65. for (int c = 0; c < out_channels; c += 4) {
  66. outputs[OUT1_OUTPUT].setVoltageSimd(out[c / 4], c);
  67. out[c / 4] *= -1.f;
  68. outputs[OUT2_OUTPUT].setVoltageSimd(out[c / 4], c);
  69. }
  70. if (out_channels == 1) {
  71. float light = outputs[OUT1_OUTPUT].getVoltage();
  72. lights[OUT_POS_LIGHT].setSmoothBrightness(light / 5.f, args.sampleTime);
  73. lights[OUT_NEG_LIGHT].setSmoothBrightness(-light / 5.f, args.sampleTime);
  74. }
  75. else {
  76. float light = 0.0f;
  77. for (int c = 0; c < out_channels; c++) {
  78. float tmp = outputs[OUT1_OUTPUT].getVoltage(c);
  79. light += tmp * tmp;
  80. }
  81. light = std::sqrt(light);
  82. lights[OUT_POS_LIGHT].setBrightness(0.0f);
  83. lights[OUT_NEG_LIGHT].setBrightness(0.0f);
  84. lights[OUT_BLUE_LIGHT].setSmoothBrightness(light / 5.f, args.sampleTime);
  85. }
  86. }
  87. };
  88. struct MixerWidget : ModuleWidget {
  89. MixerWidget(Mixer* module) {
  90. setModule(module);
  91. setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Mixer.svg")));
  92. addChild(createWidget<Knurlie>(Vec(15, 0)));
  93. addChild(createWidget<Knurlie>(Vec(15, 365)));
  94. addParam(createParam<Davies1900hWhiteKnob>(Vec(19, 32), module, Mixer::CH1_PARAM));
  95. addParam(createParam<Davies1900hWhiteKnob>(Vec(19, 85), module, Mixer::CH2_PARAM));
  96. addParam(createParam<Davies1900hWhiteKnob>(Vec(19, 137), module, Mixer::CH3_PARAM));
  97. addParam(createParam<Davies1900hWhiteKnob>(Vec(19, 190), module, Mixer::CH4_PARAM));
  98. addInput(createInput<BefacoInputPort>(Vec(7, 242), module, Mixer::IN1_INPUT));
  99. addInput(createInput<BefacoInputPort>(Vec(43, 242), module, Mixer::IN2_INPUT));
  100. addInput(createInput<BefacoInputPort>(Vec(7, 281), module, Mixer::IN3_INPUT));
  101. addInput(createInput<BefacoInputPort>(Vec(43, 281), module, Mixer::IN4_INPUT));
  102. addOutput(createOutput<BefacoOutputPort>(Vec(7, 324), module, Mixer::OUT1_OUTPUT));
  103. addOutput(createOutput<BefacoOutputPort>(Vec(43, 324), module, Mixer::OUT2_OUTPUT));
  104. addChild(createLight<MediumLight<RedGreenBlueLight>>(Vec(32.7, 310), module, Mixer::OUT_POS_LIGHT));
  105. }
  106. };
  107. Model* modelMixer = createModel<Mixer, MixerWidget>("Mixer");