Skip to content

Stave sharing - Part 3#33838

Open
mike-spa wants to merge 9 commits into
musescore:mainfrom
mike-spa:STAVE_SHARING
Open

Stave sharing - Part 3#33838
mike-spa wants to merge 9 commits into
musescore:mainfrom
mike-spa:STAVE_SHARING

Conversation

@mike-spa

Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR adds a new StaveSharingLabel engraving item, its style and XML mappings, and integrates it into creation, layout, rendering, editing, selection, drag-and-drop, and read/write paths. It also refactors StaveSharingLayout to use context-based helpers, tighten unison and same-voice checks, rebuild shared notation with tuplets, ties, spanners, and annotations, and expand cleanup for orphaned shared elements.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning No PR description was provided, so the required template sections and checklist items are missing. Add the issue reference, a short summary and motivation, and complete the template checklist items.
Docstring Coverage ⚠️ Warning Docstring coverage is 9.52% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is related to the change set, but it's too generic to convey the primary change. Use a concise, specific title that names the main feature or fix, e.g. 'Add stave sharing labels and layout support'.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/engraving/rendering/score/stavesharinglayout.cpp`:
- Around line 411-417: The forward-tie compatibility check is comparing the
wrong endpoint for tie consistency. In the condition that checks
`tieFor1->startElement()` against `tieFor2->startElement()`, you are checking
the start of the ties when you should be checking the end. Replace the
`startElement()` calls with `endElement()` calls (or `endNote()` if that is the
appropriate method) to correctly compare whether forward ties have matching
open-vs-closed endpoint configurations.
- Around line 703-708: There is a null dereference bug in the tieFor cloning
logic. When the condition checks if sharedTieFor is null with if
(!sharedTieFor), the code immediately tries to call sharedTieFor->clone() inside
that block, which dereferences a null pointer and causes a crash. The fix is to
clone tieFor (the original tie object) instead of sharedTieFor when sharedTieFor
is null. Change the clone call from sharedTieFor->clone() to tieFor->clone() to
use the correct source object for cloning.
- Around line 375-395: The annotation matching logic does not enforce one-to-one
correspondence between annotations on the previous and next tracks. Currently,
when iterating through annotationsOnPrevTrack and comparing each against
candidates in annotationsOnNextTrack via equal_range, there is no mechanism to
remove or mark matched annotations as consumed. This means a single annotation
from the next track can be matched multiple times, breaking duplicate handling.
To fix this, modify the matching logic to track which annotations from
annotationsOnNextTrack have already been matched (for example, using a set of
matched keys or erasing matched items), and ensure that each annotation is only
matched once. After finding a matching annotation in the inner loop (the loop
iterating through equal_range results), immediately mark or remove it so
subsequent iterations in the outer loop cannot reuse it. This will enforce
strict one-to-one pairing of annotations between the two tracks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7217ee5e-37fa-4426-a4f4-4c3b1b31a392

📥 Commits

Reviewing files that changed from the base of the PR and between d402227 and bc1de3d.

📒 Files selected for processing (5)
  • src/engraving/dom/engravingitem.cpp
  • src/engraving/dom/engravingobject.cpp
  • src/engraving/rendering/score/stavesharinglayout.cpp
  • src/engraving/rendering/score/stavesharinglayout.h
  • src/engraving/types/types.h
💤 Files with no reviewable changes (1)
  • src/engraving/dom/engravingitem.cpp

Comment thread src/engraving/rendering/score/stavesharinglayout.cpp
Comment thread src/engraving/rendering/score/stavesharinglayout.cpp
Comment thread src/engraving/rendering/score/stavesharinglayout.cpp

@miiizen miiizen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Spotted a few things, but this is looking so good! 😍

Comment thread src/engraving/rendering/score/stavesharinglayout.cpp Outdated
Comment thread src/engraving/rendering/score/stavesharinglayout.cpp Outdated
Comment thread src/engraving/rendering/score/stavesharinglayout.cpp
Comment thread src/engraving/rendering/score/stavesharinglayout.cpp Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/engraving/dom/engravingitem.cpp (1)

1348-1350: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Missing assertion for originItem->ldata()->m_sharedItem == nullptr.

The assertion validates that sharedItem isn't already a shared item and that originItem isn't acting as a shared item, but it doesn't verify that originItem isn't already connected to a different shared item.

If originItem->m_sharedItem points to oldSharedItem (not sharedItem), the early return on line 1340 is bypassed, and line 1352 overwrites m_sharedItem. This leaves oldSharedItem->m_originItems with a stale pointer to originItem.

🛡️ Suggested fix
-    IF_ASSERT_FAILED(sharedItem->ldata()->m_sharedItem == nullptr && originItem->ldata()->m_originItems.empty()) {
+    IF_ASSERT_FAILED(sharedItem->ldata()->m_sharedItem == nullptr
+                     && originItem->ldata()->m_sharedItem == nullptr
+                     && originItem->ldata()->m_originItems.empty()) {
         return;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/engraving/dom/engravingitem.cpp` around lines 1348 - 1350, The assertion
in the IF_ASSERT_FAILED condition is incomplete and missing a check to ensure
originItem is not already connected to a different shared item. Currently it
only validates that sharedItem->ldata()->m_sharedItem is nullptr and
originItem->ldata()->m_originItems is empty, but it does not check that
originItem->ldata()->m_sharedItem is also nullptr. Add the missing condition
originItem->ldata()->m_sharedItem == nullptr to the assertion to prevent the
code from overwriting m_sharedItem when originItem is already connected to
another shared item, which would leave a stale pointer in the old shared item's
m_originItems collection.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/engraving/dom/engravingitem.cpp`:
- Around line 1348-1350: The assertion in the IF_ASSERT_FAILED condition is
incomplete and missing a check to ensure originItem is not already connected to
a different shared item. Currently it only validates that
sharedItem->ldata()->m_sharedItem is nullptr and
originItem->ldata()->m_originItems is empty, but it does not check that
originItem->ldata()->m_sharedItem is also nullptr. Add the missing condition
originItem->ldata()->m_sharedItem == nullptr to the assertion to prevent the
code from overwriting m_sharedItem when originItem is already connected to
another shared item, which would leave a stale pointer in the old shared item's
m_originItems collection.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cc234357-b50d-4106-9d08-bd1952b9db4a

📥 Commits

Reviewing files that changed from the base of the PR and between bc1de3d and 18abaea.

📒 Files selected for processing (6)
  • src/engraving/dom/engravingitem.cpp
  • src/engraving/dom/engravingitem.h
  • src/engraving/dom/engravingobject.cpp
  • src/engraving/rendering/score/stavesharinglayout.cpp
  • src/engraving/rendering/score/stavesharinglayout.h
  • src/engraving/types/types.h
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/engraving/dom/engravingobject.cpp
  • src/engraving/types/types.h
  • src/engraving/rendering/score/stavesharinglayout.h
  • src/engraving/rendering/score/stavesharinglayout.cpp

mike-spa added 8 commits June 24, 2026 15:45
Dynamics, text, etc
Because the current m_sharedItem may have been already invalidated, so don't try to use it.
They can never belong to one of the origin staves, e.g. the top ones always belong to track 0, which is the shared staves. So exclude them from disconnect and cleanup
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.

2 participants