Skip to content

Fix beat clips being created with a lenght of 0 in the pattern editor#8355

Merged
bratpeki merged 3 commits into
LMMS:masterfrom
Itreza2:tracks-without-steps
May 13, 2026
Merged

Fix beat clips being created with a lenght of 0 in the pattern editor#8355
bratpeki merged 3 commits into
LMMS:masterfrom
Itreza2:tracks-without-steps

Conversation

@Itreza2
Copy link
Copy Markdown
Contributor

@Itreza2 Itreza2 commented Apr 11, 2026

closes #8101
The context and motivations for this pr can be found in the issue's thread

@messmerd messmerd added the bug label May 2, 2026
@rubiefawn rubiefawn added the needs testing This pull request needs more testing label May 12, 2026
@bratpeki bratpeki self-assigned this May 13, 2026
@bratpeki
Copy link
Copy Markdown
Member

Could we get a little explanation as to why this works? It'd help with the code review!

@bratpeki
Copy link
Copy Markdown
Member

I asked GH Copilot and got this, so feel free to expand on this.


Issue #8101 is about the pattern editor showing blank tracks (no steps) for newly created sample tracks. The error messages you're seeing (called Track::getClip(X), but Clip X doesn't exist) indicate that the code is trying to access clips that haven't been created yet.

The original init() method unconditionally calls:

saveJournallingState(false);
updateLength();
restoreJournallingState();

This happens for all MidiClip instances, including those created in the PatternStore (the pattern editor's internal container).

When a new MidiClip is created in the pattern store:

  1. updateLength() calls updatePatternTrack()
  2. updatePatternTrack() triggers pattern regeneration
  3. During this process, other tracks try to access clips via getClip() that don't exist yet
  4. The journalling state save/restore causes issues with incomplete clip initialization

The PR wraps the problematic code in a conditional check:

if (getTrack()->trackContainer() != Engine::patternStore())
{
	saveJournallingState(false);
	updateLength();
	restoreJournallingState();
}

This means:

  • For regular tracks (song editor): Process normally with journalling
  • For pattern store tracks (pattern editor): Skip the journalling and length update

By skipping these operations for pattern store clips, the code avoids triggering clip access during initialization, preventing the "Clip doesn't exist" errors. The pattern store handles its own initialization separately, so this code path isn't needed there anyway.

This is why the PR works! It prevents the premature clip access that was causing blank pattern editor tracks.

@Itreza2
Copy link
Copy Markdown
Contributor Author

Itreza2 commented May 13, 2026

Copilot (almost) got it perfectly right !

As I detailed in my original comment on #8101, updateLenght()'s call chain is in fine trying to access clips that don't yet exist and this is what is causing the bug.
Fortunately, updateLenght() is completely superfluous for tracks in the pattern store, so adding a if clause is an easy fix.

(And no, this PR should not affect journalling in any way, I think copilot hallucinated this point)

@bratpeki
Copy link
Copy Markdown
Member

Thanks for the awesome explanation!

Copy link
Copy Markdown
Member

@bratpeki bratpeki left a comment

Choose a reason for hiding this comment

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

Approved for code and testing. Will merge soon.

Copy link
Copy Markdown
Member

@regulus79 regulus79 left a comment

Choose a reason for hiding this comment

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

I tested this, and it seems to work fine.

@bratpeki
Copy link
Copy Markdown
Member

Okay, testing now!

@bratpeki bratpeki merged commit 0cea870 into LMMS:master May 13, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug needs testing This pull request needs more testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pattern editor - some tracks without steps

5 participants