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.

91 lines
1.9KB

  1. #include "DS.hpp"
  2. namespace rack_plugin_SubmarineFree {
  3. struct FF_212 : DS_Module {
  4. static const int deviceCount = 12;
  5. enum ParamIds {
  6. NUM_PARAMS
  7. };
  8. enum InputIds {
  9. INPUT_1,
  10. INPUT_2,
  11. INPUT_3,
  12. INPUT_4,
  13. INPUT_5,
  14. INPUT_6,
  15. INPUT_7,
  16. INPUT_8,
  17. INPUT_9,
  18. INPUT_10,
  19. INPUT_11,
  20. INPUT_12,
  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. OUTPUT_7,
  31. OUTPUT_8,
  32. OUTPUT_9,
  33. OUTPUT_10,
  34. OUTPUT_11,
  35. OUTPUT_12,
  36. NUM_OUTPUTS
  37. };
  38. enum LightIds {
  39. NUM_LIGHTS
  40. };
  41. int state[deviceCount] = {0,0,0,0,0,0,0,0,0,0,0,0};
  42. DS_Schmitt schmittTrigger[deviceCount];
  43. FF_212() : DS_Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  44. void step() override;
  45. };
  46. void FF_212::step() {
  47. for (int i = 0; i < deviceCount; i++) {
  48. if (inputs[INPUT_1 + i].active) {
  49. if (schmittTrigger[i].redge(this, inputs[INPUT_1 + i].value))
  50. state[i] = !state[i];
  51. }
  52. else {
  53. if (i) {
  54. if (schmittTrigger[i].redge(this, state[i-1]?voltage0:voltage1))
  55. state[i] = !state[i];
  56. }
  57. }
  58. outputs[OUTPUT_1 + i].value = state[i]?voltage1:voltage0;
  59. }
  60. }
  61. struct FF212 : ModuleWidget {
  62. FF212(FF_212 *module) : ModuleWidget(module) {
  63. setPanel(SVG::load(assetPlugin(plugin, "res/FF-212.svg")));
  64. for (int i = 0; i < FF_212::deviceCount; i++) {
  65. int offset = 29 * i;
  66. addInput(Port::create<sub_port_blue>(Vec(4,19 + offset), Port::INPUT, module, FF_212::INPUT_1 + i));
  67. addOutput(Port::create<sub_port_blue>(Vec(62,19 + offset), Port::OUTPUT, module, FF_212::OUTPUT_1 + i));
  68. }
  69. }
  70. void appendContextMenu(Menu *menu) override {
  71. ((DS_Module *)module)->appendContextMenu(menu);
  72. }
  73. };
  74. } // namespace rack_plugin_SubmarineFree
  75. using namespace rack_plugin_SubmarineFree;
  76. RACK_PLUGIN_MODEL_INIT(SubmarineFree, FF212) {
  77. Model *modelFF212 = Model::create<FF_212, FF212>("SubmarineFree", "FF-212", "FF-212 Edge Triggered Flip-Flops", LOGIC_TAG, MULTIPLE_TAG);
  78. return modelFF212;
  79. }