From e81d3bb9857d9de7ec9468a3efcb812042f5cef9 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 13 Dec 2018 01:06:46 +0000 Subject: [PATCH] swaroop: partial rework of SPL management. --- src/wx/film_viewer.cc | 5 +++ src/wx/film_viewer.h | 2 + src/wx/swaroop_controls.cc | 92 +++++++++++++++----------------------- src/wx/swaroop_controls.h | 6 +-- 4 files changed, 46 insertions(+), 59 deletions(-) diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index 0f3869761..90f8c9fd2 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -121,6 +121,9 @@ FilmViewer::set_film (shared_ptr film) } _film = film; + _video_position = DCPTime (); + _player_video.first.reset (); + _player_video.second = DCPTime (); _frame.reset (); _closed_captions_dialog->clear (); @@ -295,6 +298,8 @@ FilmViewer::timer () if (next >= _film->length()) { stop (); + Finished (); + return; } _timer.Start (max ((next.seconds() - time().seconds()) * 1000, 1.0), wxTIMER_ONE_SHOT); diff --git a/src/wx/film_viewer.h b/src/wx/film_viewer.h index 8b45048a7..73c923c26 100644 --- a/src/wx/film_viewer.h +++ b/src/wx/film_viewer.h @@ -93,6 +93,8 @@ public: boost::signals2::signal Started; boost::signals2::signal Stopped; boost::signals2::signal Seeked; + /** While playing back we reached the end of the film (emitted from GUI thread) */ + boost::signals2::signal Finished; boost::signals2::signal PlaybackPermitted; diff --git a/src/wx/swaroop_controls.cc b/src/wx/swaroop_controls.cc index 99a19f5de..909cb0dc4 100644 --- a/src/wx/swaroop_controls.cc +++ b/src/wx/swaroop_controls.cc @@ -98,7 +98,7 @@ SwaroopControls::SwaroopControls (wxWindow* parent, shared_ptr viewe _stop_button->Bind (wxEVT_BUTTON, boost::bind(&SwaroopControls::stop_clicked, this)); _spl_view->Bind (wxEVT_LIST_ITEM_SELECTED, boost::bind(&SwaroopControls::spl_selection_changed, this)); _spl_view->Bind (wxEVT_LIST_ITEM_DESELECTED, boost::bind(&SwaroopControls::spl_selection_changed, this)); - _viewer->ImageChanged.connect (boost::bind(&SwaroopControls::image_changed, this, _1)); + _viewer->Finished.connect (boost::bind(&SwaroopControls::viewer_finished, this)); _refresh_spl_view->Bind (wxEVT_BUTTON, boost::bind(&SwaroopControls::update_playlist_directory, this)); _refresh_content_view->Bind (wxEVT_BUTTON, boost::bind(&ContentView::update, _content_view)); @@ -135,9 +135,8 @@ SwaroopControls::setup_sensitivity () bool const active_job = _active_job && *_active_job != "examine_content"; bool const c = _film && !_film->content().empty() && !active_job; _play_button->Enable (c && !_viewer->playing()); - _pause_button->Enable (c && (!_current_kind || _current_kind != dcp::ADVERTISEMENT) && _viewer->playing()); - _stop_button->Enable (c && (!_current_kind || _current_kind != dcp::ADVERTISEMENT)); - _slider->Enable (c && (!_current_kind || _current_kind != dcp::ADVERTISEMENT) && !_current_disable_timeline); + _pause_button->Enable (_viewer->playing()); + _slider->Enable (!_current_disable_timeline); _spl_view->Enable (!_viewer->playing()); } @@ -167,45 +166,6 @@ SwaroopControls::log (wxString s) _log->SetValue(_log->GetValue() + ts + s + "\n"); } -void -SwaroopControls::image_changed (boost::weak_ptr weak_pv) -{ - shared_ptr pv = weak_pv.lock (); - if (!pv) { - return; - } - - shared_ptr c = pv->content().lock(); - if (!c) { - return; - } - - if (c == _current_content.lock()) { - return; - } - - _current_content = c; - - if (_selected_playlist) { - BOOST_FOREACH (SPLEntry i, _playlists[*_selected_playlist].get()) { - if (i.content == c) { - _current_disable_timeline = i.disable_timeline; - setup_sensitivity (); - } - } - } - - shared_ptr dc = dynamic_pointer_cast (c); - if (!dc) { - return; - } - - if (!_current_kind || *_current_kind != dc->content_kind()) { - _current_kind = dc->content_kind (); - setup_sensitivity (); - } -} - void SwaroopControls::add_playlist_to_list (SPL spl) { @@ -266,21 +226,12 @@ SwaroopControls::spl_selection_changed () return; } - wxProgressDialog* progress = new wxProgressDialog (_("DCP-o-matic"), _("Loading playlist")); - - shared_ptr film (new Film(optional())); - BOOST_FOREACH (SPLEntry i, _playlists[selected].get()) { - film->add_content (i.content); - if (!progress->Pulse()) { - /* user pressed cancel */ - _selected_playlist = boost::none; - _spl_view->SetItemState (selected, 0, wxLIST_STATE_SELECTED); - progress->Destroy (); - return; - } + if (_playlists[selected].get().empty()) { + error_dialog (this, "This playlist is empty."); + return; } - progress->Destroy (); + _current_spl_view->DeleteAllItems (); int N = 0; @@ -294,6 +245,16 @@ SwaroopControls::spl_selection_changed () } _selected_playlist = selected; + _selected_playlist_position = 0; + reset_film (); +} + +void +SwaroopControls::reset_film () +{ + DCPOMATIC_ASSERT (_selected_playlist); + shared_ptr film (new Film(optional())); + film->add_content (_playlists[*_selected_playlist].get()[_selected_playlist_position].content); ResetFilm (film); } @@ -315,3 +276,22 @@ SwaroopControls::set_film (shared_ptr film) Controls::set_film (film); setup_sensitivity (); } + +void +SwaroopControls::viewer_finished () +{ + if (!_selected_playlist) { + return; + } + + ++_selected_playlist_position; + + SPL const & playlist = _playlists[*_selected_playlist]; + + if (_selected_playlist_position < int(playlist.get().size())) { + _current_disable_timeline = playlist.get()[_selected_playlist_position].disable_timeline; + setup_sensitivity (); + reset_film (); + _viewer->start (); + } +} diff --git a/src/wx/swaroop_controls.h b/src/wx/swaroop_controls.h index 54f77de17..7012bcb47 100644 --- a/src/wx/swaroop_controls.h +++ b/src/wx/swaroop_controls.h @@ -45,8 +45,9 @@ private: void started (); void stopped (); void setup_sensitivity (); - void image_changed (boost::weak_ptr weak_pv); void config_changed (int); + void viewer_finished (); + void reset_film (); wxButton* _play_button; wxButton* _pause_button; @@ -59,10 +60,9 @@ private: wxListCtrl* _current_spl_view; wxTextCtrl* _log; - boost::weak_ptr _current_content; - boost::optional _current_kind; bool _current_disable_timeline; std::vector _playlists; boost::optional _selected_playlist; + int _selected_playlist_position; }; -- 2.30.2