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

WIP: Piano Roll mouse refactor + extras #6063

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

Veratil
Copy link
Contributor

@Veratil Veratil commented Jun 19, 2021

This is part of my continued effort to clean up the Piano Roll code to make it easier to maintain and read (and be faster), with help from @IanCaio. I wanted to open this now since most of the major work is done, and I'd like to start getting some testing and reviews. I'm certain there are some edge cases from the refactor that myself and Ian haven't found. Also if there are any suggestions for duplicated code that we can pull out into their own function would be helpful.

Quick summary of changes:

My known issues:

Veratil and others added 16 commits June 19, 2021 02:16
	Changes variable names from PianoRoll::mousePressEvent to
camelCase and changes 2 comments.
	Removes a loop that removed every note except one and replaced
it with a clear() call plus appending the note.
	Removes a magic number used for finding the closest note.
* Changes mousePressEvent variables to camelCase

	Changes variable names from PianoRoll::mousePressEvent to
camelCase and changes 2 comments.

* Style fixes on mouseDoubleClickEvent

* Removes magic number and costy loop

	Removes a loop that removed every note except one and replaced
it with a clear() call plus appending the note.
	Removes a magic number used for finding the closest note.

* Small fixes + Code style

	Fixes small bug with the vertical selection mode scrolling.
	Improves logic on the cursor selection of ActionNone.
	Adds update() + return statements for the actions that didn't
have them, and removed the update() from outside the switch.
	Fixes the code style.
* Changes mousePressEvent variables to camelCase

	Changes variable names from PianoRoll::mousePressEvent to
camelCase and changes 2 comments.

* Style fixes on mouseDoubleClickEvent

* Removes magic number and costy loop

	Removes a loop that removed every note except one and replaced
it with a clear() call plus appending the note.
	Removes a magic number used for finding the closest note.

* Small fixes + Code style

	Fixes small bug with the vertical selection mode scrolling.
	Improves logic on the cursor selection of ActionNone.
	Adds update() + return statements for the actions that didn't
have them, and removed the update() from outside the switch.
	Fixes the code style.

* Adds Remove Note action

	Adds a action to remove notes on the PianoRoll, and remove an
unnecessary member variable that was only being used to handle that
action (m_mouseDownRight).
	Also removes unnecessary handling of the play key action on the
ActionNone case switch from the mouseMoveEvent. Adds a update() call on
the ActionPlayKeys (so it updates the cursor) and a break; statement
for consistency. Also fixes the calculation of the velocity.
@LmmsBot
Copy link

LmmsBot commented Jun 19, 2021

🤖 Hey, I'm @LmmsBot from github.com/lmms/bot and I made downloads for this pull request, click me to make them magically appear! 🎩

Linux

Windows

macOS

🤖
{"platform_name_to_artifacts": {"Linux": [{"artifact": {"title": {"title": "(AppImage)", "platform_name": "Linux"}, "link": {"link": "https://14048-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.132%2Bg6ea5ae0-linux-x86_64.AppImage"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/14048?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}], "Windows": [{"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://14049-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.132%2Bg6ea5ae036-mingw-win32.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/14049?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://14050-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.132%2Bg6ea5ae036-mingw-win64.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/14050?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/u78yqfavievs41po/artifacts/build/lmms-1.3.0-alpha-msvc2017-win32.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/39669311"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/f7c0x8st2rj88220/artifacts/build/lmms-1.3.0-alpha-msvc2017-win64.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/39669311"}], "macOS": [{"artifact": {"title": {"title": "", "platform_name": "macOS"}, "link": {"link": "https://14046-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.132%2Bg6ea5ae036-mac10.14.dmg"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/14046?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}]}, "commit_sha": "231e38d742551e739411613e88748c014af672fb"}

Copy link
Member

@PhysSong PhysSong left a comment

Choose a reason for hiding this comment

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

This is not a complete review yet. I have to read the remaining part later.

const int visible_space = keyAreaBottom() - keyAreaTop();
m_totalKeysToScroll = qMax(0, NumKeys - 1 - visible_space / 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.

Suggested change

@@ -449,6 +447,8 @@ PianoRoll::PianoRoll() :
this, SLOT(changeSnapMode()));

m_stepRecorder.initialize();

m_lastChord = nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

Why do you have this here instead of the member initializer list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question. I don't know what I was thinking!

Comment on lines 1078 to +1080
PR_TOP_MARGIN,
width() - m_whiteKeyWidth,
keyAreaBottom() - PR_TOP_MARGIN);
noteAreaWidth(),
keyAreaBottom() - keyAreaTop());
Copy link
Member

Choose a reason for hiding this comment

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

Why are you still using PR_TOP_MARGIN instead of keyAreaTop()?

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 am using keyAreaTop()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh nevermind you're talking about the line above the change. I just missed it is all.

}

if( m_editMode == ModeEditDetuning && noteUnderMouse() )
PianoRoll::PianoRollArea PianoRoll::getPianoRollAreaIn(const int x, const int y)
Copy link
Member

Choose a reason for hiding this comment

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

I would name it like coordToArea or pointToArea, but I'll leave the naming stuff up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, yeah I think pointToPianoArea could work?

// ticks per pixel = ticks per bar / pixels per bar
// const int tpp = static_cast<int>(static_cast<float>(TimePos::ticksPerBar()) / m_ppb);
// pixels per tick = pixels per bar / ticks per bar
const int ppt = static_cast<int>(static_cast<float>(m_ppb) / TimePos::ticksPerBar());
Copy link
Member

Choose a reason for hiding this comment

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

This will truncate the decimal part and affect ticks to position calculation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason that just didn't click in my head. 😂 I'll change to float.

const int ppt = static_cast<int>(static_cast<float>(m_ppb) / TimePos::ticksPerBar());

// Area mouse clicked in
const PianoRollArea pra = getPianoRollAreaIn(mex, mey);
Copy link
Member

Choose a reason for hiding this comment

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

I prefer using this directly in switch statements. The same for the other occurrences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That can be done. 👍

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.

4 participants