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.

66 lines
1.4KB

  1. #pragma once
  2. #include <memory>
  3. #include <set>
  4. class MidiEvent;
  5. class MidiSelectionModel;
  6. using MidiSelectionModelPtr = std::shared_ptr<MidiSelectionModel>;
  7. /**
  8. * Central manager for tracking selections in the MidiSong being edited.
  9. */
  10. class MidiSelectionModel
  11. {
  12. public:
  13. MidiSelectionModel();
  14. ~MidiSelectionModel();
  15. /**
  16. * replace the current selection with a single event
  17. */
  18. void select(std::shared_ptr<MidiEvent>);
  19. void extendSelection(std::shared_ptr<MidiEvent>);
  20. /**
  21. * select nothing
  22. */
  23. void clear();
  24. using container = std::set<std::shared_ptr<MidiEvent>>;
  25. using const_iterator = container::const_iterator;
  26. const_iterator begin() const;
  27. const_iterator end() const;
  28. int size() const
  29. {
  30. return (int) selection.size();
  31. }
  32. bool empty() const
  33. {
  34. return selection.empty();
  35. }
  36. MidiSelectionModelPtr clone() const;
  37. std::shared_ptr<MidiEvent> getLast();
  38. /** Returns true is this object instance is in selection.
  39. * i.e. changes on pointer value.
  40. * O(1)
  41. */
  42. bool isSelected(std::shared_ptr<MidiEvent>) const;
  43. /** Returns true is there is an object in selection equivalent
  44. * to 'event'. i.e. selection contains entry == *event.
  45. * O(n), where n is the number of items in selection
  46. */
  47. bool isSelectedDeep(std::shared_ptr<MidiEvent> event) const;
  48. private:
  49. container selection;
  50. };