diff options
author | Magnus Holmgren <magnushol@gmail.com> | 2007-10-25 19:18:20 +0000 |
---|---|---|
committer | Magnus Holmgren <magnushol@gmail.com> | 2007-10-25 19:18:20 +0000 |
commit | ccbe242453112054e5219615e112b0d1cb518063 (patch) | |
tree | 51c7db472406428d3bf3a0c65242f96653d2fa86 | |
parent | 06aca924f814c228b33bdba1b59a452751b4b929 (diff) | |
download | rockbox-ccbe242453112054e5219615e112b0d1cb518063.tar.gz rockbox-ccbe242453112054e5219615e112b0d1cb518063.zip |
Factor out some common code, for simplicity (I hope...) and to save size.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15305 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/playlist.c | 114 |
1 files changed, 44 insertions, 70 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index ad60c84d38..676fc1e2c7 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -143,8 +143,6 @@ struct directory_search_context { | |||
143 | int count; | 143 | int count; |
144 | }; | 144 | }; |
145 | 145 | ||
146 | static bool changing_dir = false; | ||
147 | |||
148 | static struct playlist_info current_playlist; | 146 | static struct playlist_info current_playlist; |
149 | static char now_playing[MAX_PATH+1]; | 147 | static char now_playing[MAX_PATH+1]; |
150 | 148 | ||
@@ -563,6 +561,46 @@ exit: | |||
563 | } | 561 | } |
564 | 562 | ||
565 | /* | 563 | /* |
564 | * Utility function to create a new playlist, fill it with the next or | ||
565 | * previous directory, shuffle it if needed, and start playback. | ||
566 | * If play_last is true and direction zero or negative, start playing | ||
567 | * the last file in the directory, otherwise start playing the first. | ||
568 | */ | ||
569 | static int create_and_play_dir(int direction, bool play_last) | ||
570 | { | ||
571 | char dir[MAX_PATH + 1]; | ||
572 | int res; | ||
573 | int index = -1; | ||
574 | |||
575 | if(direction > 0) | ||
576 | res = get_next_directory(dir); | ||
577 | else | ||
578 | res = get_previous_directory(dir); | ||
579 | |||
580 | if (!res) | ||
581 | { | ||
582 | if (playlist_create(dir, NULL) != -1) | ||
583 | { | ||
584 | ft_build_playlist(tree_get_context(), 0); | ||
585 | |||
586 | if (global_settings.playlist_shuffle) | ||
587 | playlist_shuffle(current_tick, -1); | ||
588 | |||
589 | if (play_last && direction <= 0) | ||
590 | index = current_playlist.amount - 1; | ||
591 | else | ||
592 | index = 0; | ||
593 | |||
594 | #if (CONFIG_CODEC != SWCODEC) | ||
595 | playlist_start(index, 0); | ||
596 | #endif | ||
597 | } | ||
598 | } | ||
599 | |||
600 | return index; | ||
601 | } | ||
602 | |||
603 | /* | ||
566 | * Removes all tracks, from the playlist, leaving the presently playing | 604 | * Removes all tracks, from the playlist, leaving the presently playing |
567 | * track queued. | 605 | * track queued. |
568 | */ | 606 | */ |
@@ -2534,44 +2572,12 @@ int playlist_next(int steps) | |||
2534 | } | 2572 | } |
2535 | else if (playlist->in_ram && global_settings.next_folder) | 2573 | else if (playlist->in_ram && global_settings.next_folder) |
2536 | { | 2574 | { |
2537 | char dir[MAX_PATH+1]; | 2575 | index = create_and_play_dir(steps, true); |
2538 | 2576 | ||
2539 | changing_dir = true; | 2577 | if (index >= 0) |
2540 | if (steps > 0) | ||
2541 | { | ||
2542 | if (!get_next_directory(dir)) | ||
2543 | { | ||
2544 | /* start playing next directory */ | ||
2545 | if (playlist_create(dir, NULL) != -1) | ||
2546 | { | ||
2547 | ft_build_playlist(tree_get_context(), 0); | ||
2548 | if (global_settings.playlist_shuffle) | ||
2549 | playlist_shuffle(current_tick, -1); | ||
2550 | #if CONFIG_CODEC != SWCODEC | ||
2551 | playlist_start(0, 0); | ||
2552 | #endif | ||
2553 | playlist->index = index = 0; | ||
2554 | } | ||
2555 | } | ||
2556 | } | ||
2557 | else | ||
2558 | { | 2578 | { |
2559 | if (!get_previous_directory(dir)) | 2579 | playlist->index = index; |
2560 | { | ||
2561 | /* start playing previous directory */ | ||
2562 | if (playlist_create(dir, NULL) != -1) | ||
2563 | { | ||
2564 | ft_build_playlist(tree_get_context(), 0); | ||
2565 | if (global_settings.playlist_shuffle) | ||
2566 | playlist_shuffle(current_tick, -1); | ||
2567 | #if CONFIG_CODEC != SWCODEC | ||
2568 | playlist_start(current_playlist.amount-1, 0); | ||
2569 | #endif | ||
2570 | playlist->index = index = current_playlist.amount - 1; | ||
2571 | } | ||
2572 | } | ||
2573 | } | 2580 | } |
2574 | changing_dir = false; | ||
2575 | } | 2581 | } |
2576 | 2582 | ||
2577 | return index; | 2583 | return index; |
@@ -2609,43 +2615,11 @@ int playlist_next(int steps) | |||
2609 | /* try playing next or previous folder */ | 2615 | /* try playing next or previous folder */ |
2610 | bool playlist_next_dir(int direction) | 2616 | bool playlist_next_dir(int direction) |
2611 | { | 2617 | { |
2612 | char dir[MAX_PATH+1]; | ||
2613 | bool result; | ||
2614 | int res; | ||
2615 | |||
2616 | /* not to mess up real playlists */ | 2618 | /* not to mess up real playlists */ |
2617 | if(!current_playlist.in_ram) | 2619 | if(!current_playlist.in_ram) |
2618 | return false; | 2620 | return false; |
2619 | 2621 | ||
2620 | if(changing_dir) | 2622 | return create_and_play_dir(direction, false) >= 0; |
2621 | return false; | ||
2622 | |||
2623 | changing_dir = true; | ||
2624 | if(direction > 0) | ||
2625 | res = get_next_directory(dir); | ||
2626 | else | ||
2627 | res = get_previous_directory(dir); | ||
2628 | if (!res) | ||
2629 | { | ||
2630 | if (playlist_create(dir, NULL) != -1) | ||
2631 | { | ||
2632 | ft_build_playlist(tree_get_context(), 0); | ||
2633 | if (global_settings.playlist_shuffle) | ||
2634 | playlist_shuffle(current_tick, -1); | ||
2635 | #if (CONFIG_CODEC != SWCODEC) | ||
2636 | playlist_start(0,0); | ||
2637 | #endif | ||
2638 | result = true; | ||
2639 | } | ||
2640 | else | ||
2641 | result = false; | ||
2642 | } | ||
2643 | else | ||
2644 | result = false; | ||
2645 | |||
2646 | changing_dir = false; | ||
2647 | |||
2648 | return result; | ||
2649 | } | 2623 | } |
2650 | 2624 | ||
2651 | /* Get resume info for current playing song. If return value is -1 then | 2625 | /* Get resume info for current playing song. If return value is -1 then |