Skip to content

Add a sub-menu to the shuffle playlist menu to decide how to shuffle.#2037

Open
Vinzzzze wants to merge 1 commit into
strawberrymusicplayer:masterfrom
Vinzzzze:shuffle_playlist
Open

Add a sub-menu to the shuffle playlist menu to decide how to shuffle.#2037
Vinzzzze wants to merge 1 commit into
strawberrymusicplayer:masterfrom
Vinzzzze:shuffle_playlist

Conversation

@Vinzzzze

@Vinzzzze Vinzzzze commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

Change the menu Shuffle playlist (mainwindow ui) to offer three shuffle modes :

  • track based shuffle (the actual playlist shuffle mode)
  • album based shuffle : shuffle the playlist by album and make the album played in the track number order
  • grouped track shuffle : keep the grouped tracks together, other tracks and distinct track group are shuffled.

Correct what I consider as an issue : when playing a playlist with a mode shuffle grouped, the tracks are played in the order they have in the playlist. Grouped tracks must be played following the track number order.

Update mainwindow for updating the menus
Update playlist to make the ReshuffleIndices reusable for both Reshuffling indices when playing in shuffle mode and when shuffling the playlist from the menu. I left some commented code with a TODO mark for some code linked to another PR to remind me what to do when I will merge one branch in the other.
Update the playlistmanager and it's interface to handle the choice we can now make while shuffling a playlist.
Add the translations for the created menu

Summary by CodeRabbit

  • New Features
    • Added a Shuffle playlist submenu with three mutually-exclusive modes: Single track as random element, Album as random element, and Grouped tracks as random element (existing Ctrl+H preserved for the single-track mode).
  • Behavior Updates
    • Shuffle is now mode-aware.
    • Album and Grouped modes keep album/group boundaries and preserve disc/track ordering within the selected album or group while randomizing the chosen units.

@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch 4 times, most recently from b67c38c to 37f312f Compare March 20, 2026 18:24
Comment thread src/playlist/playlist.cpp Outdated
Comment thread src/playlist/playlist.cpp Outdated
Comment thread src/playlist/playlist.h Outdated
Comment thread src/playlist/playlist.h Outdated
@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch 3 times, most recently from da0abb6 to 151a5d1 Compare April 4, 2026 18:36
@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch 3 times, most recently from 9f20871 to b40c2ea Compare April 10, 2026 19:29
@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch 5 times, most recently from 7294324 to 32dc249 Compare April 23, 2026 22:53
@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch 3 times, most recently from b293551 to c867763 Compare May 10, 2026 21:41
@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch from c867763 to 46e9772 Compare May 17, 2026 14:13
@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch 4 times, most recently from 63f0947 to e01dd29 Compare May 31, 2026 14:47
@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch 2 times, most recently from 0d83afe to 669ccd7 Compare June 5, 2026 19:19
@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch 2 times, most recently from ef4b509 to 59bfc08 Compare June 13, 2026 18:52
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Three shuffle modes are added across the playlist API, shuffle logic, and main window menu wiring. The playlist manager now forwards a selected mode, the shuffle algorithm branches by mode, and the shuffle action opens a submenu for all, albums, or grouped tracks.

Changes

Mode-aware playlist shuffle with submenu UI

Layer / File(s) Summary
Shuffle API contracts and forwarding
src/playlist/playlist.h, src/playlist/playlistmanagerinterface.h, src/playlist/playlistmanager.h, src/playlist/playlistmanager.cpp
Playlist::Shuffle now takes PlaylistSequence::ShuffleMode with a default of All; ReshuffleIndices(...) is declared; PlaylistManagerInterface and PlaylistManager add ShuffleCurrent(ShuffleMode), and the manager forwards that mode to current()->Shuffle(shuffle_mode).
Mode-aware shuffle algorithm in Playlist
src/playlist/playlist.cpp
Shuffle() now builds mode-specific eligible indices and reconstructs items after reshuffling. The helper handles Off, All, InsideAlbum, Albums, and Grouping, including album/group key handling, front-forcing of the current reference, and track-order-preserving sorting.
Shuffle submenu UI and handler
src/core/mainwindow.ui, src/core/mainwindow.h, src/core/mainwindow.cpp
action_shuffle is relabeled, three non-checkable shuffle-mode actions are added, and MainWindow builds a submenu backed by QActionGroup. The old direct shuffle connection is removed, and a new slot maps the selected action to a shuffle mode and calls ShuffleCurrent.

Sequence Diagram

sequenceDiagram
  participant User
  participant MainWindow
  participant PlaylistManager
  participant Playlist

  User->>MainWindow: selects shuffle submenu action
  MainWindow->>MainWindow: ShufflePlaylistActionTriggered(QAction*)
  MainWindow->>PlaylistManager: ShuffleCurrent(ShuffleMode)
  PlaylistManager->>Playlist: Shuffle(ShuffleMode)
  Playlist->>Playlist: ReshuffleIndices(virtual_items, ShuffleMode, album_keep_track_order)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I hop through tracks with shuffle cheer,
Three modes now twirl and dart right here.
Albums, groups, or all in play,
A submenu guides the merry way.
With ears a-twitch and paws alight,
The playlist dances through the night.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.65% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a shuffle submenu to choose among shuffle modes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/playlist/playlist.cpp`:
- Around line 2194-2196: The reference front-forcing logic has index arithmetic
issues at three locations in playlist.cpp. At lines 2194-2196, the condition
checks if reference_row is greater than base_reference but does not validate
that the adjusted index (reference_row - base_reference) is within bounds of
virtual_items; when the reference row is excluded (e.g., in ShuffleMode::All),
this can cause an out-of-bounds access. Fix this by ensuring the adjusted index
is less than the size of virtual_items. At lines 2225-2227 and 2278-2280, the
code subtracts base_reference from pos when performing the swap operations, but
pos is already relative to shuffled_*_keys, so the subtraction causes incorrect
indexing; remove the base_reference subtraction from both locations since pos
does not need adjustment.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e17dc230-f4f9-405d-a6dd-4aa6f4bff545

📥 Commits

Reviewing files that changed from the base of the PR and between de3ad29 and ba28391.

📒 Files selected for processing (8)
  • src/core/mainwindow.cpp
  • src/core/mainwindow.h
  • src/core/mainwindow.ui
  • src/playlist/playlist.cpp
  • src/playlist/playlist.h
  • src/playlist/playlistmanager.cpp
  • src/playlist/playlistmanager.h
  • src/playlist/playlistmanagerinterface.h

Comment thread src/playlist/playlist.cpp Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/playlist/playlist.h`:
- Around line 370-371: The ReshuffleIndices function declaration is missing a
comma between the shuffle_mode parameter and the const bool
album_keep_track_order parameter. Add a comma after shuffle_mode to fix the
syntax error in the parameter list.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 41daddfc-5ae5-49f0-b363-483a4ac1c5fa

📥 Commits

Reviewing files that changed from the base of the PR and between ba28391 and bf6d7b9.

📒 Files selected for processing (8)
  • src/core/mainwindow.cpp
  • src/core/mainwindow.h
  • src/core/mainwindow.ui
  • src/playlist/playlist.cpp
  • src/playlist/playlist.h
  • src/playlist/playlistmanager.cpp
  • src/playlist/playlistmanager.h
  • src/playlist/playlistmanagerinterface.h
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/playlist/playlistmanager.h
  • src/playlist/playlistmanagerinterface.h
  • src/core/mainwindow.ui
  • src/core/mainwindow.h
  • src/core/mainwindow.cpp

Comment thread src/playlist/playlist.h Outdated
@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch 2 times, most recently from f58a918 to 72d39a8 Compare June 21, 2026 14:03
@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch 5 times, most recently from a2f6091 to febaf7a Compare June 29, 2026 21:13
@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch 2 times, most recently from c2c070b to a1942c3 Compare July 5, 2026 15:53
@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch 3 times, most recently from d388cad to f12f440 Compare July 15, 2026 18:32
@Vinzzzze
Vinzzzze force-pushed the shuffle_playlist branch 2 times, most recently from 9a4a10e to 2d7d831 Compare July 20, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants