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.

88 lines
2.5KB

  1. #include "DS.hpp"
  2. namespace rack_plugin_SubmarineFree {
  3. template <int x>
  4. struct XG_1 : DS_Module {
  5. enum ParamIds {
  6. NUM_PARAMS
  7. };
  8. enum InputIds {
  9. INPUT_A_1,
  10. INPUT_B_1 = x,
  11. NUM_INPUTS = x + x
  12. };
  13. enum OutputIds {
  14. OUTPUT_1,
  15. NUM_OUTPUTS = x
  16. };
  17. enum LightIds {
  18. NUM_LIGHTS
  19. };
  20. XG_1() : DS_Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  21. void step() override {
  22. int setCount = 0;
  23. for (int i = 0; i < x; i++) {
  24. if (inputs[INPUT_A_1 + i].active)
  25. if (inputs[INPUT_A_1 + i].value > midpoint())
  26. setCount++;
  27. if (inputs[INPUT_B_1 + i].active)
  28. if (inputs[INPUT_B_1 + i].value > midpoint())
  29. setCount++;
  30. if (outputs[OUTPUT_1 + i].active) {
  31. outputs[OUTPUT_1 + i].value = (setCount % 2)?voltage1:voltage0;
  32. setCount = 0;
  33. }
  34. }
  35. }
  36. };
  37. struct XG104 : ModuleWidget {
  38. XG104(XG_1<4> *module) : ModuleWidget(module) {
  39. setPanel(SVG::load(assetPlugin(plugin, "res/XG-104.svg")));
  40. for (int i = 0; i < 4; i++) {
  41. int offset = 87 * i;
  42. addInput(Port::create<BluePort>(Vec(2.5,19 + offset), Port::INPUT, module, XG_1<4>::INPUT_A_1 + i));
  43. addInput(Port::create<BluePort>(Vec(2.5,47 + offset), Port::INPUT, module, XG_1<4>::INPUT_B_1 + i));
  44. addOutput(Port::create<BluePort>(Vec(2.5,75 + offset), Port::OUTPUT, module, XG_1<4>::OUTPUT_1 + i));
  45. }
  46. }
  47. void appendContextMenu(Menu *menu) override {
  48. ((DS_Module *)module)->appendContextMenu(menu);
  49. }
  50. };
  51. struct XG106 : ModuleWidget {
  52. XG106(XG_1<6> *module) : ModuleWidget(module) {
  53. setPanel(SVG::load(assetPlugin(plugin, "res/XG-106.svg")));
  54. for (int i = 0; i < 6; i++) {
  55. int offset = 58 * i;
  56. addInput(Port::create<BluePort>(Vec(4,19 + offset), Port::INPUT, module, XG_1<6>::INPUT_A_1 + i));
  57. addInput(Port::create<BluePort>(Vec(4,47 + offset), Port::INPUT, module, XG_1<6>::INPUT_B_1 + i));
  58. addOutput(Port::create<BluePort>(Vec(62,33 + offset), Port::OUTPUT, module, XG_1<6>::OUTPUT_1 + i));
  59. }
  60. }
  61. void appendContextMenu(Menu *menu) override {
  62. ((DS_Module *)module)->appendContextMenu(menu);
  63. }
  64. };
  65. } // namespace rack_plugin_SubmarineFree
  66. using namespace rack_plugin_SubmarineFree;
  67. RACK_PLUGIN_MODEL_INIT(SubmarineFree, XG104) {
  68. Model *modelXG104 = Model::create<XG_1<4>, XG104>("Submarine (Free)", "XG-104", "XG-104 XOR Gates", LOGIC_TAG, MULTIPLE_TAG);
  69. return modelXG104;
  70. }
  71. RACK_PLUGIN_MODEL_INIT(SubmarineFree, XG106) {
  72. Model *modelXG106 = Model::create<XG_1<6>, XG106>("Submarine (Free)", "XG-106", "XG-106 XOR Gates", LOGIC_TAG, MULTIPLE_TAG);
  73. return modelXG106;
  74. }