Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
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/SampleClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public slots:
SampleClip( const SampleClip& orig );

private:
Track* m_sampleTrack;
Sample m_sample;
BoolModel m_recordModel;
bool m_isPlaying;
Expand Down
6 changes: 6 additions & 0 deletions src/core/AutomationClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ void AutomationClip::updateLength()
// checks if it has been resized from either direction.
if (getAutoResize())
{
if ( m_autoTrack != nullptr && m_autoTrack->trackContainer() == Engine::patternStore() )
{
// If inside a pattern, the clip is always the lenght of it.
changeLength(TimePos::ticksPerBar() * Engine::patternStore()->lengthOfPattern(m_autoTrack->getClipNum(this)));
return;
}
// 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(), static_cast<tick_t>(timeMapLength())));
Expand Down
2 changes: 1 addition & 1 deletion src/core/PatternStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bar_t PatternStore::lengthOfPattern(int pattern) const
for (Track * t : tl)
{
// Don't create Clips here if they don't exist
if (pattern < t->numOfClips())
if (pattern < t->numOfClips() && t->type() == Track::Type::Instrument)
{
maxLength = std::max(maxLength, t->getClip(pattern)->length());
}
Expand Down
8 changes: 8 additions & 0 deletions src/core/SampleClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <QDomElement>
#include <QFileInfo>

#include "PatternStore.h"
#include "PathUtil.h"
#include "SampleClipView.h"
#include "SampleTrack.h"
Expand All @@ -37,6 +38,7 @@ namespace lmms

SampleClip::SampleClip(Track* _track, Sample sample, bool isPlaying)
: Clip(_track)
, m_sampleTrack(_track)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Clip already stores a Track, and has a getter called getTrack().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's the first thing I should have checked. Thank you for pointing it out.

, m_sample(std::move(sample))
, m_isPlaying(false)
{
Expand Down Expand Up @@ -75,6 +77,7 @@ SampleClip::SampleClip(Track* track)

SampleClip::SampleClip(const SampleClip& orig) :
Clip(orig),
m_sampleTrack(orig.m_sampleTrack),
m_sample(std::move(orig.m_sample)),
m_isPlaying(orig.m_isPlaying)
{
Expand Down Expand Up @@ -227,6 +230,11 @@ void SampleClip::updateLength()
// If the clip has already been manually resized, don't automatically resize it.
if (getAutoResize())
{
if (m_sampleTrack->trackContainer() == Engine::patternStore())
{
changeLength(TimePos::ticksPerBar() * Engine::patternStore()->lengthOfPattern(m_sampleTrack->getClipNum(this)));
return;
}
changeLength(sampleLength());
setStartTimeOffset(0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/clips/AutomationClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void AutomationClipView::paintEvent( QPaintEvent * )
// pixels per bar
const float ppb = fixedClips() ?
( parentWidget()->width() - 2 * BORDER_WIDTH )
/ (float) m_clip->timeMapLength().getBar() :
/ (float) m_clip->length().getBar() :
Comment thread
bratpeki marked this conversation as resolved.
pixelsPerBar();

const auto min = m_clip->firstObject()->minValue<float>();
Expand Down
7 changes: 7 additions & 0 deletions src/gui/editors/PatternEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ void PatternEditor::updateMaxSteps()
auto mClip = static_cast<MidiClip*>(track->getClip(m_ps->currentPattern()));
m_maxClipLength = std::max(m_maxClipLength, static_cast<tick_t>(mClip->length()));
}
else
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This else covers every track type that isn't Instrument, which btw...

enum class Type
{
	Instrument,
	Pattern,
	Sample,
	Event,
	Video,
	Automation,
	HiddenAutomation,
	Count
} ;

Cursed, cursed, cursed!

@messmerd is it a safe assumption that this else only catches Sample and Automation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I completely missed the fact that there were so many types of tracks 😅 (What even is a Video or Count track?)

I guess it would indeed do no harm to be explicit here, as we only only resize Sample and Automation clips for visual purposes (and all these other types, even if they happened to be present in the pattern store, are never displayed anyway).
But in the end, it doesn't change much.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, maybe an else if for samples and automation, and an else assert(false) since we're not supposed to reach that for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could also use a switch statement:

switch (track->type())
{
	case Track::Type::Instrument:
	{
		auto mClip = static_cast<MidiClip*>(track->getClip(m_ps->currentPattern()));
		m_maxClipLength = std::max(m_maxClipLength, static_cast<tick_t>(mClip->length()));
		break;
	}
	case Track::Type::Sample: [[fallthrough]];
	case Track::Type::Automation:
	{
		auto clip = track->getClip(m_ps->currentPattern());
		clip->updateLength();
		break;
	}
	default:
		assert(false);
		break;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should the m_maxClipLength variable be updated for sample and automation tracks too?

Copy link
Copy Markdown
Contributor Author

@Itreza2 Itreza2 May 16, 2026

Choose a reason for hiding this comment

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

Well... actually yes...

I'm a little embarrassed by my self from 2 weeks ago. (I believe I somehow thought that it had an impact on the pattern length ?!)

(Edit: I fact my past me just left this block as it was previously, which is pretty reasonable)

{
// The length of automation and sample clips is updated here.
// "Why here ?" will you ask. The answer is: Because.
auto clip = track->getClip(m_ps->currentPattern());
clip->updateLength();
}
}
updatePixelsPerBar();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tracks/MidiClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void MidiClip::updateLength()
// If the clip hasn't already been manually resized, automatically resize it.
if (getAutoResize())
{
if (m_clipType == Type::BeatClip)
if (m_instrumentTrack->trackContainer()->type() == TrackContainer::Type::Pattern)
{
changeLength(beatClipLength());
updatePatternTrack();
Expand Down
Loading