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.

85 lines
2.4KB

  1. #include "rack.hpp"
  2. #include <vector>
  3. namespace rack_plugin_rcm {
  4. struct Step;
  5. class PatternData {
  6. public:
  7. PatternData();
  8. int getStepsInPattern(int pattern) const;
  9. int getStepsPerMeasure(int pattern) const;
  10. void setMeasures(int pattern, int measures);
  11. int getMeasures(int pattern) const;
  12. void setBeatsPerMeasure(int pattern, int beats);
  13. void setDivisionsPerBeat(int pattern, int divisions);
  14. int getBeatsPerMeasure(int pattern) const;
  15. int getDivisionsPerBeat(int pattern) const;
  16. void copyPattern(int pattern);
  17. void copyMeasure(int pattern, int measure);
  18. void pastePattern(int targetPattern);
  19. void pasteMeasure(int targetPattern, int targetMeasure);
  20. void toggleStepActive(int pattern, int measure, int step);
  21. void setStepActive(int pattern, int measure, int step, bool active);
  22. void setStepPitch(int pattern, int measure, int step, int pitch);
  23. void toggleStepRetrigger(int pattern, int measure, int step);
  24. void setStepRetrigger(int pattern, int measure, int step, bool retrigger);
  25. void setStepVelocity(int pattern, int measure, int step, float velocity);
  26. void increaseStepVelocityTo(int pattern, int measure, int step, float targetVelocity);
  27. bool isStepActive(int pattern, int measure, int step) const;
  28. bool isStepRetriggered(int pattern, int measure, int step) const;
  29. float getStepVelocity(int pattern, int measure, int step) const;
  30. int getStepPitch(int pattern, int measure, int step) const;
  31. float adjustVelocity(int pattern, int measure, int step, float delta);
  32. void clearPatternSteps(int pattern);
  33. void reset();
  34. json_t *toJson() const;
  35. void fromJson(json_t *rootJ);
  36. bool dirty = true;
  37. bool consumeDirty();
  38. private:
  39. struct Step {
  40. int pitch = 0;
  41. float velocity = 0.f;
  42. bool retrigger = false;
  43. bool active = false;
  44. };
  45. struct Measure {
  46. std::vector<Step> steps;
  47. };
  48. struct Pattern {
  49. std::vector<Measure> measures;
  50. int numberOfMeasures = 1;
  51. int beatsPerMeasure = 4;
  52. int divisionsPerBeat = 4;
  53. };
  54. std::vector<Pattern> patterns;
  55. void copyPatternData(const Pattern& sourcePattern, Pattern& targetPattern);
  56. void copyMeasureData(const Measure& sourceMeasure, Measure& targetMeasure);
  57. void copyStepData(const Step& sourceStep, Step& targetStep);
  58. void reassignSteps(int pattern, int fromSteps, int toSteps);
  59. Pattern copiedPattern;
  60. Measure copiedMeasure;
  61. };
  62. } // namespace rack_plugin_rcm