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.

94 lines
2.4KB

  1. // Copyright 2015 Olivier Gillet.
  2. //
  3. // Author: Olivier Gillet (ol.gillet@gmail.com)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. // See http://creativecommons.org/licenses/MIT/ for more information.
  24. //
  25. // -----------------------------------------------------------------------------
  26. //
  27. // Quad euclidean sequencer with envelope generation.
  28. #ifndef FRAMES_EUCLIDEAN_
  29. #define FRAMES_EUCLIDEAN_
  30. #include "stmlib/stmlib.h"
  31. namespace frames {
  32. class Euclidean {
  33. public:
  34. Euclidean() { }
  35. ~Euclidean() { }
  36. void Init();
  37. void Render();
  38. void Step(int32_t clock);
  39. inline uint8_t level() const {
  40. return value_ >> 8;
  41. }
  42. inline uint8_t gate() const {
  43. return gate_;
  44. }
  45. inline const uint16_t dac_code() const {
  46. return dac_code_;
  47. }
  48. inline void set_length(uint8_t length) {
  49. length_ = length;
  50. }
  51. inline void set_fill(uint16_t fill) {
  52. fill_ = fill;
  53. }
  54. inline void set_rotate(uint16_t rotate) {
  55. rotate_ = rotate;
  56. }
  57. inline void set_shape(uint16_t shape) {
  58. shape_ = shape;
  59. }
  60. private:
  61. void ComputeAttackDecay(uint16_t shape, uint16_t* a, uint16_t* d);
  62. uint8_t length_;
  63. uint16_t fill_;
  64. uint16_t rotate_;
  65. uint16_t shape_;
  66. uint32_t value_;
  67. uint32_t phase_;
  68. uint16_t attack_;
  69. bool gate_;
  70. uint16_t dac_code_;
  71. DISALLOW_COPY_AND_ASSIGN(Euclidean);
  72. };
  73. } // namespace frames
  74. #endif // FRAMES_EUCLIDEAN_