summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2019-07-24 14:17:37 -0400
committerSolomon Peachy <pizza@shaftnet.org>2019-07-24 14:20:03 -0400
commit7bef453e0318acee10adbc2b561ba7d2f4b81fe3 (patch)
treebcd2a87507937be9fccd3c97781f245698b7e95e /apps
parentef9ee8935f3ec95a636272cf6c19f55573f5ee6d (diff)
downloadrockbox-7bef453e0318acee10adbc2b561ba7d2f4b81fe3.tar.gz
rockbox-7bef453e0318acee10adbc2b561ba7d2f4b81fe3.zip
FS#12887: Fix playlist order after moving a track before current
Original patch by Juan Gonzalez Updated by Igor Poretsky Change-Id: I913d96df906e56fb4063485a6725cd13e395f165
Diffstat (limited to 'apps')
-rw-r--r--apps/playlist.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index b6f19418ed..0b5662b47c 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -3288,6 +3288,11 @@ int playlist_move(struct playlist_info* playlist, int index, int new_index)
3288 bool queue; 3288 bool queue;
3289 bool current = false; 3289 bool current = false;
3290 int r; 3290 int r;
3291 struct playlist_track_info info;
3292 int idx_cur; /* display index of the currently playing track */
3293 int idx_from; /* display index of the track we're moving */
3294 int idx_to; /* display index of the position we're moving to */
3295 bool displace_current = false;
3291 char filename[MAX_PATH]; 3296 char filename[MAX_PATH];
3292 3297
3293 if (!playlist) 3298 if (!playlist)
@@ -3303,8 +3308,35 @@ int playlist_move(struct playlist_info* playlist, int index, int new_index)
3303 return -1; 3308 return -1;
3304 3309
3305 if (index == playlist->index) 3310 if (index == playlist->index)
3311 {
3306 /* Moving the current track */ 3312 /* Moving the current track */
3307 current = true; 3313 current = true;
3314 }
3315 else
3316 {
3317 /* Get display index of the currently playing track */
3318 if (playlist_get_track_info(playlist, playlist->index, &info) != -1)
3319 {
3320 idx_cur = info.display_index;
3321 /* Get display index of the position we're moving to */
3322 if (playlist_get_track_info(playlist, new_index, &info) != -1)
3323 {
3324 idx_to = info.display_index;
3325 /* Get display index of the track we're trying to move */
3326 if (playlist_get_track_info(playlist, index, &info) != -1)
3327 {
3328 idx_from = info.display_index;
3329 /* Check if moving will displace the current track.
3330 Displace happens when moving from after current to
3331 before, but also when moving from before to before
3332 due to the removal from the original position */
3333 if ( ((idx_from > idx_cur) && (idx_to <= idx_cur)) ||
3334 ((idx_from < idx_cur) && (idx_to < idx_cur)) )
3335 displace_current = true;
3336 }
3337 }
3338 }
3339 }
3308 3340
3309 control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK; 3341 control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
3310 queue = playlist->indices[index] & PLAYLIST_QUEUE_MASK; 3342 queue = playlist->indices[index] & PLAYLIST_QUEUE_MASK;
@@ -3320,7 +3352,7 @@ int playlist_move(struct playlist_info* playlist, int index, int new_index)
3320 We calculate this before we do the remove as it depends on the 3352 We calculate this before we do the remove as it depends on the
3321 size of the playlist before the track removal */ 3353 size of the playlist before the track removal */
3322 r = rotate_index(playlist, new_index); 3354 r = rotate_index(playlist, new_index);
3323 3355
3324 /* Delete track from original position */ 3356 /* Delete track from original position */
3325 result = remove_track_from_playlist(playlist, index, true); 3357 result = remove_track_from_playlist(playlist, index, true);
3326 3358
@@ -3338,7 +3370,7 @@ int playlist_move(struct playlist_info* playlist, int index, int new_index)
3338 3370
3339 result = add_track_to_playlist(playlist, filename, new_index, queue, 3371 result = add_track_to_playlist(playlist, filename, new_index, queue,
3340 -1); 3372 -1);
3341 3373
3342 if (result != -1) 3374 if (result != -1)
3343 { 3375 {
3344 if (current) 3376 if (current)
@@ -3359,6 +3391,10 @@ int playlist_move(struct playlist_info* playlist, int index, int new_index)
3359 break; 3391 break;
3360 } 3392 }
3361 } 3393 }
3394 else
3395 if ((displace_current) && (new_index != PLAYLIST_PREPEND))
3396 /* make the index point to the currently playing track */
3397 playlist->index++;
3362 3398
3363 if ((audio_status() & AUDIO_STATUS_PLAY) && playlist->started) 3399 if ((audio_status() & AUDIO_STATUS_PLAY) && playlist->started)
3364 audio_flush_and_reload_tracks(); 3400 audio_flush_and_reload_tracks();