A game framework written with osu! in mind.
at master 69 lines 2.4 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 System.Collections.Specialized; 5using System.Diagnostics; 6using System.Linq; 7using osu.Framework.Allocation; 8using osu.Framework.Audio; 9using osu.Framework.Bindables; 10using osu.Framework.Graphics.Containers; 11using osuTK; 12 13namespace osu.Framework.Graphics.Visualisation.Audio 14{ 15 internal class AudioMixerVisualiser : ToolWindow 16 { 17 [Resolved] 18 private AudioManager audioManager { get; set; } 19 20 private readonly FillFlowContainer<MixerDisplay> mixerFlow; 21 private readonly IBindableList<int> activeMixerHandles = new BindableList<int>(); 22 23 public AudioMixerVisualiser() 24 : base("AudioMixer", "(Ctrl+F9 to toggle)") 25 { 26 ScrollContent.Expire(); 27 MainHorizontalContent.Add(new BasicScrollContainer(Direction.Horizontal) 28 { 29 RelativeSizeAxes = Axes.Y, 30 Width = WIDTH, 31 Children = new[] 32 { 33 mixerFlow = new FillFlowContainer<MixerDisplay> 34 { 35 RelativeSizeAxes = Axes.Y, 36 AutoSizeAxes = Axes.X, 37 Spacing = new Vector2(10), 38 Padding = new MarginPadding(10) 39 } 40 } 41 }); 42 } 43 44 protected override void LoadComplete() 45 { 46 base.LoadComplete(); 47 48 activeMixerHandles.BindTo(audioManager.ActiveMixerHandles); 49 activeMixerHandles.BindCollectionChanged(onActiveMixerHandlesChanged, true); 50 } 51 52 private void onActiveMixerHandlesChanged(object sender, NotifyCollectionChangedEventArgs e) => Schedule(() => 53 { 54 switch (e.Action) 55 { 56 case NotifyCollectionChangedAction.Add: 57 Debug.Assert(e.NewItems != null); 58 foreach (var handle in e.NewItems.OfType<int>()) 59 mixerFlow.Add(new MixerDisplay(handle)); 60 break; 61 62 case NotifyCollectionChangedAction.Remove: 63 Debug.Assert(e.OldItems != null); 64 mixerFlow.RemoveAll(m => e.OldItems.OfType<int>().Contains(m.MixerHandle)); 65 break; 66 } 67 }); 68 } 69}