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.

135 lines
6.0KB

  1. #include "plugin.hpp"
  2. struct Mutes : Module {
  3. enum ParamIds {
  4. ENUMS(MUTE_PARAMS, 10),
  5. NUM_PARAMS
  6. };
  7. enum InputIds {
  8. ENUMS(IN_INPUTS, 10),
  9. NUM_INPUTS
  10. };
  11. enum OutputIds {
  12. ENUMS(OUT_OUTPUTS, 10),
  13. NUM_OUTPUTS
  14. };
  15. enum LightIds {
  16. ENUMS(MUTE_LIGHTS, 10),
  17. NUM_LIGHTS
  18. };
  19. Mutes() {
  20. config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
  21. for (int i = 0; i < 10; i++) {
  22. configSwitch(MUTE_PARAMS + i, 0.f, 1.f, 0.f, string::f("Row %d mute", i + 1));
  23. configInput(IN_INPUTS + i, string::f("Row %d", i + 1));
  24. configOutput(OUT_OUTPUTS + i, string::f("Row %d", i + 1));
  25. }
  26. }
  27. void process(const ProcessArgs& args) override {
  28. // Iterate rows
  29. for (int i = 0; i < 10; i++) {
  30. int channels = 1;
  31. const float zero[16] = {};
  32. float out[16] = {};
  33. bool mute = params[MUTE_PARAMS + i].getValue() > 0.f;
  34. // Get input
  35. // Inputs are normalized to the input above it, so only set if connected
  36. if (inputs[IN_INPUTS + i].isConnected()) {
  37. channels = inputs[IN_INPUTS + i].getChannels();
  38. inputs[IN_INPUTS + i].readVoltages(out);
  39. }
  40. // Set output
  41. if (outputs[OUT_OUTPUTS + i].isConnected()) {
  42. outputs[OUT_OUTPUTS + i].setChannels(channels);
  43. outputs[OUT_OUTPUTS + i].writeVoltages(mute ? zero : out);
  44. }
  45. // Set light
  46. lights[MUTE_LIGHTS + i].setBrightness(mute);
  47. }
  48. }
  49. void dataFromJson(json_t* rootJ) override {
  50. // In <2.0, states were stored in data
  51. json_t* statesJ = json_object_get(rootJ, "states");
  52. if (statesJ) {
  53. for (int i = 0; i < 10; i++) {
  54. json_t* stateJ = json_array_get(statesJ, i);
  55. if (stateJ)
  56. params[MUTE_PARAMS + i].setValue(!json_boolean_value(stateJ));
  57. }
  58. }
  59. }
  60. void invert() {
  61. for (int i = 0; i < 10; i++) {
  62. params[MUTE_PARAMS + i].setValue(!params[MUTE_PARAMS + i].getValue());
  63. }
  64. }
  65. };
  66. struct MutesWidget : ModuleWidget {
  67. MutesWidget(Mutes* module) {
  68. setModule(module);
  69. setPanel(createPanel(asset::plugin(pluginInstance, "res/Mutes.svg")));
  70. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  71. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  72. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  73. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  74. addParam(createLightParamCentered<VCVLightBezelLatch<>>(mm2px(Vec(20.312, 21.968)), module, Mutes::MUTE_PARAMS + 0, Mutes::MUTE_LIGHTS + 0));
  75. addParam(createLightParamCentered<VCVLightBezelLatch<>>(mm2px(Vec(20.312, 32.095)), module, Mutes::MUTE_PARAMS + 1, Mutes::MUTE_LIGHTS + 1));
  76. addParam(createLightParamCentered<VCVLightBezelLatch<>>(mm2px(Vec(20.312, 42.222)), module, Mutes::MUTE_PARAMS + 2, Mutes::MUTE_LIGHTS + 2));
  77. addParam(createLightParamCentered<VCVLightBezelLatch<>>(mm2px(Vec(20.312, 52.35)), module, Mutes::MUTE_PARAMS + 3, Mutes::MUTE_LIGHTS + 3));
  78. addParam(createLightParamCentered<VCVLightBezelLatch<>>(mm2px(Vec(20.312, 62.477)), module, Mutes::MUTE_PARAMS + 4, Mutes::MUTE_LIGHTS + 4));
  79. addParam(createLightParamCentered<VCVLightBezelLatch<>>(mm2px(Vec(20.312, 72.605)), module, Mutes::MUTE_PARAMS + 5, Mutes::MUTE_LIGHTS + 5));
  80. addParam(createLightParamCentered<VCVLightBezelLatch<>>(mm2px(Vec(20.312, 82.732)), module, Mutes::MUTE_PARAMS + 6, Mutes::MUTE_LIGHTS + 6));
  81. addParam(createLightParamCentered<VCVLightBezelLatch<>>(mm2px(Vec(20.312, 92.86)), module, Mutes::MUTE_PARAMS + 7, Mutes::MUTE_LIGHTS + 7));
  82. addParam(createLightParamCentered<VCVLightBezelLatch<>>(mm2px(Vec(20.312, 102.987)), module, Mutes::MUTE_PARAMS + 8, Mutes::MUTE_LIGHTS + 8));
  83. addParam(createLightParamCentered<VCVLightBezelLatch<>>(mm2px(Vec(20.312, 113.115)), module, Mutes::MUTE_PARAMS + 9, Mutes::MUTE_LIGHTS + 9));
  84. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.291, 21.968)), module, Mutes::IN_INPUTS + 0));
  85. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.291, 32.095)), module, Mutes::IN_INPUTS + 1));
  86. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.291, 42.222)), module, Mutes::IN_INPUTS + 2));
  87. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.291, 52.35)), module, Mutes::IN_INPUTS + 3));
  88. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.291, 62.477)), module, Mutes::IN_INPUTS + 4));
  89. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.291, 72.605)), module, Mutes::IN_INPUTS + 5));
  90. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.291, 82.732)), module, Mutes::IN_INPUTS + 6));
  91. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.291, 92.86)), module, Mutes::IN_INPUTS + 7));
  92. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.291, 102.987)), module, Mutes::IN_INPUTS + 8));
  93. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.291, 113.115)), module, Mutes::IN_INPUTS + 9));
  94. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.332, 21.968)), module, Mutes::OUT_OUTPUTS + 0));
  95. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.332, 32.095)), module, Mutes::OUT_OUTPUTS + 1));
  96. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.332, 42.222)), module, Mutes::OUT_OUTPUTS + 2));
  97. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.332, 52.35)), module, Mutes::OUT_OUTPUTS + 3));
  98. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.332, 62.477)), module, Mutes::OUT_OUTPUTS + 4));
  99. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.332, 72.605)), module, Mutes::OUT_OUTPUTS + 5));
  100. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.332, 82.732)), module, Mutes::OUT_OUTPUTS + 6));
  101. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.332, 92.86)), module, Mutes::OUT_OUTPUTS + 7));
  102. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.332, 102.987)), module, Mutes::OUT_OUTPUTS + 8));
  103. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(33.332, 113.115)), module, Mutes::OUT_OUTPUTS + 9));
  104. }
  105. void appendContextMenu(Menu* menu) override {
  106. Mutes* module = dynamic_cast<Mutes*>(this->module);
  107. assert(module);
  108. menu->addChild(new MenuSeparator);
  109. menu->addChild(createMenuItem("Invert mutes", "",
  110. [=]() {module->invert();}
  111. ));
  112. }
  113. };
  114. Model* modelMutes = createModel<Mutes, MutesWidget>("Mutes");