A game framework written with osu! in mind.
at master 68 lines 2.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 System.Linq; 5using ManagedBass.Mix; 6using osu.Framework.Extensions.Color4Extensions; 7using osu.Framework.Graphics.Containers; 8using osu.Framework.Graphics.Shapes; 9using osuTK; 10using osuTK.Graphics; 11 12namespace osu.Framework.Graphics.Visualisation.Audio 13{ 14 public class MixerDisplay : CompositeDrawable 15 { 16 public readonly int MixerHandle; 17 18 private readonly FillFlowContainer<AudioChannelDisplay> channelsContainer; 19 20 public MixerDisplay(int mixerHandle) 21 { 22 MixerHandle = mixerHandle; 23 24 RelativeSizeAxes = Axes.Y; 25 AutoSizeAxes = Axes.X; 26 27 InternalChild = new Container 28 { 29 RelativeSizeAxes = Axes.Y, 30 AutoSizeAxes = Axes.X, 31 Children = new Drawable[] 32 { 33 new Box 34 { 35 RelativeSizeAxes = Axes.Both, 36 Colour = Color4.Black.Opacity(0.2f) 37 }, 38 channelsContainer = new FillFlowContainer<AudioChannelDisplay> 39 { 40 RelativeSizeAxes = Axes.Y, 41 AutoSizeAxes = Axes.X, 42 Direction = FillDirection.Horizontal, 43 Spacing = new Vector2(10), 44 Padding = new MarginPadding { Horizontal = 10 } 45 } 46 } 47 }; 48 } 49 50 protected override void Update() 51 { 52 base.Update(); 53 54 var channels = BassMix.MixerGetChannels(MixerHandle); 55 56 if (channels == null) 57 return; 58 59 foreach (var channel in channels) 60 { 61 if (channelsContainer.All(ch => ch.ChannelHandle != channel)) 62 channelsContainer.Add(new AudioChannelDisplay(channel)); 63 } 64 65 channelsContainer.RemoveAll(ch => !channels.Contains(ch.ChannelHandle)); 66 } 67 } 68}