Fix playback queue bug when "Insert Next" is used with multiple songs at once

After using “Insert Next” to insert multiple songs at once (e.g. an album from the database browser or folder from the file browser), subsequent Insert operations will incorrectly insert items after the first song of all items that were previously inserted, instead of after the last song of the previously inserted items.

A bug fix was originally written by Costas Calamvokis for the file browser only. I adopted the original fix and added code analogous to it so that it works from the database browser as well.

See FS#7898, FS#7363 or this forum post for more info:
https://forums.rockbox.org/index.php/topic,53741.0.html

Change-Id: Ie2718e136df0b340000f7a171e9e806cf23a27b4
This commit is contained in:
Christian Soffke 2021-02-15 15:05:56 +01:00 committed by Solomon Peachy
parent abebc6b9ac
commit 436e64e09e
2 changed files with 21 additions and 25 deletions

View file

@ -858,10 +858,10 @@ static int directory_search_callback(char* filename, void* context)
(c->count)++;
/* Make sure tracks are inserted in correct order if user requests
INSERT_FIRST */
if (c->position == PLAYLIST_INSERT_FIRST || c->position >= 0)
c->position = insert_pos + 1;
/* After first INSERT_FIRST switch to INSERT so that all the
rest of the tracks get inserted one after the other */
if (c->position == PLAYLIST_INSERT_FIRST)
c->position = PLAYLIST_INSERT;
if (((c->count)%PLAYLIST_DISPLAY_COUNT) == 0)
{
@ -3189,10 +3189,10 @@ int playlist_insert_playlist(struct playlist_info* playlist, const char *filenam
break;
}
/* Make sure tracks are inserted in correct order if user
requests INSERT_FIRST */
if (position == PLAYLIST_INSERT_FIRST || position >= 0)
position = insert_pos + 1;
/* After first INSERT_FIRST switch to INSERT so that all the
rest of the tracks get inserted one after the other */
if (position == PLAYLIST_INSERT_FIRST)
position = PLAYLIST_INSERT;
count++;

View file

@ -2018,18 +2018,9 @@ static bool insert_all_playlist(struct tree_context *c, int position, bool queue
}
}
if (position == PLAYLIST_INSERT_FIRST)
{
from = c->filesindir - 1;
to = -1;
direction = -1;
}
else
{
from = 0;
to = c->filesindir;
direction = 1;
}
from = 0;
to = c->filesindir;
direction = 1;
for (i = from; i != to; i += direction)
{
@ -2049,6 +2040,11 @@ static bool insert_all_playlist(struct tree_context *c, int position, bool queue
break;
}
yield();
if (position == PLAYLIST_INSERT_FIRST)
{
position = PLAYLIST_INSERT;
}
}
playlist_sync(NULL);
tagcache_search_finish(&tcs);