Skip to content

Commit

Permalink
Only automatically resize automation clips if the user has not resize…
Browse files Browse the repository at this point in the history
…d them yet
  • Loading branch information
regulus79 committed Nov 26, 2024
1 parent f0134ba commit ccbb00d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 2 deletions.
17 changes: 17 additions & 0 deletions include/Clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ class LMMS_EXPORT Clip : public Model, public JournallingObject
return m_autoResize;
}

/*! \brief Set whether a clip has been resized yet by the user or the knife tool.
*
* If a clip has been resized previously, it will not automatically
* resize when editing it.
*
*/
inline void setHasBeenResized( const bool r )
{
m_hasBeenResized = r;
}

inline const bool getHasBeenResized() const
{
return m_hasBeenResized;
}

auto color() const -> const std::optional<QColor>& { return m_color; }
void setColor(const std::optional<QColor>& color);

Expand Down Expand Up @@ -159,6 +175,7 @@ public slots:
BoolModel m_mutedModel;
BoolModel m_soloModel;
bool m_autoResize;
bool m_hasBeenResized;

bool m_selectViewOnCreate;

Expand Down
14 changes: 12 additions & 2 deletions src/core/AutomationClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,14 @@ TimePos AutomationClip::timeMapLength() const

void AutomationClip::updateLength()
{
// Do not resize down in case user manually extended up
changeLength(std::max(length(), timeMapLength()));
// Technically it only matters if the clip has been resized from the right, but this
// checks if it has been resized from either direction.
if (!getHasBeenResized())
{
// Using 1 bar as the min length for an un-resized clip.
// This does not prevent the user from resizing the clip to be less than a bar later on.
changeLength(std::max(TimePos::ticksPerBar(), timeMapLength() + startTimeOffset()));
}
}


Expand Down Expand Up @@ -835,6 +841,8 @@ void AutomationClip::saveSettings( QDomDocument & _doc, QDomElement & _this )
_this.setAttribute( "prog", QString::number( static_cast<int>(progressionType()) ) );
_this.setAttribute( "tens", QString::number( getTension() ) );
_this.setAttribute( "mute", QString::number( isMuted() ) );
_this.setAttribute("off", startTimeOffset());
_this.setAttribute("been_resized", QString::number(getHasBeenResized()));

if (const auto& c = color())
{
Expand Down Expand Up @@ -885,6 +893,8 @@ void AutomationClip::loadSettings( const QDomElement & _this )
"prog" ).toInt() ) );
setTension( _this.attribute( "tens" ) );
setMuted(_this.attribute( "mute", QString::number( false ) ).toInt() );
setHasBeenResized(_this.attribute( "been_resized" ).toInt());
setStartTimeOffset(_this.attribute( "off" ).toInt());

for( QDomNode node = _this.firstChild(); !node.isNull();
node = node.nextSibling() )
Expand Down
2 changes: 2 additions & 0 deletions src/core/PatternClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void PatternClip::saveSettings(QDomDocument& doc, QDomElement& element)
element.setAttribute( "len", length() );
element.setAttribute("off", startTimeOffset());
element.setAttribute( "muted", isMuted() );
element.setAttribute("been_resized", QString::number(getHasBeenResized()));
if (const auto& c = color())
{
element.setAttribute("color", c->name());
Expand All @@ -79,6 +80,7 @@ void PatternClip::loadSettings(const QDomElement& element)
movePosition( element.attribute( "pos" ).toInt() );
}
changeLength( element.attribute( "len" ).toInt() );
setHasBeenResized(element.attribute( "been_resized" ).toInt());
setStartTimeOffset(element.attribute("off").toInt());
if (static_cast<bool>(element.attribute("muted").toInt()) != isMuted())
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/SampleClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ void SampleClip::saveSettings( QDomDocument & _doc, QDomElement & _this )
_this.setAttribute( "muted", isMuted() );
_this.setAttribute( "src", sampleFile() );
_this.setAttribute( "off", startTimeOffset() );
_this.setAttribute("been_resized", QString::number(getHasBeenResized()));
if( sampleFile() == "" )
{
QString s;
Expand Down Expand Up @@ -315,6 +316,7 @@ void SampleClip::loadSettings( const QDomElement & _this )
changeLength( _this.attribute( "len" ).toInt() );
setMuted( _this.attribute( "muted" ).toInt() );
setStartTimeOffset( _this.attribute( "off" ).toInt() );
setHasBeenResized(_this.attribute( "been_resized" ).toInt());

if (_this.hasAttribute("color"))
{
Expand Down
1 change: 1 addition & 0 deletions src/gui/clips/AutomationClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ bool AutomationClipView::splitClip(const TimePos pos)
rightClip->movePosition(splitPos);
rightClip->changeLength(m_initialClipEnd - splitPos);
rightClip->setStartTimeOffset(m_clip->startTimeOffset() - m_clip->length());
m_clip->setHasBeenResized(true);

m_clip->getTrack()->restoreJournallingState();
return true;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/clips/ClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ void ClipView::mouseMoveEvent( QMouseEvent * me )
setInitialPos( m_initialMousePos );
// Don't resize to less than 1 tick
m_clip->changeLength( qMax<int>( 1, l ) );
m_clip->setHasBeenResized(true);
}
else if ( me->modifiers() & Qt::ShiftModifier )
{ // If shift is held, quantize clip's end position
Expand All @@ -897,6 +898,7 @@ void ClipView::mouseMoveEvent( QMouseEvent * me )
TimePos min = m_initialClipPos.quantize( snapSize );
if ( min <= m_initialClipPos ) min += snapLength;
m_clip->changeLength( qMax<int>(min - m_initialClipPos, end - m_initialClipPos) );
m_clip->setHasBeenResized(true);
}
else
{ // Otherwise, resize in fixed increments
Expand All @@ -906,6 +908,7 @@ void ClipView::mouseMoveEvent( QMouseEvent * me )
auto min = TimePos(initialLength % snapLength);
if (min < 1) min += snapLength;
m_clip->changeLength( qMax<int>( min, initialLength + offset) );
m_clip->setHasBeenResized(true);
}
}
else
Expand Down Expand Up @@ -970,6 +973,7 @@ void ClipView::mouseMoveEvent( QMouseEvent * me )
{
aClip->setStartTimeOffset(aClip->startTimeOffset() + positionOffset);
}
m_clip->setHasBeenResized(true);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/clips/PatternClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ bool PatternClipView::splitClip(const TimePos pos)
rightClip->movePosition(splitPos);
rightClip->changeLength(m_initialClipEnd - splitPos);
rightClip->setStartTimeOffset(m_patternClip->startTimeOffset() - m_patternClip->length());
m_patternClip->setHasBeenResized(true);
rightClip->setHasBeenResized(true);

m_patternClip->getTrack()->restoreJournallingState();
return true;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/clips/SampleClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ bool SampleClipView::splitClip(const TimePos pos)
rightClip->movePosition(splitPos);
rightClip->changeLength(m_initialClipEnd - splitPos);
rightClip->setStartTimeOffset(m_clip->startTimeOffset() - m_clip->length());
m_clip->setHasBeenResized(true);
rightClip->setHasBeenResized(true);

m_clip->getTrack()->restoreJournallingState();
return true;
Expand Down

0 comments on commit ccbb00d

Please sign in to comment.