Skip to content

PianoRoll: fix getKey and remove dead code#8008

Merged
regulus79 merged 5 commits intoLMMS:masterfrom
allejok96:prGetKey
Aug 9, 2025
Merged

PianoRoll: fix getKey and remove dead code#8008
regulus79 merged 5 commits intoLMMS:masterfrom
allejok96:prGetKey

Conversation

@allejok96
Copy link
Contributor

  • Fixes: when right clicking on a piano key close to the lower edge of the screen, "Mark semitone" will mark the wrong key because it uses the upper edge of the context menu as reference.
  • Fixes: getKey() is off by 2 pixels
  • Introduces: yCoordOfKey() which is the reverse of getKey()
  • Removes: section of code that can never be reached

@allejok96 allejok96 changed the title PianoRoll: fix getKey calculations and remove unrachable code PianoRoll: fix getKey calculations and remove unreachable code Jul 13, 2025
@allejok96 allejok96 changed the title PianoRoll: fix getKey calculations and remove unreachable code PianoRoll: fix getKey and remove dead code Jul 13, 2025
@JohannesLorenz JohannesLorenz self-requested a review July 14, 2025 18:23
Copy link
Contributor

@JohannesLorenz JohannesLorenz left a comment

Choose a reason for hiding this comment

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

Only 2 editorials.

Checked:

  • Code logic
  • Code style
  • Partial testing: I checked that the dead code cannot be reached

Suggesting to test the other points of the OP.

@allejok96
Copy link
Contributor Author

Suggesting to test the other points of the OP

I glanced through the various mouse*Event() and I didn't see any obvious dead ends.

Copy link
Contributor

@JohannesLorenz JohannesLorenz left a comment

Choose a reason for hiding this comment

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

Rework check OK, only grammar issues.

This PR can be tested.

@JohannesLorenz JohannesLorenz added the needs testing This pull request needs more testing label Jul 19, 2025
@bratpeki bratpeki self-assigned this Jul 19, 2025
Co-authored-by: Johannes Lorenz <1042576+JohannesLorenz@users.noreply.github.com>
@bratpeki
Copy link
Member

  • when right clicking on a piano key close to the lower edge of the screen, "Mark semitone" will mark the wrong key because it uses the upper edge of the context menu as reference.

I can recreate this!


The PR does indeed fix this! Approving as a tester.

@bratpeki
Copy link
Member

bratpeki commented Aug 2, 2025

Looked at the code. Again, I'm just starting out reviewing, but this looks great!

Gonna just sum up my understanding of the code and ask @allejok96 to confirm:

  • Relative height is the y-coordinate relative to the visible bit of Piano Roll
  • Absolute height is the y-coordinate relative to the whole Piano Roll
  • getKey returns the key value (ex. A4 = 69) for the absolute height passed to it
  • yCoordOfKey is the inverse function of getKey, per se

As for my questions, I'm gonna make them in the code viewer.

y,
width() - 10,
m_keyLineHeight + 1,
m_keyLineHeight,
Copy link
Member

Choose a reason for hiding this comment

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

Why was the + 1 there in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My guess is it compensated for the - 1 a few lines earlier.

@bratpeki
Copy link
Member

bratpeki commented Aug 2, 2025

Actually, other than that, I've no other questions, the comments are terrific!

@allejok96
Copy link
Contributor Author

@bratpeki thank's for the testing. You're right about the relative and absolute values, although I just call them "distances from bottom" and not "coordinates" since Qt always measures coordinates from the upper left corner of the widget.

So with that in mind getKey takes a Y coordinate as input, and yCoordOfKey returns the Y coordinate of the top of key (both measured from top of editor).

@bratpeki
Copy link
Member

bratpeki commented Aug 2, 2025

Thanks for the clarification! @regulus79 can we get a brief look at this and then merge?

Copy link
Member

@regulus79 regulus79 left a comment

Choose a reason for hiding this comment

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

I have not tested this, nor can I confirm that the code block removed cannot be reached. But, just from a brief look, the changes look fine. If other people have tested it, I'm fine with it.

@bratpeki
Copy link
Member

bratpeki commented Aug 5, 2025

@allejok96: Yeah, could you delve a bit into that bit of code that can't be reached? How are you sure that such a big chunk of code is unreachable?

@allejok96
Copy link
Contributor Author

@bratpeki This is the outer shell of the if statement, starting on line 2459

// If mouse is below timeline OR user is performing an action
if( me->y() > PR_TOP_MARGIN || m_action != Action::None )
{
    ...
}
else
{
    // If left button is pressed AND select mode is active AND is performing select action
    if( me->buttons() & Qt::LeftButton &&				
					m_editMode == EditMode::Select &&
					m_action == Action::SelectNotes )
	{
	    // This cannot be reached since if action == SelectNotes it will always match the first statement
    }
}

@bratpeki bratpeki added needs code review A functional code review is currently required for this PR and removed needs testing This pull request needs more testing labels Aug 9, 2025
@bratpeki
Copy link
Member

bratpeki commented Aug 9, 2025

Thanks for the clarification, @allejok96.

I see @regulus79 also thinks this is okay, @messmerd is okay with the code changes, @JohannesLorenz too. There have been no changes since my approval, so @regulus79 can we get this merged?

@regulus79 regulus79 merged commit 4dc7784 into LMMS:master Aug 9, 2025
10 of 11 checks passed
@allejok96 allejok96 deleted the prGetKey branch August 9, 2025 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs code review A functional code review is currently required for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants