summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/playlist.c53
1 files changed, 40 insertions, 13 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index af5e1b5df0..23d3355708 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
@@ -436,9 +437,6 @@ static int update_control_unlocked(struct playlist_info* playlist,
436 case PLAYLIST_COMMAND_RESET: 437 case PLAYLIST_COMMAND_RESET:
437 result = write(fd, "R\n", 2); 438 result = write(fd, "R\n", 2);
438 break; 439 break;
439 case PLAYLIST_COMMAND_CLEAR:
440 result = fdprintf(fd, "C:%d\n", i1);
441 break;
442 case PLAYLIST_COMMAND_FLAGS: 440 case PLAYLIST_COMMAND_FLAGS:
443 result = fdprintf(fd, "F:%u:%u\n", i1, i2); 441 result = fdprintf(fd, "F:%u:%u\n", i1, i2);
444 break; 442 break;
@@ -1174,9 +1172,32 @@ static int create_and_play_dir(int direction, bool play_last)
1174 */ 1172 */
1175static int remove_all_tracks_unlocked(struct playlist_info *playlist, bool write) 1173static int remove_all_tracks_unlocked(struct playlist_info *playlist, bool write)
1176{ 1174{
1175 char filename[MAX_PATH];
1176 int seek_pos = -1;
1177
1177 if (playlist->amount <= 0) 1178 if (playlist->amount <= 0)
1178 return 0; 1179 return 0;
1179 1180
1181 if (write) /* Write control file commands to disk */
1182 {
1183 if (playlist->control_fd < 0)
1184 return -1;
1185
1186 if (get_track_filename(playlist, playlist->index,
1187 filename, sizeof(filename)) != 0)
1188 return -1;
1189
1190 /* Start over with fresh control file for emptied dynamic playlist */
1191 pl_close_control(playlist);
1192 create_control_unlocked(playlist);
1193 update_control_unlocked(playlist, PLAYLIST_COMMAND_PLAYLIST,
1194 PLAYLIST_CONTROL_FILE_VERSION, -1,
1195 "", "", NULL);
1196 update_control_unlocked(playlist, PLAYLIST_COMMAND_QUEUE,
1197 0, 0, filename, NULL, &seek_pos);
1198 sync_control_unlocked(playlist);
1199 }
1200
1180 /* Move current track down to position 0 */ 1201 /* Move current track down to position 0 */
1181 playlist->indices[0] = playlist->indices[playlist->index]; 1202 playlist->indices[0] = playlist->indices[playlist->index];
1182#ifdef HAVE_DIRCACHE 1203#ifdef HAVE_DIRCACHE
@@ -1190,22 +1211,25 @@ static int remove_all_tracks_unlocked(struct playlist_info *playlist, bool write
1190 1211
1191 /* Update playlist state as if by remove_track_unlocked() */ 1212 /* Update playlist state as if by remove_track_unlocked() */
1192 playlist->first_index = 0; 1213 playlist->first_index = 0;
1214 playlist->index = 0;
1193 playlist->amount = 1; 1215 playlist->amount = 1;
1194 playlist->indices[0] |= PLAYLIST_QUEUED; 1216 playlist->indices[0] |= PLAYLIST_QUEUED;
1217 playlist->flags = 0; /* Reset dirplay and modified flags */
1195 1218
1196 if (playlist->last_insert_pos == 0) 1219 if (playlist->last_insert_pos == 0)
1197 playlist->last_insert_pos = -1; 1220 playlist->last_insert_pos = -1;
1198 else 1221 else
1199 playlist->last_insert_pos = 0; 1222 playlist->last_insert_pos = 0;
1200 1223
1201 if (write && playlist->control_fd >= 0) 1224 if (seek_pos == -1)
1202 { 1225 return 0;
1203 update_control_unlocked(playlist, PLAYLIST_COMMAND_CLEAR,
1204 playlist->index, -1, NULL, NULL, NULL);
1205 sync_control_unlocked(playlist);
1206 }
1207 1226
1208 playlist->index = 0; 1227 /* Update seek offset so it points into the new control file. */
1228 playlist->indices[0] &= ~PLAYLIST_INSERT_TYPE_MASK & ~PLAYLIST_SEEK_MASK;
1229 playlist->indices[0] |= PLAYLIST_INSERT_TYPE_INSERT | seek_pos;
1230
1231 /* Cut connection to playlist file */
1232 update_playlist_filename_unlocked(playlist, "", "");
1209 1233
1210 return 0; 1234 return 0;
1211} 1235}
@@ -3402,6 +3426,8 @@ int playlist_resume(void)
3402 playlist->last_insert_pos = -1; 3426 playlist->last_insert_pos = -1;
3403 break; 3427 break;
3404 } 3428 }
3429 /* FIXME: Deprecated.
3430 * Adjust PLAYLIST_CONTROL_FILE_MIN_VERSION after removal */
3405 case PLAYLIST_COMMAND_CLEAR: 3431 case PLAYLIST_COMMAND_CLEAR:
3406 { 3432 {
3407 if (strp[0]) 3433 if (strp[0])
@@ -3960,11 +3986,12 @@ static int pl_save_update_control(struct playlist_info* playlist,
3960 playlist->last_insert_pos = rotate_index(playlist, playlist->last_insert_pos); 3986 playlist->last_insert_pos = rotate_index(playlist, playlist->last_insert_pos);
3961 playlist->first_index = 0; 3987 playlist->first_index = 0;
3962 } 3988 }
3963 3989
3964 for (int index = 0; index < playlist->amount; ++index) 3990 for (int index = 0; index < playlist->amount; ++index)
3965 { 3991 {
3966 /* We only need to update queued files */ 3992 /* We only need to update queued files */
3967 if (!(playlist->indices[index] & PLAYLIST_QUEUED)) 3993 if (!(playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK &&
3994 playlist->indices[index] & PLAYLIST_QUEUED))
3968 continue; 3995 continue;
3969 3996
3970 /* Read filename from old control file */ 3997 /* Read filename from old control file */