-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fixes bug with pasting of TCOs (#5840) #5847
Conversation
TimePos::quantize works for negative values, but ends up snapping the TCO to the opposite direction. This is because the snapping happens in the direction of the origin, which is left for positive values and right for negative values. That wasn't accounted for in the pasteSelection method and we ended up with wrong positions when pasting before the TCO(s) we copied. This PR attempts a fix by doing the following: - Changing TimePos::quantize to have a boolean parameter that will define whether it snaps the position up if we are halfway through the interval or not (this removes the need to use that trick of subtracting "TimePos::ticksPerBar() * snapSize / 2" from the offset to try to "bias" it. - Checking if we need quantizing at all by checking if the offset falls outsize the snap grid. - If we do need quantizing and the offset is negative we subtract one snap, since the quantization will move the TCO to the opposite end (to the right). Then we call quantize.
🤖 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
🤖{"platform_name_to_artifacts": {"Linux": [{"artifact": {"title": {"title": "(AppImage)", "platform_name": "Linux"}, "link": {"link": "https://11626-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.52%2Bged45d65-linux-x86_64.AppImage"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/11626?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://11627-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.52%2Bged45d65e3-mingw-win32.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/11627?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://11628-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.52%2Bged45d65e3-mingw-win64.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/11628?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/goef72vby99x24n5/artifacts/build/lmms-1.3.0-alpha-msvc2017-win32.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/36831754"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/rbiosgxowofrwylt/artifacts/build/lmms-1.3.0-alpha-msvc2017-win64.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/36831754"}]}, "commit_sha": "971b14c83d8da141003eb71aa93ca219ba951f83"} |
As the original author: If When the latter is needed one could just write |
I tried to fix it without changing the logic of |
Huh. Assuming |
Situation 1:snapSize is 1 bar (192 ticks). Situation 2:snapSize is 1 bar (192 ticks). The illustration on the PR message illustrates it well, the quantization works fine. It's just that when we are exactly in the middle of the interval, the logic is that we snap to the next one. Problem is the next one on the positive side is to the right and the next one on the negative side is to the left. The biasing code depends on that behavior and assumes that it will snap to the right. That's why I wanted to keep the The alternative I see is having |
This PR reverts the changes from the previous ones and implements an alternative fix for the snapping issue. I'm pushing the changes for the sake of comparison, so it can be decided which approach is better. This one might be better as it changes less code and might be slightly less confusing than the previous one to the reader.
@Spekular I used the alternative approach I mentioned in the last commit. I think it might be better since it's requires less change to the code. The only drawback, which in practice is not a problem at all, is that |
What should the following calls return in an ideal implementation?
|
I think it always should snap to the closes quantized distance even on negative values (like the timeline extended backwards). It actually already does that on master. The last commit just changes the snapping direction when we have
*The paste method assumed this would snap to the right instead of to the "next" quantized position, which walking to the negative side is to the left |
I think the behavior as of the latest commit is good. Negative inputs don't make any sense for positions, so this should only affect deltas, like moving or resizing. In those cases I can't see any downsides to the new behavior, and it should fix the issue found in #5840. |
Since we are working with integers, using "offset / (interval/2)" would be problematic if interval was odd. We instead multiply both sides by two and use "(2 * offset) / interval" to obtain the result for snapUp.
Merge? |
* Fixes bug with pasting of TCOs (LMMS#5840) TimePos::quantize works for negative values, but ends up snapping the TCO to the opposite direction. This is because the snapping happens in the direction of the origin, which is left for positive values and right for negative values. That wasn't accounted for in the pasteSelection method and we ended up with wrong positions when pasting before the TCO(s) we copied. This PR fixes the issue by ensuring that we snap in the same direction when halfway through an interval, regardless of negative or positive offset. * Fixes a calculation on TimePos::quantize Since we are working with integers, using "offset / (interval/2)" would be problematic if interval was odd. We instead multiply both sides by two and use "(2 * offset) / interval" to obtain the result for snapUp.
* Fixes bug with pasting of TCOs (LMMS#5840) TimePos::quantize works for negative values, but ends up snapping the TCO to the opposite direction. This is because the snapping happens in the direction of the origin, which is left for positive values and right for negative values. That wasn't accounted for in the pasteSelection method and we ended up with wrong positions when pasting before the TCO(s) we copied. This PR fixes the issue by ensuring that we snap in the same direction when halfway through an interval, regardless of negative or positive offset. * Fixes a calculation on TimePos::quantize Since we are working with integers, using "offset / (interval/2)" would be problematic if interval was odd. We instead multiply both sides by two and use "(2 * offset) / interval" to obtain the result for snapUp.
* Fixes bug with pasting of TCOs (LMMS#5840) TimePos::quantize works for negative values, but ends up snapping the TCO to the opposite direction. This is because the snapping happens in the direction of the origin, which is left for positive values and right for negative values. That wasn't accounted for in the pasteSelection method and we ended up with wrong positions when pasting before the TCO(s) we copied. This PR fixes the issue by ensuring that we snap in the same direction when halfway through an interval, regardless of negative or positive offset. * Fixes a calculation on TimePos::quantize Since we are working with integers, using "offset / (interval/2)" would be problematic if interval was odd. We instead multiply both sides by two and use "(2 * offset) / interval" to obtain the result for snapUp.
Fixes second issue of #5840 . I'd like feedback on the approach, I didn't want to create an exception on the behavior of
TimePos::quantize
since it's consistent, it just happens that we are working with negative values and expected them to be quantized the same way as positive ones. This makes a minor change to thequantize
and moves most of the fix to thepasteSelection
method.TimePos::quantize
works for negative values, but ends up snapping the TCO to the opposite direction. This is because the snapping down happens in the direction of the origin, which is left for positive values and right for negative values. The snapping up (when we are halfway through the interval) also happens in the opposite direction, away from the origin or right for positive values and left for negative ones:That wasn't accounted for in the pasteSelection method and we ended up with wrong positions when pasting before the TCO(s) we copied. This PR attempts a fix by doing the following:
TimePos::ticksPerBar() * snapSize / 2
from the offset to try to "bias" it.