summaryrefslogtreecommitdiff
path: root/apps/plugins/pictureflow
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/plugins/pictureflow
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/plugins/pictureflow')
-rw-r--r--apps/plugins/pictureflow/pictureflow.c216
1 files changed, 125 insertions, 91 deletions
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 }