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.8KB

  1. ///////////////////////////////////////////////////
  2. //
  3. // 8 way switch with Binary Decoder selector VCV Module
  4. //
  5. // Strum 2017
  6. //
  7. ///////////////////////////////////////////////////
  8. #include "mental.hpp"
  9. namespace rack_plugin_mental {
  10. struct MentalSwitch8 : Module {
  11. enum ParamIds {
  12. NUM_PARAMS
  13. };
  14. enum InputIds {
  15. SIG_INPUT,
  16. INPUT_1,
  17. INPUT_2,
  18. INPUT_4,
  19. NUM_INPUTS
  20. };
  21. enum OutputIds {
  22. OUTPUT,
  23. NUM_OUTPUTS = OUTPUT + 8
  24. };
  25. enum LightIds {
  26. OUTPUT_LEDS,
  27. NUM_LIGHTS = OUTPUT_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. MentalSwitch8() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  34. void step() override;
  35. };
  36. void MentalSwitch8::step()
  37. {
  38. for ( int i = 0 ; i < 8 ; i ++)
  39. {
  40. lights[OUTPUT_LEDS + i].value = 0.0;
  41. outputs[OUTPUT + i].value = 0.0;
  42. }
  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 + decoded].value = inputs[SIG_INPUT].value;
  69. lights[OUTPUT_LEDS + decoded].value = 1.0;
  70. }
  71. ////////////////////////////////////////////////////////////////////////////////////////////////////
  72. struct MentalSwitch8Widget : ModuleWidget {
  73. MentalSwitch8Widget(MentalSwitch8 *module);
  74. };
  75. MentalSwitch8Widget::MentalSwitch8Widget(MentalSwitch8 *module) : ModuleWidget(module)
  76. {
  77. setPanel(SVG::load(assetPlugin(plugin, "res/MentalSwitch8.svg")));
  78. int spacing = 25;
  79. int top_space = 15;
  80. addInput(Port::create<GateInPort>(Vec(3, top_space), Port::INPUT, module, MentalSwitch8::INPUT_1));
  81. addInput(Port::create<GateInPort>(Vec(3, top_space + spacing), Port::INPUT, module, MentalSwitch8::INPUT_2));
  82. addInput(Port::create<GateInPort>(Vec(3, top_space + spacing * 2), Port::INPUT, module, MentalSwitch8::INPUT_4));
  83. addInput(Port::create<InPort>(Vec(3, top_space + spacing * 3 + 15), Port::INPUT, module, MentalSwitch8::SIG_INPUT));
  84. for (int i = 0; i < 8 ; i++)
  85. {
  86. addOutput(Port::create<OutPort>(Vec(30, top_space + spacing * i), Port::OUTPUT, module, MentalSwitch8::OUTPUT + i));
  87. addChild(ModuleLightWidget::create<MedLight<BlueLED>>(Vec(60, top_space + spacing * i + 8), module,MentalSwitch8::OUTPUT_LEDS + i));
  88. }
  89. }
  90. } // namespace rack_plugin_mental
  91. using namespace rack_plugin_mental;
  92. RACK_PLUGIN_MODEL_INIT(mental, MentalSwitch8) {
  93. Model *modelMentalSwitch8 = Model::create<MentalSwitch8, MentalSwitch8Widget>("mental", "MentalSwitch8", "8 Way Switch", SWITCH_TAG, UTILITY_TAG);
  94. return modelMentalSwitch8;
  95. }