1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 15:32:56 +08:00
osu-lazer/osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs

71 lines
2.5 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Overlays.Options.Sections.Audio
{
public class AudioDevicesOptions : OptionsSubsection
{
protected override string Header => "Devices";
private AudioManager audio;
2017-03-22 22:32:32 +08:00
private OptionDropdown<string> dropdown;
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
this.audio = audio;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
audio.OnNewDevice -= onDeviceChanged;
audio.OnLostDevice -= onDeviceChanged;
}
private void updateItems()
{
2017-03-07 09:59:19 +08:00
var deviceItems = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("Default", string.Empty) };
deviceItems.AddRange(audio.AudioDeviceNames.Select(d => new KeyValuePair<string, string>(d, d)));
var preferredDeviceName = audio.AudioDevice.Value;
2017-03-07 09:59:19 +08:00
if (deviceItems.All(kv => kv.Value != preferredDeviceName))
deviceItems.Add(new KeyValuePair<string, string>(preferredDeviceName, preferredDeviceName));
// The option dropdown for audio device selection lists all audio
// device names. Dropdowns, however, may not have multiple identical
// keys. Thus, we remove duplicate audio device names from
// the dropdown. BASS does not give us a simple mechanism to select
2017-04-08 17:01:41 +08:00
// specific audio devices in such a case anyways. Such
// functionality would require involved OS-specific code.
dropdown.Items = deviceItems.Distinct().ToList();
}
private void onDeviceChanged(string name) => updateItems();
protected override void LoadComplete()
{
base.LoadComplete();
Children = new Drawable[]
{
2017-03-22 22:32:32 +08:00
dropdown = new OptionDropdown<string>
{
Bindable = audio.AudioDevice
},
};
updateItems();
audio.OnNewDevice += onDeviceChanged;
audio.OnLostDevice += onDeviceChanged;
}
}
2016-11-03 12:26:49 +08:00
}