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.

105 lines
2.6KB

  1. #include "Bidoo.hpp"
  2. #include "BidooComponents.hpp"
  3. #include "dsp/digital.hpp"
  4. #include <ctime>
  5. using namespace std;
  6. namespace rack_plugin_Bidoo {
  7. struct LATE : Module {
  8. enum ParamIds {
  9. SWING_PARAM,
  10. CVCOEFF_PARAM,
  11. NUM_PARAMS
  12. };
  13. enum InputIds {
  14. SWING_INPUT,
  15. CLOCK_INPUT,
  16. RESET_INPUT,
  17. NUM_INPUTS
  18. };
  19. enum OutputIds {
  20. CLOCK_OUTPUT,
  21. NUM_OUTPUTS
  22. };
  23. enum LightIds {
  24. NUM_LIGHTS
  25. };
  26. bool odd = true;
  27. bool armed = false;
  28. SchmittTrigger clockTrigger;
  29. SchmittTrigger resetTrigger;
  30. clock_t tCurrent = clock();
  31. clock_t tPrevious = clock();
  32. LATE() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { }
  33. void step() override;
  34. };
  35. void LATE::step() {
  36. outputs[CLOCK_OUTPUT].value = 0;
  37. clock_t now = clock();
  38. if (resetTrigger.process(inputs[RESET_INPUT].value)) {
  39. odd=true;
  40. }
  41. if (clockTrigger.process(inputs[CLOCK_INPUT].value)) {
  42. tPrevious = tCurrent;
  43. tCurrent = now;
  44. if (odd) {
  45. outputs[CLOCK_OUTPUT].value = 10.0f;
  46. odd = false;
  47. armed = false;
  48. }
  49. else {
  50. armed = true;
  51. }
  52. }
  53. float lag = rescale(clamp(params[SWING_PARAM].value + params[CVCOEFF_PARAM].value * inputs[SWING_INPUT].value,0.0f,9.0f),0.0f,10.0f,0.0f,(float)tCurrent-(float)tPrevious);
  54. if (armed && !odd && (((float)now - (float)tCurrent) >= lag)) {
  55. outputs[CLOCK_OUTPUT].value = 10.0f;
  56. armed = false;
  57. odd = true;
  58. }
  59. }
  60. struct LATEWidget : ModuleWidget {
  61. LATEWidget(LATE *module) : ModuleWidget(module) {
  62. setPanel(SVG::load(assetPlugin(plugin, "res/LATE.svg")));
  63. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  64. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  65. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  66. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  67. addParam(ParamWidget::create<BidooBlueKnob>(Vec(8, 70), module, LATE::SWING_PARAM, 0, 9, 0));
  68. addParam(ParamWidget::create<BidooBlueTrimpot>(Vec(13, 105), module, LATE::CVCOEFF_PARAM, -1.0f, 1.0f, 0.0f));
  69. addInput(Port::create<PJ301MPort>(Vec(10, 130), Port::INPUT, module, LATE::SWING_INPUT));
  70. addInput(Port::create<PJ301MPort>(Vec(10, 186.33f), Port::INPUT, module, LATE::RESET_INPUT));
  71. addInput(Port::create<PJ301MPort>(Vec(10, 242.66f), Port::INPUT, module, LATE::CLOCK_INPUT));
  72. addOutput(Port::create<PJ301MPort>(Vec(10, 299), Port::OUTPUT, module, LATE::CLOCK_OUTPUT));
  73. }
  74. };
  75. } // namespace rack_plugin_Bidoo
  76. using namespace rack_plugin_Bidoo;
  77. RACK_PLUGIN_MODEL_INIT(Bidoo, LATE) {
  78. Model *modelLATE = Model::create<LATE, LATEWidget>("Bidoo", "lATe", "lATe clock modulator", CLOCK_MODULATOR_TAG);
  79. return modelLATE;
  80. }