Skip to content

Commit

Permalink
Knife tool fixes (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrudenko committed Oct 12, 2024
1 parent 85d078e commit 0fdd663
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
18 changes: 14 additions & 4 deletions Source/UI/Sequencer/Helpers/PatternOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,30 @@ void PatternOperations::cutClip(ProjectNode &project, const Clip &clip,

SequencerOperations::cutNotes(intersectedEvents, intersectionPoints, false);

Array<Note> eventsToBeMoved;
Array<Note> eventsRemove;
Array<Note> eventsToAdd;
for (int i = 0; i < sequence->size(); ++i)
{
auto *note = static_cast<Note *>(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<AutomationTrackNode *>(track))
Expand Down
16 changes: 12 additions & 4 deletions Source/UI/Sequencer/Helpers/SequencerOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2632,22 +2632,30 @@ UniquePointer<MidiTrackNode> SequencerOperations::createPianoTrack(const PianoSe

UniquePointer<MidiTrackNode> SequencerOperations::createPianoTrack(const Array<Note> &events, const Pattern *pattern)
{
if (events.size() == 0) { return {}; }

Array<Clip> clips;
for (const auto *clip : pattern->getClips())
{
clips.add(*clip);
}

if (clips.size() == 0)
{
jassertfalse;
return {};
}

return createPianoTrack(events, clips);
}

UniquePointer<MidiTrackNode> SequencerOperations::createPianoTrack(const Array<Note> &events, const Array<Clip> &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();
Expand Down

0 comments on commit 0fdd663

Please sign in to comment.