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.

160 lines
6.4KB

  1. #include "plugin.hpp"
  2. struct Mutes : Module {
  3. enum ParamIds {
  4. ENUMS(MUTE_PARAM, 10),
  5. NUM_PARAMS
  6. };
  7. enum InputIds {
  8. ENUMS(IN_INPUT, 10),
  9. NUM_INPUTS
  10. };
  11. enum OutputIds {
  12. ENUMS(OUT_OUTPUT, 10),
  13. NUM_OUTPUTS
  14. };
  15. enum LightIds {
  16. ENUMS(MUTE_LIGHT, 10),
  17. NUM_LIGHTS
  18. };
  19. bool state[10];
  20. dsp::BooleanTrigger muteTrigger[10];
  21. Mutes() {
  22. config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
  23. for (int i = 0; i < 10; i++) {
  24. configParam(MUTE_PARAM + i, 0.0, 1.0, 0.0, string::f("Ch %d mute", i + 1));
  25. }
  26. onReset();
  27. }
  28. void process(const ProcessArgs& args) override {
  29. const float zero[16] = {};
  30. float out[16] = {};
  31. int channels = 1;
  32. // Iterate rows
  33. for (int i = 0; i < 10; i++) {
  34. // Process trigger
  35. if (muteTrigger[i].process(params[MUTE_PARAM + i].getValue() > 0.f))
  36. state[i] ^= true;
  37. // Get input
  38. // Inputs are normalized to the input above it, so only set if connected
  39. if (inputs[IN_INPUT + i].isConnected()) {
  40. channels = inputs[IN_INPUT + i].getChannels();
  41. inputs[IN_INPUT + i].readVoltages(out);
  42. }
  43. // Set output
  44. if (outputs[OUT_OUTPUT + i].isConnected()) {
  45. outputs[OUT_OUTPUT + i].setChannels(channels);
  46. outputs[OUT_OUTPUT + i].writeVoltages(state[i] ? out : zero);
  47. }
  48. // Set light
  49. lights[MUTE_LIGHT + i].setBrightness(state[i] ? 0.9f : 0.f);
  50. }
  51. }
  52. void onReset() override {
  53. for (int i = 0; i < 10; i++) {
  54. state[i] = true;
  55. }
  56. }
  57. void onRandomize() override {
  58. for (int i = 0; i < 10; i++) {
  59. state[i] = (random::uniform() < 0.5f);
  60. }
  61. }
  62. json_t* dataToJson() override {
  63. json_t* rootJ = json_object();
  64. // states
  65. json_t* statesJ = json_array();
  66. for (int i = 0; i < 10; i++) {
  67. json_t* stateJ = json_boolean(state[i]);
  68. json_array_append_new(statesJ, stateJ);
  69. }
  70. json_object_set_new(rootJ, "states", statesJ);
  71. return rootJ;
  72. }
  73. void dataFromJson(json_t* rootJ) override {
  74. // states
  75. json_t* statesJ = json_object_get(rootJ, "states");
  76. if (statesJ) {
  77. for (int i = 0; i < 10; i++) {
  78. json_t* stateJ = json_array_get(statesJ, i);
  79. if (stateJ)
  80. state[i] = json_boolean_value(stateJ);
  81. }
  82. }
  83. }
  84. };
  85. struct MutesWidget : ModuleWidget {
  86. MutesWidget(Mutes* module) {
  87. setModule(module);
  88. setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Mutes.svg")));
  89. addChild(createWidget<ScrewSilver>(Vec(15, 0)));
  90. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 30, 0)));
  91. addChild(createWidget<ScrewSilver>(Vec(15, 365)));
  92. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 30, 365)));
  93. addParam(createParam<LEDBezel>(mm2px(Vec(16.57, 18.165)), module, Mutes::MUTE_PARAM + 0));
  94. addParam(createParam<LEDBezel>(mm2px(Vec(16.57, 28.164)), module, Mutes::MUTE_PARAM + 1));
  95. addParam(createParam<LEDBezel>(mm2px(Vec(16.57, 38.164)), module, Mutes::MUTE_PARAM + 2));
  96. addParam(createParam<LEDBezel>(mm2px(Vec(16.57, 48.165)), module, Mutes::MUTE_PARAM + 3));
  97. addParam(createParam<LEDBezel>(mm2px(Vec(16.57, 58.164)), module, Mutes::MUTE_PARAM + 4));
  98. addParam(createParam<LEDBezel>(mm2px(Vec(16.57, 68.165)), module, Mutes::MUTE_PARAM + 5));
  99. addParam(createParam<LEDBezel>(mm2px(Vec(16.57, 78.164)), module, Mutes::MUTE_PARAM + 6));
  100. addParam(createParam<LEDBezel>(mm2px(Vec(16.57, 88.164)), module, Mutes::MUTE_PARAM + 7));
  101. addParam(createParam<LEDBezel>(mm2px(Vec(16.57, 98.165)), module, Mutes::MUTE_PARAM + 8));
  102. addParam(createParam<LEDBezel>(mm2px(Vec(16.57, 108.166)), module, Mutes::MUTE_PARAM + 9));
  103. addInput(createInput<PJ301MPort>(mm2px(Vec(4.214, 17.81)), module, Mutes::IN_INPUT + 0));
  104. addInput(createInput<PJ301MPort>(mm2px(Vec(4.214, 27.809)), module, Mutes::IN_INPUT + 1));
  105. addInput(createInput<PJ301MPort>(mm2px(Vec(4.214, 37.809)), module, Mutes::IN_INPUT + 2));
  106. addInput(createInput<PJ301MPort>(mm2px(Vec(4.214, 47.81)), module, Mutes::IN_INPUT + 3));
  107. addInput(createInput<PJ301MPort>(mm2px(Vec(4.214, 57.81)), module, Mutes::IN_INPUT + 4));
  108. addInput(createInput<PJ301MPort>(mm2px(Vec(4.214, 67.809)), module, Mutes::IN_INPUT + 5));
  109. addInput(createInput<PJ301MPort>(mm2px(Vec(4.214, 77.81)), module, Mutes::IN_INPUT + 6));
  110. addInput(createInput<PJ301MPort>(mm2px(Vec(4.214, 87.81)), module, Mutes::IN_INPUT + 7));
  111. addInput(createInput<PJ301MPort>(mm2px(Vec(4.214, 97.809)), module, Mutes::IN_INPUT + 8));
  112. addInput(createInput<PJ301MPort>(mm2px(Vec(4.214, 107.809)), module, Mutes::IN_INPUT + 9));
  113. addOutput(createOutput<PJ301MPort>(mm2px(Vec(28.214, 17.81)), module, Mutes::OUT_OUTPUT + 0));
  114. addOutput(createOutput<PJ301MPort>(mm2px(Vec(28.214, 27.809)), module, Mutes::OUT_OUTPUT + 1));
  115. addOutput(createOutput<PJ301MPort>(mm2px(Vec(28.214, 37.809)), module, Mutes::OUT_OUTPUT + 2));
  116. addOutput(createOutput<PJ301MPort>(mm2px(Vec(28.214, 47.81)), module, Mutes::OUT_OUTPUT + 3));
  117. addOutput(createOutput<PJ301MPort>(mm2px(Vec(28.214, 57.809)), module, Mutes::OUT_OUTPUT + 4));
  118. addOutput(createOutput<PJ301MPort>(mm2px(Vec(28.214, 67.809)), module, Mutes::OUT_OUTPUT + 5));
  119. addOutput(createOutput<PJ301MPort>(mm2px(Vec(28.214, 77.81)), module, Mutes::OUT_OUTPUT + 6));
  120. addOutput(createOutput<PJ301MPort>(mm2px(Vec(28.214, 87.81)), module, Mutes::OUT_OUTPUT + 7));
  121. addOutput(createOutput<PJ301MPort>(mm2px(Vec(28.214, 97.809)), module, Mutes::OUT_OUTPUT + 8));
  122. addOutput(createOutput<PJ301MPort>(mm2px(Vec(28.214, 107.809)), module, Mutes::OUT_OUTPUT + 9));
  123. addChild(createLight<LEDBezelLight<GreenLight>>(mm2px(Vec(17.32, 18.915)), module, Mutes::MUTE_LIGHT + 0));
  124. addChild(createLight<LEDBezelLight<GreenLight>>(mm2px(Vec(17.32, 28.916)), module, Mutes::MUTE_LIGHT + 1));
  125. addChild(createLight<LEDBezelLight<GreenLight>>(mm2px(Vec(17.32, 38.915)), module, Mutes::MUTE_LIGHT + 2));
  126. addChild(createLight<LEDBezelLight<GreenLight>>(mm2px(Vec(17.32, 48.915)), module, Mutes::MUTE_LIGHT + 3));
  127. addChild(createLight<LEDBezelLight<GreenLight>>(mm2px(Vec(17.32, 58.916)), module, Mutes::MUTE_LIGHT + 4));
  128. addChild(createLight<LEDBezelLight<GreenLight>>(mm2px(Vec(17.32, 68.916)), module, Mutes::MUTE_LIGHT + 5));
  129. addChild(createLight<LEDBezelLight<GreenLight>>(mm2px(Vec(17.32, 78.915)), module, Mutes::MUTE_LIGHT + 6));
  130. addChild(createLight<LEDBezelLight<GreenLight>>(mm2px(Vec(17.32, 88.916)), module, Mutes::MUTE_LIGHT + 7));
  131. addChild(createLight<LEDBezelLight<GreenLight>>(mm2px(Vec(17.32, 98.915)), module, Mutes::MUTE_LIGHT + 8));
  132. addChild(createLight<LEDBezelLight<GreenLight>>(mm2px(Vec(17.32, 108.915)), module, Mutes::MUTE_LIGHT + 9));
  133. }
  134. };
  135. Model* modelMutes = createModel<Mutes, MutesWidget>("Mutes");