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.

40 lines
872B

  1. #pragma once
  2. #include "GateTrigger.h"
  3. /**
  4. * Output processing for triggers.
  5. * Outputs a finite duration trigger when gate changes.
  6. */
  7. class TriggerOutput
  8. {
  9. public:
  10. TriggerOutput() :
  11. _gateProcessor(false), // defeat reset logic that we don't want
  12. _counter(0),
  13. _duration(TRIGGER_OUT_TIME_MS * 44100 / 1000) // TODO: make this better
  14. {
  15. }
  16. void go(bool gate)
  17. {
  18. if (_counter) {
  19. --_counter;
  20. return;
  21. }
  22. _gateProcessor.go(gate ? cGateOutHi : cGateOutLow);
  23. if (_gateProcessor.trigger()) {
  24. _counter = _duration;
  25. }
  26. }
  27. float get() const
  28. {
  29. return (_counter > 0) ? cGateOutHi : cGateOutLow; // TODO: 0..10 for gates/trig/clock?
  30. }
  31. private:
  32. GateTrigger _gateProcessor;
  33. int _counter;
  34. const int _duration;
  35. };