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.

103 lines
2.2KB

  1. #include "DS.hpp"
  2. #include "dsp/digital.hpp"
  3. namespace rack_plugin_SubmarineFree {
  4. struct PG_112 : DS_Module {
  5. static const int deviceCount = 12;
  6. enum ParamIds {
  7. PARAM_1,
  8. PARAM_2,
  9. PARAM_3,
  10. PARAM_4,
  11. PARAM_5,
  12. PARAM_6,
  13. PARAM_7,
  14. PARAM_8,
  15. PARAM_9,
  16. PARAM_10,
  17. PARAM_11,
  18. PARAM_12,
  19. NUM_PARAMS
  20. };
  21. enum InputIds {
  22. INPUT_1,
  23. INPUT_2,
  24. INPUT_3,
  25. INPUT_4,
  26. INPUT_5,
  27. INPUT_6,
  28. INPUT_7,
  29. INPUT_8,
  30. INPUT_9,
  31. INPUT_10,
  32. INPUT_11,
  33. INPUT_12,
  34. NUM_INPUTS
  35. };
  36. enum OutputIds {
  37. OUTPUT_1,
  38. OUTPUT_2,
  39. OUTPUT_3,
  40. OUTPUT_4,
  41. OUTPUT_5,
  42. OUTPUT_6,
  43. OUTPUT_7,
  44. OUTPUT_8,
  45. OUTPUT_9,
  46. OUTPUT_10,
  47. OUTPUT_11,
  48. OUTPUT_12,
  49. NUM_OUTPUTS
  50. };
  51. enum LightIds {
  52. NUM_LIGHTS
  53. };
  54. DS_Schmitt schmitt[deviceCount];
  55. PulseGenerator pulse[deviceCount];
  56. PG_112() : DS_Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  57. void step() override;
  58. };
  59. void PG_112::step() {
  60. float deltaTime = 1.0f / engineGetSampleRate();
  61. for (int i = 0; i < deviceCount; i++) {
  62. if (schmitt[i].redge(this, inputs[INPUT_1 + i].value)) {
  63. pulse[i].process(deltaTime);
  64. pulse[i].trigger(powf(10.0f, params[PARAM_1 + i].value));
  65. outputs[OUTPUT_1 + i].value = voltage1;
  66. }
  67. else {
  68. outputs[OUTPUT_1 + i].value = pulse[i].process(deltaTime)?voltage1:voltage0;
  69. }
  70. }
  71. }
  72. struct PG112 : ModuleWidget {
  73. PG112(PG_112 *module) : ModuleWidget(module) {
  74. setPanel(SVG::load(assetPlugin(plugin, "res/PG-112.svg")));
  75. for (int i = 0; i < PG_112::deviceCount; i++) {
  76. int offset = 29 * i;
  77. addInput(Port::create<sub_port_blue>(Vec(4,19 + offset), Port::INPUT, module, PG_112::INPUT_1 + i));
  78. addOutput(Port::create<sub_port_blue>(Vec(92,19 + offset), Port::OUTPUT, module, PG_112::OUTPUT_1 + i));
  79. addParam(ParamWidget::create<sub_knob_small>(Vec(33,19.5 + offset), module, PG_112::PARAM_1 + i, -5.0f, 2.0f, -2.0f));
  80. }
  81. }
  82. void appendContextMenu(Menu *menu) override {
  83. ((DS_Module *)module)->appendContextMenu(menu);
  84. }
  85. };
  86. } // namespace rack_plugin_SubmarineFree
  87. using namespace rack_plugin_SubmarineFree;
  88. RACK_PLUGIN_MODEL_INIT(SubmarineFree, PG112) {
  89. Model *modelPG112 = Model::create<PG_112, PG112>("SubmarineFree", "PG-112", "PG-112 Pulse Generators", LOGIC_TAG, MULTIPLE_TAG);
  90. return modelPG112;
  91. }