FS#7898 - Fix for bug in "Insert Next" with multiple insertions

Attached to Project: Rockbox
Opened by Costas Calamvokis (cc) - Sunday, 07 October 2007, 11:45 GMT
Last edited by Thomas Martitz (kugel.) - Friday, 16 October 2009, 22:15 GMT
Task Type Patches
Category Playlists
Status Closed
Assigned To No-one
Operating System All players
Severity Low
Priority Normal
Reported Version Daily build (which?)
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 2
Private No


This patch fixes a bug: When using "Insert Next" to insert multiple files to a playlist, last_insert_pos only gets updated for the first file inserted, so a subsequent "Insert" inserts in the wrong position.

Eg: Insert 1 2 3, Insert Next 4 5 6, Insert 7 8 9 gives:
1 4 7 8 9 5 6 2 3
Instead of
1 4 5 6 7 8 9 2 3

The problem is that for "Insert Next" the directory_search_callback function keeps track of the insert position and add_track_to_playlist does not update last_insert_pos when called with a specific insert position ahead of the last_insert_pos.

This patch works by not keeping track of the insert position in directory_search_callback and instead just switching to "Insert" mode after the first file is inserted - which makes sure the next file gets put in the right place (after the first file) and that last_insert_pos gets updated correctly.

The patch also fixes the same problem when inserting a playlist with "Insert next".
This task depends upon

Closed by  Thomas Martitz (kugel.)
Friday, 16 October 2009, 22:15 GMT
Reason for closing:  Out of Date
Additional comments about closing:  Should work fine nowadays.
Comment by Joaquim Dias (dunno) - Friday, 12 October 2007, 08:07 GMT
I asked the devs in irc to look at this patch and 7911, they voiced objections to both patches, 7898 and 7911, would you mind popping in to irc and chatting to them about their issues, perhaps it might speed up the incorporation of the patches to svn.

Many Thanks.
Comment by Costas Calamvokis (cc) - Friday, 12 October 2007, 12:40 GMT
OK, while I'm waiting on irc - maybe I should point out that in my examples I am talking about inserting directories (each containing 3 files). Also during the insertions song 1 is playing.

So after doing "insert next" of a directory containing 4 5 6 the playlist is:
1 4 5 6 2 3

Then doing an "Insert" (song 1 is still playing) inserts after 4 - so the initial "Insert Next" does move the position where the "Insert" occurs (otherwise it would have inserted after 1), but not to after the last track inserted.

Another possibility is that the "Insert Next" should not move the pointer ever (that is one interpretation of what the manual says at the moment) - but this is not what happens when inserting single tracks, and I think would be more confusing.
Comment by Costas Calamvokis (cc) - Saturday, 20 October 2007, 09:41 GMT

I was searching for something else and found this bug, which I think is the same problem that this
patch fixes:

My apologies for not finding it before I started this task.