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

Revert "BeatGrid: Remove fuzzy behavior from findNthBeat" #4334

Closed
wants to merge 2 commits into from

Conversation

ywwg
Copy link
Member

@ywwg ywwg commented Sep 28, 2021

This reverts commit 95f7d36.

Due to floating point inaccuracy, it's not a good idea to blindly round beat positions without some amount of fuzz. The reverted change caused https://bugs.launchpad.net/mixxx/+bug/1945238

@Holzhaus
Copy link
Member

Holzhaus commented Sep 28, 2021

There must be way to fix this without doing the opposite of what the method name and documentation says (it should never be possible that findNextBeat returns a position before the search position). This is just wrong.

This rounding issue should be handled in the calling code, e. g. by calling findClosestBeat or something like that.

@Holzhaus
Copy link
Member

Please add a test for the actual issue where the beatloop size is wrong.

@JoergAtGithub
Copy link
Member

I struggled with the Fuzzy behaviour, while reimplementing the beat_active CO. It took me some debugging to find out, why my algorithm sometimes failed. The reason was that I got the wrong beat positions, due to this Epsilon in find prev/next beat. This was really unexpected behaviour.

@Be-ing
Copy link
Contributor

Be-ing commented Sep 28, 2021

I tested and confirm this fixes https://bugs.launchpad.net/mixxx/+bug/1942657

double nextBeat = ceil(beatFraction);

// If the position is within 1/100th of the next or previous beat, treat it
// as if it is that beat.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please elaborate in the comment explaining this is required due to the imprecision of floating points.

@Be-ing
Copy link
Contributor

Be-ing commented Sep 28, 2021

Please amend the commit message to link https://bugs.launchpad.net/mixxx/+bug/1945238 and https://bugs.launchpad.net/mixxx/+bug/1942657

@JoergAtGithub
Copy link
Member

Would this also work, if epsilon is smaller than the duration of one frame?
Than I would expect, that the issue, that the next beat is bevore the current position, will not occur anymore.

@Holzhaus
Copy link
Member

Holzhaus commented Sep 28, 2021

The fuzzyness should not be a feature of the beatgrid, it should be handled in the calling code where it's actually needed.

Otherwise it's extremely confusing (see #3418) and we'd have to rename findNextBeat to findNextBeatExceptSometimesWhenWeJustReturnThePreviousBeatInstead.

@Be-ing
Copy link
Contributor

Be-ing commented Sep 28, 2021

If it is required everywhere I think it should be handled in the called function, not the callers.

@Holzhaus
Copy link
Member

If it is required everywhere I think it should be handled in the called function, not the callers.

I doubt that it's needed everywhere.

@JoergAtGithub
Copy link
Member

It's definitely not required everywhere: For findPrevNextBeats, there are two callers, which would fail with the Fuzzy behaviour enabled. Therefore this function has the additonal argumnent to enable/disable this "snap tolerance".


// If the position is within 1/100th of the next or previous beat, treat it
// as if it is that beat.
const double kEpsilon = .01;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be passed as a parameter instead if hardcoding it, e.g. beatPositionTolerance. A value of 0.0 should disable the fuzzy behavior. The caller knows best about the precision of the position.

Copy link
Contributor

Choose a reason for hiding this comment

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

A 1/100th of a frame?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Holzhaus Other ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

What would be a use case for setting a different value for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Counter question: What is the rationale for the hard-coded constant 0.01?

Copy link
Contributor

Choose a reason for hiding this comment

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

I presume it was determined experimentally in the old code this is reverting to.

@ywwg
Copy link
Member Author

ywwg commented Sep 30, 2021

This is not a new PR with new code, it is just reverting back to the old code (with a tiny fix to the test so that it compiles).
This is the traditional approach for fixing a reversion bug: reverting the bad commit first to restore the correct behavior (which was working for years). After that we can talk about better ways to fix the behavior if we want to clean it up.

@Holzhaus
Copy link
Member

Holzhaus commented Sep 30, 2021

This is the traditional approach for fixing a reversion bug: reverting the bad commit first to restore the correct behavior (which was working for years).

Except that it doesn't restore "correct behavior" because the old code blatantly violated the spec and method documentation and sometimes did the opposite of what is expected. In that sense, this PR swaps out a bug with another (the latter is admittedly less severe because it's not user facing).

IIUC you were able to reproduce the issue with wrongly sized beatloops/beat jumps locally. This is why I asked if you could add a test for that instead of adding back a test that ensures the wrong method behavior. Then we can later revert this revert and implement another way to satisfy that test instead.

@ywwg
Copy link
Member Author

ywwg commented Sep 30, 2021

ok I think I can construct such a test -- it might be tricky because it relies on very small floating point errors, which may not be consistent between platforms. But if I can get it to fail on one, that's a start.

@ywwg
Copy link
Member Author

ywwg commented Sep 30, 2021

test added

@daschuer
Copy link
Member

daschuer commented Oct 4, 2021

Looking at the using code, I think the issue happens in most cases where we have found a beat in first step and we just need a corresponding other beat. This is translated to a position just to fulfill the interface of the findNthBeat() function.
If we use a function that is based on a beat self the rounding cant appear at all.
I am just verifying if this works for all invocations.

@ywwg
Copy link
Member Author

ywwg commented Oct 7, 2021

so can we at least merge the fix for the buggy behavior first?

@uklotzde
Copy link
Contributor

uklotzde commented Oct 7, 2021

Still waiting for a response to my review comments. That's what reviews are for.

@ywwg
Copy link
Member Author

ywwg commented Oct 7, 2021

why is it my job to fix these things? @Holzhaus wrote bad code which broke mixxx, and I identified the problem and a simple remedy to get back to a working state. I'm sorry I don't have time to improve on the state of the code as it used to be. Since Jan wanted to change this code, I feel like he should be responsible for fixing his own bug. I'm really sorry I don't have more time or energy to do this but I'm not working on this any more.

@ywwg
Copy link
Member Author

ywwg commented Oct 7, 2021

It is very hard to be in the position of being one of the only developers that seemingly uses mixxx on a regular basis. I find so many regressions and it's very hard to be asked by 5 different people to fix all of their bugs for them.

@uklotzde
Copy link
Contributor

uklotzde commented Oct 7, 2021

So you suggest us to stop working on Mixxx and leave it as is?

@uklotzde uklotzde dismissed their stale review October 7, 2021 13:42

My review doesn't seem to be welcome.

@ywwg
Copy link
Member Author

ywwg commented Oct 7, 2021

No, I'm asking us to follow basic software engineering process when fixing a bug: if a bad commit is found, revert the bad commit cleanly. then, after, consider the code and how it can be improved. Combining code improvements into a commit-revert is bad practice (fixing forward)

@ywwg
Copy link
Member Author

ywwg commented Oct 7, 2021

I do a lot of work on Mixxx, I have many PRs open on which I have addressed comments. But I am out of patience for review-creep on every review.

@ywwg
Copy link
Member Author

ywwg commented Oct 7, 2021

https://cloud.google.com/blog/products/gcp/reliable-releases-and-rollbacks-cre-life-lessons

" When an error is found or reasonably suspected in a new release, the releasing team rolls back first and investigates the problem second. A request for a rollback is not interpreted as an attack on the releasing team, or even the person who wrote the code containing the bug; rather, it is understood as The Right Thing To Do to make the system as reliable as possible for the user. No-one will ask “why did you roll back this change?” as long as the rollback changelist describes the problem that was seen."

They are talking about releases specifically, but the same thing applies to individual code commits. You start be resolving the problem. Then you take a look at improving the situation. This PR was supposed to be a rubber-stamp first step toward that goal. I do not have the time to improve every part of mixxx I find a problem with. Would you prefer I have not investigated this problem and found the bug at all? I have done my part, I would like to hand this issue off to someone else.

@ywwg
Copy link
Member Author

ywwg commented Oct 7, 2021

My review doesn't seem to be welcome.

These are perfectly good observations and notes for whomever wants to take another stab at fixing this code. A revert is not the right place to ask for those changes.

I wish y'all could see my PRs for my job, they are short and sweet and we do what we can to get code in and make things better. I'm not asking for anything that isn't industry standard.

@daschuer
Copy link
Member

daschuer commented Oct 7, 2021

I have made a good progress to fix the root cause. I think I can publish a PR today.

@daschuer daschuer mentioned this pull request Oct 7, 2021
@daschuer
Copy link
Member

daschuer commented Oct 7, 2021

Here it is: #4366

@ywwg ywwg closed this Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants