Remove m_resizable from Clips (#7954)

Minor refactor of `Clip` methods related to resizing
This commit is contained in:
regulus79
2025-07-21 09:39:14 -04:00
committed by GitHub
parent 997764a0dc
commit e79945ffc5
8 changed files with 28 additions and 94 deletions

View File

@@ -94,21 +94,12 @@ public:
return m_length;
}
/*! \brief Specify whether or not a TCO automatically resizes.
*
* If a TCO does automatically resize, it cannot be manually
* resized by clicking and dragging its edge.
*
*/
inline void setResizable( const bool r )
{
m_resizable = r;
}
inline const bool getResizable() const
{
return m_resizable;
}
bool hasTrackContainer() const;
bool isInPattern() const;
bool manuallyResizable() const;
/*! \brief Set whether a clip has been resized yet by the user or the knife tool.
*
@@ -183,7 +174,6 @@ private:
BoolModel m_mutedModel;
BoolModel m_soloModel;
bool m_resizable = true;
bool m_autoResize = true;
bool m_selectViewOnCreate;

View File

@@ -60,21 +60,6 @@ AutomationClip::AutomationClip( AutomationTrack * _auto_track ) :
m_lastRecordedValue( 0 )
{
changeLength( TimePos( 1, 0 ) );
if( getTrack() )
{
switch( getTrack()->trackContainer()->type() )
{
case TrackContainer::Type::Pattern:
setResizable(false);
break;
case TrackContainer::Type::Song:
// move down
default:
setResizable(true);
break;
}
}
}
@@ -105,19 +90,6 @@ AutomationClip::AutomationClip( const AutomationClip & _clip_to_copy ) :
// Sets the node's clip to this one
m_timeMap[POS(it)].setClip(this);
}
if (!getTrack()){ return; }
switch( getTrack()->trackContainer()->type() )
{
case TrackContainer::Type::Pattern:
setResizable(false);
break;
case TrackContainer::Type::Song:
// move down
default:
setResizable(true);
break;
}
}
bool AutomationClip::addObject( AutomatableModel * _obj, bool _search_dup )

View File

@@ -31,6 +31,8 @@
#include "Engine.h"
#include "GuiApplication.h"
#include "Song.h"
#include "Track.h"
#include "TrackContainer.h"
namespace lmms
@@ -75,7 +77,6 @@ Clip::Clip(const Clip& other):
m_length(other.m_length),
m_startTimeOffset(other.m_startTimeOffset),
m_mutedModel(other.m_mutedModel.value(), this, tr( "Mute" )),
m_resizable(other.m_resizable),
m_autoResize(other.m_autoResize),
m_selectViewOnCreate{other.m_selectViewOnCreate},
m_color(other.m_color)
@@ -173,6 +174,21 @@ void Clip::copyStateTo( Clip *src, Clip *dst )
}
}
bool Clip::hasTrackContainer() const
{
return getTrack() != nullptr && getTrack()->trackContainer() != nullptr;
}
bool Clip::isInPattern() const
{
return hasTrackContainer()
&& getTrack()->trackContainer()->type() == TrackContainer::Type::Pattern;
}
bool Clip::manuallyResizable() const
{
return !isInPattern();
}

View File

@@ -45,7 +45,6 @@ PatternClip::PatternClip(Track* track) :
changeLength( TimePos( t, 0 ) );
restoreJournallingState();
}
setResizable(true);
}
void PatternClip::saveSettings(QDomDocument& doc, QDomElement& element)

View File

@@ -67,18 +67,6 @@ SampleClip::SampleClip(Track* _track, Sample sample, bool isPlaying)
//care about Clip position
connect( this, SIGNAL(positionChanged()), this, SLOT(updateTrackClips()));
switch( getTrack()->trackContainer()->type() )
{
case TrackContainer::Type::Pattern:
setResizable(false);
break;
case TrackContainer::Type::Song:
// move down
default:
setResizable(true);
break;
}
updateTrackClips();
}
@@ -117,18 +105,6 @@ SampleClip::SampleClip(const SampleClip& orig) :
//care about Clip position
connect( this, SIGNAL(positionChanged()), this, SLOT(updateTrackClips()));
switch( getTrack()->trackContainer()->type() )
{
case TrackContainer::Type::Pattern:
setResizable(false);
break;
case TrackContainer::Type::Song:
// move down
default:
setResizable(true);
break;
}
updateTrackClips();
}
@@ -251,8 +227,7 @@ void SampleClip::setIsPlaying(bool isPlaying)
void SampleClip::updateLength()
{
// If the clip has already been manually resized, don't automatically resize it.
// Unless we are in a pattern, where you can't resize stuff manually
if (getAutoResize() || !getResizable())
if (getAutoResize())
{
changeLength(sampleLength());
setStartTimeOffset(0);

View File

@@ -298,7 +298,7 @@ AutomatedValueMap TrackContainer::automatedValuesFromTracks(const TrackList &tra
continue;
}
TimePos relTime = time - p->startPosition() - p->startTimeOffset();
if (p->getResizable()) {
if (!p->isInPattern()) {
relTime = std::min(static_cast<int>(relTime), p->length() - p->startTimeOffset());
}
float value = p->valueAt(relTime);

View File

@@ -502,7 +502,7 @@ void ClipView::dropEvent( QDropEvent * de )
void ClipView::updateCursor(QMouseEvent * me)
{
// If we are at the edges, use the resize cursor
if (!me->buttons() && m_clip->getResizable() && !isSelected()
if (!me->buttons() && m_clip->manuallyResizable() && !isSelected()
&& ((me->x() > width() - RESIZE_GRIP_WIDTH) || (me->x() < RESIZE_GRIP_WIDTH)))
{
setCursor(Qt::SizeHorCursor);
@@ -669,7 +669,7 @@ void ClipView::mousePressEvent( QMouseEvent * me )
setInitialPos( me->pos() );
setInitialOffsets();
if (!m_clip->getResizable() && !knifeMode)
if (!m_clip->manuallyResizable() && !knifeMode)
{ // Always move clips that can't be manually resized
m_action = Action::Move;
setCursor( Qt::SizeAllCursor );

View File

@@ -48,11 +48,6 @@ MidiClip::MidiClip( InstrumentTrack * _instrument_track ) :
if (_instrument_track->trackContainer() == Engine::patternStore())
{
resizeToFirstTrack();
setResizable(false);
}
else
{
setResizable(true);
}
init();
}
@@ -72,18 +67,6 @@ MidiClip::MidiClip( const MidiClip& other ) :
}
init();
switch( getTrack()->trackContainer()->type() )
{
case TrackContainer::Type::Pattern:
setResizable(false);
break;
case TrackContainer::Type::Song:
// move down
default:
setResizable(true);
break;
}
}
@@ -149,9 +132,8 @@ void MidiClip::updateLength()
return;
}
// If the clip has already been manually resized, don't automatically resize it.
// Unless we are in a pattern, where you can't resize stuff manually
if (getAutoResize() || !getResizable())
// If the clip hasn't already been manually resized, automatically resize it.
if (getAutoResize())
{
tick_t max_length = TimePos::ticksPerBar();