swaroop: partial rework of SPL management.
authorCarl Hetherington <cth@carlh.net>
Thu, 13 Dec 2018 01:06:46 +0000 (01:06 +0000)
committerCarl Hetherington <cth@carlh.net>
Thu, 13 Dec 2018 01:06:46 +0000 (01:06 +0000)
src/wx/film_viewer.cc
src/wx/film_viewer.h
src/wx/swaroop_controls.cc
src/wx/swaroop_controls.h

index 0f3869761897f932106dd2fc1b7797854277ec5f..90f8c9fd2d885c20c974c13eb96835ade8b6866f 100644 (file)
@@ -121,6 +121,9 @@ FilmViewer::set_film (shared_ptr<Film> 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);
index 8b45048a7b5d2e1e5aac7054d0a1380c4a2ed701..73c923c26c03b2de156bd6b064cc08787c6422e1 100644 (file)
@@ -93,6 +93,8 @@ public:
        boost::signals2::signal<void (DCPTime)> Started;
        boost::signals2::signal<void (DCPTime)> Stopped;
        boost::signals2::signal<void (DCPTime)> Seeked;
+       /** While playing back we reached the end of the film (emitted from GUI thread) */
+       boost::signals2::signal<void ()> Finished;
 
        boost::signals2::signal<bool ()> PlaybackPermitted;
 
index 99a19f5de7fd17ace10440a3b239e5c00cd8548f..909cb0dc46a8554d0eccff68785934f3bddcbe38 100644 (file)
@@ -98,7 +98,7 @@ SwaroopControls::SwaroopControls (wxWindow* parent, shared_ptr<FilmViewer> 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<PlayerVideo> weak_pv)
-{
-       shared_ptr<PlayerVideo> pv = weak_pv.lock ();
-       if (!pv) {
-               return;
-       }
-
-       shared_ptr<Content> 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<DCPContent> dc = dynamic_pointer_cast<DCPContent> (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> film (new Film(optional<boost::filesystem::path>()));
-       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> film (new Film(optional<boost::filesystem::path>()));
+       film->add_content (_playlists[*_selected_playlist].get()[_selected_playlist_position].content);
        ResetFilm (film);
 }
 
@@ -315,3 +276,22 @@ SwaroopControls::set_film (shared_ptr<Film> 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 ();
+       }
+}
index 54f77de17bb54a565dce3da5285fe454e367a974..7012bcb4782ff78d6695b54c2194e590eee87564 100644 (file)
@@ -45,8 +45,9 @@ private:
        void started ();
        void stopped ();
        void setup_sensitivity ();
-       void image_changed (boost::weak_ptr<PlayerVideo> 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<Content> _current_content;
-       boost::optional<dcp::ContentKind> _current_kind;
        bool _current_disable_timeline;
 
        std::vector<SPL> _playlists;
        boost::optional<int> _selected_playlist;
+       int _selected_playlist_position;
 };