summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Soffke <christian.soffke@gmail.com>2023-11-06 00:42:20 +0100
committerChristian Soffke <christian.soffke@gmail.com>2023-11-11 00:36:14 +0100
commitba14aecd5eee99742bef94f782a5a10b0821f0ad (patch)
tree31e019d6d7e2b8d6b7652f2b7c28d28522cdf0c6
parent8a6aaaa5eda552548e5efc1b19e837c4dad4d88a (diff)
downloadrockbox-ba14aecd5e.tar.gz
rockbox-ba14aecd5e.zip
Fix INSERT_LAST_SHUFFLED when playlist's first_index > 0
Tracks were inserted into the middle of the playlist Change-Id: I2a665fd3e0fe9d8900d6555e6affc5cb3d7513f8
-rw-r--r--apps/playlist.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index 78d41ea45e..c0e943cf37 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -1298,9 +1298,12 @@ static int add_track_to_playlist_unlocked(struct playlist_info* playlist,
}
case PLAYLIST_INSERT_LAST_SHUFFLED:
{
+ int playlist_end = playlist->first_index > 0 ?
+ playlist->first_index : playlist->amount;
+
int newpos = playlist->last_shuffled_start +
- rand() % (playlist->amount - playlist->last_shuffled_start + 1);
-
+ rand() % (playlist_end - playlist->last_shuffled_start + 1);
+
position = insert_position = newpos;
break;
}
@@ -3557,13 +3560,14 @@ out:
return result;
}
-/* set playlist->last_shuffle_start to playlist->amount for
+/* set playlist->last_shuffle_start to playlist end for
PLAYLIST_INSERT_LAST_SHUFFLED command purposes*/
void playlist_set_last_shuffled_start(void)
{
struct playlist_info* playlist = &current_playlist;
playlist_write_lock(playlist);
- playlist->last_shuffled_start = playlist->amount;
+ playlist->last_shuffled_start = playlist->first_index > 0 ?
+ playlist->first_index : playlist->amount;
playlist_write_unlock(playlist);
}