Add an option to change behavior of `IsAlive` in SampleChannel
This PR provides an option to change behavior of IsAlive in SampleChannel. To make auto-free work, https://github.com/ppy/osu-framework/pull/6397 is required.
If ManualFree is false (default), it works the same as before: IsAlive will be false after Stop or the end of playback.
If ManualFree is true, IsAlive will never be true until the user explicitly calls Dispose.
It also contains a fix for an issue where calling Play after disposal makes Playing true.
Should we make
SampleChannelsnot resumable?
How about we add a bool ManualFree { get; set; } to the interface? Opposite of BASS' auto-free because interfaces can't have default values (we really should be doing sample.GetChannel(new ChannelProperties { ... }) or similar, but...).
And then, every other case should auto-free when playback ends or Stop() is called.
I believe everywhere in osu! we operate under the assumption that channels are auto-freeing by default as I believe that's effectively how they work in BASS when they're HCHANNELs, so this could be considered a regression from when mixers were added (and they were made into HSTREAMs).
I think adding ManualFree flag is unnecessary as it's only relevant when Looping is true. Adding a comment about this may be helpful?
When
Loopingis false,SampleChannelis automatically disposed once playback ends, but whenLoopingis true, you're responsible for disposing this channel manually, as the framework can't detect its end.
So what happens when the channel is played, manually stopped, and the ISample is just left to live (as we never dispose samples in game)? It sounds like in this case samples would never be disposed, no?
That's right. I'll live until it gets disposed somehow.
I think there is a misunderstanding about ManualFree. Do you want channels to be unable to resume playback once it is stopped when ManualFree is false?
I first assumed that you don't want such behavior, but I guess I misread your comment.
I'm okay with that if that's what you mean.
Yeah, my idea is to consider Stop() the same as playback end. That way everything is safe except when you set ManualFree = true, which is the only case you need to make a conscious effort to handle it.