-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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?
GraceNotesGroup gnBefore = mainChord->graceNotesBefore(); | ||
GraceNotesGroup gnAfter = mainChord->graceNotesAfter(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::vector<Chord*> chordList = ch->allGraceChordsOfMainChord(); | |
const std::vector<Chord*> chordList = ch->allGraceChordsOfMainChord(); |
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; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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:
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.
Resolves: #25299
If there are other grace notes (
Chord
s) 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.