Skip to content

Conversation

@mike-spa
Copy link
Contributor

@mike-spa mike-spa commented Jan 16, 2024

Resolves: #9302

A complete rewrite of the accidental placement algorithms, making good use of the recently introduced accidental cutouts. Basically see the vtests.

@MarcSabatella
Copy link
Contributor

MarcSabatella commented Jan 16, 2024

Wow, quite the project! I look forward to checking out the results. I wanted to find my old test file based on Daniel Spreadbury's blog article https://blog.dorico.com/2014/03/development-diary-part-six, but unfortunately I can't seem to find the MSCZ file itself. I did find the results of one of my other tests from back then, and I'll be curious to compare:

image

@mike-spa mike-spa marked this pull request as draft January 17, 2024 08:26
@mike-spa
Copy link
Contributor Author

Disclaimer: don't get overexcited over any particular details. This is just me not resisting the urge to use the new cutouts and trying out stuff.

@Tantacrul
Copy link
Contributor

LOVING THIS

@bkunda
Copy link

bkunda commented Jan 18, 2024

Fabulous progress @mike-spa!

@igorkorsukov igorkorsukov force-pushed the master branch 6 times, most recently from fa1f8d3 to 525a11a Compare February 14, 2024 09:08
@mike-spa mike-spa force-pushed the accidentalsReform branch from dd89567 to 63f35fc Compare April 2, 2024 10:30
@mike-spa mike-spa marked this pull request as ready for review April 2, 2024 10:30
@musescore musescore deleted a comment from sammik Apr 2, 2024
@mike-spa mike-spa requested a review from its-not-nice April 2, 2024 10:44
@its-not-nice its-not-nice added the vtests This PR produces approved changes to vtest results label Apr 3, 2024
@mike-spa mike-spa force-pushed the accidentalsReform branch 2 times, most recently from 642a240 to 5777d2e Compare April 16, 2024 07:30
@musescore musescore deleted a comment from Jojo-Schmitz Apr 16, 2024
@mike-spa mike-spa force-pushed the accidentalsReform branch from 5777d2e to 7bfe8d1 Compare April 18, 2024 09:04
@RomanPudashkin RomanPudashkin requested a review from Eism April 26, 2024 14:22
@mike-spa mike-spa force-pushed the accidentalsReform branch from 7bfe8d1 to 1ceb6a0 Compare May 2, 2024 08:41
@mike-spa mike-spa force-pushed the accidentalsReform branch 2 times, most recently from d5c2f0e to ec94049 Compare May 15, 2024 07:55
@mike-spa mike-spa force-pushed the accidentalsReform branch 2 times, most recently from ecee97a to e1b8bb6 Compare May 17, 2024 11:20
@mike-spa
Copy link
Contributor Author

@RomanPudashkin done! 👍

{
std::vector<Accidental*> accidentals;

for (Chord* chord : chords) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use const with pointers unless you are going to change their value

if (!acc) {
continue;
}
acc->setPos(0.0, 0.0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not ideal... This function not only collects accidentals but also changes some properties. Ideally, it should have only one responsibility (find and return accidentals)

verticallyAlignAccidentals(ctx);
}

void AccidentalsLayout::findOctaves(AccidentalsLayoutContext& ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this code will be called quite often, it is probably better to combine this function with findSeconds. This way, we will reduce the complexity of the algorithm

firstGroup.push_back(ctx.allAccidentals.front());
ctx.accidentalSubChords.push_back(firstGroup);

for (int i = 1; i < ctx.allAccidentals.size(); ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will generate a warning as size() returns size_t

TLayout::layoutAccidental(acc, acc->mutldata(), ctx.conf());
}

AccidentalsLayoutContext accidentalsLayoutContext(allAccidentals, chords);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to use std::move with allAccidentals to avoid creating a copy (the AccidentalsLayoutContext constructor also needs to be adjusted)

void AccidentalsLayout::mergeSubGroupsWithOctavesAcross(AccidentalsLayoutContext& ctx)
{
bool foundOctave = false;
do {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what's going on in this function, but it's very complex (5 nested loops + lots of operations on std::vector). Is there any way to simplify/optimize it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved out some code to make it more readable, but unfortunately I can't think of any way to simplify this. These are very gnarly engraving requirements resulting in very gnarly code logic. Luckily this function (and the next one that you pointed out) is used rarely so it shouldn't impact performance

applyOrderingOffsets(accidentals);
}

std::vector<std::vector<Accidental*> > AccidentalsLayout::splitIntoPriorityGroups
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to add an alias for this type

void AccidentalsLayout::moveOctavesToSecondGroup(std::vector<std::vector<Accidental*> >& subGroups)
{
std::vector<Accidental*>& firstGroup = subGroups[0];
std::vector<Accidental*>& secondGroup = subGroups[1];
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like std::array might be a better type for subGroups

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one particular case (with conditions defined by the caller), but in general subGroups may have different sizes

Copy link
Contributor

Choose a reason for hiding this comment

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

worth adding this

IF_ASSERT_FAILED(subGroups.size() == 2) {
return;
}

return 0.0;
}

double AccidentalsLayout::computePadding(Accidental* acc, const EngravingItem* chordElement, AccidentalsLayoutContext& ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

const AccidentalsLayoutContext&

AccidentalType accType = acc->accidentalType();
if (chordItem->isLedgerLine() && (accType == AccidentalType::NATURAL || accType == AccidentalType::SHARP)) {
if (chordItem->y() > accShape.top() && chordItem->y() < accShape.bottom()) {
return accShape.right() - chordElement.left() + 0.1 * ctx.spatium();
Copy link
Contributor

Choose a reason for hiding this comment

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

0.1?

for (int j = 0; j < thisGroup.size(); ++j) {
Accidental* acc1 = thisGroup[j];
for (Accidental* secondAcc : acc1->ldata()->seconds.value()) {
if (muse::remove(nextGroup, secondAcc)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same question. remove() isn't very efficient with std::vector

@mike-spa mike-spa force-pushed the accidentalsReform branch 2 times, most recently from adc9a8a to 6e0f341 Compare May 22, 2024 09:33
@mike-spa
Copy link
Contributor Author

@RomanPudashkin done! 👍

TLayout::layoutAccidental(acc, acc->mutldata(), ctx.conf());
}

AccidentalsLayoutContext accidentalsLayoutContext(std::move(allAccidentals), std::move(chords));
Copy link
Contributor

Choose a reason for hiding this comment

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

std::move(chords) - this has no effect as chords is const std::vector<Chord*>& :)

return subGroups;
}

AccidentalGroups AccidentalsLayout::groupAccidentalsByNoteXPos(std::vector<Accidental*>& accidentals)
Copy link
Contributor

Choose a reason for hiding this comment

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

This vector should be const

@mike-spa mike-spa force-pushed the accidentalsReform branch from 6e0f341 to f27403f Compare May 24, 2024 11:41
@mike-spa mike-spa force-pushed the accidentalsReform branch from f27403f to f074b44 Compare May 24, 2024 11:44
@RomanPudashkin RomanPudashkin merged commit 6644d91 into musescore:master May 24, 2024
@mike-spa mike-spa deleted the accidentalsReform branch February 17, 2025 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vtests This PR produces approved changes to vtest results

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MU4 Issue] Sharps are not laid out correctly when notes are a 6th apart

6 participants