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

Fix shifting of sample waveform during zoom #7222

Merged
merged 4 commits into from
May 2, 2024

Conversation

khoidauminh
Copy link
Contributor

@khoidauminh khoidauminh commented Apr 24, 2024

The original code was doing division in int, which causes loss of accuracy and results in the waveform randomly shifting when zooming in and out.

This should fix it by casting variables to float before dividing, as well as keeping the values in float type.

The original code was doing division in `int`, which causes lost of accuracy and results in the waveform randomly shifting when zooming in and out.

This should fix it by casting variables to `float` before dividing, as well as keeping the values in `float` type.

The pull request also changes some type declaration to explicit to increase readability
src/gui/SampleWaveform.cpp Show resolved Hide resolved
src/gui/SampleWaveform.cpp Outdated Show resolved Hide resolved
src/gui/SampleWaveform.cpp Outdated Show resolved Hide resolved
src/gui/SampleWaveform.cpp Outdated Show resolved Hide resolved
@sakertooth
Copy link
Contributor

Why were the type declaration changes removed? I see @Veratil mentioned going back to auto for some of them, but I think he was referring to that part of the code alone (though, even that part of the code should specify the type in its declaration IMO, since they are used in calculations later where the types of these variables are important to get right).

@Veratil
Copy link
Contributor

Veratil commented Apr 24, 2024

Why were the type declaration changes removed? I see @Veratil mentioned going back to auto for some of them, but I think he was referring to that part of the code alone (though, even that part of the code should specify the type in its declaration IMO, since they are used in calculations later where the types of these variables are important to get right).

I did mean the part mentioned only, but that's fine if we want to specify.

@khoidauminh
Copy link
Contributor Author

Sorry for the previous weird changes, I misunderstood some of the conversations in the review. Should I change all primitive type declarations to explicit this time @sakertooth ?

@sakertooth
Copy link
Contributor

Sorry for the previous weird changes, I misunderstood some of the conversations in the review. Should I change all primitive type declarations to explicit this time?

For clarity as to what the types are, I would say yes. It's important here because we do a lot of arithmetic, so we need to be careful to avoid truncation when dividing, thinking variables are in a certain type when they aren't, etc. The use of auto exclusively also might be the reason why I didn't see the bug initially when I wrote this. Though I think some people have varying opinions on the use of auto, it wouldn't hurt to specify some of the types here.

@khoidauminh
Copy link
Contributor Author

@sakertooth I think it's still better to make all primitive declarations explicit, even though it doesn't seem necessary. It can help detect more bugs, and make future code changes easier in general, in this case the arrival of sample caching. I'll go ahead and make all primitive type declarations explicit.

For the variables created from the QRect methods at the start @Veratil, I read through the Qt docs (for both Qt5 and Qt6) and they all return int, so it's safe to also declare them as int.

@Veratil
Copy link
Contributor

Veratil commented Apr 25, 2024

Sorry for causing the back and forth churn. :)

@sakertooth
Copy link
Contributor

I think it's still better to make all primitive declarations explicit, even though it doesn't seem necessary. It can help detect more bugs, and make future code changes easier in general, in this case the arrival of sample caching. I'll go ahead and make all primitive type declarations explicit.

Yes, this is what I mentioned 🤣 I was in agreement in making the primitive declarations explicit for the same reasons.

Copy link
Contributor

@sakertooth sakertooth left a comment

Choose a reason for hiding this comment

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

After the discussion in Discord, keeping them auto is fine, but if you want to specify the type here, that's fine too (as long as there are no implicit conversions, which I believe you mentioned there weren't any).

@khoidauminh khoidauminh requested a review from Veratil May 1, 2024 15:36
@sakertooth sakertooth merged commit d5f5d00 into LMMS:master May 2, 2024
9 checks passed
@khoidauminh khoidauminh deleted the fix-sample-shifting branch May 2, 2024 10:24
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.

3 participants