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 mods wrongly adding audio adjustments after being toggled off #18196

Closed

Conversation

bdach
Copy link
Collaborator

@bdach bdach commented May 9, 2022

Closes #18178.

First, an explanation why this broke. On master, ModTimeRamp stores a reference to the last track supplied on IApplicableToTrack:

this.track = track;

It then uses this track reference to access CurrentTime (which is not the problem), but also to dynamically add/remove audio adjustments when the "Adjust Pitch" option is toggled (which is the problem):

private void applyPitchAdjustment(ValueChangedEvent<bool> adjustPitchSetting)
{
// remove existing old adjustment
track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), SpeedChange);
track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), SpeedChange);
}

It turns out that this only worked correctly on the old overlay due to a particular ordering of operations. With the old mod overlay, the following happened:

On the new design, the ordering there ends up basically swapped - the adjustments are reset, the mod is reset to defaults after that, which causes an AdjustPitch change, which causes a dynamic adjustment to be added and triggers the bug.

Rather than focus on which ordering is correct, I initially resolved to add an IApplicableToTrack.UnapplyFromTrack() method, but then figured that this isn't really required so long as mods stop adding adjustments on held references to tracks. Which is what this pull does - ModTimeRamp and ModAdaptiveSpeed are changed so that they don't apply adjustments to held references to tracks, and ample warning is added to xmldoc to not do this. Unfortunately in ModTimeRamp I cannot fully get rid of the reference, as that mod also accesses ITrack.CurrentTime.

I know that @frenzibyte was really adamant about some fool-proof way to add adjustments that would make it impossible for this to ever happen, but (a) my brain somehow just stops working when reading any of that proposal, and (b) it doesn't solve the fact that ModTimeRamp needs ITrack to work, and at the point where you've got a track reference in hand again, you can bug out again.

@frenzibyte
Copy link
Member

frenzibyte commented May 9, 2022

I'm just going to note that I'm personally fine with either solutions, but I thought it may be better going the fool-proof way as it wouldn't require that many lines of changes (maybe, maybe not...), and have only brought it up initially as an overall improvement suggestion, yet I was failing to understand what the concern was about it.

I've looked into it and this is pretty much what I imagine to be done (275e5dc), with the second point in OP being fixed by using playfield.Clock.CurrentTime instead of track.CurrentTime.

@smoogipoo
Copy link
Contributor

I'm not against this, but I would also like to explore @frenzibyte 's version in the future, since I think that reads better.

smoogipoo
smoogipoo previously approved these changes May 10, 2022
@smoogipoo smoogipoo requested a review from peppy May 10, 2022 03:17
peppy
peppy previously approved these changes May 10, 2022
@peppy peppy enabled auto-merge May 10, 2022 10:49
@peppy peppy disabled auto-merge May 10, 2022 10:53
@peppy
Copy link
Member

peppy commented May 10, 2022

Honestly I was going to just let this one fly without worrying too much about the implementation, but I think @frenzibyte's proposal holds out better. At least I can understand the code by reading it, while this PR's unbind logic is a bit... hard to follow.

@frenzibyte can you PR your version with the test from this one to confirm it works as expected?

@peppy peppy dismissed their stale review May 10, 2022 10:54

probably alternative

@bdach
Copy link
Collaborator Author

bdach commented May 10, 2022

I have... several doubts about the correctness of the alternative, on a five second read. But whatever, if it gets PRed then I'll say my piece about it and leave it be, and you can decide which one you prefer.

@bdach
Copy link
Collaborator Author

bdach commented May 12, 2022

Closing as no longer required.

@bdach bdach closed this May 12, 2022
@bdach bdach deleted the mod-overlay/audio-adjustment-breakage-2 branch May 12, 2022 06:52
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.

Deselecting Wind Up/Down mod when pitch adjustment is turned off results in it turning back on
4 participants