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.

84 lines
2.5KB

  1. #include "plugin.hpp"
  2. using simd::float_4;
  3. struct Mixer : Module {
  4. enum ParamId {
  5. LEVEL_PARAM,
  6. PARAMS_LEN
  7. };
  8. enum InputId {
  9. ENUMS(IN_INPUTS, 6),
  10. INPUTS_LEN
  11. };
  12. enum OutputId {
  13. OUT_OUTPUT,
  14. OUTPUTS_LEN
  15. };
  16. enum LightId {
  17. LIGHTS_LEN
  18. };
  19. Mixer() {
  20. config(PARAMS_LEN, INPUTS_LEN, OUTPUTS_LEN, LIGHTS_LEN);
  21. configParam(LEVEL_PARAM, 0.f, 1.f, 1.f, "Level", "%", 0, 100);
  22. for (int i = 0; i < 6; i++)
  23. configInput(IN_INPUTS + i, string::f("Channel %d", i + 1));
  24. configOutput(OUT_OUTPUT, "Mix");
  25. }
  26. void process(const ProcessArgs& args) override {
  27. // Get number of channels
  28. int channels = 1;
  29. for (int i = 0; i < 6; i++)
  30. channels = std::max(channels, inputs[IN_INPUTS + i].getChannels());
  31. float gain = params[LEVEL_PARAM].getValue();
  32. // Iterate polyphonic channels
  33. for (int c = 0; c < channels; c += 4) {
  34. float_4 out = 0.f;
  35. // Mix input
  36. for (int i = 0; i < 6; i++) {
  37. out += inputs[IN_INPUTS + i].getVoltageSimd<float_4>(c);
  38. }
  39. // Apply gain
  40. out *= gain;
  41. // Set output
  42. outputs[OUT_OUTPUT].setVoltageSimd(out, c);
  43. }
  44. outputs[OUT_OUTPUT].setChannels(channels);
  45. }
  46. };
  47. struct MixerWidget : ModuleWidget {
  48. MixerWidget(Mixer* module) {
  49. setModule(module);
  50. setPanel(createPanel(asset::plugin(pluginInstance, "res/Mixer.svg")));
  51. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  52. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  53. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  54. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  55. addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec(7.62, 24.723)), module, Mixer::LEVEL_PARAM));
  56. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.62, 46.059)), module, Mixer::IN_INPUTS + 0));
  57. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.62, 56.219)), module, Mixer::IN_INPUTS + 1));
  58. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.62, 66.379)), module, Mixer::IN_INPUTS + 2));
  59. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.62, 76.539)), module, Mixer::IN_INPUTS + 3));
  60. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.62, 86.699)), module, Mixer::IN_INPUTS + 4));
  61. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.62, 96.859)), module, Mixer::IN_INPUTS + 5));
  62. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(7.62, 113.115)), module, Mixer::OUT_OUTPUT));
  63. }
  64. };
  65. Model* modelMixer = createModel<Mixer, MixerWidget>("Mixer");