Skip to content

Fix appendPart not applying tablature staff type from template#33821

Open
knoguchi wants to merge 1 commit into
musescore:mainfrom
knoguchi:fix-appendpart-stafftype-preset
Open

Fix appendPart not applying tablature staff type from template#33821
knoguchi wants to merge 1 commit into
musescore:mainfrom
knoguchi:fix-appendpart-stafftype-preset

Conversation

@knoguchi

@knoguchi knoguchi commented Jun 15, 2026

Copy link
Copy Markdown

Resolves: #33820

Summary

Score::appendPart(const InstrumentTemplate*) was passing the freshly-created default StaffType into Staff::init as the explicit preset, which shadowed t->staffTypePreset and forced every appended staff to a default standard 5-line — breaking tablature templates via the plugin API.

Passing nullptr lets Staff::init fall through to t->staffTypePreset, as the post-#29478 refactor intended.

Prior attempt

#29478 (commit 451b451bd8, "Set default clefs when creating parts") was the first attempt at this consolidation: it correctly replaced the old hand-rolled body of appendPart with a delegation to Staff::init. But it left the vestigial stt = staff->staffType(Fraction(0, 1)) local from the previous body and threaded it into the new init call. Since Factory::createStaff constructs a Staff with the default STANDARD preset already assigned, that pointer is non-null and Staff::init takes the if (staffType) branch, shadowing t->staffTypePreset and defeating the refactor's intent.

This PR drops the stale local and passes nullptr instead, finishing what #29478 started.

Changes

  • src/engraving/dom/score.cpp: drop the vestigial stt local; pass nullptr to Staff::init so the template's staffTypePreset wins.
  • src/engraving/tests/scoreutils_tests.cpp: two regression tests
  • AppendPartFromTablatureTemplate — appending the guitar-nylon-tablature template yields a TAB-group, 6-line staff.
  • AppendPartFromStandardTemplatePreservesClefs — appending the piano template still yields the per-staff treble + bass default clefs.

Local validation

[==========] Running 2 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 2 tests from Engraving_ScoreUtilsTests
[ RUN      ] Engraving_ScoreUtilsTests.AppendPartFromTablatureTemplate
[       OK ] Engraving_ScoreUtilsTests.AppendPartFromTablatureTemplate (3 ms)
[ RUN      ] Engraving_ScoreUtilsTests.AppendPartFromStandardTemplatePreservesClefs
[       OK ] Engraving_ScoreUtilsTests.AppendPartFromStandardTemplatePreservesClefs (3 ms)
[----------] 2 tests from Engraving_ScoreUtilsTests (6 ms total)
[----------] Global test environment tear-down
[==========] 2 tests from 1 test suite ran. (6 ms total)
[  PASSED  ] 2 tests.

  • I signed the CLA as tokyo246
  • The title of the PR describes the problem it addresses.
  • Each commit's message describes its purpose and effects, and references the issue it resolves.
  • The code in the PR follows the coding rules.
  • I understand all aspects of the code I'm contributing and I'm able to explain it if requested.
  • The code compiles and runs on my machine — see "Local validation" above.
  • Prior attempt Fix #26640: Set default clefs when creating parts #29478 listed in the PR description; this PR finishes its refactor by dropping the vestigial stt local.
  • There are no unnecessary changes.
  • I created a unit test or vtest to verify the changes I made.

Score::appendPart(const InstrumentTemplate*) was passing the freshly-
created default StaffType into Staff::init as the explicit preset,
which shadowed t->staffTypePreset and forced every appended staff to
a default standard 5-line, breaking tablature templates via the
plugin API.

Passing nullptr lets Staff::init fall through to t->staffTypePreset,
as the post-musescore#29478 refactor intended.

Adds regression tests:
- AppendPartFromTablatureTemplate: asserts appendPart of a TAB
  instrument yields a TAB-group, 6-line staff.
- AppendPartFromStandardTemplatePreservesClefs: asserts piano gets
  treble + bass default clefs across its two staves.
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Score::appendPart is modified to pass nullptr as the StaffType* argument to staff->init, removing the prior two-line pattern that looked up the staff's existing StaffType via staff->staffType(Fraction(0, 1)) and forwarded it. The initialization now derives the staff type solely from the provided InstrumentTemplate. Two new unit tests in the scoreutils test suite cover this path: one asserts that appending a guitar nylon tablature template produces a TAB (non-pitched) staff, and another asserts that appending a piano template produces two pitched staves whose default concert clefs match the treble and bass assignments declared in the template.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix appendPart not applying tablature staff type from template' clearly and specifically describes the main change: fixing a bug where appendPart fails to apply the template's staff type preset, with tablature as a concrete example.
Linked Issues check ✅ Passed The PR fully addresses the requirements in issue #33820: fixes the appendPart function to pass nullptr instead of the default StaffType, includes two regression tests (tablature and standard template clef preservation), and demonstrates that both tests pass.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #33820: the core fix in score.cpp, two targeted regression tests in scoreutils_tests.cpp, and no unnecessary modifications.
Description check ✅ Passed The PR description is comprehensive and complete, covering all required template sections with detailed context, prior work, and validation results.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Linked repositories: Your configuration references 1 linked repositories, but your current plan allows 0. Analyzed ``, skipped musescore/muse_framework.git.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mathesoncalum mathesoncalum self-requested a review June 15, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin API: Score.appendPart() does not apply tablature staff type from instrument template

3 participants