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.

92 lines
2.0KB

  1. #include "DS.hpp"
  2. namespace rack_plugin_SubmarineFree {
  3. struct AG_106 : DS_Module {
  4. static const int deviceCount = 6;
  5. enum ParamIds {
  6. NUM_PARAMS
  7. };
  8. enum InputIds {
  9. INPUT_A_1,
  10. INPUT_A_2,
  11. INPUT_A_3,
  12. INPUT_A_4,
  13. INPUT_A_5,
  14. INPUT_A_6,
  15. INPUT_B_1,
  16. INPUT_B_2,
  17. INPUT_B_3,
  18. INPUT_B_4,
  19. INPUT_B_5,
  20. INPUT_B_6,
  21. NUM_INPUTS
  22. };
  23. enum OutputIds {
  24. OUTPUT_1,
  25. OUTPUT_2,
  26. OUTPUT_3,
  27. OUTPUT_4,
  28. OUTPUT_5,
  29. OUTPUT_6,
  30. NUM_OUTPUTS
  31. };
  32. enum LightIds {
  33. NUM_LIGHTS
  34. };
  35. AG_106() : DS_Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  36. void step() override;
  37. };
  38. void AG_106::step() {
  39. int connCount = 0;
  40. int setCount = 0;
  41. for (int i = 0; i < deviceCount; i++) {
  42. if (inputs[INPUT_A_1 + i].active) {
  43. connCount++;
  44. if (inputs[INPUT_A_1 + i].value > midpoint())
  45. setCount++;
  46. }
  47. if (inputs[INPUT_B_1 + i].active) {
  48. connCount++;
  49. if (inputs[INPUT_B_1 + i].value > midpoint())
  50. setCount++;
  51. }
  52. if (outputs[OUTPUT_1 + i].active) {
  53. if (connCount)
  54. outputs[OUTPUT_1 + i].value = (connCount == setCount)?voltage1:voltage0;
  55. else
  56. outputs[OUTPUT_1 + i].value = voltage0;
  57. connCount = 0;
  58. setCount = 0;
  59. }
  60. }
  61. }
  62. struct AG106 : ModuleWidget {
  63. AG106(AG_106 *module) : ModuleWidget(module) {
  64. setPanel(SVG::load(assetPlugin(plugin, "res/AG-106.svg")));
  65. for (int i = 0; i < AG_106::deviceCount; i++) {
  66. int offset = 58 * i;
  67. addInput(Port::create<sub_port_blue>(Vec(4,19 + offset), Port::INPUT, module, AG_106::INPUT_A_1 + i));
  68. addInput(Port::create<sub_port_blue>(Vec(4,47 + offset), Port::INPUT, module, AG_106::INPUT_B_1 + i));
  69. addOutput(Port::create<sub_port_blue>(Vec(62,33 + offset), Port::OUTPUT, module, AG_106::OUTPUT_1 + i));
  70. }
  71. }
  72. void appendContextMenu(Menu *menu) override {
  73. ((DS_Module *)module)->appendContextMenu(menu);
  74. }
  75. };
  76. } // namespace rack_plugin_SubmarineFree
  77. using namespace rack_plugin_SubmarineFree;
  78. RACK_PLUGIN_MODEL_INIT(SubmarineFree, AG106) {
  79. Model *modelAG106 = Model::create<AG_106, AG106>("SubmarineFree", "AG-106", "AG-106 AND Gates", LOGIC_TAG, MULTIPLE_TAG);
  80. return modelAG106;
  81. }