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.

113 lines
2.7KB

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