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 OG_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. OG_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 > 0)?voltage1:voltage0;
  32. setCount = 0;
  33. }
  34. }
  35. }
  36. };
  37. struct OG104 : ModuleWidget {
  38. OG104(OG_1<4> *module) : ModuleWidget(module) {
  39. setPanel(SVG::load(assetPlugin(plugin, "res/OG-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, OG_1<4>::INPUT_A_1 + i));
  43. addInput(Port::create<BluePort>(Vec(2.5,47 + offset), Port::INPUT, module, OG_1<4>::INPUT_B_1 + i));
  44. addOutput(Port::create<BluePort>(Vec(2.5,75 + offset), Port::OUTPUT, module, OG_1<4>::OUTPUT_1 + i));
  45. }
  46. }
  47. void appendContextMenu(Menu *menu) override {
  48. ((DS_Module *)module)->appendContextMenu(menu);
  49. }
  50. };
  51. struct OG106 : ModuleWidget {
  52. OG106(OG_1<6> *module) : ModuleWidget(module) {
  53. setPanel(SVG::load(assetPlugin(plugin, "res/OG-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, OG_1<6>::INPUT_A_1 + i));
  57. addInput(Port::create<BluePort>(Vec(4,47 + offset), Port::INPUT, module, OG_1<6>::INPUT_B_1 + i));
  58. addOutput(Port::create<BluePort>(Vec(62,33 + offset), Port::OUTPUT, module, OG_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, OG104) {
  68. Model *modelOG104 = Model::create<OG_1<4>, OG104>("Submarine (Free)", "OG-104", "OG-104 OR Gates", LOGIC_TAG, MULTIPLE_TAG);
  69. return modelOG104;
  70. }
  71. RACK_PLUGIN_MODEL_INIT(SubmarineFree, OG106) {
  72. Model *modelOG106 = Model::create<OG_1<6>, OG106>("Submarine (Free)", "OG-106", "OG-106 OR Gates", LOGIC_TAG, MULTIPLE_TAG);
  73. return modelOG106;
  74. }