Add asserts to ensure correct state when attaching/detaching the filter

This commit is contained in:
Jamie Taylor 2021-10-06 17:34:24 +09:00
parent fc0c3e8758
commit bd0c986144
No known key found for this signature in database
GPG Key ID: 2ACFA8B6370B8C8C
1 changed files with 16 additions and 5 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Diagnostics;
using ManagedBass.Fx;
using osu.Framework.Audio.Mixing;
using osu.Framework.Bindables;
@ -44,7 +45,7 @@ public Filter(AudioMixer mixer, BQFType type = BQFType.LowPass)
break;
}
Cutoff = new BindableNumber<int>
Cutoff = new BindableNumber<int>(initialCutoff)
{
MinValue = 1,
MaxValue = MaxCutoff
@ -57,14 +58,24 @@ public Filter(AudioMixer mixer, BQFType type = BQFType.LowPass)
fQ = 0.7f // This allows fCenter to go up to 22049hz (nyquist - 1hz) without overflowing and causing weird filter behaviour (see: https://www.un4seen.com/forum/?topic=19542.0)
};
attachFilter();
// Don't start attached if this is low-pass or high-pass filter (as they have special auto-attach/detach logic)
if (type != BQFType.LowPass && type != BQFType.HighPass)
attachFilter();
Cutoff.ValueChanged += updateFilter;
Cutoff.Value = initialCutoff;
}
private void attachFilter() => mixer.Effects.Add(filter);
private void attachFilter()
{
Debug.Assert(!mixer.Effects.Contains(filter));
mixer.Effects.Add(filter);
}
private void detachFilter() => mixer.Effects.Remove(filter);
private void detachFilter()
{
Debug.Assert(mixer.Effects.Contains(filter));
mixer.Effects.Remove(filter);
}
private void updateFilter(ValueChangedEvent<int> cutoff)
{