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

Fix #25299: Allow navigating to grace notes when inputting fingerings #26033

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kennysiucho
Copy link
Contributor

Resolves: #25299

If there are other grace notes (Chords) in the current group, navigate to those first before going to other non-grace chords.

Also restructured some of the other logic to make it more readable.

Added Chord::allGraceChordsOfMainChord() to return the list of grace and non-grace Chords in the current group. I'm also working on fixing grace note navigation using Alt-arrow keys, so this function will come in useful later.

  • I signed the CLA
  • 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
  • If changes are extensive, there is a sequence of easily reviewable commits
  • The code in the PR follows the coding rules
  • There are no unnecessary changes
  • The code compiles and runs on my machine, preferably after each commit individually
  • I created a unit test or vtest to verify the changes I made (if applicable)

Copy link
Contributor

@mathesoncalum mathesoncalum left a comment

Choose a reason for hiding this comment

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

Thanks for this @kennysiucho - I've highlighted a couple of bits.

How does it look from an accessibility standpoint @shoogle?

Comment on lines +2564 to +2565
GraceNotesGroup gnBefore = mainChord->graceNotesBefore();
GraceNotesGroup gnAfter = mainChord->graceNotesAfter();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
GraceNotesGroup gnBefore = mainChord->graceNotesBefore();
GraceNotesGroup gnAfter = mainChord->graceNotesAfter();
const GraceNotesGroup& gnBefore = mainChord->graceNotesBefore();
const GraceNotesGroup& gnAfter = mainChord->graceNotesAfter();

}

// next, try going to next/prev grace note chord in the same group as the current
std::vector<Chord*> chordList = ch->allGraceChordsOfMainChord();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
std::vector<Chord*> chordList = ch->allGraceChordsOfMainChord();
const std::vector<Chord*> chordList = ch->allGraceChordsOfMainChord();

Comment on lines +5937 to +5945
if (!el && ch != (back ? chordList.front() : chordList.back())) {
for (auto it = chordList.begin(); it != chordList.end(); ++it) {
if (*it == ch) {
Chord* targetChord = back ? *(it - 1) : *(it + 1);
el = back ? targetChord->notes().front() : targetChord->notes().back();
break;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We can make this more concise with some std methods:

Suggested change
if (!el && ch != (back ? chordList.front() : chordList.back())) {
for (auto it = chordList.begin(); it != chordList.end(); ++it) {
if (*it == ch) {
Chord* targetChord = back ? *(it - 1) : *(it + 1);
el = back ? targetChord->notes().front() : targetChord->notes().back();
break;
}
}
}
if (!el && ch != (back ? chordList.front() : chordList.back())) {
auto it = std::find(chordList.begin(), chordList.end(), ch);
if (it != chordList.end()) {
const Chord* targetChord = back ? *std::prev(it) : *std::next(it);
el = back ? targetChord->notes().front() : targetChord->notes().back();
}
}

...
Arguably it would be a bit more readable if we swapped those final ternary operators with a simple if/else - the tradeoff is that the nesting gets a bit painful. I'll leave it up to you:

if (back) {
    const Chord* targetChord = *std::prev(it);
    el = targetChord->notes().front();
} else {
    const Chord* targetChord = *std::next(it);
    el = targetChord->notes().back();
}

...
As a general note, if this method gets any more complicated I think we should consider splitting it up into lambdas or helpers. Early returns would help a lot with readability here.

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.

Note after grace note is skipped when inputting fingering
2 participants