Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom playlist music order was ignored. Queue music by filter and collection. #30343

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions osu.Game/Overlays/Music/Playlist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
Expand Down Expand Up @@ -49,6 +50,7 @@ public void Filter(FilterCriteria criteria)
}

public Live<BeatmapSetInfo>? FirstVisibleSet => Items.FirstOrDefault(i => ((PlaylistItem)ItemMap[i]).MatchingFilter);
public IEnumerable<Live<BeatmapSetInfo>> AllVisibleSets => Items.Where(i => ((PlaylistItem)ItemMap[i]).MatchingFilter);

protected override OsuRearrangeableListItem<Live<BeatmapSetInfo>> CreateOsuDrawable(Live<BeatmapSetInfo> item) =>
new PlaylistItem(item)
Expand Down
12 changes: 6 additions & 6 deletions osu.Game/Overlays/Music/PlaylistOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public partial class PlaylistOverlay : VisibilityContainer
private IDisposable beatmapSubscription;

private FilterControl filter;
private Playlist list;
public Playlist List;

[BackgroundDependencyLoader]
private void load(OsuColour colours, Bindable<WorkingBeatmap> beatmap)
Expand All @@ -66,7 +66,7 @@ private void load(OsuColour colours, Bindable<WorkingBeatmap> beatmap)
Colour = colours.Gray3,
RelativeSizeAxes = Axes.Both,
},
list = new Playlist
List = new Playlist
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 95, Bottom = 10, Right = 10 },
Expand All @@ -76,7 +76,7 @@ private void load(OsuColour colours, Bindable<WorkingBeatmap> beatmap)
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
FilterChanged = criteria => list.Filter(criteria),
FilterChanged = criteria => List.Filter(criteria),
Padding = new MarginPadding(10),
},
},
Expand All @@ -85,7 +85,7 @@ private void load(OsuColour colours, Bindable<WorkingBeatmap> beatmap)

filter.Search.OnCommit += (_, _) =>
{
list.FirstVisibleSet?.PerformRead(set =>
List.FirstVisibleSet?.PerformRead(set =>
{
BeatmapInfo toSelect = set.Beatmaps.FirstOrDefault();

Expand All @@ -104,8 +104,8 @@ protected override void LoadComplete()

beatmapSubscription = realm.RegisterForNotifications(r => r.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected), beatmapsChanged);

list.Items.BindTo(beatmapSets);
beatmap.BindValueChanged(working => list.SelectedSet.Value = working.NewValue.BeatmapSetInfo.ToLive(realm), true);
List.Items.BindTo(beatmapSets);
beatmap.BindValueChanged(working => List.SelectedSet.Value = working.NewValue.BeatmapSetInfo.ToLive(realm), true);
}

private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes)
Expand Down
42 changes: 25 additions & 17 deletions osu.Game/Overlays/MusicController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public void ReloadCurrentTrack()

private ScheduledDelegate? seekDelegate;

private IEnumerable<Live<BeatmapSetInfo>>? currentPlaylist;

public void SeekTo(double position)
{
seekDelegate?.Cancel();
Expand Down Expand Up @@ -223,9 +225,12 @@ public bool TogglePause()
/// </summary>
/// <param name="onSuccess">Invoked when the operation has been performed successfully.</param>
/// <param name="allowProtectedTracks">Whether to include <see cref="BeatmapSetInfo.Protected"/> beatmap sets when navigating.</param>
public void PreviousTrack(Action<PreviousTrackResult>? onSuccess = null, bool allowProtectedTracks = false) => Schedule(() =>
/// <param name="playlist">A playlist to navigate through. Otherwise use the current or list of all beatmap sets.</param>
public void PreviousTrack(Action<PreviousTrackResult>? onSuccess = null, bool allowProtectedTracks = false, IEnumerable<Live<BeatmapSetInfo>>? playlist = null) => Schedule(() =>
wezwery marked this conversation as resolved.
Show resolved Hide resolved
{
PreviousTrackResult res = prev(allowProtectedTracks);
if (playlist != null && !EqualityComparer<IEnumerable<Live<BeatmapSetInfo>>?>.Default.Equals(playlist, currentPlaylist))
currentPlaylist = playlist;
PreviousTrackResult res = prev(allowProtectedTracks, currentPlaylist);
if (res != PreviousTrackResult.None)
onSuccess?.Invoke(res);
});
Expand All @@ -234,8 +239,9 @@ public void PreviousTrack(Action<PreviousTrackResult>? onSuccess = null, bool al
/// Play the previous track or restart the current track if it's current time below <see cref="restart_cutoff_point"/>.
/// </summary>
/// <param name="allowProtectedTracks">Whether to include <see cref="BeatmapSetInfo.Protected"/> beatmap sets when navigating.</param>
/// <param name="playlist">A playlist to navigate through. Otherwise use the current or list of all beatmap sets.</param>
/// <returns>The <see cref="PreviousTrackResult"/> that indicate the decided action.</returns>
private PreviousTrackResult prev(bool allowProtectedTracks)
private PreviousTrackResult prev(bool allowProtectedTracks, IEnumerable<Live<BeatmapSetInfo>>? playlist = null)
{
if (beatmap.Disabled || !AllowTrackControl.Value)
return PreviousTrackResult.None;
Expand All @@ -253,11 +259,11 @@ private PreviousTrackResult prev(bool allowProtectedTracks)
Live<BeatmapSetInfo>? playableSet;

if (Shuffle.Value)
playableSet = getNextRandom(-1, allowProtectedTracks);
playableSet = getNextRandom(-1, allowProtectedTracks, playlist);
else
{
playableSet = getBeatmapSets().TakeWhile(i => !i.Value.Equals(current?.BeatmapSetInfo)).LastOrDefault(s => !s.Value.Protected || allowProtectedTracks)
?? getBeatmapSets().LastOrDefault(s => !s.Value.Protected || allowProtectedTracks);
playableSet = (playlist ?? getBeatmapSets()).TakeWhile(i => !i.Value.Equals(current?.BeatmapSetInfo)).LastOrDefault(s => !s.Value.Protected || allowProtectedTracks)
?? (playlist ?? getBeatmapSets()).LastOrDefault(s => !s.Value.Protected || allowProtectedTracks);
}

if (playableSet != null)
Expand All @@ -275,10 +281,12 @@ private PreviousTrackResult prev(bool allowProtectedTracks)
/// </summary>
/// <param name="onSuccess">Invoked when the operation has been performed successfully.</param>
/// <param name="allowProtectedTracks">Whether to include <see cref="BeatmapSetInfo.Protected"/> beatmap sets when navigating.</param>
/// <returns>A <see cref="ScheduledDelegate"/> of the operation.</returns>
public void NextTrack(Action? onSuccess = null, bool allowProtectedTracks = false) => Schedule(() =>
/// <param name="playlist">A playlist to navigate through. Otherwise use the current or list of all beatmap sets.</param>
public void NextTrack(Action? onSuccess = null, bool allowProtectedTracks = false, IEnumerable<Live<BeatmapSetInfo>>? playlist = null) => Schedule(() =>
{
bool res = next(allowProtectedTracks);
if (playlist != null && !EqualityComparer<IEnumerable<Live<BeatmapSetInfo>>?>.Default.Equals(playlist, currentPlaylist))
currentPlaylist = playlist;
bool res = next(allowProtectedTracks, currentPlaylist);
if (res)
onSuccess?.Invoke();
});
Expand Down Expand Up @@ -339,7 +347,7 @@ public void DuckMomentarily(double delayUntilRestore, DuckParameters? parameters
Scheduler.AddDelayed(() => duckOperation.Dispose(), delayUntilRestore);
}

private bool next(bool allowProtectedTracks)
private bool next(bool allowProtectedTracks, IEnumerable<Live<BeatmapSetInfo>>? playlist = null)
{
if (beatmap.Disabled || !AllowTrackControl.Value)
return false;
Expand All @@ -349,13 +357,13 @@ private bool next(bool allowProtectedTracks)
Live<BeatmapSetInfo>? playableSet;

if (Shuffle.Value)
playableSet = getNextRandom(1, allowProtectedTracks);
playableSet = getNextRandom(1, allowProtectedTracks, playlist);
else
{
playableSet = getBeatmapSets().SkipWhile(i => !i.Value.Equals(current?.BeatmapSetInfo))
.Where(i => !i.Value.Protected || allowProtectedTracks)
.ElementAtOrDefault(1)
?? getBeatmapSets().FirstOrDefault(i => !i.Value.Protected || allowProtectedTracks);
playableSet = (playlist ?? getBeatmapSets()).SkipWhile(i => !i.Value.Equals(current?.BeatmapSetInfo))
.Where(i => !i.Value.Protected || allowProtectedTracks)
.ElementAtOrDefault(1)
?? (playlist ?? getBeatmapSets()).FirstOrDefault(i => !i.Value.Protected || allowProtectedTracks);
}

var playableBeatmap = playableSet?.Value.Beatmaps.FirstOrDefault();
Expand All @@ -370,13 +378,13 @@ private bool next(bool allowProtectedTracks)
return false;
}

private Live<BeatmapSetInfo>? getNextRandom(int direction, bool allowProtectedTracks)
private Live<BeatmapSetInfo>? getNextRandom(int direction, bool allowProtectedTracks, IEnumerable<Live<BeatmapSetInfo>>? playlist = null)
{
try
{
Live<BeatmapSetInfo> result;

var possibleSets = getBeatmapSets().Where(s => !s.Value.Protected || allowProtectedTracks).ToList();
var possibleSets = (playlist ?? getBeatmapSets()).Where(s => !s.Value.Protected || allowProtectedTracks).ToList();

if (possibleSets.Count == 0)
return null;
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Overlays/NowPlayingOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void load()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Action = () => musicController.PreviousTrack(),
Action = () => musicController.PreviousTrack(playlist: playlist?.List.AllVisibleSets),
Icon = FontAwesome.Solid.StepBackward,
},
playButton = new MusicIconButton
Expand All @@ -161,7 +161,7 @@ private void load()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Action = () => musicController.NextTrack(),
Action = () => musicController.NextTrack(playlist: playlist?.List.AllVisibleSets),
Icon = FontAwesome.Solid.StepForward,
},
}
Expand Down