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.

33 lines
563B

  1. #pragma once
  2. #include <functional>
  3. /**
  4. * Calls a lambda ever 'n' calls
  5. * Purpose is to make it simple do run a subset of a plugin every
  6. * 'n' cycles.
  7. *
  8. * lambda is always called on the first call to step();
  9. */
  10. class Divider
  11. {
  12. public:
  13. void setup(int n, std::function<void()> l)
  14. {
  15. lambda = l;
  16. divisor = n;
  17. }
  18. void step()
  19. {
  20. if (--counter == 0) {
  21. counter = divisor;
  22. lambda();
  23. }
  24. }
  25. private:
  26. std::function<void()> lambda = nullptr;
  27. int divisor = 0;
  28. int counter = 1;
  29. };