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

Knife Tool for Sample Clips (Again) #5524

Merged
merged 35 commits into from
Mar 12, 2021
Merged

Knife Tool for Sample Clips (Again) #5524

merged 35 commits into from
Mar 12, 2021

Conversation

Spekular
Copy link
Member

@Spekular Spekular commented Jun 2, 2020

New version of #4998, with copy constructors for SampleBuffer and SampleTCO and a scalpel cursor when hovering over sample tracks in Knife/Split mode. Also adds copy assignment operator for SampleBuffer and a comment about this being missing in SampleTCO.h.

It's worth noting that this PR currently creates a new sample buffer with each cut, because apparently sample clips rely on having a unique buffer. This means that memory use will increase by the samplebuffer size with each cut. Cloning clips currently behaves the same way, so this isn't a regression, but I believe it eventually needs to be fixed as this leads to performance issues.

TODO:

  • Add a TODO comment about the sample buffer issue

@LmmsBot
Copy link

LmmsBot commented Jun 2, 2020

🤖 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://12522-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.101%2Bg572b6a8-linux-x86_64.AppImage"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/12522?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://12525-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.101%2Bg572b6a8d5-mingw-win32.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/12525?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://12523-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.101%2Bg572b6a8d5-mingw-win64.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/12523?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/l47dfyj97k2o0epx/artifacts/build/lmms-1.3.0-alpha-msvc2017-win32.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/37736706"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/dwxivln8okg8jmnm/artifacts/build/lmms-1.3.0-alpha-msvc2017-win64.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/37736706"}], "macOS": [{"artifact": {"title": {"title": "", "platform_name": "macOS"}, "link": {"link": "https://12521-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.101%2Bg572b6a8d5-mac10.14.dmg"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/12521?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}]}, "commit_sha": "4c604d86dc8cb3b49bdb590639b4a1aca413f333"}

@Spekular Spekular added this to the 1.3 milestone Jun 2, 2020
@thmueller64
Copy link
Contributor

Tested, works great!

@Spekular
Copy link
Member Author

Issues with move and resize should be fixed. While I was at it I ended up making box select behave in an (IMO) better and (IME) more standard way. Rather than toggling over to box select mode when control is held, it just starts a box selection when you control + click an empty space, and doesn't visually affect the selected edit mode. On release the edit mode is restored by re-triggering the selected edit button, which seems to be less buggy than the previous implementation based on my quick tests (no more getting stuck in select mode).

@PhysSong
Copy link
Member

Is the stuck Ctrl issue #5394?

@Spekular
Copy link
Member Author

Is the stuck Ctrl issue #5394?

Yes. I can still reproduce that issue in 1.3-alpha.1, but not in the current state of this PR.

@IanCaio
Copy link
Contributor

IanCaio commented Jan 24, 2021

On TrackContentObjectView::mouseMoveEvent() if there's no action being done the following code runs:

		SampleTCO * sTco = dynamic_cast<SampleTCO*>( m_tco );

		if (sTco && m_trackView->trackContainerView()->knifeMode())
		{ setCursor( m_cursorKnife ); }


		if( ( me->x() > width() - RESIZE_GRIP_WIDTH && !me->buttons() && !m_tco->getAutoResize() )
		||  ( me->x() < RESIZE_GRIP_WIDTH && !me->buttons() && sTco && !m_tco->getAutoResize() ) )
		{
			setCursor( Qt::SizeHorCursor );
		}
		else
		{
			leaveEvent( NULL );
		}

There are two issues I noticed with this block:

  1. If you are on the Knife mode there's some "flickering" of cursor changes when hovering the edges, because both if (sTco && m_trackView->trackContainerView()->knifeMode()) and if( ( me->x() > width() - RESIZE_GRIP_WIDTH && !me->buttons() && !m_tco->getAutoResize() ) || ( me->x() < RESIZE_GRIP_WIDTH && !me->buttons() && sTco && !m_tco->getAutoResize() ) ) are true, so you set the cursor to the m_cursorKnife and right after you set the cursor to Qt::SizeHorCursor.

  2. If you are on the Knife mode, hovers the mouse on the middle of the sTCO and leave it, switch to the Draw Mode and hover again in the middle of the sTCO you'll end up with the knife cursor. That's because when leaveEvent is called, the cursor of the widget is still m_cursorKnife, which is of type Qt::BitmapCursor. So the conditional that switches the cursor back to the m_cursorHand isn't met and you end up with a knife on the draw mode, until you move to one of the edges and then back to the middle. That's because when you move to the edges the cursor is changed to Qt::SizeHorCursor, then when you move back to the middle the if( cursor()->shape() != Qt::BitmapCursor ) conditional is true and leaveEvent changes the cursor back to the hand one.

To be honest I'm not sure why leaveEvent is being called in that particular part of the code instead of dealing with the cursor changes inside TrackContentObjectView::mouseMoveEvent alone. Maybe someone can clarify if there's another meaning for that method call there. If not, we can get rid of it and just rewrite the logic so it accounts for those situations more appropriately, checking for all 3 situations (mouse in the middle in knife mode, mouse in the middle in draw mode and mouse on the edges).

@IanCaio
Copy link
Contributor

IanCaio commented Jan 24, 2021

And as mentioned in Discord, there is a small bug I still didn't manage to track down, could use some help on this one. The steps to reproduce it:

  1. Add a SampleTCO to a Sample Track
  2. Split that SampleTCO
  3. Try to Copy and Paste (either through the context menu or by dragging and dropping) the left-most SampleTCO from the two splitted ones

It will fail to paste the TCO, pasting a infinitely small SampleTCO instead. If you move or resize the left-most SampleTCO before copying and pasting however it does work. Which makes me think that it has something to do with some update routine that is not being called and is causing the TCO data to be corrupt or something. I still didn't find out what it is, I only know that copying the right-most SampleTCO works fine.

I also unresolved a change request from a one-liner if that ended up not being changed in the last commits. Besides those issues I don't see anything else. I like the changes on the way Ctrl is being handled on the Song Editor. If I find out anything more about this bug I'll update you.

@IanCaio
Copy link
Contributor

IanCaio commented Jan 24, 2021

Already messaged on Discord, but just for reference, apparently the cause of the bug mentioned above are the following lines:

// move or resize
m_tco->setJournalling( false );

Even though the comment says move or resize, it's being called for Move, Resize, ResizeLeft and Split. However, the journalling is only being set back to true for the first 3:

else if( m_action == Move || m_action == Resize || m_action == ResizeLeft )
{
// TODO: Fix m_tco->setJournalling() consistency
m_tco->setJournalling( true );
}

Because setJournalling is not set back to true on the SampleTCO being split, when it's being copied saveState will not save the data from the TCO because it only does so when isJournalling is true. Moving or Resizing the TCO fixes the problem because then mouseReleaseEvent sets the journalling back to true.

src/gui/widgets/TrackContentWidget.cpp Outdated Show resolved Hide resolved
src/gui/TrackContentObjectView.cpp Outdated Show resolved Hide resolved
src/gui/TrackContentObjectView.cpp Outdated Show resolved Hide resolved
	- Fixes a typo where QWidget::mousePressEvent was being called
inside mouseReleaseEvent.
	- Avoids unnecessarily disabling journalling on the Split
action, since it doesn't require it.
Copy link
Contributor

@IanCaio IanCaio left a comment

Choose a reason for hiding this comment

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

As discussed on Discord, I pushed the last review's suggestions to the PR, gave the code another broad look and it all looks fine.

Style guidelines kept aside, the code LGTM

@PhysSong PhysSong linked an issue Feb 12, 2021 that may be closed by this pull request
@PhysSong
Copy link
Member

@DomClark Do you still want to review this?

@IanCaio IanCaio mentioned this pull request Feb 14, 2021
cyber-bridge pushed a commit to cyber-bridge/lmms that referenced this pull request Feb 24, 2021
ryuukumar pushed a commit that referenced this pull request Feb 26, 2021
* Initial PianoRoll razor feature

* Restore PianoRoll edit mode after focusOut and in razor mode.

* Show changes directly after cut.

* Fix hanging note after adjusting vol/pan with razor action.

* Extract the split action to a separate method

	This PR addresses some suggestions from a review, the most
important ones being:
	- Extracting the note split action to a separate method, called
Pattern::splitNotes
	- Removing getMouseTickPos method
	- Adding a variable that holds the current razor position and a
method to update it (quantizing if CTRL is not pressed)
	- Using [this] to capture "this" on the lambda function instead
of [=], since the latter doesn't work as intended from C++20 forward
	- Fixing some code style and adding comments

* Removes an extra call to noteUnderMouse

	By removing "&& noteUnderMouse()" from the mousePressEvent
conditional, we avoid an extra call to noteUnderMouse. The only
difference in the behavior of the tool is that now clicking on a place
that doesn't have a note will exit Razor mode.

* Style change suggested by @russiankumar

* Cancel razor action on SHIFT release.

* Make razor cut-line (color) themable.

* Add razor cut-line color to classic theme style.css

* Rename razor to knife.

* Change pixmap from razor to knife (from #5524)

* Remove SHIFT behavior.

* Change knife shortcut to SHIFT+K

Co-authored-by: CYBERDEViL <cyberdevil@notabug.org>
Co-authored-by: Ian Caio <iancaio_dev@hotmail.com>
@tresf tresf mentioned this pull request Feb 26, 2021
Copy link
Member

@DomClark DomClark left a comment

Choose a reason for hiding this comment

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

Looks good to me. include/Track.h and src/core/Track.cpp only have formatting changes; can you revert these before merging?

* Revert format changes in Track.h

* Revert formatting changes in Track.cpp
@Spekular
Copy link
Member Author

Reverted, and merging now! Huge thanks to everyone who reviewed and helped out, including of course BaraMGB for making the PR this is rooted in.

@Spekular Spekular merged commit 8acb922 into LMMS:master Mar 12, 2021
@JohannesLorenz
Copy link
Contributor

Causes #5949 .

IanCaio added a commit to IanCaio/lmms that referenced this pull request Mar 28, 2021
* Initial PianoRoll razor feature

* Restore PianoRoll edit mode after focusOut and in razor mode.

* Show changes directly after cut.

* Fix hanging note after adjusting vol/pan with razor action.

* Extract the split action to a separate method

	This PR addresses some suggestions from a review, the most
important ones being:
	- Extracting the note split action to a separate method, called
Pattern::splitNotes
	- Removing getMouseTickPos method
	- Adding a variable that holds the current razor position and a
method to update it (quantizing if CTRL is not pressed)
	- Using [this] to capture "this" on the lambda function instead
of [=], since the latter doesn't work as intended from C++20 forward
	- Fixing some code style and adding comments

* Removes an extra call to noteUnderMouse

	By removing "&& noteUnderMouse()" from the mousePressEvent
conditional, we avoid an extra call to noteUnderMouse. The only
difference in the behavior of the tool is that now clicking on a place
that doesn't have a note will exit Razor mode.

* Style change suggested by @russiankumar

* Cancel razor action on SHIFT release.

* Make razor cut-line (color) themable.

* Add razor cut-line color to classic theme style.css

* Rename razor to knife.

* Change pixmap from razor to knife (from LMMS#5524)

* Remove SHIFT behavior.

* Change knife shortcut to SHIFT+K

Co-authored-by: CYBERDEViL <cyberdevil@notabug.org>
Co-authored-by: Ian Caio <iancaio_dev@hotmail.com>
IanCaio added a commit to IanCaio/lmms that referenced this pull request Mar 28, 2021
* Rebase BaraMGB's Knife
Co-authored-by: Steffen Baranowsky <BaraMGB@freenet.de>

* Draw marker

* Refactoring and shift mode

* Allow resizing

* Add Icon

* Fix stuck marker on RMB, remove unnecessary cast

* Remove redundant line, more const

* Fix

* Review fixes

* Only perform split logic for SampleTCO

* Add unquantizedModHeld function

* missed one

* Don't use copy/paste

* Don't use copy/paste

* More git troubles

* Fix undo

* git dammit

* Cleaner solution?

* Set cursor, add copy assignment to SampleBuffer

* Add TODO comment

* Make it build

* Fixes from review

* Make splitTCO virtual

* Make splitTCO more generic

Co-authored-by: IanCaio <iancaio_dev@hotmail.com>

* Prevent resizing of MIDI clips in knife mode

* Fix move/resize and rework box select via ctrl

* Apply suggestions from code review.

Co-authored-by: IanCaio <iancaio_dev@hotmail.com>

* Don't show inaccurate/useless/empty text float in knife mode

* Addresses Github review

	- Fixes a typo where QWidget::mousePressEvent was being called
inside mouseReleaseEvent.
	- Avoids unnecessarily disabling journalling on the Split
action, since it doesn't require it.

* Revert format changes in Track

* Revert format changes in Track.h

* Revert formatting changes in Track.cpp

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>
Co-authored-by: IanCaio <iancaio_dev@hotmail.com>
devnexen pushed a commit to devnexen/lmms that referenced this pull request Apr 10, 2021
* Initial PianoRoll razor feature

* Restore PianoRoll edit mode after focusOut and in razor mode.

* Show changes directly after cut.

* Fix hanging note after adjusting vol/pan with razor action.

* Extract the split action to a separate method

	This PR addresses some suggestions from a review, the most
important ones being:
	- Extracting the note split action to a separate method, called
Pattern::splitNotes
	- Removing getMouseTickPos method
	- Adding a variable that holds the current razor position and a
method to update it (quantizing if CTRL is not pressed)
	- Using [this] to capture "this" on the lambda function instead
of [=], since the latter doesn't work as intended from C++20 forward
	- Fixing some code style and adding comments

* Removes an extra call to noteUnderMouse

	By removing "&& noteUnderMouse()" from the mousePressEvent
conditional, we avoid an extra call to noteUnderMouse. The only
difference in the behavior of the tool is that now clicking on a place
that doesn't have a note will exit Razor mode.

* Style change suggested by @russiankumar

* Cancel razor action on SHIFT release.

* Make razor cut-line (color) themable.

* Add razor cut-line color to classic theme style.css

* Rename razor to knife.

* Change pixmap from razor to knife (from LMMS#5524)

* Remove SHIFT behavior.

* Change knife shortcut to SHIFT+K

Co-authored-by: CYBERDEViL <cyberdevil@notabug.org>
Co-authored-by: Ian Caio <iancaio_dev@hotmail.com>
devnexen pushed a commit to devnexen/lmms that referenced this pull request Apr 10, 2021
* Rebase BaraMGB's Knife
Co-authored-by: Steffen Baranowsky <BaraMGB@freenet.de>

* Draw marker

* Refactoring and shift mode

* Allow resizing

* Add Icon

* Fix stuck marker on RMB, remove unnecessary cast

* Remove redundant line, more const

* Fix

* Review fixes

* Only perform split logic for SampleTCO

* Add unquantizedModHeld function

* missed one

* Don't use copy/paste

* Don't use copy/paste

* More git troubles

* Fix undo

* git dammit

* Cleaner solution?

* Set cursor, add copy assignment to SampleBuffer

* Add TODO comment

* Make it build

* Fixes from review

* Make splitTCO virtual

* Make splitTCO more generic

Co-authored-by: IanCaio <iancaio_dev@hotmail.com>

* Prevent resizing of MIDI clips in knife mode

* Fix move/resize and rework box select via ctrl

* Apply suggestions from code review.

Co-authored-by: IanCaio <iancaio_dev@hotmail.com>

* Don't show inaccurate/useless/empty text float in knife mode

* Addresses Github review

	- Fixes a typo where QWidget::mousePressEvent was being called
inside mouseReleaseEvent.
	- Avoids unnecessarily disabling journalling on the Split
action, since it doesn't require it.

* Revert format changes in Track

* Revert format changes in Track.h

* Revert formatting changes in Track.cpp

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>
Co-authored-by: IanCaio <iancaio_dev@hotmail.com>
@Spekular Spekular deleted the ROT branch April 23, 2021 14:16
sdasda7777 pushed a commit to sdasda7777/lmms that referenced this pull request Jun 28, 2022
* Initial PianoRoll razor feature

* Restore PianoRoll edit mode after focusOut and in razor mode.

* Show changes directly after cut.

* Fix hanging note after adjusting vol/pan with razor action.

* Extract the split action to a separate method

	This PR addresses some suggestions from a review, the most
important ones being:
	- Extracting the note split action to a separate method, called
Pattern::splitNotes
	- Removing getMouseTickPos method
	- Adding a variable that holds the current razor position and a
method to update it (quantizing if CTRL is not pressed)
	- Using [this] to capture "this" on the lambda function instead
of [=], since the latter doesn't work as intended from C++20 forward
	- Fixing some code style and adding comments

* Removes an extra call to noteUnderMouse

	By removing "&& noteUnderMouse()" from the mousePressEvent
conditional, we avoid an extra call to noteUnderMouse. The only
difference in the behavior of the tool is that now clicking on a place
that doesn't have a note will exit Razor mode.

* Style change suggested by @russiankumar

* Cancel razor action on SHIFT release.

* Make razor cut-line (color) themable.

* Add razor cut-line color to classic theme style.css

* Rename razor to knife.

* Change pixmap from razor to knife (from LMMS#5524)

* Remove SHIFT behavior.

* Change knife shortcut to SHIFT+K

Co-authored-by: CYBERDEViL <cyberdevil@notabug.org>
Co-authored-by: Ian Caio <iancaio_dev@hotmail.com>
sdasda7777 pushed a commit to sdasda7777/lmms that referenced this pull request Jun 28, 2022
* Rebase BaraMGB's Knife
Co-authored-by: Steffen Baranowsky <BaraMGB@freenet.de>

* Draw marker

* Refactoring and shift mode

* Allow resizing

* Add Icon

* Fix stuck marker on RMB, remove unnecessary cast

* Remove redundant line, more const

* Fix

* Review fixes

* Only perform split logic for SampleTCO

* Add unquantizedModHeld function

* missed one

* Don't use copy/paste

* Don't use copy/paste

* More git troubles

* Fix undo

* git dammit

* Cleaner solution?

* Set cursor, add copy assignment to SampleBuffer

* Add TODO comment

* Make it build

* Fixes from review

* Make splitTCO virtual

* Make splitTCO more generic

Co-authored-by: IanCaio <iancaio_dev@hotmail.com>

* Prevent resizing of MIDI clips in knife mode

* Fix move/resize and rework box select via ctrl

* Apply suggestions from code review.

Co-authored-by: IanCaio <iancaio_dev@hotmail.com>

* Don't show inaccurate/useless/empty text float in knife mode

* Addresses Github review

	- Fixes a typo where QWidget::mousePressEvent was being called
inside mouseReleaseEvent.
	- Avoids unnecessarily disabling journalling on the Split
action, since it doesn't require it.

* Revert format changes in Track

* Revert format changes in Track.h

* Revert formatting changes in Track.cpp

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>
Co-authored-by: IanCaio <iancaio_dev@hotmail.com>
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 needs testing This pull request needs more testing
Projects
Development

Successfully merging this pull request may close these issues.

Song editor mode sticks if modal is opened while holding control
10 participants