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.

117 lines
2.6KB

  1. ///////////////////////////////////////////////////
  2. //
  3. // 8 to 1 Mux with Binary Decoder selector VCV Module
  4. //
  5. // Strum 2017
  6. //
  7. ///////////////////////////////////////////////////
  8. #include "mental.hpp"
  9. namespace rack_plugin_mental {
  10. struct MentalMux8 : Module {
  11. enum ParamIds {
  12. NUM_PARAMS
  13. };
  14. enum InputIds {
  15. INPUT_1,
  16. INPUT_2,
  17. INPUT_4,
  18. SIG_INPUT,
  19. NUM_INPUTS = SIG_INPUT + 8
  20. };
  21. enum OutputIds {
  22. OUTPUT,
  23. NUM_OUTPUTS
  24. };
  25. enum LightIds {
  26. INPUT_LEDS,
  27. NUM_LIGHTS = INPUT_LEDS + 8
  28. };
  29. float in_1 = 0.0;
  30. float in_2 = 0.0;
  31. float in_4 = 0.0;
  32. int one, two, four, decoded;
  33. MentalMux8() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  34. void step() override;
  35. };
  36. void MentalMux8::step()
  37. {
  38. for ( int i = 0 ; i < 8 ; i ++)
  39. {
  40. lights[INPUT_LEDS + i].value = 0.0;
  41. }
  42. outputs[OUTPUT].value = 0.0;
  43. in_1 = inputs[INPUT_1].value;
  44. in_2 = inputs[INPUT_2].value;
  45. in_4 = inputs[INPUT_4].value;
  46. if (in_1 > 0.0 )
  47. {
  48. one = 1;
  49. } else
  50. {
  51. one = 0;
  52. }
  53. if (in_2 > 0.0)
  54. {
  55. two = 2;
  56. } else
  57. {
  58. two = 0;
  59. }
  60. if (in_4 > 0.0)
  61. {
  62. four = 4;
  63. } else
  64. {
  65. four = 0;
  66. }
  67. decoded = one + two + four;
  68. outputs[OUTPUT].value = inputs[SIG_INPUT + decoded].value;
  69. lights[INPUT_LEDS + decoded].value = 1.0;
  70. }
  71. //////////////////////////////////////////////////////////////
  72. struct MentalMux8Widget : ModuleWidget {
  73. MentalMux8Widget(MentalMux8 *module);
  74. };
  75. MentalMux8Widget::MentalMux8Widget(MentalMux8 *module) : ModuleWidget(module)
  76. {
  77. setPanel(SVG::load(assetPlugin(plugin, "res/MentalMux8.svg")));
  78. int spacing = 25;
  79. int top_space = 15;
  80. addInput(Port::create<GateInPort>(Vec(3, top_space), Port::INPUT, module, MentalMux8::INPUT_1));
  81. addInput(Port::create<GateInPort>(Vec(3, top_space + spacing), Port::INPUT, module, MentalMux8::INPUT_2));
  82. addInput(Port::create<GateInPort>(Vec(3, top_space + spacing * 2), Port::INPUT, module, MentalMux8::INPUT_4));
  83. for (int i = 0; i < 8 ; i++)
  84. {
  85. addInput(Port::create<InPort>(Vec(3, top_space + spacing * i + 100), Port::INPUT, module, MentalMux8::SIG_INPUT + i));
  86. addChild(ModuleLightWidget::create<MedLight<BlueLED>>(Vec(33, top_space + spacing * i + 8 + 100), module, MentalMux8::INPUT_LEDS + i));
  87. }
  88. addOutput(Port::create<OutPort>(Vec(30, top_space + spacing), Port::OUTPUT, module, MentalMux8::OUTPUT));
  89. }
  90. } // namespace rack_plugin_mental
  91. using namespace rack_plugin_mental;
  92. RACK_PLUGIN_MODEL_INIT(mental, MentalMux8) {
  93. Model *modelMentalMux8 = Model::create<MentalMux8, MentalMux8Widget>("mental", "MentalMux8", "8 Way Multiplexer", UTILITY_TAG);
  94. return modelMentalMux8;
  95. }