Skip to content

Commit

Permalink
Make Shift-Knife delete cut portion (whichever side is shorter)
Browse files Browse the repository at this point in the history
  • Loading branch information
regulus79 committed Feb 16, 2025
1 parent f5e3823 commit c9cff97
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/MidiClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class LMMS_EXPORT MidiClip : public Clip
void splitNotes(const NoteVector& notes, TimePos pos);

// Split the list of notes along a line
void splitNotesAlongLine(TimePos pos1, int key1, TimePos pos2, int key2);
void splitNotesAlongLine(TimePos pos1, int key1, TimePos pos2, int key2, bool deleteShortEnds);

// clip-type stuff
inline Type type() const
Expand Down
3 changes: 2 additions & 1 deletion src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2270,7 +2270,8 @@ void PianoRoll::mouseReleaseEvent( QMouseEvent * me )
}
else if (m_action == Action::Knife)
{
m_midiClip->splitNotesAlongLine(TimePos(m_knifeStartTickPos), m_knifeStartKey, TimePos(m_knifeEndTickPos), m_knifeEndKey);
bool deleteShortEnds = me->modifiers() & Qt::ShiftModifier;
m_midiClip->splitNotesAlongLine(TimePos(m_knifeStartTickPos), m_knifeStartKey, TimePos(m_knifeEndTickPos), m_knifeEndKey, deleteShortEnds);
m_knifeDown = false;
}

Expand Down
15 changes: 12 additions & 3 deletions src/tracks/MidiClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void MidiClip::splitNotes(const NoteVector& notes, TimePos pos)
}
}

void MidiClip::splitNotesAlongLine(TimePos pos1, int key1, TimePos pos2, int key2)
void MidiClip::splitNotesAlongLine(TimePos pos1, int key1, TimePos pos2, int key2, bool deleteShortEnds)
{
if (m_notes.empty()) { return; }
// Don't split if the line is horitzontal
Expand All @@ -365,12 +365,21 @@ void MidiClip::splitNotesAlongLine(TimePos pos1, int key1, TimePos pos2, int key
{
Note newNote1 = Note(*note);
newNote1.setLength(keyIntercept - note->pos());
addNote(newNote1, false);

Note newNote2 = Note(*note);
newNote2.setPos(keyIntercept);
newNote2.setLength(note->endPos() - keyIntercept);
addNote(newNote2, false);

if (deleteShortEnds)
{
if (newNote1.length() >= newNote2.length()) { addNote(newNote1, false); }
else { addNote(newNote2, false); }
}
else
{
addNote(newNote1, false);
addNote(newNote2, false);
}

removeNote(note);
}
Expand Down

0 comments on commit c9cff97

Please sign in to comment.