Skip to content

Fix #21609: Implement highlighting hard chords #22997

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

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

Conversation

lllll03
Copy link

@lllll03 lllll03 commented May 27, 2024

We have developed this feature. Because there have been discussions on whether to turn this feature into a plugin (or whether to add this feature at all), we opted by adding a checkbox in the preferences (note input) to turn this option on/off. We also implemented this feature only for keyboards, because implementing for the other instruments would demand information we unfortunately don't have access to.

Resolves: #21609

  • 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
Member

@cbjeukendrup cbjeukendrup Jun 9, 2024

Choose a reason for hiding this comment

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

It looks like relatively complicated computations are being done here. As I explained before, the drawing code (i.e. TDraw) is not the good place for that. This code is called every single time that the screen is redrawn, which means every single time that you scroll, click, drag, move to another window, etc., even when nothing has actually changed in the score. So if the drawing code contains any non-trivial computations, the whole app becomes slow.

As I also explained, the correct place to do it is TLayout, because that code is called only when there are changes in the score. You can then store the results of the computations, for example using setIsImpossibleChord. In the drawing code, you can reuse these results to do some trivial logic to determine the pen color for example.

|| (item->chord()->withUpNoteDistance(i) > 24)
|| (item->chord()->withDownNoteDistance(i) > 24)) {
item->chord()->setIsImpossibleChord(true);
item->chord()->setColor(item->selected() ? config->criticalSelectedColor() : config->criticalColor());
Copy link
Member

Choose a reason for hiding this comment

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

Calling chord()->setColor() is unsafe, because it modifies the property of the chord itself but doesn't register that change in the undo stack. During drawing, all elements must be treated as read-only, so you shouldn't change properties of them. To still change the color, you can either change the color of the pen of the painter, or make changes to the curColor method.

id: colorChordsNotesBox
width: parent.width

text: qsTrc("appshell/preferences", "Color chord notes outside of usable pitch range")
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this is good wording. This feature doesn't really have to do with "usable pitch range" ("range" implies that it would have something to do with the highest or lowest pitch that an instrument could possibly play but that is not what this is about).

How about something like just "Color unplayable chords"?
(I'd then also update the method names in the code everywhere to reflect how this feature is called in the UI, because otherwise it becomes confusing)

// withUpNoteDistance
//---------------------------------------------------------

int Chord::withUpNoteDistance(int inPitch) const
Copy link
Member

Choose a reason for hiding this comment

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

From the name, I don't understand what this method does (I don't know very well either how to interpret the name at all). So:

  • What does it do?
  • How was the name supposed to explain that?
  • Can we find a better name that explains that even better?

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.

Consider highlighting hard/impossible chords
3 participants