Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add splitting to all types of clips #7477

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
09fccac
Initial clip splitting
regulus79 Aug 31, 2024
e010f28
Force midi clip splitting to be roudned to 1 bar
regulus79 Aug 31, 2024
ff8a47d
Make midi clip split into two clips and delete the old, instead of tr…
regulus79 Aug 31, 2024
8767dfd
Change splitting automation clips to be like midi clips: spawning two…
regulus79 Aug 31, 2024
fb2a222
Remove unecessary spacing and replace iterator type with auto
regulus79 Aug 31, 2024
70cf4dc
Invert if statement to return false early
regulus79 Aug 31, 2024
06b645e
Separate brackets from code with space
regulus79 Sep 2, 2024
4afdc87
Add space between for and parentheses
regulus79 Sep 2, 2024
c287cd0
Change spacing in if statment
regulus79 Sep 2, 2024
0f92817
Make param comment multiline
regulus79 Sep 2, 2024
6108c5d
Add spaces between // and comments
regulus79 Sep 2, 2024
360a5d1
Add space between if and parentheses
regulus79 Sep 2, 2024
273520c
Remove space between const and *
regulus79 Sep 2, 2024
607e810
Remove space between const and star again
regulus79 Sep 2, 2024
790a01f
Change code style for the other clip types
regulus79 Sep 2, 2024
1c45810
Code style changes for SampleClipView, plus inverting the if statement
regulus79 Sep 2, 2024
292e998
Update comment in ClipView.h
regulus79 Sep 2, 2024
da2e97c
Remove comments from .cpp files, and add single comment in ClipView.h
regulus79 Sep 2, 2024
c1f2928
Make rounded_pos lowerCamelCase
regulus79 Sep 2, 2024
de01890
Declare movedNote on the stack
regulus79 Sep 2, 2024
2995ba8
Force left clip to remain at original position after splitting
regulus79 Sep 2, 2024
72356bf
Change Knife Mode button tooltip
regulus79 Sep 4, 2024
ac8a1c4
Make knife cursor appear for all types of clips
regulus79 Sep 4, 2024
19b6916
Make double-click do nothing when in knife mode
regulus79 Sep 4, 2024
b2db31a
Fix midi clips having wrong length after splitting
regulus79 Sep 4, 2024
aa773a0
Remove spaces to fix code style
regulus79 Sep 4, 2024
39a8bb3
Use removeNodes() instead of recreating entire left clip
regulus79 Sep 4, 2024
a39be95
Add split marker to all clip types, and remove bar rounding on midi c…
regulus79 Sep 5, 2024
8f3955a
Do not populate notes as quantized in the new midi clips
regulus79 Sep 5, 2024
df5b49b
Change remove() to close() to fix undoing bug
regulus79 Sep 5, 2024
bf7d1f2
Remove spaces to fix code style
regulus79 Sep 7, 2024
6d13da1
Make splitClip() pure virtual
regulus79 Sep 22, 2024
19837bc
Remove whitespace
regulus79 Sep 22, 2024
f8b763c
Remove whitespace from PatternClipView
regulus79 Sep 22, 2024
7974445
Remove whitespace from AutomationClipView
regulus79 Sep 22, 2024
650b8b4
Remove whitespace from ClipView
regulus79 Sep 22, 2024
858330a
Initialize variables in AutomationClip's copy constructor
regulus79 Sep 22, 2024
e1269e7
Use remove() instead of close() to solve problem of midi clip playing…
regulus79 Sep 23, 2024
aa655ec
Fix automation clip behavior with out/in vals and tangents
regulus79 Sep 29, 2024
037497d
Simplify tangent setting code
regulus79 Oct 9, 2024
3c858b5
Allow resizing automation clips from the left and update splitting to…
regulus79 Oct 9, 2024
e8c25f0
Change offset from float to int
regulus79 Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/AutomationClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected slots:

QStaticText m_staticTextName;
void scaleTimemapToFit( float oldMin, float oldMax );
bool splitClip(const TimePos pos) override;
} ;


Expand Down
2 changes: 2 additions & 0 deletions include/MidiClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ protected slots:
QStaticText m_staticTextName;

bool m_legacySEPattern;

bool splitClip(const TimePos pos) override;
} ;


Expand Down
2 changes: 2 additions & 0 deletions include/PatternClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ protected slots:
QPixmap m_paintPixmap;

QStaticText m_staticTextName;

bool splitClip(const TimePos pos) override;
} ;


Expand Down
50 changes: 50 additions & 0 deletions src/gui/clips/AutomationClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,5 +486,55 @@ void AutomationClipView::scaleTimemapToFit( float oldMin, float oldMax )
m_clip->generateTangents();
}

//! Split this Clip.
/**
param pos the position of the split, relative to the start of the clip
*/
regulus79 marked this conversation as resolved.
Show resolved Hide resolved
bool AutomationClipView::splitClip(const TimePos pos)
{
setMarkerEnabled(false);

const TimePos splitPos = m_initialClipPos + pos;

// Don't split if we slid off the Clip or if we're on the clip's start/end
// Cutting at exactly the start/end position would create a zero length
// clip (bad), and a clip the same length as the original one (pointless).
if (splitPos <= m_initialClipPos || splitPos >= m_initialClipEnd) { return false; }

m_clip->getTrack()->addJournalCheckPoint();
m_clip->getTrack()->saveJournallingState(false);

auto rightClip = new AutomationClip(*m_clip);
auto leftClip = new AutomationClip(*m_clip);
rightClip->clear();
leftClip->clear();

for (auto it = m_clip->getTimeMap().begin(); it != m_clip->getTimeMap().end(); ++it)
{
if (POS(it) >= pos)
{
rightClip->putValues(POS(it) - pos, INVAL(it), OUTVAL(it), false);
}
else
{
leftClip->putValues(POS(it), INVAL(it), OUTVAL(it), false);
}
}
rightClip->putValue(0, m_clip->valueAt(pos));
leftClip->putValue(pos, m_clip->valueAt(pos));

leftClip->changeLength(splitPos - m_initialClipPos);

rightClip->movePosition(splitPos);
rightClip->changeLength(m_initialClipEnd - splitPos);

// For some reason, the new clips sometime randomly put themselves in record mode. This is a temportary fix which forces them to match the original clip.
rightClip->setRecording(m_clip->isRecording());
leftClip->setRecording(m_clip->isRecording());
messmerd marked this conversation as resolved.
Show resolved Hide resolved

m_clip->getTrack()->restoreJournallingState();
remove();
regulus79 marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

} // namespace lmms::gui
4 changes: 2 additions & 2 deletions src/gui/clips/ClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ void ClipView::mousePressEvent( QMouseEvent * me )
setInitialPos( me->pos() );
setInitialOffsets();

if( m_clip->getAutoResize() )
if (m_clip->getAutoResize() && !knifeMode)
{ // Always move clips that can't be manually resized
m_action = Action::Move;
setCursor( Qt::SizeAllCursor );
Expand All @@ -680,7 +680,7 @@ void ClipView::mousePressEvent( QMouseEvent * me )
m_action = Action::ResizeLeft;
setCursor( Qt::SizeHorCursor );
}
else if( sClip && knifeMode )
else if (knifeMode)
{
m_action = Action::Split;
setCursor( m_cursorKnife );
Expand Down
51 changes: 51 additions & 0 deletions src/gui/clips/MidiClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,4 +675,55 @@ void MidiClipView::paintEvent( QPaintEvent * )
}


//! Split this Clip.
/*! \param pos the position of the split, relative to the start of the clip */
regulus79 marked this conversation as resolved.
Show resolved Hide resolved
bool MidiClipView::splitClip(const TimePos pos)
{
// Currently, due to midi clips being required to be multiples of 1 bar in length, restrict the split pos to the nearest bar:
const TimePos rounded_pos = (pos + TimePos::ticksPerBar() / 2) - (pos + TimePos::ticksPerBar() / 2) % TimePos::ticksPerBar();
setMarkerEnabled( false );

const TimePos splitPos = m_initialClipPos + rounded_pos;

//Don't split if we slid off the Clip or if we're on the clip's start/end
//Cutting at exactly the start/end position would create a zero length
//clip (bad), and a clip the same length as the original one (pointless).
if (splitPos <= m_initialClipPos || splitPos >= m_initialClipEnd) {return false;}
regulus79 marked this conversation as resolved.
Show resolved Hide resolved

m_clip->getTrack()->addJournalCheckPoint();
m_clip->getTrack()->saveJournallingState(false);

auto rightClip = new MidiClip(m_clip->instrumentTrack());
auto leftClip = new MidiClip(m_clip->instrumentTrack());

for (Note const* note : m_clip->m_notes)
{
if (note->pos() >= rounded_pos)
{
Note *moved_note = new Note(*note);
moved_note->setPos(note->pos() - rounded_pos);
rightClip->addNote(*moved_note);
}
}

for (Note const* note : m_clip->m_notes)
{
if (note->pos() < rounded_pos)
{
leftClip->addNote(*note);
}
}
regulus79 marked this conversation as resolved.
Show resolved Hide resolved

leftClip->changeLength(splitPos - m_initialClipPos);

rightClip->movePosition(splitPos);
rightClip->changeLength(m_initialClipEnd - splitPos);

m_clip->getTrack()->restoreJournallingState();
remove();
return true;
}



} // namespace lmms::gui
27 changes: 27 additions & 0 deletions src/gui/clips/PatternClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,32 @@ void PatternClipView::update()
ClipView::update();
}

//! Split this Clip.
/*! \param pos the position of the split, relative to the start of the clip */
regulus79 marked this conversation as resolved.
Show resolved Hide resolved
bool PatternClipView::splitClip(const TimePos pos)
{
setMarkerEnabled(false);

const TimePos splitPos = m_initialClipPos + pos;

//Don't split if we slid off the Clip or if we're on the clip's start/end
//Cutting at exactly the start/end position would create a zero length
//clip (bad), and a clip the same length as the original one (pointless).
if (splitPos <= m_initialClipPos || splitPos >= m_initialClipEnd) {return false;}
regulus79 marked this conversation as resolved.
Show resolved Hide resolved

m_patternClip->getTrack()->addJournalCheckPoint();
m_patternClip->getTrack()->saveJournallingState(false);

auto rightClip = new PatternClip(m_patternClip->getTrack());

m_patternClip->changeLength(splitPos - m_initialClipPos);

rightClip->movePosition(splitPos);
rightClip->changeLength(m_initialClipEnd - splitPos);
rightClip->setStartTimeOffset(m_patternClip->startTimeOffset() - m_patternClip->length());

m_patternClip->getTrack()->restoreJournallingState();
return true;
}

} // namespace lmms::gui
Loading