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.

49 lines
645B

  1. #if!defined PULSEGATE_HPP
  2. #define PULSEGATE_HPP
  3. class PulseGate
  4. {
  5. public:
  6. explicit PulseGate(float pulseDuration = 250.f);
  7. void reset();
  8. bool process(bool gate);
  9. private:
  10. /*! The pulse duration in second. */
  11. float m_pulseDuration;
  12. float m_current = 0.f;
  13. bool m_pulse = false;
  14. };
  15. class Pulser
  16. {
  17. public:
  18. explicit Pulser(float pulseDuration = 0.001f) :
  19. m_gate(pulseDuration)
  20. {
  21. }
  22. void trigger()
  23. {
  24. m_trigger = true;
  25. }
  26. void reset()
  27. {
  28. m_gate.reset();
  29. }
  30. bool step()
  31. {
  32. auto const result = m_gate.process(m_trigger);
  33. m_trigger = false;
  34. return result;
  35. }
  36. private:
  37. PulseGate m_gate;
  38. bool m_trigger = false;
  39. };
  40. #endif