2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2017-02-06 19:26:32 +08:00
|
|
|
|
|
2017-02-06 08:22:37 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2017-05-15 09:55:29 +08:00
|
|
|
|
namespace osu.Game.Overlays.Settings.Sections.Audio
|
2017-02-06 19:26:32 +08:00
|
|
|
|
{
|
2017-05-15 09:55:29 +08:00
|
|
|
|
public class AudioDevicesSettings : SettingsSubsection
|
2017-02-06 19:26:32 +08:00
|
|
|
|
{
|
|
|
|
|
protected override string Header => "Devices";
|
|
|
|
|
|
|
|
|
|
private AudioManager audio;
|
2017-05-15 09:55:29 +08:00
|
|
|
|
private SettingsDropdown<string> dropdown;
|
2017-02-06 19:26:32 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2017-02-06 08:22:37 +08:00
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
|
|
|
|
this.audio = audio;
|
2017-02-06 19:26:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-11 23:29:33 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2017-02-06 08:22:37 +08:00
|
|
|
|
{
|
2017-02-11 23:29:33 +08:00
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
2017-08-16 19:16:40 +08:00
|
|
|
|
if (audio != null)
|
|
|
|
|
{
|
|
|
|
|
audio.OnNewDevice -= onDeviceChanged;
|
|
|
|
|
audio.OnLostDevice -= onDeviceChanged;
|
|
|
|
|
}
|
2017-02-11 23:29:33 +08:00
|
|
|
|
}
|
2017-02-06 08:22:37 +08:00
|
|
|
|
|
2017-02-11 23:29:33 +08:00
|
|
|
|
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) };
|
2017-02-11 23:29:33 +08:00
|
|
|
|
deviceItems.AddRange(audio.AudioDeviceNames.Select(d => new KeyValuePair<string, string>(d, d)));
|
2017-02-11 23:33:54 +08:00
|
|
|
|
|
|
|
|
|
var preferredDeviceName = audio.AudioDevice.Value;
|
2017-03-07 09:59:19 +08:00
|
|
|
|
if (deviceItems.All(kv => kv.Value != preferredDeviceName))
|
2017-02-11 23:33:54 +08:00
|
|
|
|
deviceItems.Add(new KeyValuePair<string, string>(preferredDeviceName, preferredDeviceName));
|
|
|
|
|
|
2017-04-07 23:00:34 +08:00
|
|
|
|
// 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.
|
2017-04-07 23:00:34 +08:00
|
|
|
|
dropdown.Items = deviceItems.Distinct().ToList();
|
2017-02-11 23:29:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onDeviceChanged(string name) => updateItems();
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2017-02-06 19:26:32 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-10-22 11:52:57 +08:00
|
|
|
|
dropdown = new SettingsDropdown<string>()
|
2017-02-06 08:22:37 +08:00
|
|
|
|
};
|
2017-02-11 23:29:33 +08:00
|
|
|
|
|
|
|
|
|
updateItems();
|
|
|
|
|
|
2017-09-18 21:32:49 +08:00
|
|
|
|
dropdown.Bindable = audio.AudioDevice;
|
|
|
|
|
|
2017-02-11 23:29:33 +08:00
|
|
|
|
audio.OnNewDevice += onDeviceChanged;
|
|
|
|
|
audio.OnLostDevice += onDeviceChanged;
|
2017-02-06 19:26:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-03 12:26:49 +08:00
|
|
|
|
}
|