summaryrefslogtreecommitdiff
path: root/apps/playlist.c
diff options
context:
space:
mode:
authorHardeep Sidhu <dyp@pobox.com>2003-01-09 06:08:41 +0000
committerHardeep Sidhu <dyp@pobox.com>2003-01-09 06:08:41 +0000
commit86ced78567b73f6a41c384351899f3215834f8c2 (patch)
tree63caabf46e4d9096fa4686ee86f44173ab91910c /apps/playlist.c
parent12d184408406cb3adf4e75c6e1b156df7d2c6515 (diff)
downloadrockbox-86ced78567b73f6a41c384351899f3215834f8c2.tar.gz
rockbox-86ced78567b73f6a41c384351899f3215834f8c2.zip
Comments.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3044 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/playlist.c')
-rw-r--r--apps/playlist.c46
1 files changed, 41 insertions, 5 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index 0a99cb91f4..a8996c8452 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -126,9 +126,17 @@ static int get_next_index(int steps, bool *queue)
126 int next_index = -1; 126 int next_index = -1;
127 127
128 if (global_settings.repeat_mode == REPEAT_ONE) 128 if (global_settings.repeat_mode == REPEAT_ONE)
129 {
130 /* this is needed for repeat one to work with queue mode */
129 steps = 0; 131 steps = 0;
132 }
130 else if (steps >= 0) 133 else if (steps >= 0)
134 {
135 /* Queue index starts from 0 which needs to be accounted for. Also,
136 after resume, this handles case where we want to begin with
137 playlist */
131 steps -= playlist.start_queue; 138 steps -= playlist.start_queue;
139 }
132 140
133 if (steps >= 0 && playlist.num_queued > 0 && 141 if (steps >= 0 && playlist.num_queued > 0 &&
134 playlist.num_queued - steps > 0) 142 playlist.num_queued - steps > 0)
@@ -139,9 +147,16 @@ static int get_next_index(int steps, bool *queue)
139 if (playlist.num_queued) 147 if (playlist.num_queued)
140 { 148 {
141 if (steps >= 0) 149 if (steps >= 0)
150 {
151 /* skip the queued tracks */
142 steps -= (playlist.num_queued - 1); 152 steps -= (playlist.num_queued - 1);
153 }
143 else if (!playlist.start_queue) 154 else if (!playlist.start_queue)
155 {
156 /* previous from queue list needs to go to current track in
157 playlist */
144 steps += 1; 158 steps += 1;
159 }
145 } 160 }
146 } 161 }
147 162
@@ -166,6 +181,8 @@ static int get_next_index(int steps, bool *queue)
166 break; 181 break;
167 182
168 case REPEAT_ONE: 183 case REPEAT_ONE:
184 /* if we are still in playlist when repeat one is set, don't go to
185 queue list */
169 if (*queue && !playlist.start_queue) 186 if (*queue && !playlist.start_queue)
170 next_index = playlist.queue_index; 187 next_index = playlist.queue_index;
171 else 188 else
@@ -201,6 +218,9 @@ int playlist_first_index(void)
201 return playlist.first_index; 218 return playlist.first_index;
202} 219}
203 220
221/* Get resume info for current playing song. If return value is -1 then
222 settings shouldn't be saved (eg. when playing queued song and save queue
223 disabled) */
204int playlist_get_resume_info(int *resume_index, int *queue_resume, 224int playlist_get_resume_info(int *resume_index, int *queue_resume,
205 int *queue_resume_index) 225 int *queue_resume_index)
206{ 226{
@@ -214,6 +234,7 @@ int playlist_get_resume_info(int *resume_index, int *queue_resume,
214 { 234 {
215 *queue_resume_index = 235 *queue_resume_index =
216 playlist.queue_indices[playlist.queue_index]; 236 playlist.queue_indices[playlist.queue_index];
237 /* have we started playing the queue list yet? */
217 if (playlist.start_queue) 238 if (playlist.start_queue)
218 *queue_resume = QUEUE_BEGIN_PLAYLIST; 239 *queue_resume = QUEUE_BEGIN_PLAYLIST;
219 else 240 else
@@ -288,6 +309,8 @@ int queue_add(char *filename)
288 return -1; 309 return -1;
289 } 310 }
290 311
312 /* save the file name with a trailing \n. QUEUE_FILE can be used as a
313 playlist if desired */
291 filename[len] = '\n'; 314 filename[len] = '\n';
292 result = write(fd, filename, len+1); 315 result = write(fd, filename, len+1);
293 if (result < 0) 316 if (result < 0)
@@ -307,6 +330,7 @@ int queue_add(char *filename)
307 (playlist.last_queue_index + 1) % MAX_QUEUED_FILES; 330 (playlist.last_queue_index + 1) % MAX_QUEUED_FILES;
308 playlist.num_queued++; 331 playlist.num_queued++;
309 332
333 /* the play order has changed */
310 mpeg_flush_and_reload_tracks(); 334 mpeg_flush_and_reload_tracks();
311 335
312 return playlist.num_queued; 336 return playlist.num_queued;
@@ -319,6 +343,7 @@ int playlist_next(int steps)
319 343
320 if (queue) 344 if (queue)
321 { 345 {
346 /* queue_diff accounts for bad songs in queue list */
322 int queue_diff = index - playlist.queue_index; 347 int queue_diff = index - playlist.queue_index;
323 if (queue_diff < 0) 348 if (queue_diff < 0)
324 queue_diff += MAX_QUEUED_FILES; 349 queue_diff += MAX_QUEUED_FILES;
@@ -334,11 +359,16 @@ int playlist_next(int steps)
334 { 359 {
335 if (steps >= 0) 360 if (steps >= 0)
336 { 361 {
362 /* done with queue list */
337 playlist.queue_index = playlist.last_queue_index; 363 playlist.queue_index = playlist.last_queue_index;
338 playlist.num_queued = 0; 364 playlist.num_queued = 0;
339 } 365 }
340 else 366 else
341 playlist.start_queue = true; 367 {
368 /* user requested previous. however, don't forget about queue
369 list */
370 playlist.start_queue = 1;
371 }
342 } 372 }
343 } 373 }
344 374
@@ -469,10 +499,15 @@ char* playlist_peek(int steps)
469 buf = strchr(buf+1, '/'); 499 buf = strchr(buf+1, '/');
470 } 500 }
471 501
472 if (buf) 502 if (!buf)
473 return buf; 503 {
504 /* Even though this is an invalid file, we still need to pass a file
505 name to the caller because NULL is used to indicate end of
506 playlist */
507 return now_playing;
508 }
474 509
475 return now_playing; 510 return buf;
476} 511}
477 512
478/* 513/*
@@ -573,13 +608,14 @@ int play_list(char *dir, /* "current directory" */
573 } 608 }
574 } 609 }
575 610
576 /* update the queue indices */
577 if (queue_resume) 611 if (queue_resume)
578 { 612 {
613 /* update the queue indices */
579 add_indices_to_queuelist(queue_resume_index); 614 add_indices_to_queuelist(queue_resume_index);
580 615
581 if (queue_resume == QUEUE_BEGIN_PLAYLIST) 616 if (queue_resume == QUEUE_BEGIN_PLAYLIST)
582 { 617 {
618 /* begin with current playlist index */
583 playlist.start_queue = 1; 619 playlist.start_queue = 1;
584 playlist.index++; /* so we begin at the correct track */ 620 playlist.index++; /* so we begin at the correct track */
585 } 621 }