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.

138 lines
6.2KB

  1. #include "RJModules.hpp"
  2. #include "dsp/digital.hpp"
  3. namespace rack_plugin_RJModules {
  4. #define NUM_CHANNELS 10
  5. struct Volumes : Module {
  6. enum ParamIds {
  7. MUTE_PARAM,
  8. NUM_PARAMS = MUTE_PARAM + NUM_CHANNELS
  9. };
  10. enum InputIds {
  11. IN_INPUT,
  12. NUM_INPUTS = IN_INPUT + NUM_CHANNELS
  13. };
  14. enum OutputIds {
  15. OUT_OUTPUT,
  16. NUM_OUTPUTS = OUT_OUTPUT + NUM_CHANNELS
  17. };
  18. enum LightIds {
  19. MUTE_LIGHT,
  20. NUM_LIGHTS = MUTE_LIGHT + NUM_CHANNELS
  21. };
  22. bool state[NUM_CHANNELS];
  23. SchmittTrigger muteTrigger[NUM_CHANNELS];
  24. Volumes() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
  25. reset();
  26. }
  27. void step() override;
  28. void reset() override {
  29. for (int i = 0; i < NUM_CHANNELS; i++) {
  30. state[i] = true;
  31. }
  32. }
  33. void randomize() override {
  34. for (int i = 0; i < NUM_CHANNELS; i++) {
  35. state[i] = (randomUniform() < 0.5);
  36. }
  37. }
  38. json_t *toJson() override {
  39. json_t *rootJ = json_object();
  40. // states
  41. json_t *statesJ = json_array();
  42. for (int i = 0; i < NUM_CHANNELS; i++) {
  43. json_t *stateJ = json_boolean(state[i]);
  44. json_array_append_new(statesJ, stateJ);
  45. }
  46. json_object_set_new(rootJ, "states", statesJ);
  47. return rootJ;
  48. }
  49. void fromJson(json_t *rootJ) override {
  50. // states
  51. json_t *statesJ = json_object_get(rootJ, "states");
  52. if (statesJ) {
  53. for (int i = 0; i < NUM_CHANNELS; i++) {
  54. json_t *stateJ = json_array_get(statesJ, i);
  55. if (stateJ)
  56. state[i] = json_boolean_value(stateJ);
  57. }
  58. }
  59. }
  60. };
  61. void Volumes::step() {
  62. for (int i = 0; i < NUM_CHANNELS; i++) {
  63. float in = inputs[IN_INPUT + i].value;
  64. outputs[OUT_OUTPUT + i].value = in * params[MUTE_PARAM + i].value;
  65. }
  66. }
  67. template <typename BASE>
  68. struct MuteLight : BASE {
  69. MuteLight() {
  70. this->box.size = mm2px(Vec(6.0, 6.0));
  71. }
  72. };
  73. struct VolumesWidget: ModuleWidget {
  74. VolumesWidget(Volumes *module);
  75. };
  76. VolumesWidget::VolumesWidget(Volumes *module) : ModuleWidget(module) {
  77. setPanel(SVG::load(assetPlugin(plugin, "res/Volumes.svg")));
  78. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  79. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 30, 0)));
  80. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  81. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 30, 365)));
  82. addParam(ParamWidget::create<RoundSmallBlackKnob>(mm2px(Vec(15.57, 17.165)), module, Volumes::MUTE_PARAM + 0, 0.0, 2.0, 1.0));
  83. addParam(ParamWidget::create<RoundSmallBlackKnob>(mm2px(Vec(15.57, 27.164)), module, Volumes::MUTE_PARAM + 1, 0.0, 2.0, 1.0));
  84. addParam(ParamWidget::create<RoundSmallBlackKnob>(mm2px(Vec(15.57, 37.164)), module, Volumes::MUTE_PARAM + 2, 0.0, 2.0, 1.0));
  85. addParam(ParamWidget::create<RoundSmallBlackKnob>(mm2px(Vec(15.57, 47.165)), module, Volumes::MUTE_PARAM + 3, 0.0, 2.0, 1.0));
  86. addParam(ParamWidget::create<RoundSmallBlackKnob>(mm2px(Vec(15.57, 57.164)), module, Volumes::MUTE_PARAM + 4, 0.0, 2.0, 1.0));
  87. addParam(ParamWidget::create<RoundSmallBlackKnob>(mm2px(Vec(15.57, 67.165)), module, Volumes::MUTE_PARAM + 5, 0.0, 2.0, 1.0));
  88. addParam(ParamWidget::create<RoundSmallBlackKnob>(mm2px(Vec(15.57, 77.164)), module, Volumes::MUTE_PARAM + 6, 0.0, 2.0, 1.0));
  89. addParam(ParamWidget::create<RoundSmallBlackKnob>(mm2px(Vec(15.57, 87.164)), module, Volumes::MUTE_PARAM + 7, 0.0, 2.0, 1.0));
  90. addParam(ParamWidget::create<RoundSmallBlackKnob>(mm2px(Vec(15.57, 97.165)), module, Volumes::MUTE_PARAM + 8, 0.0, 2.0, 1.0));
  91. addParam(ParamWidget::create<RoundSmallBlackKnob>(mm2px(Vec(15.57, 107.166)), module, Volumes::MUTE_PARAM + 9, 0.0, 2.0, 1.0));
  92. addInput(Port::create<PJ301MPort>(mm2px(Vec(4.214, 17.81)), Port::INPUT, module, Volumes::IN_INPUT + 0));
  93. addInput(Port::create<PJ301MPort>(mm2px(Vec(4.214, 27.809)), Port::INPUT, module, Volumes::IN_INPUT + 1));
  94. addInput(Port::create<PJ301MPort>(mm2px(Vec(4.214, 37.809)), Port::INPUT, module, Volumes::IN_INPUT + 2));
  95. addInput(Port::create<PJ301MPort>(mm2px(Vec(4.214, 47.81)), Port::INPUT, module, Volumes::IN_INPUT + 3));
  96. addInput(Port::create<PJ301MPort>(mm2px(Vec(4.214, 57.81)), Port::INPUT, module, Volumes::IN_INPUT + 4));
  97. addInput(Port::create<PJ301MPort>(mm2px(Vec(4.214, 67.809)), Port::INPUT, module, Volumes::IN_INPUT + 5));
  98. addInput(Port::create<PJ301MPort>(mm2px(Vec(4.214, 77.81)), Port::INPUT, module, Volumes::IN_INPUT + 6));
  99. addInput(Port::create<PJ301MPort>(mm2px(Vec(4.214, 87.81)), Port::INPUT, module, Volumes::IN_INPUT + 7));
  100. addInput(Port::create<PJ301MPort>(mm2px(Vec(4.214, 97.809)), Port::INPUT, module, Volumes::IN_INPUT + 8));
  101. addInput(Port::create<PJ301MPort>(mm2px(Vec(4.214, 107.809)), Port::INPUT, module, Volumes::IN_INPUT + 9));
  102. addOutput(Port::create<PJ301MPort>(mm2px(Vec(28.214, 17.81)), Port::OUTPUT, module, Volumes::OUT_OUTPUT + 0));
  103. addOutput(Port::create<PJ301MPort>(mm2px(Vec(28.214, 27.809)), Port::OUTPUT, module, Volumes::OUT_OUTPUT + 1));
  104. addOutput(Port::create<PJ301MPort>(mm2px(Vec(28.214, 37.809)), Port::OUTPUT, module, Volumes::OUT_OUTPUT + 2));
  105. addOutput(Port::create<PJ301MPort>(mm2px(Vec(28.214, 47.81)), Port::OUTPUT, module, Volumes::OUT_OUTPUT + 3));
  106. addOutput(Port::create<PJ301MPort>(mm2px(Vec(28.214, 57.809)), Port::OUTPUT, module, Volumes::OUT_OUTPUT + 4));
  107. addOutput(Port::create<PJ301MPort>(mm2px(Vec(28.214, 67.809)), Port::OUTPUT, module, Volumes::OUT_OUTPUT + 5));
  108. addOutput(Port::create<PJ301MPort>(mm2px(Vec(28.214, 77.81)), Port::OUTPUT, module, Volumes::OUT_OUTPUT + 6));
  109. addOutput(Port::create<PJ301MPort>(mm2px(Vec(28.214, 87.81)), Port::OUTPUT, module, Volumes::OUT_OUTPUT + 7));
  110. addOutput(Port::create<PJ301MPort>(mm2px(Vec(28.214, 97.809)), Port::OUTPUT, module, Volumes::OUT_OUTPUT + 8));
  111. addOutput(Port::create<PJ301MPort>(mm2px(Vec(28.214, 107.809)), Port::OUTPUT, module, Volumes::OUT_OUTPUT + 9));
  112. }
  113. } // namespace rack_plugin_RJModules
  114. using namespace rack_plugin_RJModules;
  115. RACK_PLUGIN_MODEL_INIT(RJModules, Volumes) {
  116. Model *modelVolumes = Model::create<Volumes, VolumesWidget>("RJModules", "Volumes", "[MIX] Volumes", AMPLIFIER_TAG);
  117. return modelVolumes;
  118. }