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.

184 lines
6.1KB

  1. ///////////////////////////////////////////////////
  2. //
  3. // Multiplexers VCV Module
  4. //
  5. // Strum 2017
  6. //
  7. ///////////////////////////////////////////////////
  8. #include "mental.hpp"
  9. namespace rack_plugin_mental {
  10. struct MentalMuxes : Module {
  11. enum ParamIds {
  12. NUM_PARAMS
  13. };
  14. enum InputIds {
  15. INPUT_1A,
  16. INPUT_2A,
  17. SELECT_A,
  18. INPUT_1B,
  19. INPUT_2B,
  20. SELECT_B,
  21. INPUT_1C,
  22. INPUT_2C,
  23. INPUT_3C,
  24. INPUT_4C,
  25. SELECT_C,
  26. NUM_INPUTS
  27. };
  28. enum OutputIds {
  29. OUTPUT_A,
  30. OUTPUT_B,
  31. OUTPUT_C,
  32. NUM_OUTPUTS
  33. };
  34. enum LightIds {
  35. LEVEL_LED_A1,
  36. LEVEL_LED_A2,
  37. LEVEL_LED_B1,
  38. LEVEL_LED_B2,
  39. LEVEL_LED_C1,
  40. LEVEL_LED_C2,
  41. LEVEL_LED_C3,
  42. LEVEL_LED_C4,
  43. NUM_LIGHTS
  44. };
  45. MentalMuxes() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  46. void step() override;
  47. };
  48. void MentalMuxes::step()
  49. {
  50. float signal_in_a1 = inputs[INPUT_1A].value;
  51. float signal_in_a2 = inputs[INPUT_2A].value;
  52. float select_a = inputs[SELECT_A].value;
  53. if (select_a > 0.0 )
  54. {
  55. outputs[OUTPUT_A].value = signal_in_a2;
  56. lights[LEVEL_LED_A2].value = std::abs((signal_in_a2 / 3));
  57. lights[LEVEL_LED_A1].value = 0.0;
  58. }
  59. else
  60. {
  61. outputs[OUTPUT_A].value = signal_in_a1;
  62. lights[LEVEL_LED_A1].value = std::abs((signal_in_a1 / 3));
  63. lights[LEVEL_LED_A2].value = 0.0;
  64. }
  65. float signal_in_b1 = inputs[INPUT_1B].value;
  66. float signal_in_b2 = inputs[INPUT_2B].value;
  67. float select_b = inputs[SELECT_B].value;
  68. if (select_b > 0.0 )
  69. {
  70. outputs[OUTPUT_B].value = signal_in_b2;
  71. lights[LEVEL_LED_B2].value = std::abs((signal_in_b2 / 3));
  72. lights[LEVEL_LED_B1].value = 0.0;
  73. }
  74. else
  75. {
  76. outputs[OUTPUT_B].value = signal_in_b1;
  77. lights[LEVEL_LED_B1].value = std::abs((signal_in_b1 / 3));
  78. lights[LEVEL_LED_B2].value = 0.0;
  79. }
  80. float signal_in_c1 = inputs[INPUT_1C].value;
  81. float signal_in_c2 = inputs[INPUT_2C].value;
  82. float signal_in_c3 = inputs[INPUT_3C].value;
  83. float signal_in_c4 = inputs[INPUT_4C].value;
  84. float select_c = inputs[SELECT_C].value;
  85. int selector = round(std::abs(select_c));
  86. if (selector > 3) selector = 3;
  87. if (selector == 0 )
  88. {
  89. outputs[OUTPUT_C].value = signal_in_c1;
  90. lights[LEVEL_LED_C1].value = std::abs((signal_in_c1 / 3));
  91. lights[LEVEL_LED_C2].value = 0.0;
  92. lights[LEVEL_LED_C3].value = 0.0;
  93. lights[LEVEL_LED_C4].value = 0.0;
  94. }
  95. if (selector == 1 )
  96. {
  97. outputs[OUTPUT_C].value = signal_in_c2;
  98. lights[LEVEL_LED_C2].value = std::abs((signal_in_c2 / 3));
  99. lights[LEVEL_LED_C1].value = 0.0;
  100. lights[LEVEL_LED_C3].value = 0.0;
  101. lights[LEVEL_LED_C4].value = 0.0;
  102. }
  103. if (selector == 2 )
  104. {
  105. outputs[OUTPUT_C].value = signal_in_c3;
  106. lights[LEVEL_LED_C3].value = std::abs((signal_in_c3 / 3));
  107. lights[LEVEL_LED_C2].value = 0.0;
  108. lights[LEVEL_LED_C2].value = 0.0;
  109. lights[LEVEL_LED_C4].value = 0.0;
  110. }
  111. if (selector == 3 )
  112. {
  113. outputs[OUTPUT_C].value = signal_in_c4;
  114. lights[LEVEL_LED_C4].value = std::abs((signal_in_c4 / 3));
  115. lights[LEVEL_LED_C1].value = 0.0;
  116. lights[LEVEL_LED_C2].value = 0.0;
  117. lights[LEVEL_LED_C3].value = 0.0;
  118. }
  119. }
  120. ///////////////////////////////////////////////////////////////////////////////////////////////
  121. struct MentalMuxesWidget : ModuleWidget {
  122. MentalMuxesWidget(MentalMuxes *module);
  123. };
  124. MentalMuxesWidget::MentalMuxesWidget(MentalMuxes *module) : ModuleWidget(module)
  125. {
  126. setPanel(SVG::load(assetPlugin(plugin, "res/MentalMuxes.svg")));
  127. int group_offset = 90;
  128. addInput(Port::create<GateInPort>(Vec(3, 75), Port::INPUT, module, MentalMuxes::SELECT_A));
  129. addInput(Port::create<InPort>(Vec(3, 25), Port::INPUT, module, MentalMuxes::INPUT_1A));
  130. addInput(Port::create<InPort>(Vec(3, 50), Port::INPUT, module, MentalMuxes::INPUT_2A));
  131. addOutput(Port::create<OutPort>(Vec(33, 75), Port::OUTPUT, module, MentalMuxes::OUTPUT_A));
  132. addChild(ModuleLightWidget::create<MedLight<BlueLED>>(Vec(41, 32), module, MentalMuxes::LEVEL_LED_A1));
  133. addChild(ModuleLightWidget::create<MedLight<BlueLED>>(Vec(41, 58), module, MentalMuxes::LEVEL_LED_A2));
  134. addInput(Port::create<GateInPort>(Vec(3, group_offset + 75), Port::INPUT, module, MentalMuxes::SELECT_B));
  135. addInput(Port::create<InPort>(Vec(3, group_offset + 25), Port::INPUT, module, MentalMuxes::INPUT_1B));
  136. addInput(Port::create<InPort>(Vec(3, group_offset + 50), Port::INPUT, module, MentalMuxes::INPUT_2B));
  137. addOutput(Port::create<OutPort>(Vec(33,group_offset + 75), Port::OUTPUT, module, MentalMuxes::OUTPUT_B));
  138. addChild(ModuleLightWidget::create<MedLight<BlueLED>>(Vec(41,group_offset + 32), module, MentalMuxes::LEVEL_LED_B1));
  139. addChild(ModuleLightWidget::create<MedLight<BlueLED>>(Vec(41,group_offset + 58), module, MentalMuxes::LEVEL_LED_B2));
  140. addInput(Port::create<CVInPort>(Vec(3, group_offset * 2 + 125), Port::INPUT, module, MentalMuxes::SELECT_C));
  141. addInput(Port::create<InPort>(Vec(3, group_offset * 2 + 25), Port::INPUT, module, MentalMuxes::INPUT_1C));
  142. addInput(Port::create<InPort>(Vec(3, group_offset * 2 + 50), Port::INPUT, module, MentalMuxes::INPUT_2C));
  143. addInput(Port::create<InPort>(Vec(3, group_offset * 2 + 75), Port::INPUT, module, MentalMuxes::INPUT_3C));
  144. addInput(Port::create<InPort>(Vec(3, group_offset * 2 + 100), Port::INPUT, module, MentalMuxes::INPUT_4C));
  145. addOutput(Port::create<OutPort>(Vec(33,group_offset * 2 + 125), Port::OUTPUT, module, MentalMuxes::OUTPUT_C));
  146. addChild(ModuleLightWidget::create<MedLight<BlueLED>>(Vec(41,group_offset * 2 + 32), module, MentalMuxes::LEVEL_LED_C1));
  147. addChild(ModuleLightWidget::create<MedLight<BlueLED>>(Vec(41,group_offset * 2 + 58), module, MentalMuxes::LEVEL_LED_C2));
  148. addChild(ModuleLightWidget::create<MedLight<BlueLED>>(Vec(41,group_offset * 2 + 82), module, MentalMuxes::LEVEL_LED_C3));
  149. addChild(ModuleLightWidget::create<MedLight<BlueLED>>(Vec(41,group_offset * 2 + 108), module, MentalMuxes::LEVEL_LED_C4));
  150. }
  151. } // namespace rack_plugin_mental
  152. using namespace rack_plugin_mental;
  153. RACK_PLUGIN_MODEL_INIT(mental, MentalMuxes) {
  154. Model *modelMentalMuxes = Model::create<MentalMuxes, MentalMuxesWidget>("mental", "MentalMuxes", "Multiplexers", DUAL_TAG, UTILITY_TAG);
  155. return modelMentalMuxes;
  156. }