summaryrefslogtreecommitdiff
path: root/apps/playlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/playlist.c')
-rw-r--r--apps/playlist.c77
1 files changed, 57 insertions, 20 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index 70637b39a2..f1edfe7323 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -138,9 +138,10 @@
138 * v4 added the (F)lags command. 138 * v4 added the (F)lags command.
139 * v5 added index to the (C)lear command. Added PLAYLIST_INSERT_LAST_ROTATED (-8) as 139 * v5 added index to the (C)lear command. Added PLAYLIST_INSERT_LAST_ROTATED (-8) as
140 * a supported position for (A)dd or (Q)eue commands. 140 * a supported position for (A)dd or (Q)eue commands.
141 * v6 removed the (C)lear command.
141 */ 142 */
142#define PLAYLIST_CONTROL_FILE_MIN_VERSION 2 143#define PLAYLIST_CONTROL_FILE_MIN_VERSION 2
143#define PLAYLIST_CONTROL_FILE_VERSION 5 144#define PLAYLIST_CONTROL_FILE_VERSION 6
144 145
145#define PLAYLIST_COMMAND_SIZE (MAX_PATH+12) 146#define PLAYLIST_COMMAND_SIZE (MAX_PATH+12)
146 147
@@ -366,6 +367,9 @@ static int convert_m3u_name(char* buf, int buf_len, int buf_max, char* temp)
366 */ 367 */
367static void create_control_unlocked(struct playlist_info* playlist) 368static void create_control_unlocked(struct playlist_info* playlist)
368{ 369{
370 if (playlist == &current_playlist && file_exists(PLAYLIST_CONTROL_FILE))
371 rename(PLAYLIST_CONTROL_FILE, PLAYLIST_CONTROL_FILE".old");
372
369 playlist->control_fd = open(playlist->control_filename, 373 playlist->control_fd = open(playlist->control_filename,
370 O_CREAT|O_RDWR|O_TRUNC, 0666); 374 O_CREAT|O_RDWR|O_TRUNC, 0666);
371 375
@@ -436,9 +440,6 @@ static int update_control_unlocked(struct playlist_info* playlist,
436 case PLAYLIST_COMMAND_RESET: 440 case PLAYLIST_COMMAND_RESET:
437 result = write(fd, "R\n", 2); 441 result = write(fd, "R\n", 2);
438 break; 442 break;
439 case PLAYLIST_COMMAND_CLEAR:
440 result = fdprintf(fd, "C:%d\n", i1);
441 break;
442 case PLAYLIST_COMMAND_FLAGS: 443 case PLAYLIST_COMMAND_FLAGS:
443 result = fdprintf(fd, "F:%u:%u\n", i1, i2); 444 result = fdprintf(fd, "F:%u:%u\n", i1, i2);
444 break; 445 break;
@@ -1174,9 +1175,32 @@ static int create_and_play_dir(int direction, bool play_last)
1174 */ 1175 */
1175static int remove_all_tracks_unlocked(struct playlist_info *playlist, bool write) 1176static int remove_all_tracks_unlocked(struct playlist_info *playlist, bool write)
1176{ 1177{
1178 char filename[MAX_PATH];
1179 int seek_pos = -1;
1180
1177 if (playlist->amount <= 0) 1181 if (playlist->amount <= 0)
1178 return 0; 1182 return 0;
1179 1183
1184 if (write) /* Write control file commands to disk */
1185 {
1186 if (playlist->control_fd < 0)
1187 return -1;
1188
1189 if (get_track_filename(playlist, playlist->index,
1190 filename, sizeof(filename)) != 0)
1191 return -1;
1192
1193 /* Start over with fresh control file for emptied dynamic playlist */
1194 pl_close_control(playlist);
1195 create_control_unlocked(playlist);
1196 update_control_unlocked(playlist, PLAYLIST_COMMAND_PLAYLIST,
1197 PLAYLIST_CONTROL_FILE_VERSION, -1,
1198 "", "", NULL);
1199 update_control_unlocked(playlist, PLAYLIST_COMMAND_QUEUE,
1200 0, 0, filename, NULL, &seek_pos);
1201 sync_control_unlocked(playlist);
1202 }
1203
1180 /* Move current track down to position 0 */ 1204 /* Move current track down to position 0 */
1181 playlist->indices[0] = playlist->indices[playlist->index]; 1205 playlist->indices[0] = playlist->indices[playlist->index];
1182#ifdef HAVE_DIRCACHE 1206#ifdef HAVE_DIRCACHE
@@ -1190,22 +1214,25 @@ static int remove_all_tracks_unlocked(struct playlist_info *playlist, bool write
1190 1214
1191 /* Update playlist state as if by remove_track_unlocked() */ 1215 /* Update playlist state as if by remove_track_unlocked() */
1192 playlist->first_index = 0; 1216 playlist->first_index = 0;
1217 playlist->index = 0;
1193 playlist->amount = 1; 1218 playlist->amount = 1;
1194 playlist->indices[0] |= PLAYLIST_QUEUED; 1219 playlist->indices[0] |= PLAYLIST_QUEUED;
1220 playlist->flags = 0; /* Reset dirplay and modified flags */
1195 1221
1196 if (playlist->last_insert_pos == 0) 1222 if (playlist->last_insert_pos == 0)
1197 playlist->last_insert_pos = -1; 1223 playlist->last_insert_pos = -1;
1198 else 1224 else
1199 playlist->last_insert_pos = 0; 1225 playlist->last_insert_pos = 0;
1200 1226
1201 if (write && playlist->control_fd >= 0) 1227 if (seek_pos == -1)
1202 { 1228 return 0;
1203 update_control_unlocked(playlist, PLAYLIST_COMMAND_CLEAR,
1204 playlist->index, -1, NULL, NULL, NULL);
1205 sync_control_unlocked(playlist);
1206 }
1207 1229
1208 playlist->index = 0; 1230 /* Update seek offset so it points into the new control file. */
1231 playlist->indices[0] &= ~PLAYLIST_INSERT_TYPE_MASK & ~PLAYLIST_SEEK_MASK;
1232 playlist->indices[0] |= PLAYLIST_INSERT_TYPE_INSERT | seek_pos;
1233
1234 /* Cut connection to playlist file */
1235 update_playlist_filename_unlocked(playlist, "", "");
1209 1236
1210 return 0; 1237 return 0;
1211} 1238}
@@ -1949,10 +1976,14 @@ void playlist_init(void)
1949 * Clean playlist at shutdown 1976 * Clean playlist at shutdown
1950 */ 1977 */
1951void playlist_shutdown(void) 1978void playlist_shutdown(void)
1979
1952{ 1980{
1981 /*BugFix we need to save resume info first */
1982 /*if (usb_detect() == USB_INSERTED)*/
1983 audio_stop();
1953 struct playlist_info* playlist = &current_playlist; 1984 struct playlist_info* playlist = &current_playlist;
1954 playlist_write_lock(playlist); 1985 playlist_write_lock(playlist);
1955 1986 logf("Closing Control %s", __func__);
1956 if (playlist->control_fd >= 0) 1987 if (playlist->control_fd >= 0)
1957 pl_close_control(playlist); 1988 pl_close_control(playlist);
1958 1989
@@ -2519,6 +2550,7 @@ bool playlist_entries_iterate(const char *filename,
2519 bool ret = false; 2550 bool ret = false;
2520 int max; 2551 int max;
2521 char *dir; 2552 char *dir;
2553 off_t filesize;
2522 2554
2523 char temp_buf[MAX_PATH+1]; 2555 char temp_buf[MAX_PATH+1];
2524 char trackname[MAX_PATH+1]; 2556 char trackname[MAX_PATH+1];
@@ -2533,14 +2565,16 @@ bool playlist_entries_iterate(const char *filename,
2533 notify_access_error(); 2565 notify_access_error();
2534 goto out; 2566 goto out;
2535 } 2567 }
2536 2568 off_t start = lseek(fd, 0, SEEK_CUR);
2569 filesize = lseek(fd, 0, SEEK_END);
2570 lseek(fd, start, SEEK_SET);
2537 /* we need the directory name for formatting purposes */ 2571 /* we need the directory name for formatting purposes */
2538 size_t dirlen = path_dirname(filename, (const char **)&dir); 2572 size_t dirlen = path_dirname(filename, (const char **)&dir);
2539 //dir = strmemdupa(dir, dirlen); 2573 //dir = strmemdupa(dir, dirlen);
2540 2574
2541 2575
2542 if (action_cb) 2576 if (action_cb)
2543 show_search_progress(true, 0); 2577 show_search_progress(true, 0, 0, 0);
2544 2578
2545 while ((max = read_line(fd, temp_buf, sizeof(temp_buf))) > 0) 2579 while ((max = read_line(fd, temp_buf, sizeof(temp_buf))) > 0)
2546 { 2580 {
@@ -2561,17 +2595,17 @@ bool playlist_entries_iterate(const char *filename,
2561 2595
2562 /* we need to format so that relative paths are correctly 2596 /* we need to format so that relative paths are correctly
2563 handled */ 2597 handled */
2564 if (format_track_path(trackname, temp_buf, 2598 if ((max = format_track_path(trackname, temp_buf,
2565 sizeof(trackname), dir, dirlen) < 0) 2599 sizeof(trackname), dir, dirlen)) < 0)
2566 { 2600 {
2567 goto out; 2601 goto out;
2568 } 2602 }
2569 2603 start += max;
2570 if (action_cb) 2604 if (action_cb)
2571 { 2605 {
2572 if (!action_cb(trackname)) 2606 if (!action_cb(trackname))
2573 goto out; 2607 goto out;
2574 else if (!show_search_progress(false, i)) 2608 else if (!show_search_progress(false, i, start, filesize))
2575 break; 2609 break;
2576 } 2610 }
2577 else if (playlist_insert_context_add(pl_context, trackname) < 0) 2611 else if (playlist_insert_context_add(pl_context, trackname) < 0)
@@ -3395,6 +3429,8 @@ int playlist_resume(void)
3395 playlist->last_insert_pos = -1; 3429 playlist->last_insert_pos = -1;
3396 break; 3430 break;
3397 } 3431 }
3432 /* FIXME: Deprecated.
3433 * Adjust PLAYLIST_CONTROL_FILE_MIN_VERSION after removal */
3398 case PLAYLIST_COMMAND_CLEAR: 3434 case PLAYLIST_COMMAND_CLEAR:
3399 { 3435 {
3400 if (strp[0]) 3436 if (strp[0])
@@ -3953,11 +3989,12 @@ static int pl_save_update_control(struct playlist_info* playlist,
3953 playlist->last_insert_pos = rotate_index(playlist, playlist->last_insert_pos); 3989 playlist->last_insert_pos = rotate_index(playlist, playlist->last_insert_pos);
3954 playlist->first_index = 0; 3990 playlist->first_index = 0;
3955 } 3991 }
3956 3992
3957 for (int index = 0; index < playlist->amount; ++index) 3993 for (int index = 0; index < playlist->amount; ++index)
3958 { 3994 {
3959 /* We only need to update queued files */ 3995 /* We only need to update queued files */
3960 if (!(playlist->indices[index] & PLAYLIST_QUEUED)) 3996 if (!(playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK &&
3997 playlist->indices[index] & PLAYLIST_QUEUED))
3961 continue; 3998 continue;
3962 3999
3963 /* Read filename from old control file */ 4000 /* Read filename from old control file */