A game framework written with osu! in mind.
at master 3.1 kB view raw
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 osu.Framework.Allocation; 5using osu.Framework.Audio; 6using osu.Framework.Audio.Sample; 7using osu.Framework.Audio.Track; 8using osu.Framework.Graphics; 9using osu.Framework.Graphics.Audio; 10using osu.Framework.Graphics.Containers; 11using osu.Framework.Graphics.Visualisation.Audio; 12 13namespace osu.Framework.Tests.Visual.Testing 14{ 15 public class TestSceneAudioMixerVisualiser : FrameworkTestScene 16 { 17 private Container<TestAudioPlayingSource> mixedSources = new Container<TestAudioPlayingSource>(); 18 private TestAudioPlayingSource globalSource; 19 20 [BackgroundDependencyLoader] 21 private void load(AudioManager audioManager) 22 { 23 AudioMixerVisualiser visualiser; 24 25 Children = new Drawable[] 26 { 27 globalSource = new TestAudioPlayingSource(false), 28 mixedSources = new Container<TestAudioPlayingSource>(), 29 visualiser = new AudioMixerVisualiser() 30 }; 31 32 visualiser.Show(); 33 } 34 35 protected override void LoadComplete() 36 { 37 base.LoadComplete(); 38 39 addButtonsForSource("global", globalSource); 40 41 AddStep("add mixer", () => 42 { 43 var source = new TestAudioPlayingSource(true); 44 mixedSources.Add(source); 45 addButtonsForSource($"mixer {mixedSources.Count}", source); 46 }); 47 } 48 49 private void addButtonsForSource(string name, TestAudioPlayingSource source) 50 { 51 AddStep($"play track on {name}", source.PlayTrack); 52 AddStep($"stop track on {name}", source.StopTrack); 53 AddStep($"play sample on {name}", source.PlaySample); 54 55 if (source != globalSource) 56 AddStep($"remove mixer {name}", () => source.Expire()); 57 } 58 59 private class TestAudioPlayingSource : CompositeDrawable 60 { 61 private readonly bool withMixer; 62 private DrawableTrack track; 63 private DrawableSample sample; 64 65 public TestAudioPlayingSource(bool withMixer) 66 { 67 this.withMixer = withMixer; 68 } 69 70 [BackgroundDependencyLoader] 71 private void load(ITrackStore tracks, ISampleStore samples) 72 { 73 track = new DrawableTrack(tracks.Get("sample-track.mp3")); 74 sample = new DrawableSample(samples.Get("long.mp3")); 75 76 if (withMixer) 77 InternalChild = new DrawableAudioMixer { Children = new Drawable[] { track, sample } }; 78 else 79 InternalChildren = new Drawable[] { track, sample }; 80 } 81 82 public void PlayTrack() => Schedule(() => track.Start()); 83 public void StopTrack() => Schedule(() => track.Stop()); 84 public void PlaySample() => Schedule(() => sample.Play()); 85 } 86 } 87}