A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System.Diagnostics;
5using ManagedBass;
6using osu.Framework.Allocation;
7using osu.Framework.Audio;
8using osu.Framework.Audio.Mixing;
9using osu.Framework.Bindables;
10using osu.Framework.Graphics.Containers;
11
12namespace osu.Framework.Graphics.Audio
13{
14 public class DrawableAudioMixer : AudioContainer, IAudioMixer
15 {
16 private AudioMixer mixer;
17
18 [BackgroundDependencyLoader]
19 private void load(AudioManager audio)
20 {
21 mixer = audio.CreateAudioMixer();
22 mixer.Effects.BindTo(Effects);
23 }
24
25 public BindableList<IEffectParameter> Effects { get; } = new BindableList<IEffectParameter>();
26
27 public void Add(IAudioChannel channel)
28 {
29 if (LoadState < LoadState.Ready)
30 Schedule(() => mixer.Add(channel));
31 else
32 {
33 Debug.Assert(mixer != null);
34 mixer.Add(channel);
35 }
36 }
37
38 public void Remove(IAudioChannel channel)
39 {
40 if (LoadState < LoadState.Ready)
41 Schedule(() => mixer.Remove(channel));
42 else
43 {
44 Debug.Assert(mixer != null);
45 mixer.Remove(channel);
46 }
47 }
48
49 protected override void Dispose(bool isDisposing)
50 {
51 base.Dispose(isDisposing);
52 mixer?.Dispose();
53 }
54 }
55}