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

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5c23a2c
Fixed a bug where custom playlist music order was ignored.
wezwery Oct 18, 2024
814d2ed
Return BeatmapSets visibility to private.
wezwery Oct 18, 2024
9ee8e4f
Removed nullable from IEnumerable<Live<BeatmapSetInfo>>
wezwery Oct 18, 2024
854a412
Formatting code and change equals methods.
wezwery Oct 19, 2024
aa57ca3
Add Playlist to MusicController. It seems to work.
wezwery Oct 21, 2024
7b989b5
Code formatting. Calling a method once per frame.
wezwery Oct 21, 2024
1916990
Register a realm notification for beatmaps changes. Tests seem to work.
wezwery Oct 23, 2024
a75ad5c
Added empty playlist checks to other tests in TestSceneMusicActionHan…
wezwery Oct 23, 2024
42d712b
Remove bad code. Add beatmapsets to MusicController.Playlist when Pla…
wezwery Oct 24, 2024
0fcd5e7
Adding spaces
wezwery Oct 24, 2024
d4aaa86
Get all beatmap sets when playlist is empty
wezwery Nov 1, 2024
bd467a6
Code Quality fix
wezwery Nov 1, 2024
138b516
Merge branch 'master' into music-player-queue-by-results
wezwery Nov 7, 2024
0400e8f
Update Playlist from PlaylistOverlay. Again.
wezwery Nov 11, 2024
e70fdc2
Directly add PlaylistOverlay to playlistContainer.
wezwery Nov 11, 2024
c4f95a9
Added logging to view the number of beatmap sets.
wezwery Nov 11, 2024
de0f002
Remove logging. Add beatmapsets on load. Change Clear to RemoveAll un…
wezwery Nov 15, 2024
412a254
Clear Playlist in MusicController when Realm have BeatmapSets changes.
wezwery Nov 15, 2024
f80a727
Revert changes in NowPlayingOverlay.cs
wezwery Nov 15, 2024
7c58c59
Revert changes in PlaylistOverlay.cs
wezwery Nov 15, 2024
e8197bf
Merge branch 'master' into music-player-queue-by-results
wezwery Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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