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.

141 lines
4.0KB

  1. /*
  2. CoSuOf
  3. Co(mparator)
  4. Su(bstractor)
  5. Of(fsetter)
  6. "a la D-A167"
  7. INS:
  8. POS * POS_ATTN[0..1]
  9. NEG * NEG_ATTN[0..1]
  10. OUTS:
  11. SUM = POS - NEG + OFFSET[-10..10]
  12. GATE = high[10] if SUM is > 0 / low[0] if SUM is <= 0
  13. NATE = !GATE
  14. WARNING: due to how the module operates you can produce excessivly high (or
  15. low) voltages on the SUM output (+/- 30V for the extreme cases of inputs).
  16. i didn't want to clamp or scale the output.
  17. so, use the attenuators and a meter to adjust for desired V-range!
  18. */////////////////////////////////////////////////////////////////////////////
  19. #include "pvc.hpp"
  20. struct CoSuOf : Module {
  21. enum ParamIds {
  22. POS_LVL,
  23. NEG_LVL,
  24. OFFSET,
  25. GAP,
  26. NUM_PARAMS
  27. };
  28. enum InputIds {
  29. POS_IN,
  30. NEG_IN,
  31. NUM_INPUTS
  32. };
  33. enum OutputIds {
  34. SUM_OUT,
  35. GATE_OUT,
  36. NATE_OUT,
  37. MUS_OUT,
  38. G_SUM,
  39. N_SUM,
  40. G_POS,
  41. N_POS,
  42. G_NEG,
  43. N_NEG,
  44. NUM_OUTPUTS
  45. };
  46. enum LightIds {
  47. GATE_LED,
  48. NATE_LED,
  49. NUM_LIGHTS
  50. };
  51. bool gate = false;
  52. CoSuOf() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  53. void step() override;
  54. void reset() override {
  55. gate = false;
  56. }
  57. };
  58. void CoSuOf::step() {
  59. float posIn = inputs[POS_IN].value * params[POS_LVL].value;
  60. float negIn = inputs[NEG_IN].value * params[NEG_LVL].value;
  61. float sumOut = clamp(posIn - negIn + params[OFFSET].value, -10.0f, 10.0f);
  62. float gap = params[GAP].value;
  63. if (sumOut > gap) gate = true;
  64. if (sumOut <= -gap) gate = false;
  65. outputs[SUM_OUT].value = sumOut; // TODO:
  66. outputs[MUS_OUT].value = -sumOut;
  67. outputs[GATE_OUT].value = gate * 10.0f;
  68. outputs[NATE_OUT].value = !gate * 10.0f;
  69. outputs[G_SUM].value = gate * sumOut;
  70. outputs[N_SUM].value = !gate * sumOut;
  71. outputs[G_POS].value = gate * posIn;
  72. outputs[N_POS].value = !gate * posIn;
  73. outputs[G_NEG].value = gate * negIn;
  74. outputs[N_NEG].value = !gate * negIn;
  75. lights[GATE_LED].value = gate;
  76. lights[NATE_LED].value = !gate;
  77. }
  78. struct CoSuOfWidget : ModuleWidget {
  79. CoSuOfWidget(CoSuOf *module);
  80. };
  81. CoSuOfWidget::CoSuOfWidget(CoSuOf *module) : ModuleWidget(module) {
  82. setPanel(SVG::load(assetPlugin(plugin, "res/panels/CoSuOf.svg")));
  83. // screws
  84. addChild(Widget::create<ScrewHead1>(Vec(0, 0)));
  85. addChild(Widget::create<ScrewHead2>(Vec(box.size.x - 15, 0)));
  86. addChild(Widget::create<ScrewHead3>(Vec(0, 365)));
  87. addChild(Widget::create<ScrewHead4>(Vec(box.size.x - 15, 365)));
  88. addInput(Port::create<InPortAud>(Vec(4,22), Port::INPUT, module,CoSuOf::POS_IN));
  89. addInput(Port::create<InPortAud>(Vec(34,22), Port::INPUT, module,CoSuOf::NEG_IN));
  90. addParam(ParamWidget::create<PvCKnob>(Vec(4,64),module,CoSuOf::POS_LVL, 0.0f, 1.0f, 1.0f));
  91. addParam(ParamWidget::create<PvCKnob>(Vec(34,64),module,CoSuOf::NEG_LVL, 0.0f, 1.0f, 1.0f));
  92. addParam(ParamWidget::create<PvCKnob>(Vec(19,104),module,CoSuOf::OFFSET, -10.0f, 10.0f, 0.0f));
  93. addOutput(Port::create<OutPortVal>(Vec(4,158), Port::OUTPUT, module,CoSuOf::SUM_OUT));
  94. addOutput(Port::create<OutPortVal>(Vec(34,158), Port::OUTPUT, module,CoSuOf::MUS_OUT));
  95. addParam(ParamWidget::create<PvCKnob>(Vec(19,192),module,CoSuOf::GAP, 0.0f, 10.0f, 0.0f));
  96. addChild(ModuleLightWidget::create<FourPixLight<OrangeLED>>(Vec(13, 244),module, CoSuOf::GATE_LED));
  97. addChild(ModuleLightWidget::create<FourPixLight<BlueLED>>(Vec(43, 244),module, CoSuOf::NATE_LED));
  98. addOutput(Port::create<OutPortBin>(Vec(4,250), Port::OUTPUT, module,CoSuOf::GATE_OUT));
  99. addOutput(Port::create<OutPortBin>(Vec(34,250), Port::OUTPUT, module,CoSuOf::NATE_OUT));
  100. addOutput(Port::create<OutPortVal>(Vec(4,288), Port::OUTPUT, module,CoSuOf::G_SUM));
  101. addOutput(Port::create<OutPortVal>(Vec(34,288), Port::OUTPUT, module,CoSuOf::N_SUM));
  102. addOutput(Port::create<OutPortVal>(Vec(4,312), Port::OUTPUT, module,CoSuOf::G_POS));
  103. addOutput(Port::create<OutPortVal>(Vec(34,312), Port::OUTPUT, module,CoSuOf::N_POS));
  104. addOutput(Port::create<OutPortVal>(Vec(4,336), Port::OUTPUT, module,CoSuOf::G_NEG));
  105. addOutput(Port::create<OutPortVal>(Vec(34,336), Port::OUTPUT, module,CoSuOf::N_NEG));
  106. }
  107. Model *modelCoSuOf = Model::create<CoSuOf, CoSuOfWidget>(
  108. "PvC", "CoSuOf", "CoSuOf", LOGIC_TAG, ATTENUATOR_TAG);