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 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 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
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
9 changes: 7 additions & 2 deletions include/ClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,13 @@ protected slots:
TimePos draggedClipPos( QMouseEvent * me );
int knifeMarkerPos( QMouseEvent * me );
void setColor(const std::optional<QColor>& color);
//! Return true iff the clip could be split. Currently only implemented for samples
virtual bool splitClip( const TimePos pos ){ return false; };

/**
* Split this Clip into two clips
* @param pos the position of the split, relative to the start of the clip
* @return true iff the clip could be split
*/
messmerd marked this conversation as resolved.
Show resolved Hide resolved
virtual bool splitClip(const TimePos pos) = 0;
void updateCursor(QMouseEvent * me);
} ;

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
5 changes: 4 additions & 1 deletion src/core/AutomationClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ AutomationClip::AutomationClip( const AutomationClip & _clip_to_copy ) :
m_autoTrack( _clip_to_copy.m_autoTrack ),
m_objects( _clip_to_copy.m_objects ),
m_tension( _clip_to_copy.m_tension ),
m_progressionType( _clip_to_copy.m_progressionType )
m_progressionType(_clip_to_copy.m_progressionType),
m_dragging(false),
m_isRecording(_clip_to_copy.m_isRecording),
m_lastRecordedValue(0)
{
// Locks the mutex of the copied AutomationClip to make sure it
// doesn't change while it's being copied
Expand Down
53 changes: 53 additions & 0 deletions src/gui/clips/AutomationClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "StringPairDrag.h"
#include "TextFloat.h"
#include "Track.h"
#include "TrackContainerView.h"
#include "TrackView.h"

#include "Engine.h"

Expand Down Expand Up @@ -209,6 +211,8 @@ void AutomationClipView::constructContextMenu( QMenu * _cm )

void AutomationClipView::mouseDoubleClickEvent( QMouseEvent * me )
{
if (m_trackView->trackContainerView()->knifeMode()) { return; }

if(me->button() != Qt::LeftButton)
{
me->ignore();
Expand Down Expand Up @@ -390,6 +394,11 @@ void AutomationClipView::paintEvent( QPaintEvent * )
p.drawPixmap( spacing, height() - ( size + spacing ),
embed::getIconPixmap( "muted", size, size ) );
}

if (m_marker)
{
p.drawLine(m_markerPos, rect().bottom(), m_markerPos, rect().top());
}
Comment on lines +398 to +401
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do? I'm not sure why it's in the double click event


p.end();

Expand Down Expand Up @@ -487,4 +496,48 @@ void AutomationClipView::scaleTimemapToFit( float oldMin, float oldMax )
}




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->removeNodes(splitPos, m_initialClipEnd);

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);
}
}
rightClip->putValue(0, m_clip->valueAt(pos));
leftClip->putValue(pos, m_clip->valueAt(pos));

leftClip->movePosition(m_initialClipPos);
leftClip->changeLength(splitPos - m_initialClipPos);

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

remove();
regulus79 marked this conversation as resolved.
Show resolved Hide resolved

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

} // namespace lmms::gui
23 changes: 8 additions & 15 deletions src/gui/clips/ClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void ClipView::updateCursor(QMouseEvent * me)
setCursor(Qt::SizeHorCursor);
}
// If we are in the middle on knife mode, use the knife cursor
else if (sClip && m_trackView->trackContainerView()->knifeMode() && !isSelected())
else if (m_trackView->trackContainerView()->knifeMode() && !isSelected())
{
setCursor(m_cursorKnife);
}
Expand Down Expand Up @@ -633,7 +633,7 @@ void ClipView::mousePressEvent( QMouseEvent * me )
auto pClip = dynamic_cast<PatternClip*>(m_clip);
const bool knifeMode = m_trackView->trackContainerView()->knifeMode();

if ( me->modifiers() & Qt::ControlModifier && !(sClip && knifeMode) )
if (me->modifiers() & Qt::ControlModifier && !knifeMode)
{
if( isSelected() )
{
Expand Down 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 Expand Up @@ -743,12 +743,8 @@ void ClipView::mousePressEvent( QMouseEvent * me )
if (m_action == Action::Split)
{
m_action = Action::None;
auto sClip = dynamic_cast<SampleClip*>(m_clip);
if (sClip)
{
setMarkerEnabled( false );
update();
}
setMarkerEnabled(false);
update();
}
}
else if( me->button() == Qt::MiddleButton )
Expand Down Expand Up @@ -984,11 +980,8 @@ void ClipView::mouseMoveEvent( QMouseEvent * me )
}
else if( m_action == Action::Split )
{
auto sClip = dynamic_cast<SampleClip*>(m_clip);
if (sClip) {
setCursor( m_cursorKnife );
setMarkerPos( knifeMarkerPos( me ) );
}
setCursor(m_cursorKnife);
setMarkerPos(knifeMarkerPos(me));
update();
}
// None of the actions above, we will just handle the cursor
Expand Down
59 changes: 59 additions & 0 deletions src/gui/clips/MidiClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "MidiClip.h"
#include "PianoRoll.h"
#include "RenameDialog.h"
#include "TrackContainerView.h"
#include "TrackView.h"

namespace lmms::gui
Expand Down Expand Up @@ -299,6 +300,8 @@ void MidiClipView::mousePressEvent( QMouseEvent * _me )

void MidiClipView::mouseDoubleClickEvent(QMouseEvent *_me)
{
if (m_trackView->trackContainerView()->knifeMode()) { return; }

if( _me->button() != Qt::LeftButton )
{
_me->ignore();
Expand Down Expand Up @@ -670,9 +673,65 @@ void MidiClipView::paintEvent( QPaintEvent * )
p.drawPixmap( spacing, height() - ( size + spacing ),
embed::getIconPixmap( "muted", size, size ) );
}

if (m_marker)
{
p.drawLine(m_markerPos, rect().bottom(), m_markerPos, rect().top());
}
Comment on lines +677 to +680
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


painter.drawPixmap( 0, 0, m_paintPixmap );
}




bool MidiClipView::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 leftClip = new MidiClip(m_clip->instrumentTrack());
auto rightClip = new MidiClip(m_clip->instrumentTrack());

for (Note const* note : m_clip->m_notes)
{
if (note->pos() >= pos)
{
auto movedNote = Note{*note};
movedNote.setPos(note->pos() - pos);
rightClip->addNote(movedNote, false);
}
}

for (Note const* note : m_clip->m_notes)
{
if (note->pos() < pos)
{
leftClip->addNote(*note, false);
}
}

leftClip->movePosition(m_initialClipPos);
leftClip->updateLength();

rightClip->movePosition(splitPos);
rightClip->updateLength();

remove();

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



} // namespace lmms::gui
37 changes: 37 additions & 0 deletions src/gui/clips/PatternClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "PatternClip.h"
#include "PatternStore.h"
#include "RenameDialog.h"
#include "TrackContainerView.h"
#include "TrackView.h"

namespace lmms::gui
{
Expand Down Expand Up @@ -70,6 +72,8 @@ void PatternClipView::constructContextMenu(QMenu* _cm)

void PatternClipView::mouseDoubleClickEvent(QMouseEvent*)
{
if (m_trackView->trackContainerView()->knifeMode()) { return; }

openInPatternEditor();
}

Expand Down Expand Up @@ -155,6 +159,11 @@ void PatternClipView::paintEvent(QPaintEvent*)
embed::getIconPixmap( "muted", size, size ) );
}

if (m_marker)
{
p.drawLine(m_markerPos, rect().bottom(), m_markerPos, rect().top());
}
Comment on lines +162 to +165
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here too. SampleClipView doesn't have this.


p.end();

painter.drawPixmap( 0, 0, m_paintPixmap );
Expand Down Expand Up @@ -196,4 +205,32 @@ void PatternClipView::update()
}




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; }

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
Loading