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.

69 lines
1.2KB

  1. #include "Clock.hpp"
  2. namespace SynthDevKit {
  3. Clock::Clock (uint16_t count, float threshold) {
  4. if (count > CLOCK_LIMIT) {
  5. throw CLK_ERROR_TOO_MANY;
  6. }
  7. triggerThreshold = threshold;
  8. triggerCount = count;
  9. current = 0;
  10. ready = false;
  11. step = 0;
  12. cv = new CV(threshold);
  13. for (uint16_t i = 0; i < CLOCK_LIMIT; i++) {
  14. states[i] = false;
  15. }
  16. }
  17. bool *Clock::update (float input) {
  18. cv->update(input);
  19. // only become ready after the first trigger has occurred. this allows for
  20. // an interval to be set up
  21. if (!ready) {
  22. if (cv->newTrigger()) {
  23. ready = true;
  24. }
  25. return states;
  26. }
  27. current++;
  28. if (cv->newTrigger()) {
  29. step++;
  30. current = 0;
  31. for (uint16_t i = 0; i < triggerCount; i++) {
  32. states[i] = ((step % (i + 1)) == 0) ? true : false;
  33. }
  34. } else if (current >= cv->triggerInterval() / 2) {
  35. for (uint16_t i = 0; i < triggerCount; i++) {
  36. states[i] = false;
  37. }
  38. }
  39. if (step >= triggerCount) {
  40. step = 0;
  41. }
  42. return states;
  43. }
  44. void Clock::reset ( ) {
  45. current = 0;
  46. ready = false;
  47. step = 0;
  48. for (uint16_t i = 0; i < CLOCK_LIMIT; i++) {
  49. states[i] = false;
  50. }
  51. cv->reset();
  52. }
  53. }