diff --git a/Source/UI/Sequencer/Helpers/PatternOperations.cpp b/Source/UI/Sequencer/Helpers/PatternOperations.cpp index 5549c883..229fa407 100644 --- a/Source/UI/Sequencer/Helpers/PatternOperations.cpp +++ b/Source/UI/Sequencer/Helpers/PatternOperations.cpp @@ -285,20 +285,30 @@ void PatternOperations::cutClip(ProjectNode &project, const Clip &clip, SequencerOperations::cutNotes(intersectedEvents, intersectionPoints, false); - Array eventsToBeMoved; + Array eventsRemove; + Array eventsToAdd; for (int i = 0; i < sequence->size(); ++i) { auto *note = static_cast(sequence->getUnchecked(i)); if (note->getBeat() >= cutBeat) { - eventsToBeMoved.add(*note); + eventsRemove.add(*note); + // to make it cleaner, make sure that the moved sequence starts at zero, + // while the new clips are shifted to the cut point (see below) + eventsToAdd.add(note->withDeltaBeat(-cutBeat)); } } - const auto newTrack = SequencerOperations::createPianoTrack(eventsToBeMoved, clip.getPattern()); + const auto newTrack = SequencerOperations::createPianoTrack(eventsToAdd, clip.getPattern()); + + for (auto *newClip : newTrack->getPattern()->getClips()) + { + newTrack->getPattern()->change(*newClip, newClip->withDeltaBeat(cutBeat), false); + } + const auto trackTemplate = newTrack->serialize(); - sequence->removeGroup(eventsToBeMoved, true); + sequence->removeGroup(eventsRemove, true); project.getUndoStack()->perform(new PianoTrackInsertAction(project, &project, trackTemplate, newName)); } else if (auto *autoTrack = dynamic_cast(track)) diff --git a/Source/UI/Sequencer/Helpers/SequencerOperations.cpp b/Source/UI/Sequencer/Helpers/SequencerOperations.cpp index 25937642..a2d76943 100644 --- a/Source/UI/Sequencer/Helpers/SequencerOperations.cpp +++ b/Source/UI/Sequencer/Helpers/SequencerOperations.cpp @@ -2632,22 +2632,30 @@ UniquePointer SequencerOperations::createPianoTrack(const PianoSe UniquePointer SequencerOperations::createPianoTrack(const Array &events, const Pattern *pattern) { - if (events.size() == 0) { return {}; } - Array clips; for (const auto *clip : pattern->getClips()) { clips.add(*clip); } + if (clips.size() == 0) + { + jassertfalse; + return {}; + } + return createPianoTrack(events, clips); } UniquePointer SequencerOperations::createPianoTrack(const Array &events, const Array &clips) { - if (events.size() == 0) { return {}; } + if (clips.size() == 0) + { + jassertfalse; + return {}; + } - const auto *track = events.getReference(0).getSequence()->getTrack(); + const auto *track = clips.getReference(0).getPattern()->getTrack(); const auto instrumentId = track->getTrackInstrumentId(); const auto colour = track->getTrackColour(); const auto channel = track->getTrackChannel();