diff --git a/osu-framework b/osu-framework index 6b44a9f807..a7edf9bb3b 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 6b44a9f807fadcb3b3f044780d7e27d62ffe80ac +Subproject commit a7edf9bb3bae6908f316ba0ee9dacdbbb66e8c19 diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 939c4a4915..7a2d91d733 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -133,9 +133,27 @@ namespace osu.Game Token = LocalConfig.Get(OsuSetting.Token) }); + Beatmap.ValueChanged += b => + { + // compare to last baetmap as sometimes the two may share a track representation (optimisation, see WorkingBeatmap.TransferTo) + if (lastBeatmap?.Track != b.Track) + { + // this disposal is done to stop the audio track. + // it may not be exactly what we want for cases beatmaps are reused, as it will + // trigger a fresh load of contained resources. + lastBeatmap?.Dispose(); + + Audio.Track.AddItem(b.Track); + } + + lastBeatmap = b; + }; + API.Register(this); } + private WorkingBeatmap lastBeatmap; + public void APIStateChanged(APIAccess api, APIState state) { switch (state) diff --git a/osu.Game/Overlays/Music/PlaylistOverlay.cs b/osu.Game/Overlays/Music/PlaylistOverlay.cs index 87c0afebf7..1e4c3c5ff6 100644 --- a/osu.Game/Overlays/Music/PlaylistOverlay.cs +++ b/osu.Game/Overlays/Music/PlaylistOverlay.cs @@ -3,9 +3,7 @@ using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using osu.Framework.Allocation; -using osu.Framework.Audio.Track; using osu.Framework.Configuration; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; @@ -15,7 +13,6 @@ using osu.Game.Database; using osu.Game.Graphics; using OpenTK; using OpenTK.Graphics; -using osu.Framework.Extensions; using osu.Framework.Input; using osu.Framework.Graphics.Shapes; @@ -30,7 +27,6 @@ namespace osu.Game.Overlays.Music private FilterControl filter; private PlaylistList list; - private TrackManager trackManager; private BeatmapDatabase beatmaps; private readonly Bindable beatmapBacking = new Bindable(); @@ -43,7 +39,6 @@ namespace osu.Game.Overlays.Music { this.inputManager = inputManager; this.beatmaps = beatmaps; - trackManager = game.Audio.Track; Children = new Drawable[] { @@ -154,13 +149,7 @@ namespace osu.Game.Overlays.Music private void playSpecified(BeatmapInfo info) { beatmapBacking.Value = beatmaps.GetWorkingBeatmap(info, beatmapBacking); - - Task.Run(() => - { - var track = beatmapBacking.Value.Track; - trackManager.SetExclusive(track); - track.Start(); - }).ContinueWith(task => Schedule(task.ThrowIfFaulted), TaskContinuationOptions.OnlyOnFaulted); + beatmapBacking.Value.Track.Start(); } } diff --git a/osu.Game/Screens/Menu/Intro.cs b/osu.Game/Screens/Menu/Intro.cs index aeb5282666..6e42a1bae9 100644 --- a/osu.Game/Screens/Menu/Intro.cs +++ b/osu.Game/Screens/Menu/Intro.cs @@ -72,8 +72,6 @@ namespace osu.Game.Screens.Menu menuVoice = config.GetBindable(OsuSetting.MenuVoice); menuMusic = config.GetBindable(OsuSetting.MenuMusic); - var trackManager = audio.Track; - BeatmapSetInfo setInfo = null; if (!menuMusic) @@ -106,7 +104,6 @@ namespace osu.Game.Screens.Menu Beatmap.Value = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]); track = Beatmap.Value.Track; - trackManager.SetExclusive(track); welcome = audio.Sample.Get(@"welcome"); seeya = audio.Sample.Get(@"seeya"); diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 40f24a77c9..4bbb47d419 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -119,10 +119,7 @@ namespace osu.Game.Screens.Play Track track = Beatmap.Value.Track; if (track != null) - { - audio.Track.SetExclusive(track); adjustableSourceClock = track; - } adjustableSourceClock = (IAdjustableClock)track ?? new StopwatchClock(); diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index ea012f45e4..40cf586c06 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -32,7 +32,6 @@ namespace osu.Game.Screens.Select protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(); private readonly BeatmapCarousel carousel; - private TrackManager trackManager; private DialogOverlay dialogOverlay; private static readonly Vector2 wedged_container_size = new Vector2(0.5f, 245); @@ -174,7 +173,6 @@ namespace osu.Game.Screens.Select database.BeatmapSetAdded += onBeatmapSetAdded; database.BeatmapSetRemoved += onBeatmapSetRemoved; - trackManager = audio.Track; dialogOverlay = dialog; sampleChangeDifficulty = audio.Sample.Get(@"SongSelect/select-difficulty"); @@ -358,10 +356,11 @@ namespace osu.Game.Screens.Select { Track track = Beatmap.Value.Track; - trackManager.SetExclusive(track); - - if (preview) track.Seek(Beatmap.Value.Metadata.PreviewTime); - track.Start(); + if (!track.IsRunning) + { + if (preview) track.Seek(Beatmap.Value.Metadata.PreviewTime); + track.Start(); + } } private void removeBeatmapSet(BeatmapSetInfo beatmapSet)