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.0KB

  1. #include "DS.hpp"
  2. namespace rack_plugin_SubmarineFree {
  3. struct FF_120 : DS_Module {
  4. static const int deviceCount = 20;
  5. enum ParamIds {
  6. NUM_PARAMS
  7. };
  8. enum InputIds {
  9. INPUT,
  10. NUM_INPUTS
  11. };
  12. enum OutputIds {
  13. OUTPUT_1,
  14. OUTPUT_2,
  15. OUTPUT_3,
  16. OUTPUT_4,
  17. OUTPUT_5,
  18. OUTPUT_6,
  19. OUTPUT_7,
  20. OUTPUT_8,
  21. OUTPUT_9,
  22. OUTPUT_10,
  23. OUTPUT_11,
  24. OUTPUT_12,
  25. OUTPUT_13,
  26. OUTPUT_14,
  27. OUTPUT_15,
  28. OUTPUT_16,
  29. OUTPUT_17,
  30. OUTPUT_18,
  31. OUTPUT_19,
  32. OUTPUT_20,
  33. NUM_OUTPUTS
  34. };
  35. enum LightIds {
  36. NUM_LIGHTS
  37. };
  38. int state[deviceCount] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  39. DS_Schmitt schmittTrigger[deviceCount];
  40. FF_120() : DS_Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  41. void step() override;
  42. };
  43. void FF_120::step() {
  44. if (inputs[INPUT].active) {
  45. if (schmittTrigger[0].redge(this, inputs[INPUT].value))
  46. state[0] = !state[0];
  47. }
  48. outputs[OUTPUT_1].value = state[0]?voltage1:voltage0;
  49. for (int i = 1; i < deviceCount; i++) {
  50. if (schmittTrigger[i].redge(this, state[i-1]?voltage0:voltage1))
  51. state[i] = !state[i];
  52. outputs[OUTPUT_1 + i].value = state[i]?voltage1:voltage0;
  53. }
  54. }
  55. struct FF120 : ModuleWidget {
  56. FF120(FF_120 *module) : ModuleWidget(module) {
  57. setPanel(SVG::load(assetPlugin(plugin, "res/FF-120.svg")));
  58. addInput(Port::create<sub_port_blue>(Vec(17.5,19), Port::INPUT, module, FF_120::INPUT));
  59. for (int i = 0; i < FF_120::deviceCount; i+=2) {
  60. int offset = 15 * i;
  61. addOutput(Port::create<sub_port_blue>(Vec(4,53 + offset), Port::OUTPUT, module, FF_120::OUTPUT_1 + i));
  62. addOutput(Port::create<sub_port_blue>(Vec(31,68 + offset), Port::OUTPUT, module, FF_120::OUTPUT_1 + i + 1));
  63. }
  64. }
  65. void appendContextMenu(Menu *menu) override {
  66. ((DS_Module *)module)->appendContextMenu(menu);
  67. }
  68. };
  69. } // namespace rack_plugin_SubmarineFree
  70. using namespace rack_plugin_SubmarineFree;
  71. RACK_PLUGIN_MODEL_INIT(SubmarineFree, FF120) {
  72. Model *modelFF120 = Model::create<FF_120, FF120>("SubmarineFree", "FF-120", "FF-120 20-Stage Flip-Flop Counter", LOGIC_TAG, MULTIPLE_TAG);
  73. return modelFF120;
  74. }