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.

67 lines
2.0KB

  1. #pragma once
  2. #include <vector>
  3. #include "MidiEvent.h"
  4. #include "SqCommand.h"
  5. class MidiEditorContext;
  6. class MidiEvent;
  7. class MidiNoteEvent;
  8. class MidiSong;
  9. class MidiSequencer;
  10. class MidiSelectionModel;
  11. class ReplaceDataCommand;
  12. using ReplaceDataCommandPtr = std::shared_ptr<ReplaceDataCommand>;
  13. class ReplaceDataCommand : public SqCommand
  14. {
  15. public:
  16. virtual void execute() override;
  17. virtual void undo() override;
  18. // TODO: rvalue
  19. ReplaceDataCommand(
  20. std::shared_ptr<MidiSong> song,
  21. std::shared_ptr<MidiSelectionModel>,
  22. std::shared_ptr<MidiEditorContext>,
  23. int trackNumber,
  24. const std::vector<MidiEventPtr>& inRemove,
  25. const std::vector<MidiEventPtr>& inAdd);
  26. /**
  27. * static factories for replace commands
  28. */
  29. static ReplaceDataCommandPtr makeDeleteCommand(std::shared_ptr<MidiSequencer> seq);
  30. static ReplaceDataCommandPtr makeInsertNoteCommand(std::shared_ptr<MidiSequencer> seq, std::shared_ptr<const MidiNoteEvent>);
  31. static ReplaceDataCommandPtr makeChangePitchCommand(std::shared_ptr<MidiSequencer> seq, int semitones);
  32. static ReplaceDataCommandPtr makeChangeStartTimeCommand(std::shared_ptr<MidiSequencer> seq, float delta);
  33. static ReplaceDataCommandPtr makeChangeDurationCommand(std::shared_ptr<MidiSequencer> seq, float delta);
  34. private:
  35. std::shared_ptr<MidiSong> song;
  36. int trackNumber;
  37. std::shared_ptr<MidiSelectionModel> selection;
  38. std::vector<MidiEventPtr> removeData;
  39. std::vector<MidiEventPtr> addData;
  40. static void extendTrackToMinDuration(
  41. std::shared_ptr<MidiSequencer> seq,
  42. float neededLength,
  43. std::vector<MidiEventPtr>& toAdd,
  44. std::vector<MidiEventPtr>& toDelete);
  45. // base for change pitch, start time, duration
  46. enum class Ops {Pitch, Start, Duration };
  47. using Xform = std::function<void(MidiEventPtr)>;
  48. static ReplaceDataCommandPtr makeChangeNoteCommand(
  49. Ops,
  50. std::shared_ptr<MidiSequencer> seq,
  51. Xform xform,
  52. bool canChangeLength);
  53. };