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.

70 lines
1.5KB

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