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.

124 lines
3.3KB

  1. #include "DS.hpp"
  2. namespace rack_plugin_SubmarineFree {
  3. struct LD_106 : DS_Module {
  4. static const int deviceCount = 6;
  5. enum ParamIds {
  6. PARAM_CUTOFF_1,
  7. PARAM_CUTOFF_2,
  8. PARAM_CUTOFF_3,
  9. PARAM_CUTOFF_4,
  10. PARAM_CUTOFF_5,
  11. PARAM_CUTOFF_6,
  12. PARAM_WIDTH_1,
  13. PARAM_WIDTH_2,
  14. PARAM_WIDTH_3,
  15. PARAM_WIDTH_4,
  16. PARAM_WIDTH_5,
  17. PARAM_WIDTH_6,
  18. NUM_PARAMS
  19. };
  20. enum InputIds {
  21. INPUT_1,
  22. INPUT_2,
  23. INPUT_3,
  24. INPUT_4,
  25. INPUT_5,
  26. INPUT_6,
  27. NUM_INPUTS
  28. };
  29. enum OutputIds {
  30. OUTPUT_1,
  31. OUTPUT_2,
  32. OUTPUT_3,
  33. OUTPUT_4,
  34. OUTPUT_5,
  35. OUTPUT_6,
  36. NUM_OUTPUTS
  37. };
  38. enum LightIds {
  39. NUM_LIGHTS
  40. };
  41. DS_Schmitt schmittState[deviceCount];
  42. LD_106() : DS_Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  43. void step() override;
  44. };
  45. void LD_106::step() {
  46. for (int i = 0; i < deviceCount; i++) {
  47. outputs[OUTPUT_1 + i].value = output(schmittState[i].state(params[PARAM_CUTOFF_1 + i].value - params[PARAM_WIDTH_1 + i].value, params[PARAM_CUTOFF_1 + i].value + params[PARAM_WIDTH_1 + i].value, inputs[INPUT_1 + i].value));
  48. }
  49. }
  50. struct LD106 : ModuleWidget {
  51. ParamWidget *cutoffWidgets[LD_106::deviceCount];
  52. ParamWidget *widthWidgets[LD_106::deviceCount];
  53. LD106(LD_106 *module) : ModuleWidget(module) {
  54. setPanel(SVG::load(assetPlugin(plugin, "res/LD-106.svg")));
  55. for (int i = 0; i < LD_106::deviceCount; i++) {
  56. int offset = 58 * i;
  57. addInput(Port::create<sub_port>(Vec(4,19 + offset), Port::INPUT, module, LD_106::INPUT_1 + i));
  58. addOutput(Port::create<sub_port_blue>(Vec(62,19 + offset), Port::OUTPUT, module, LD_106::OUTPUT_1 + i));
  59. cutoffWidgets[i] = ParamWidget::create<sub_knob_small>(Vec(4, 47 + offset), module, LD_106::PARAM_CUTOFF_1 + i, -10.0f, 10.0f, 5.0f);
  60. addParam(cutoffWidgets[i]);
  61. widthWidgets[i] = ParamWidget::create<sub_knob_small>(Vec(62, 47 + offset), module, LD_106::PARAM_WIDTH_1 + i, 0.0f, 5.0f, 1.0f);
  62. addParam(widthWidgets[i]);
  63. }
  64. }
  65. void appendContextMenu(Menu *menu) override;
  66. };
  67. struct LDMenuItem: MenuItem {
  68. LD106 *ld106;
  69. float cutoff;
  70. float width;
  71. void onAction(EventAction &e) override {
  72. for (int i = 0; i < LD_106::deviceCount; i++) {
  73. ld106->cutoffWidgets[i]->setValue(cutoff);
  74. ld106->widthWidgets[i]->setValue(width);
  75. }
  76. }
  77. };
  78. void LD106::appendContextMenu(Menu *menu) {
  79. menu->addChild(MenuEntry::create());
  80. LD106 *ld106 = dynamic_cast<LD106*>(this);
  81. assert(ld106);
  82. LDMenuItem *menuItem = MenuItem::create<LDMenuItem>("Cutoff 5V");
  83. menuItem->ld106 = ld106;
  84. menuItem->cutoff = 5.0f;
  85. menuItem->width = 1.0f;
  86. menu->addChild(menuItem);
  87. menuItem = MenuItem::create<LDMenuItem>("Cutoff 0V");
  88. menuItem->ld106 = ld106;
  89. menuItem->cutoff = 0.0f;
  90. menuItem->width = 0.0f;
  91. menu->addChild(menuItem);
  92. menuItem = MenuItem::create<LDMenuItem>("Cutoff 2.5V");
  93. menuItem->ld106 = ld106;
  94. menuItem->cutoff = 2.5f;
  95. menuItem->width = 0.5f;
  96. menu->addChild(menuItem);
  97. menuItem = MenuItem::create<LDMenuItem>("TTL Levels");
  98. menuItem->ld106 = ld106;
  99. menuItem->cutoff = 1.4f;
  100. menuItem->width = 0.6f;
  101. menu->addChild(menuItem);
  102. ((LD_106 *)module)->appendContextMenu(menu);
  103. }
  104. } // namespace rack_plugin_SubmarineFree
  105. using namespace rack_plugin_SubmarineFree;
  106. RACK_PLUGIN_MODEL_INIT(SubmarineFree, LD106) {
  107. Model *modelLD106 = Model::create<LD_106, LD106>("SubmarineFree", "LD-106", "LD-106 Schmitt Trigger Line Drivers", LOGIC_TAG, MULTIPLE_TAG);
  108. return modelLD106;
  109. }