diff options
author | Christian Soffke <christian.soffke@gmail.com> | 2023-11-05 02:32:39 +0100 |
---|---|---|
committer | Christian Soffke <christian.soffke@gmail.com> | 2023-11-11 00:36:14 +0100 |
commit | e9b4275d1f5b8d166fa772242af44b4d056ed482 (patch) | |
tree | 99fb350cf3fc8029954ef04cb1ce6257f7db8d66 /apps | |
parent | dd1063fc2ccc5c254ee018398c0162cccd549018 (diff) | |
download | rockbox-e9b4275d1f5b8d166fa772242af44b4d056ed482.tar.gz rockbox-e9b4275d1f5b8d166fa772242af44b4d056ed482.zip |
Playlists: Fix resuming from control commands with first_index > 0
add_track_to_playlist_unlocked only increased a playlist's
first index as necessary when its position parameter was
negative (i.e. one of the special insert positions was
specified).
A negative value was not stored in the control file, but
was always converted into an absolute position. Thus, any
adjustments to first_index weren't repeated when resuming
from the control file.
In particular, shuffled playlists were affected (in case of
first_index > 0), when inserting at positions <= first_index,
including appending a track to the end of a playlist. This
works by inserting at first_index and increasing first_index
by 1 afterwards.
Similarly, adding tracks in a shuffled fashion could increase
first index, whenever that was the value randomly calculated
for a track position, effectively appending it (I assume this
is on purpose).
To make sure that first_index adjustments are recovered when
resuming from the control file, and to be able to differentiate
between a prepended or appended track, store the special value
PLAYLIST_INSERT_LAST_ROTATED as the insert position in the
control file whenever first_index would have been used before,
and a special position (other than PLAYLIST_PREPEND) was
provided to the function.
Change-Id: I31f26796627fb136daeddd046cb1892bdf1b4014
Diffstat (limited to 'apps')
-rw-r--r-- | apps/playlist.c | 39 | ||||
-rw-r--r-- | apps/playlist.h | 3 |
2 files changed, 35 insertions, 7 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index bd2d33ea78..1f31ec81c1 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -1208,6 +1208,8 @@ static int remove_all_tracks_unlocked(struct playlist_info *playlist, bool write | |||
1208 | * PLAYLIST_INSERT_FIRST - Add track immediately after current song, no | 1208 | * PLAYLIST_INSERT_FIRST - Add track immediately after current song, no |
1209 | * matter what other tracks have been inserted | 1209 | * matter what other tracks have been inserted |
1210 | * PLAYLIST_INSERT_LAST - Add track to end of playlist | 1210 | * PLAYLIST_INSERT_LAST - Add track to end of playlist |
1211 | * PLAYLIST_INSERT_LAST_ROTATED - Add track to end of playlist, by inserting at | ||
1212 | * first_index, then increasing first_index by 1 | ||
1211 | * PLAYLIST_INSERT_SHUFFLED - Add track at some random point between the | 1213 | * PLAYLIST_INSERT_SHUFFLED - Add track at some random point between the |
1212 | * current playing track and end of playlist | 1214 | * current playing track and end of playlist |
1213 | * PLAYLIST_INSERT_LAST_SHUFFLED - Add tracks in random order to the end of | 1215 | * PLAYLIST_INSERT_LAST_SHUFFLED - Add tracks in random order to the end of |
@@ -1260,11 +1262,15 @@ static int add_track_to_playlist_unlocked(struct playlist_info* playlist, | |||
1260 | playlist->last_insert_pos = position; | 1262 | playlist->last_insert_pos = position; |
1261 | break; | 1263 | break; |
1262 | case PLAYLIST_INSERT_LAST: | 1264 | case PLAYLIST_INSERT_LAST: |
1263 | if (playlist->first_index > 0) | 1265 | if (playlist->first_index <= 0) |
1264 | position = insert_position = playlist->first_index; | 1266 | { |
1265 | else | ||
1266 | position = insert_position = playlist->amount; | 1267 | position = insert_position = playlist->amount; |
1267 | 1268 | playlist->last_insert_pos = position; | |
1269 | break; | ||
1270 | } | ||
1271 | /* fallthrough */ | ||
1272 | case PLAYLIST_INSERT_LAST_ROTATED: | ||
1273 | position = insert_position = playlist->first_index; | ||
1268 | playlist->last_insert_pos = position; | 1274 | playlist->last_insert_pos = position; |
1269 | break; | 1275 | break; |
1270 | case PLAYLIST_INSERT_SHUFFLED: | 1276 | case PLAYLIST_INSERT_SHUFFLED: |
@@ -1330,16 +1336,37 @@ static int add_track_to_playlist_unlocked(struct playlist_info* playlist, | |||
1330 | if (orig_position < 0) | 1336 | if (orig_position < 0) |
1331 | { | 1337 | { |
1332 | if (playlist->amount > 0 && insert_position <= playlist->index && | 1338 | if (playlist->amount > 0 && insert_position <= playlist->index && |
1333 | playlist->started) | 1339 | playlist->started && orig_position != PLAYLIST_INSERT_LAST_ROTATED) |
1334 | playlist->index++; | 1340 | playlist->index++; |
1335 | 1341 | ||
1342 | /* | ||
1343 | * When inserting into a playlist at positions before or equal to first_index | ||
1344 | * (unless PLAYLIST_PREPEND is specified explicitly), adjust first_index, so | ||
1345 | * that track insertion near the end does not affect the start of the playlist | ||
1346 | */ | ||
1336 | if (playlist->amount > 0 && insert_position <= playlist->first_index && | 1347 | if (playlist->amount > 0 && insert_position <= playlist->first_index && |
1337 | orig_position != PLAYLIST_PREPEND && playlist->started) | 1348 | orig_position != PLAYLIST_PREPEND && playlist->started) |
1349 | { | ||
1350 | /* | ||
1351 | * To ensure proper resuming from control file for a track that is supposed | ||
1352 | * to be appended, but is inserted at first_index, store position as special | ||
1353 | * value. | ||
1354 | * If we were to store the position unchanged, i.e. use first_index, | ||
1355 | * track would be prepended, instead, after resuming. | ||
1356 | */ | ||
1357 | if (insert_position == playlist->first_index) | ||
1358 | position = PLAYLIST_INSERT_LAST_ROTATED; | ||
1359 | |||
1338 | playlist->first_index++; | 1360 | playlist->first_index++; |
1361 | } | ||
1339 | } | 1362 | } |
1363 | else if (playlist->amount > 0 && insert_position < playlist->first_index && | ||
1364 | playlist->started) | ||
1365 | playlist->first_index++; | ||
1340 | 1366 | ||
1341 | if (insert_position < playlist->last_insert_pos || | 1367 | if (insert_position < playlist->last_insert_pos || |
1342 | (insert_position == playlist->last_insert_pos && position < 0)) | 1368 | (insert_position == playlist->last_insert_pos && position < 0 && |
1369 | position != PLAYLIST_INSERT_LAST_ROTATED)) | ||
1343 | playlist->last_insert_pos++; | 1370 | playlist->last_insert_pos++; |
1344 | 1371 | ||
1345 | if (seek_pos < 0 && playlist->control_fd >= 0) | 1372 | if (seek_pos < 0 && playlist->control_fd >= 0) |
diff --git a/apps/playlist.h b/apps/playlist.h index 5ad90db6f1..4d814c7523 100644 --- a/apps/playlist.h +++ b/apps/playlist.h | |||
@@ -62,7 +62,8 @@ enum { | |||
62 | PLAYLIST_INSERT_FIRST = -4, | 62 | PLAYLIST_INSERT_FIRST = -4, |
63 | PLAYLIST_INSERT_SHUFFLED = -5, | 63 | PLAYLIST_INSERT_SHUFFLED = -5, |
64 | PLAYLIST_REPLACE = -6, | 64 | PLAYLIST_REPLACE = -6, |
65 | PLAYLIST_INSERT_LAST_SHUFFLED = -7 | 65 | PLAYLIST_INSERT_LAST_SHUFFLED = -7, |
66 | PLAYLIST_INSERT_LAST_ROTATED = -8 | ||
66 | }; | 67 | }; |
67 | 68 | ||
68 | struct playlist_info | 69 | struct playlist_info |