Skip to content

Conversation

ronso0
Copy link
Member

@ronso0 ronso0 commented Sep 6, 2025

Closes #15315

  • select a playlist with 2++ tracks, ensure # colummn is visible (just for feedback)
  • sort playlist by BPM (or key or whatever, just not by # obviously)
  • open track table header menu, click "Adopt sort order"
  • tracks' # is now ascending, sort by # and BPM are ascending

playlist-adopt-sort-order

I decided for a separate function instead of doing multiple moveTrack.

@ronso0 ronso0 force-pushed the playlist-adopt-order-for-position branch from 169868d to 8686932 Compare September 15, 2025 08:51
@Swiftb0y
Copy link
Member

Haven't looked at this or tested, thank you for picking this up. I also tried to implement this a while ago but failed back then.

Comment on lines 1385 to +1386

//qDebug() << "Swapping tracks " << trackAPosition << " and " << trackBPosition;
trackPositionIds.insert(trackAPosition, trackBId);
trackPositionIds.insert(trackBPosition, trackAId);
// qDebug() << "Swapping tracks " << trackAPosition << " and " << trackBPosition;
Copy link
Member

Choose a reason for hiding this comment

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

huh?

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm.. whoopsy?

Comment on lines +1133 to +1135
for (auto oldIdAndPos : newOrder) {
int oldPos = oldIdAndPos.second;
const TrackId trackId = oldIdAndPos.first;
Copy link
Member

Choose a reason for hiding this comment

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

NIT: you should be able to use destructuring on a pair

Suggested change
for (auto oldIdAndPos : newOrder) {
int oldPos = oldIdAndPos.second;
const TrackId trackId = oldIdAndPos.first;
for (auto [trackId, oldPos] : newOrder) {

Comment on lines +1153 to +1156
// Print out any SQL error, if there was one.
if (query.lastError().isValid()) {
qDebug() << query.lastError();
}
Copy link
Member

Choose a reason for hiding this comment

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

dumb question: will this run if there was an error? Don't we just return then?

Copy link
Member Author

Choose a reason for hiding this comment

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

Idk 🤷‍♂️
I adopted it from the other methods.

Copy link
Member

Choose a reason for hiding this comment

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

right, but those don't return early for failed queries, right?

Comment on lines +1121 to +1123
if (newOrder.isEmpty() || playlistId == kInvalidPlaylistId) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

should we also check that newOrder.size() matches the playlist size?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmmaybe.. why not.
FWIWI also had in mind that we might use this for AutoDJ and then we'd need to exclude the first track which is already loaded as "next" (like in AutoDJ's own Shuffle function)

Comment on lines +343 to +344
QList<std::pair<TrackId, int>> idPosList;
int numOfTracks = rowCount();
Copy link
Member

Choose a reason for hiding this comment

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

NIT:

Suggested change
QList<std::pair<TrackId, int>> idPosList;
int numOfTracks = rowCount();
QList<std::pair<TrackId, int>> idPosList;
int numOfTracks = rowCount();
idPosList.reserve(numOfTracks);

cuz why not

Comment on lines +1859 to +1860
pTrackModel->orderTracksByCurrPos();
// TODO should we resort by # ??
Copy link
Member

Choose a reason for hiding this comment

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

can you elaborate?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder whether we should now sort by #, like is that what the user wants to see/use after adopting the order?

Probably yes, but my coffee break was over ; )

Also, if yes, PlaylistDAO::orderTracksByCurrPos should return true on succes, and only then we re-sort (for good UX)

Copy link
Member

Choose a reason for hiding this comment

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

yeah, I agree.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll try to implement it.

@Swiftb0y
Copy link
Member

I just tried this locally and got tripped up UX wise. I expected the "Adopt sort order" to be an action on the playlist context menu (next to "shuffle playlist") instead of the table header. How feasible is that to implement?
image

@ronso0
Copy link
Member Author

ronso0 commented Sep 20, 2025

next to "shuffle playlist") instead of the table header. How feasible is that to implement?

(I think I recently looked at the Shuffle action for Tracks, Crates which is also in the header)
Makes sense.
And that's how I just did it for "Remove duplicate tracks" (will push this soon).
It would also make it easier to disable the action for locked playlists. Not sure how to get the current sorting though.
Will check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Playlists: allow adopt new track order from current order (eg. sorted by BPM)
2 participants