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.

105 lines
2.7KB

  1. #include "rack.hpp"
  2. namespace rack_plugin_rcm {
  3. class Auditioner;
  4. class PatternData;
  5. class Transport;
  6. class PianoRollDragType;
  7. struct Key {
  8. rack::Vec pos;
  9. rack::Vec size;
  10. bool sharp;
  11. int num;
  12. int oct;
  13. Key() : pos(rack::Vec(0,0)), size(rack::Vec(0,0)), sharp(false), num(0), oct(0) {}
  14. Key(rack::Vec p, rack::Vec s, bool sh, int n, int o) : pos(p), size(s), sharp(sh), num(n), oct(o) {}
  15. int pitch() {
  16. return num + (12 * oct);
  17. }
  18. };
  19. struct BeatDiv {
  20. rack::Vec pos;
  21. rack::Vec size;
  22. int num;
  23. bool beat;
  24. bool triplet;
  25. BeatDiv() : pos(rack::Vec(0,0)), size(rack::Vec(0,0)), num(0), beat(false), triplet(false) {}
  26. };
  27. struct WidgetState {
  28. rack::Rect box;
  29. int notesToShow = 18;
  30. int lowestDisplayNote = 4 * 12;
  31. int currentMeasure = 0;
  32. int lastDrawnStep = -1;
  33. float displayVelocityHigh = -1;
  34. float displayVelocityLow = -1;
  35. double measureLockPressTime = 0.f;
  36. bool dirty = true;
  37. bool consumeDirty();
  38. };
  39. class UnderlyingRollAreaWidget : public rack::VirtualWidget {
  40. public:
  41. UnderlyingRollAreaWidget();
  42. ~UnderlyingRollAreaWidget();
  43. int fonthandle;
  44. WidgetState* state;
  45. PatternData* patternData;
  46. Transport* transport;
  47. Auditioner* auditioner;
  48. float topMargins = 15;
  49. std::vector<Key> getKeys(const rack::Rect& keysArea);
  50. std::vector<BeatDiv> getBeatDivs(const rack::Rect &roll);
  51. rack::Rect reserveKeysArea(rack::Rect& roll);
  52. std::tuple<bool, int> findMeasure(rack::Vec pos);
  53. std::tuple<bool, bool> findOctaveSwitch(rack::Vec pos);
  54. std::tuple<bool, BeatDiv, Key> findCell(rack::Vec pos);
  55. void drawKeys(NVGcontext *ctx, const std::vector<Key> &keys);
  56. void drawSwimLanes(NVGcontext *ctx, const rack::Rect &roll, const std::vector<Key> &keys);
  57. void drawBeats(NVGcontext *ctx, const std::vector<BeatDiv> &beatDivs);
  58. void drawNotes(NVGcontext *ctx, const std::vector<Key> &keys, const std::vector<BeatDiv> &beatDivs);
  59. void drawMeasures(NVGcontext *ctx);
  60. void drawPlayPosition(NVGcontext *ctx);
  61. void drawVelocityInfo(NVGcontext *ctx);
  62. void draw(NVGcontext* ctx) override;
  63. void onMouseDown(rack::EventMouseDown& e) override;
  64. void onDragStart(rack::EventDragStart& e) override;
  65. void onDragMove(rack::EventDragMove& e) override;
  66. void onDragEnd(rack::EventDragEnd& e) override;
  67. rack::Vec lastMouseDown;
  68. PianoRollDragType* currentDragType = NULL;
  69. };
  70. class RollAreaWidget : public rack::FramebufferWidget {
  71. public:
  72. WidgetState state;
  73. UnderlyingRollAreaWidget* underlyingRollAreaWidget;
  74. RollAreaWidget(PatternData* patternData, Transport* transport, Auditioner* auditioner);
  75. void step() override;
  76. private:
  77. PatternData* patternData;
  78. Transport* transport;
  79. Auditioner* auditioner;
  80. };
  81. } // namespace rack_plugin_rcm