Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy annotations and hairpins when exploding/imploding staves #23787

Merged
merged 4 commits into from
Jul 29, 2024

Conversation

miiizen
Copy link
Contributor

@miiizen miiizen commented Jul 26, 2024

Resolves: #23767

This PR copies annotations (dynamics, text etc.) and hairpins when exploding and imploding staves. Where there are voice assignments (in the case of dynamics and hairpins), these are taken into account.

Screen.Recording.2024-07-26.at.17.13.55.mov

@miiizen miiizen changed the title Copy annotations and hairpins when exploding/imloding staves Copy annotations and hairpins when exploding/imploding staves Jul 26, 2024
Comment on lines 1323 to 1342
const VoiceAssignment voiceAssignment = getProperty(Pid::VOICE_ASSIGNMENT).value<VoiceAssignment>();
if (voiceAssignment == VoiceAssignment::CURRENT_VOICE_ONLY && track() == refTrack) {
return true;
}

if (voiceAssignment == VoiceAssignment::ALL_VOICE_IN_STAFF && track2staff(track()) == track2staff(refTrack)) {
return true;
}

const Part* elementPart = part();
if (!elementPart) {
return false;
}

if (voiceAssignment == VoiceAssignment::ALL_VOICE_IN_INSTRUMENT && (elementPart->startTrack() <= refTrack
&& elementPart->endTrack() - 1 >= refTrack)) {
return true;
}
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This code is repeated identical in Spanner::elementAppliesToTrack in order to check for both track() and track2(). Here's a suggestion for how to improve it.

Move this bit of code into a protected static function, something like:

protected:
static bool elementAppliesToTrack(track_idx_t elementTrack, track_idx_t refTrack, VoiceAssignment voiceAssignment);

Then you can have:

bool EngravingItem::appliesToTrack(track_idx_t refTrack) const
{
    if (!hasVoiceAssignmentProperties()) {
        return refTrack == track();
    }
    return elementAppliesToTrack(track(), refTrack, voiceAssignment());
}

and the Spanner version as:

bool Spanner::appliesToTrack(track_idx_t refTrack) const
{
    if (!hasVoiceAssignmentProperties()) {
        return refTrack == track() || refTrack == track2();
    }
    return elementAppliesToTrack(track(), refTrack, voiceAssignment()) || elementAppliesToTrack(track2(), refTrack, voiceAssignment());
}


EngravingItem* newAnnotation;
//does a linked clone to create just this element
//otherwise element will be add in every linked stave
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a bit confused by this comment. Do I understand correctly that the cloneVoice function is used both for creating linked copies (as in parts) and non-linked copies (as in the explode command)? What do you mean by "does a linked clone to create just this element"?

Copy link
Contributor Author

@miiizen miiizen Jul 29, 2024

Choose a reason for hiding this comment

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

Yes, copied this from above. It's unclear, I'll correct it!

@mike-spa mike-spa merged commit 7c2853f into musescore:master Jul 29, 2024
11 checks passed
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.

Improve duplication of dynamics with 'Explode' feature
3 participants