summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorChristian Soffke <christian.soffke@gmail.com>2021-12-29 20:24:51 +0100
committerWilliam Wilgus <me.theuser@yahoo.com>2022-01-04 18:00:49 -0500
commite3b8b7fa80320f0c8bbc84d4364ea83b5991db20 (patch)
tree210ae8372dac52417bdcc938078589d6aebedacd /apps
parentbfe3dac3badd6ddd22f65237cbbd839f8feb4a17 (diff)
downloadrockbox-e3b8b7fa80320f0c8bbc84d4364ea83b5991db20.tar.gz
rockbox-e3b8b7fa80320f0c8bbc84d4364ea83b5991db20.zip
PictureFlow: Utilize "Current Playlist" menu (+ GS fixes)
When appending tracks, they were always inserted last. You can now choose from the usual options offered by the "Current Playlst" context menu to queue or to insert tracks at the requested position. The splash after appending that forced you to wait for 2s has been eliminated. Also fixes crashes on targets that use the grey_core lib if a splash showed up when playback was started, e.g. LANG_PLAYLIST_CONTROL_ACCESS_ERROR, or when PictureFlow quit. Change-Id: I661c59057b5315ba793ee1674f7a2ea1ffd7968d
Diffstat (limited to 'apps')
-rw-r--r--apps/onplay.c11
-rw-r--r--apps/onplay.h2
-rw-r--r--apps/playlist_viewer.c2
-rw-r--r--apps/plugin.c1
-rw-r--r--apps/plugin.h4
-rw-r--r--apps/plugins/pictureflow/pictureflow.c216
-rw-r--r--apps/shortcuts.c2
7 files changed, 141 insertions, 97 deletions
diff --git a/apps/onplay.c b/apps/onplay.c
index 93c7c93624..61ef8acad5 100644
--- a/apps/onplay.c
+++ b/apps/onplay.c
@@ -69,6 +69,7 @@ static const char *selected_file = NULL;
69static char selected_file_path[MAX_PATH]; 69static char selected_file_path[MAX_PATH];
70static int selected_file_attr = 0; 70static int selected_file_attr = 0;
71static int onplay_result = ONPLAY_OK; 71static int onplay_result = ONPLAY_OK;
72static bool (*ctx_playlist_insert)(int position, bool queue, bool create_new);
72extern struct menu_item_ex file_menu; /* settings_menu.c */ 73extern struct menu_item_ex file_menu; /* settings_menu.c */
73 74
74/* redefine MAKE_MENU so the MENU_EXITAFTERTHISMENU flag can be added easily */ 75/* redefine MAKE_MENU so the MENU_EXITAFTERTHISMENU flag can be added easily */
@@ -474,7 +475,7 @@ MAKE_ONPLAYMENU( wps_playlist_menu, ID2P(LANG_PLAYLIST),
474 &playlist_save_item, &reshuffle_item, &playing_time_item 475 &playlist_save_item, &reshuffle_item, &playing_time_item
475 ); 476 );
476 477
477/* CONTEXT_[TREE|ID3DB] playlist options */ 478/* CONTEXT_[TREE|ID3DB|STD] playlist options */
478static bool add_to_playlist(int position, bool queue) 479static bool add_to_playlist(int position, bool queue)
479{ 480{
480 bool new_playlist = false; 481 bool new_playlist = false;
@@ -510,6 +511,10 @@ static bool add_to_playlist(int position, bool queue)
510 { 511 {
511 tagtree_insert_selection_playlist(position, queue); 512 tagtree_insert_selection_playlist(position, queue);
512 } 513 }
514 else if (context == CONTEXT_STD && ctx_playlist_insert != NULL)
515 {
516 ctx_playlist_insert(position, queue, false);
517 }
513 else 518 else
514#endif 519#endif
515 { 520 {
@@ -774,9 +779,10 @@ static int treeplaylist_callback(int action,
774 return action; 779 return action;
775} 780}
776 781
777void onplay_show_playlist_menu(char* path) 782void onplay_show_playlist_menu(const char* path, void (*playlist_insert_cb))
778{ 783{
779 context = CONTEXT_STD; 784 context = CONTEXT_STD;
785 ctx_playlist_insert = playlist_insert_cb;
780 selected_file = path; 786 selected_file = path;
781 if (dir_exists(path)) 787 if (dir_exists(path))
782 selected_file_attr = ATTR_DIRECTORY; 788 selected_file_attr = ATTR_DIRECTORY;
@@ -1939,6 +1945,7 @@ int onplay(char* file, int attr, int from, bool hotkey)
1939 const struct menu_item_ex *menu; 1945 const struct menu_item_ex *menu;
1940 onplay_result = ONPLAY_OK; 1946 onplay_result = ONPLAY_OK;
1941 context = from; 1947 context = from;
1948 ctx_playlist_insert = NULL;
1942 if (file == NULL) 1949 if (file == NULL)
1943 selected_file = NULL; 1950 selected_file = NULL;
1944 else 1951 else
diff --git a/apps/onplay.h b/apps/onplay.h
index 27f0436403..bff8dafff0 100644
--- a/apps/onplay.h
+++ b/apps/onplay.h
@@ -51,6 +51,6 @@ enum hotkey_action {
51 51
52/* needed for the playlist viewer.. eventually clean this up */ 52/* needed for the playlist viewer.. eventually clean this up */
53void onplay_show_playlist_cat_menu(char* track_name); 53void onplay_show_playlist_cat_menu(char* track_name);
54void onplay_show_playlist_menu(char* path); 54void onplay_show_playlist_menu(const char* path, void (*playlist_insert_cb));
55 55
56#endif 56#endif
diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c
index 63d8697ee8..b0f30ea8a1 100644
--- a/apps/playlist_viewer.c
+++ b/apps/playlist_viewer.c
@@ -535,7 +535,7 @@ static int onplay_menu(int index)
535 { 535 {
536 case 0: 536 case 0:
537 /* playlist */ 537 /* playlist */
538 onplay_show_playlist_menu(current_track->name); 538 onplay_show_playlist_menu(current_track->name, NULL);
539 ret = 0; 539 ret = 0;
540 break; 540 break;
541 case 1: 541 case 1:
diff --git a/apps/plugin.c b/apps/plugin.c
index bd7f74e65f..0168a26323 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -805,6 +805,7 @@ static const struct plugin_api rockbox_api = {
805 warn_on_pl_erase, 805 warn_on_pl_erase,
806 playlist_insert_playlist, 806 playlist_insert_playlist,
807 battery_current, 807 battery_current,
808 onplay_show_playlist_menu,
808}; 809};
809 810
810static int plugin_buffer_handle; 811static int plugin_buffer_handle;
diff --git a/apps/plugin.h b/apps/plugin.h
index 38d44530b0..d4d86e50bd 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -110,6 +110,7 @@ int plugin_open(const char *plugin, const char *parameter);
110#include "rbpaths.h" 110#include "rbpaths.h"
111#include "core_alloc.h" 111#include "core_alloc.h"
112#include "screen_access.h" 112#include "screen_access.h"
113#include "onplay.h"
113 114
114#ifdef HAVE_ALBUMART 115#ifdef HAVE_ALBUMART
115#include "albumart.h" 116#include "albumart.h"
@@ -154,7 +155,7 @@ int plugin_open(const char *plugin, const char *parameter);
154#define PLUGIN_MAGIC 0x526F634B /* RocK */ 155#define PLUGIN_MAGIC 0x526F634B /* RocK */
155 156
156/* increase this every time the api struct changes */ 157/* increase this every time the api struct changes */
157#define PLUGIN_API_VERSION 247 158#define PLUGIN_API_VERSION 248
158 159
159/* update this to latest version if a change to the api struct breaks 160/* update this to latest version if a change to the api struct breaks
160 backwards compatibility (and please take the opportunity to sort in any 161 backwards compatibility (and please take the opportunity to sort in any
@@ -931,6 +932,7 @@ struct plugin_api {
931 int (*playlist_insert_playlist)(struct playlist_info* playlist, 932 int (*playlist_insert_playlist)(struct playlist_info* playlist,
932 const char *filename, int position, bool queue); 933 const char *filename, int position, bool queue);
933 int (*battery_current)(void); 934 int (*battery_current)(void);
935 void (*onplay_show_playlist_menu)(const char* path, void (*playlist_insert_cb));
934}; 936};
935 937
936/* plugin header */ 938/* plugin header */
diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c
index 2217c15678..d2b9ae5190 100644
--- a/apps/plugins/pictureflow/pictureflow.c
+++ b/apps/plugins/pictureflow/pictureflow.c
@@ -557,6 +557,12 @@ enum pf_states {
557 557
558static int pf_state; 558static int pf_state;
559 559
560#if PF_PLAYBACK_CAPABLE
561static bool insert_whole_album;
562static bool old_shuffle = false;
563static int old_playlist = -1;
564#endif
565
560/** code */ 566/** code */
561static bool free_slide_prio(int prio); 567static bool free_slide_prio(int prio);
562bool load_new_slide(void); 568bool load_new_slide(void);
@@ -3590,68 +3596,131 @@ static void select_prev_track(void)
3590 3596
3591#if PF_PLAYBACK_CAPABLE 3597#if PF_PLAYBACK_CAPABLE
3592 3598
3593static bool pf_warn_on_pl_erase(void) 3599static bool playlist_insert(int position, bool queue, bool create_new)
3600{
3601 if (position == PLAYLIST_REPLACE)
3602 {
3603 if ((!create_new && rb->playlist_remove_all_tracks(NULL) == 0) ||
3604 (create_new && rb->playlist_create(NULL, NULL) == 0))
3605 position = PLAYLIST_INSERT_LAST;
3606 else
3607 return false;
3608 }
3609
3610 if (!insert_whole_album)
3611 rb->playlist_insert_track(NULL, get_track_filename(pf_tracks.sel),
3612 position, queue, true);
3613 else
3614 {
3615 int i = 0;
3616 do {
3617 rb->yield();
3618 if (rb->playlist_insert_track(NULL, get_track_filename(i),
3619 position, queue, true) < 0)
3620 break;
3621 if (position == PLAYLIST_INSERT_FIRST)
3622 position = PLAYLIST_INSERT;
3623 } while(++i < pf_tracks.count);
3624 }
3625 rb->playlist_sync(NULL);
3626 old_playlist = create_new ? center_slide.slide_index : -1;
3627 return true;
3628}
3629
3630static void track_list_ready(void)
3631{
3632 if (pf_state != pf_show_tracks)
3633 {
3634 rb->splash(0, ID2P(LANG_WAIT));
3635 create_track_index(center_slide.slide_index);
3636 reset_track_list();
3637 }
3638}
3639
3640/**
3641 Brings up "Current Playlist" menu with first
3642 track of selection.
3643
3644 Onplay menu code calls back playlist_insert for
3645 adding all of the tracks.
3646*/
3647static void show_current_playlist_menu(void)
3594{ 3648{
3595#ifdef USEGSLIB 3649#ifdef USEGSLIB
3596 grey_show(false); 3650 grey_show(false);
3651 rb->lcd_clear_display();
3652 rb->lcd_update();
3597#endif 3653#endif
3598 bool ret = rb->warn_on_pl_erase(); 3654 track_list_ready();
3655 insert_whole_album = pf_state != pf_show_tracks;
3656 FOR_NB_SCREENS(i)
3657 rb->viewportmanager_theme_enable(i, true, NULL);
3658 rb->onplay_show_playlist_menu(get_track_filename(pf_tracks.sel),
3659 &playlist_insert);
3660 FOR_NB_SCREENS(i)
3661 rb->viewportmanager_theme_undo(i, false);
3662 if (insert_whole_album)
3663 free_borrowed_tracks();
3599#ifdef USEGSLIB 3664#ifdef USEGSLIB
3600 grey_show(true); 3665 grey_show(true);
3601#endif 3666#endif
3602 return ret; 3667 mylcd_set_drawmode(DRMODE_FG);
3603} 3668}
3604 3669
3670
3605/* 3671/*
3606 * Puts the current tracklist into a newly created playlist and starts playling 3672 * Puts selected album's tracks into a newly created playlist and starts playing
3607 */ 3673 */
3608static void start_playback(bool append) 3674static bool start_playback(bool return_to_WPS)
3609{ 3675{
3610 static int old_playlist = -1, old_shuffle = 0; 3676#ifdef USEGSLIB
3611 int count = 0; 3677 grey_show(false);
3612 int position = pf_tracks.sel; 3678#if LCD_DEPTH > 1
3613 int shuffle = rb->global_settings->playlist_shuffle; 3679 rb->lcd_set_background(N_BRIGHT(0));
3614 /* reuse existing playlist if possible 3680 rb->lcd_set_foreground(N_BRIGHT(255));
3615 * regenerate if shuffle is on or changed, since playlist index and 3681#endif
3616 * selected track are "out of sync" */ 3682 rb->lcd_clear_display();
3617 if (!shuffle && !append && center_slide.slide_index == old_playlist 3683 rb->lcd_update();
3618 && (old_shuffle == shuffle)) 3684#endif /* USEGSLIB */
3619 { 3685
3620 goto play; 3686 if (!rb->warn_on_pl_erase())
3621 }
3622 /* First, replace the current playlist with a new one */
3623 else if (append || (rb->playlist_remove_all_tracks(NULL) == 0
3624 && rb->playlist_create(NULL, NULL) == 0))
3625 { 3687 {
3626 do { 3688#ifdef USEGSLIB
3627 rb->yield(); 3689 grey_show(true);
3628 if (rb->playlist_insert_track(NULL, get_track_filename(count), 3690#endif
3629 PLAYLIST_INSERT_LAST, false, true) < 0) 3691 return false;
3630 break;
3631 } while(++count < pf_tracks.count);
3632 rb->playlist_sync(NULL);
3633 } 3692 }
3634 else
3635 return;
3636 3693
3637 if (!append && rb->global_settings->playlist_shuffle) 3694 track_list_ready();
3638 position = rb->playlist_shuffle(*rb->current_tick, pf_tracks.sel); 3695 insert_whole_album = true;
3639play: 3696 int start_index = pf_tracks.sel;
3640 /* TODO: can we adjust selected_track if !play_selected ? 3697 bool shuffle = rb->global_settings->playlist_shuffle;
3641 * if shuffle, we can't predict the playing track easily, and for either 3698 /* can't reuse playlist if it may be out of sync with our track list */
3642 * case the track list doesn't get auto scrolled*/ 3699 if (shuffle || center_slide.slide_index != old_playlist
3643 if(!append) 3700 || (old_shuffle != shuffle))
3644 { 3701 {
3645 rb->playlist_start(position, 0, 0); 3702 if (!playlist_insert(PLAYLIST_REPLACE, false, true))
3646 /* make warn on playlist erase work */ 3703 {
3647 rb->playlist_get_current()->num_inserted_tracks = 0; 3704#ifdef USEGSLIB
3648 old_playlist = center_slide.slide_index; 3705 grey_show(true);
3706#endif
3707 return false;
3708 }
3709 if (shuffle)
3710 start_index = rb->playlist_shuffle(*rb->current_tick, pf_tracks.sel);
3649 } 3711 }
3650 else 3712 rb->playlist_start(start_index, 0, 0);
3651 old_playlist = -1; 3713 rb->playlist_get_current()->num_inserted_tracks = 0; /* prevent warn_on_pl_erase */
3652 old_shuffle = shuffle; 3714 old_shuffle = shuffle;
3653} 3715 if (return_to_WPS)
3716 pf_cfg.last_album = center_index;
3717#ifdef USEGSLIB
3718 else
3719 grey_show(true);
3654#endif 3720#endif
3721 return true;
3722}
3723#endif /* PF_PLAYBACK_CAPABLE */
3655 3724
3656/** 3725/**
3657 Draw the current album name 3726 Draw the current album name
@@ -3729,28 +3798,6 @@ static void draw_album_text(void)
3729 } 3798 }
3730} 3799}
3731 3800
3732#if PF_PLAYBACK_CAPABLE
3733/**
3734 Display an info message when items have been added to playlist
3735*/
3736static void rb_splash_added_to_playlist(void)
3737{
3738#ifdef USEGSLIB
3739 grey_show(false);
3740#if LCD_DEPTH > 1
3741 rb->lcd_set_background(N_BRIGHT(0));
3742 rb->lcd_set_foreground(N_BRIGHT(255));
3743#endif
3744 rb->lcd_clear_display();
3745 rb->lcd_update();
3746#endif
3747 rb->splash(HZ*2, ID2P(LANG_ADDED_TO_PLAYLIST));
3748#ifdef USEGSLIB
3749 grey_show(true);
3750#endif
3751}
3752#endif
3753
3754 3801
3755static void set_initial_slide(const char* selected_file) 3802static void set_initial_slide(const char* selected_file)
3756{ 3803{
@@ -4101,19 +4148,7 @@ static int pictureflow_main(const char* selected_file)
4101 } else if (pf_state == pf_cover_out) 4148 } else if (pf_state == pf_cover_out)
4102 interrupt_cover_out_animation(); 4149 interrupt_cover_out_animation();
4103 4150
4104 if( pf_state == pf_idle ) { 4151 show_current_playlist_menu();
4105 create_track_index(center_slide.slide_index);
4106 reset_track_list();
4107 start_playback(true);
4108 free_borrowed_tracks();
4109 }
4110 else
4111 {
4112 rb->playlist_insert_track(NULL, get_track_filename(pf_tracks.sel),
4113 PLAYLIST_INSERT_LAST, false, true);
4114 rb->playlist_sync(NULL);
4115 }
4116 rb_splash_added_to_playlist();
4117 } 4152 }
4118 break; 4153 break;
4119#endif 4154#endif
@@ -4128,13 +4163,8 @@ static int pictureflow_main(const char* selected_file)
4128 set_current_slide(target); 4163 set_current_slide(target);
4129#if PF_PLAYBACK_CAPABLE 4164#if PF_PLAYBACK_CAPABLE
4130 if(pf_cfg.auto_wps == 1) { 4165 if(pf_cfg.auto_wps == 1) {
4131 if (!pf_warn_on_pl_erase()) 4166 if (start_playback(true))
4132 break; 4167 return PLUGIN_GOTO_WPS;
4133 create_track_index(center_slide.slide_index);
4134 reset_track_list();
4135 start_playback(false);
4136 pf_cfg.last_album = center_index;
4137 return PLUGIN_GOTO_WPS;
4138 } 4168 }
4139 else 4169 else
4140#endif 4170#endif
@@ -4145,12 +4175,13 @@ static int pictureflow_main(const char* selected_file)
4145 else if (pf_state == pf_cover_in) 4175 else if (pf_state == pf_cover_in)
4146 interrupt_cover_in_animation(); 4176 interrupt_cover_in_animation();
4147#if PF_PLAYBACK_CAPABLE 4177#if PF_PLAYBACK_CAPABLE
4148 else if (pf_state == pf_show_tracks && pf_warn_on_pl_erase()) { 4178 else if (pf_state == pf_show_tracks) {
4149 start_playback(false);
4150 if(pf_cfg.auto_wps != 0) { 4179 if(pf_cfg.auto_wps != 0) {
4151 pf_cfg.last_album = center_index; 4180 if (start_playback(true))
4152 return PLUGIN_GOTO_WPS; 4181 return PLUGIN_GOTO_WPS;
4153 } 4182 }
4183 else
4184 start_playback(false);
4154 } 4185 }
4155#endif 4186#endif
4156 break; 4187 break;
@@ -4226,6 +4257,9 @@ enum plugin_status plugin_start(const void *parameter)
4226 if (configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS, 4257 if (configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS,
4227 CONFIG_VERSION)) 4258 CONFIG_VERSION))
4228 { 4259 {
4260#ifdef USEGSLIB
4261 grey_show(false);
4262#endif
4229 rb->splash(HZ, ID2P(LANG_ERROR_WRITING_CONFIG)); 4263 rb->splash(HZ, ID2P(LANG_ERROR_WRITING_CONFIG));
4230 ret = PLUGIN_ERROR; 4264 ret = PLUGIN_ERROR;
4231 } 4265 }
diff --git a/apps/shortcuts.c b/apps/shortcuts.c
index 3672178647..b0a949933c 100644
--- a/apps/shortcuts.c
+++ b/apps/shortcuts.c
@@ -633,7 +633,7 @@ int do_shortcut_menu(void *ignored)
633 } 633 }
634 else 634 else
635 { 635 {
636 onplay_show_playlist_menu(sc->u.path); 636 onplay_show_playlist_menu(sc->u.path, NULL);
637 } 637 }
638 break; 638 break;
639 case SHORTCUT_FILE: 639 case SHORTCUT_FILE: