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.

142 lines
2.9KB

  1. #pragma once
  2. #include "MidiTrack.h"
  3. #include "FilteredIterator.h"
  4. #include <memory>
  5. class MidiSong;
  6. class MidiSelectionModel;
  7. class MidiEditorContext
  8. {
  9. public:
  10. MidiEditorContext(std::shared_ptr<MidiSong>);
  11. ~MidiEditorContext();
  12. float cursorPitch() const
  13. {
  14. return m_cursorPitch;
  15. }
  16. void setCursorPitch(float pitch)
  17. {
  18. m_cursorPitch = pitch;
  19. }
  20. float cursorTime() const
  21. {
  22. return m_cursorTime;
  23. }
  24. void setCursorTime(float time)
  25. {
  26. m_cursorTime = time;
  27. }
  28. MidiEvent::time_t startTime()
  29. {
  30. return m_startTime;
  31. }
  32. void setStartTime(MidiEvent::time_t t)
  33. {
  34. m_startTime = t;
  35. }
  36. void setEndTime(MidiEvent::time_t t)
  37. {
  38. m_endTime = t;
  39. }
  40. void setTimeRange(MidiEvent::time_t start, MidiEvent::time_t end)
  41. {
  42. m_startTime = start;
  43. m_endTime = end;
  44. assert(end > start);
  45. }
  46. MidiEvent::time_t endTime()
  47. {
  48. return m_endTime;
  49. }
  50. float pitchHi()
  51. {
  52. return m_pitchHi;
  53. }
  54. float pitchLow()
  55. {
  56. return m_pitchLow;
  57. }
  58. void setPitchLow(float p)
  59. {
  60. m_pitchLow = p;
  61. }
  62. void setPitchHi(float p)
  63. {
  64. m_pitchHi = p;
  65. }
  66. void setPitchRange(float l, float h)
  67. {
  68. assert(h >= l);
  69. m_pitchHi = h;
  70. m_pitchLow = l;
  71. }
  72. int getTrackNumber()
  73. {
  74. return trackNumber;
  75. }
  76. void setTrackNumber(int n)
  77. {
  78. trackNumber = n;
  79. }
  80. MidiTrackPtr getTrack();
  81. void setCursorToNote(MidiNoteEventPtrC note);
  82. void setCursorToSelection(std::shared_ptr<MidiSelectionModel> selection);
  83. // TODO: change to const_iterator
  84. using iterator = filtered_iterator<MidiEvent, MidiTrack::const_iterator>;
  85. using iterator_pair = std::pair<iterator, iterator>;
  86. iterator_pair getEvents() const;
  87. int track = 0;
  88. std::shared_ptr<MidiSong> getSong() const;
  89. void scrollVertically(float pitchCV);
  90. // Which field of note is being edited?
  91. enum class NoteAttribute
  92. {
  93. Pitch,
  94. Duration,
  95. StartTime
  96. };
  97. NoteAttribute noteAttribute;
  98. void assertValid() const;
  99. bool cursorInViewport() const;
  100. void assertCursorInViewport() const;
  101. void scrollViewportToCursorPitch();
  102. bool cursorInViewportTime() const;
  103. void adjustViewportForCursor();
  104. private:
  105. // TODO: don't allow direct access?
  106. float m_cursorTime = 0;
  107. float m_cursorPitch = 0;
  108. // range will include t == start time, but will not
  109. // include t == endTime
  110. MidiEvent::time_t m_startTime = 0;
  111. MidiEvent::time_t m_endTime = 1;
  112. // pitch is inclusive: Low and Hi will be included
  113. float m_pitchLow = 0;
  114. float m_pitchHi = 0;
  115. int trackNumber = 0;
  116. // Below is not for clients to call. TODO: use private or something.
  117. // Definitely need some architecture here.
  118. std::weak_ptr<MidiSong> _song;
  119. };
  120. using MidiEditorContextPtr = std::shared_ptr<MidiEditorContext>;