Cleanup: use simpler ownership for FilmViewer.
authorCarl Hetherington <cth@carlh.net>
Tue, 11 Oct 2022 23:03:28 +0000 (01:03 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 14 Oct 2022 09:41:18 +0000 (11:41 +0200)
41 files changed:
src/tools/dcpomatic.cc
src/tools/dcpomatic_player.cc
src/wx/audio_dialog.cc
src/wx/audio_dialog.h
src/wx/audio_plot.cc
src/wx/audio_plot.h
src/wx/content_menu.cc
src/wx/content_menu.h
src/wx/content_panel.cc
src/wx/content_panel.h
src/wx/controls.cc
src/wx/controls.h
src/wx/dcp_panel.cc
src/wx/dcp_panel.h
src/wx/film_editor.cc
src/wx/film_editor.h
src/wx/markers_dialog.cc
src/wx/markers_dialog.h
src/wx/markers_panel.cc
src/wx/markers_panel.h
src/wx/player_information.cc
src/wx/player_information.h
src/wx/playlist_controls.cc
src/wx/playlist_controls.h
src/wx/standard_controls.cc
src/wx/standard_controls.h
src/wx/system_information_dialog.cc
src/wx/system_information_dialog.h
src/wx/text_panel.cc
src/wx/text_view.cc
src/wx/text_view.h
src/wx/timeline.cc
src/wx/timeline.h
src/wx/timeline_dialog.cc
src/wx/timeline_dialog.h
src/wx/timing_panel.cc
src/wx/timing_panel.h
src/wx/video_waveform_dialog.cc
src/wx/video_waveform_dialog.h
src/wx/video_waveform_plot.cc
src/wx/video_waveform_plot.h

index 772d90050687f3daa5b0c9e97c6f2845afd5fcd8..adc7823c50a0e8a7e456abacb2bca1ca98c9161d 100644 (file)
@@ -275,6 +275,11 @@ class DOMFrame : public wxFrame
 public:
        explicit DOMFrame (wxString const& title)
                : wxFrame (nullptr, -1, title)
+               /* Use a panel as the only child of the Frame so that we avoid
+                  the dark-grey background on Windows.
+               */
+               , _overall_panel(new wxPanel(this, wxID_ANY))
+               , _film_viewer(_overall_panel)
        {
 #if defined(DCPOMATIC_WINDOWS)
                if (Config::instance()->win32_console()) {
@@ -348,18 +353,12 @@ public:
                Bind (wxEVT_CLOSE_WINDOW, boost::bind (&DOMFrame::close, this, _1));
                Bind (wxEVT_SHOW, boost::bind (&DOMFrame::show, this, _1));
 
-               /* Use a panel as the only child of the Frame so that we avoid
-                  the dark-grey background on Windows.
-               */
-               auto overall_panel = new wxPanel (this, wxID_ANY);
-
-               _film_viewer.reset (new FilmViewer (overall_panel));
-               _controls = new StandardControls (overall_panel, _film_viewer, true);
-               _film_editor = new FilmEditor (overall_panel, _film_viewer);
-               auto job_manager_view = new JobManagerView (overall_panel, false);
+               _controls = new StandardControls(_overall_panel, _film_viewer, true);
+               _film_editor = new FilmEditor(_overall_panel, _film_viewer);
+               auto job_manager_view = new JobManagerView(_overall_panel, false);
 
                auto right_sizer = new wxBoxSizer (wxVERTICAL);
-               right_sizer->Add (_film_viewer->panel(), 2, wxEXPAND | wxALL, 6);
+               right_sizer->Add(_film_viewer.panel(), 2, wxEXPAND | wxALL, 6);
                right_sizer->Add (_controls, 0, wxEXPAND | wxALL, 6);
                right_sizer->Add (job_manager_view, 1, wxEXPAND | wxALL, 6);
 
@@ -374,7 +373,7 @@ public:
 
                JobManager::instance()->ActiveJobsChanged.connect(boost::bind(&DOMFrame::active_jobs_changed, this));
 
-               overall_panel->SetSizer (main_sizer);
+               _overall_panel->SetSizer(main_sizer);
 
                UpdateChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::update_checker_state_changed, this));
 
@@ -481,8 +480,8 @@ public:
        void set_film (shared_ptr<Film> film)
        {
                _film = film;
-               _film_viewer->set_film (_film);
-               _film_editor->set_film (_film);
+               _film_viewer.set_film(_film);
+               _film_editor->set_film(_film);
                _controls->set_film (_film);
                if (_video_waveform_dialog) {
                        _video_waveform_dialog->Destroy ();
@@ -1042,7 +1041,7 @@ private:
 
        void view_closed_captions ()
        {
-               _film_viewer->show_closed_captions ();
+               _film_viewer.show_closed_captions ();
        }
 
        void view_video_waveform ()
@@ -1506,10 +1505,10 @@ private:
 
        void start_stop_pressed ()
        {
-               if (_film_viewer->playing()) {
-                       _film_viewer->stop();
+               if (_film_viewer.playing()) {
+                       _film_viewer.stop();
                } else {
-                       _film_viewer->start();
+                       _film_viewer.start();
                }
        }
 
@@ -1520,12 +1519,12 @@ private:
 
        void back_frame ()
        {
-               _film_viewer->seek_by (-_film_viewer->one_video_frame(), true);
+               _film_viewer.seek_by(-_film_viewer.one_video_frame(), true);
        }
 
        void forward_frame ()
        {
-               _film_viewer->seek_by (_film_viewer->one_video_frame(), true);
+               _film_viewer.seek_by(_film_viewer.one_video_frame(), true);
        }
 
        void analytics_message (string title, string html)
@@ -1551,7 +1550,8 @@ private:
        }
 
        FilmEditor* _film_editor;
-       std::shared_ptr<FilmViewer> _film_viewer;
+       wxPanel* _overall_panel;
+       FilmViewer _film_viewer;
        StandardControls* _controls;
        VideoWaveformDialog* _video_waveform_dialog = nullptr;
        SystemInformationDialog* _system_information_dialog = nullptr;
index d97bdd168edea4052da1a2ca1ec96b076566fefe..ace7fd7933ee66479c47ab9c62a3716b06ab0b1c 100644 (file)
@@ -194,6 +194,11 @@ public:
        DOMFrame ()
                : wxFrame (nullptr, -1, _("DCP-o-matic Player"))
                , _mode (Config::instance()->player_mode())
+               /* Use a panel as the only child of the Frame so that we avoid
+                  the dark-grey background on Windows.
+               */
+               , _overall_panel(new wxPanel(this, wxID_ANY))
+               , _viewer(_overall_panel)
                , _main_sizer (new wxBoxSizer(wxVERTICAL))
        {
                dcpomatic_log = make_shared<NullLog>();
@@ -237,12 +242,6 @@ public:
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
 
-               /* Use a panel as the only child of the Frame so that we avoid
-                  the dark-grey background on Windows.
-               */
-               _overall_panel = new wxPanel (this, wxID_ANY);
-
-               _viewer = make_shared<FilmViewer>(_overall_panel);
                if (Config::instance()->player_mode() == Config::PLAYER_MODE_DUAL) {
                        auto pc = new PlaylistControls (_overall_panel, _viewer);
                        _controls = pc;
@@ -250,10 +249,10 @@ public:
                } else {
                        _controls = new StandardControls (_overall_panel, _viewer, false);
                }
-               _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
-               _viewer->set_optimise_for_j2k (true);
-               _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
-               _viewer->TooManyDropped.connect (bind(&DOMFrame::too_many_frames_dropped, this));
+               _viewer.set_dcp_decode_reduction(Config::instance()->decode_reduction());
+               _viewer.set_optimise_for_j2k(true);
+               _viewer.PlaybackPermitted.connect(bind(&DOMFrame::playback_permitted, this));
+               _viewer.TooManyDropped.connect(bind(&DOMFrame::too_many_frames_dropped, this));
                _info = new PlayerInformation (_overall_panel, _viewer);
                setup_main_sizer (Config::instance()->player_mode());
 #ifdef __WXOSX__
@@ -309,16 +308,16 @@ public:
                /* It's important that this is stopped before our frame starts destroying its children,
                 * otherwise UI elements that it depends on will disappear from under it.
                 */
-               _viewer.reset ();
+               _viewer.stop();
        }
 
        void setup_main_sizer (Config::PlayerMode mode)
        {
-               _main_sizer->Detach (_viewer->panel());
+               _main_sizer->Detach(_viewer.panel());
                _main_sizer->Detach (_controls);
                _main_sizer->Detach (_info);
                if (mode != Config::PLAYER_MODE_DUAL) {
-                       _main_sizer->Add (_viewer->panel(), 1, wxEXPAND);
+                       _main_sizer->Add(_viewer.panel(), 1, wxEXPAND);
                }
                _main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
                _main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
@@ -351,7 +350,7 @@ public:
        void too_many_frames_dropped ()
        {
                if (!Config::instance()->nagged(Config::NAG_TOO_MANY_DROPPED_FRAMES)) {
-                       _viewer->stop ();
+                       _viewer.stop();
                }
 
                NagDialog::maybe_nag (
@@ -368,7 +367,7 @@ public:
 
        void set_decode_reduction (optional<int> reduction)
        {
-               _viewer->set_dcp_decode_reduction (reduction);
+               _viewer.set_dcp_decode_reduction(reduction);
                _info->triggered_update ();
                Config::instance()->set_decode_reduction (reduction);
        }
@@ -434,7 +433,7 @@ public:
                _film = film;
                _film->set_tolerant (true);
                _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
-               _viewer->set_film (_film);
+               _viewer.set_film(_film);
                _controls->set_film (_film);
                _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
                _info->triggered_update ();
@@ -446,8 +445,8 @@ public:
                        return;
                }
 
-               if (_viewer->playing ()) {
-                       _viewer->stop ();
+               if (_viewer.playing()) {
+                       _viewer.stop();
                }
 
                /* Start off as Flat */
@@ -474,7 +473,7 @@ public:
                        }
                }
 
-               _viewer->seek (DCPTime(), true);
+               _viewer.seek(DCPTime(), true);
                _info->triggered_update ();
 
                set_menu_sensitivity ();
@@ -689,10 +688,10 @@ private:
                        DCPOMATIC_ASSERT (dcp);
                        try {
                                if (dcp) {
-                                       _viewer->set_coalesce_player_changes (true);
+                                       _viewer.set_coalesce_player_changes(true);
                                        dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
                                        examine_content();
-                                       _viewer->set_coalesce_player_changes (false);
+                                       _viewer.set_coalesce_player_changes(false);
                                }
                        } catch (exception& e) {
                                error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
@@ -715,7 +714,7 @@ private:
                auto path = boost::filesystem::path (wx_to_std(dialog.GetPath()));
 
                auto player = make_shared<Player>(_film, Image::Alignment::PADDED);
-               player->seek (_viewer->position(), true);
+               player->seek(_viewer.position(), true);
 
                bool done = false;
                player->Video.connect ([path, &done, this](shared_ptr<PlayerVideo> video, DCPTime) {
@@ -792,10 +791,10 @@ private:
                        --id;
                }
 
-               _viewer->set_coalesce_player_changes (true);
+               _viewer.set_coalesce_player_changes(true);
                dcp->set_cpl ((*i)->id());
                examine_content ();
-               _viewer->set_coalesce_player_changes (false);
+               _viewer.set_coalesce_player_changes(false);
 
                _info->triggered_update ();
        }
@@ -838,14 +837,14 @@ private:
                _info->Show (_mode != Config::PLAYER_MODE_FULL);
                _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
                ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
-               _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
+               _viewer.set_pad_black(_mode != Config::PLAYER_MODE_WINDOW);
 
                if (_mode == Config::PLAYER_MODE_DUAL) {
                        _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
                        _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
                        _dual_screen->ShowFullScreen (true);
-                       _viewer->panel()->Reparent (_dual_screen);
-                       _viewer->panel()->SetFocus();
+                       _viewer.panel()->Reparent(_dual_screen);
+                       _viewer.panel()->SetFocus();
                        _dual_screen->Show ();
                        if (wxDisplay::GetCount() > 1) {
                                switch (Config::instance()->image_display()) {
@@ -863,7 +862,7 @@ private:
                        _dual_screen->Bind(wxEVT_CHAR_HOOK, boost::bind(&DOMFrame::dual_screen_key_press, this, _1));
                } else {
                        if (_dual_screen) {
-                               _viewer->panel()->Reparent (_overall_panel);
+                               _viewer.panel()->Reparent(_overall_panel);
                                _dual_screen->Destroy ();
                                _dual_screen = 0;
                        }
@@ -885,7 +884,7 @@ private:
 
        void view_closed_captions ()
        {
-               _viewer->show_closed_captions ();
+               _viewer.show_closed_captions();
        }
 
        void tools_verify ()
@@ -914,7 +913,7 @@ private:
 
        void tools_timing ()
        {
-               auto d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
+               auto d = new TimerDisplay(this, _viewer.state_timer(), _viewer.gets());
                d->ShowModal ();
                d->Destroy ();
        }
@@ -1053,36 +1052,36 @@ private:
 
        void start_stop_pressed ()
        {
-               if (_viewer->playing()) {
-                       _viewer->stop();
+               if (_viewer.playing()) {
+                       _viewer.stop();
                } else {
-                       _viewer->start();
+                       _viewer.start();
                }
        }
 
        void go_back_frame ()
        {
-               _viewer->seek_by (-_viewer->one_video_frame(), true);
+               _viewer.seek_by(-_viewer.one_video_frame(), true);
        }
 
        void go_forward_frame ()
        {
-               _viewer->seek_by (_viewer->one_video_frame(), true);
+               _viewer.seek_by(_viewer.one_video_frame(), true);
        }
 
        void go_seconds (int s)
        {
-               _viewer->seek_by (DCPTime::from_seconds(s), true);
+               _viewer.seek_by(DCPTime::from_seconds(s), true);
        }
 
        void go_to_start ()
        {
-               _viewer->seek (DCPTime(), true);
+               _viewer.seek(DCPTime(), true);
        }
 
        void go_to_end ()
        {
-               _viewer->seek (_film->length() - _viewer->one_video_frame(), true);
+               _viewer.seek(_film->length() - _viewer.one_video_frame(), true);
        }
 
        wxFrame* _dual_screen = nullptr;
@@ -1097,7 +1096,7 @@ private:
        int _history_items = 0;
        int _history_position = 0;
        wxMenuItem* _history_separator = nullptr;
-       shared_ptr<FilmViewer> _viewer;
+       FilmViewer _viewer;
        Controls* _controls;
        SystemInformationDialog* _system_information_dialog = nullptr;
        std::shared_ptr<Film> _film;
index c64f64e31eb4104ce612f9ca24cd98d3212b66f1..30fe2f752ff93249c7be883729a7d4d46b732cbe 100644 (file)
@@ -56,7 +56,7 @@ using namespace boost::placeholders;
  *  @param film Film we are using.
  *  @param content Content to analyse, or 0 to analyse all of the film's audio.
  */
-AudioDialog::AudioDialog (wxWindow* parent, shared_ptr<Film> film, weak_ptr<FilmViewer> viewer, shared_ptr<Content> content)
+AudioDialog::AudioDialog (wxWindow* parent, shared_ptr<Film> film, FilmViewer& viewer, shared_ptr<Content> content)
        : wxDialog (
                parent,
                wxID_ANY,
index a202ad65b1d6be3ef0bf9c81be3cd51730b13caf..746b23f40ecbbea95add7a9b57abaeb4e120b9e9 100644 (file)
@@ -37,7 +37,7 @@ class Film;
 class AudioDialog : public wxDialog
 {
 public:
-       AudioDialog (wxWindow* parent, std::shared_ptr<Film> film, std::weak_ptr<FilmViewer> viewer, std::shared_ptr<Content> content = std::shared_ptr<Content>());
+       AudioDialog(wxWindow* parent, std::shared_ptr<Film> film, FilmViewer& viewer, std::shared_ptr<Content> content = std::shared_ptr<Content>());
 
        bool Show (bool show = true) override;
 
@@ -56,7 +56,7 @@ private:
 
        std::shared_ptr<AudioAnalysis> _analysis;
        std::weak_ptr<Film> _film;
-       std::weak_ptr<FilmViewer> _viewer;
+       FilmViewer& _viewer;
        /** content to analyse, or 0 to analyse all the film's content */
        std::weak_ptr<Content> _content;
        int _channels;
index fbcd9047fbf034b717968f12b40a44f7343df939..59df0425b69824a6dc104d833da643c7a65a35f2 100644 (file)
@@ -54,7 +54,7 @@ int const AudioPlot::_cursor_size = 8;
 int const AudioPlot::max_smoothing = 128;
 
 
-AudioPlot::AudioPlot (wxWindow* parent, weak_ptr<FilmViewer> viewer)
+AudioPlot::AudioPlot(wxWindow* parent, FilmViewer& viewer)
        : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
        , _viewer (viewer)
        , _smoothing (max_smoothing / 2)
@@ -445,9 +445,7 @@ void
 AudioPlot::left_down ()
 {
        if (_cursor) {
-               if (auto fv = _viewer.lock()) {
-                       fv->seek (_cursor->time, true);
-               }
+               _viewer.seek(_cursor->time, true);
        }
 }
 
index b2ffd5ad52467aaf5f7ad6d63551bcdd2f95be20..8755053f53339bf7e107a6086c061e9a5a926aeb 100644 (file)
@@ -33,7 +33,7 @@ class FilmViewer;
 class AudioPlot : public wxPanel
 {
 public:
-       explicit AudioPlot (wxWindow *, std::weak_ptr<FilmViewer> viewer);
+       explicit AudioPlot (wxWindow *, FilmViewer& viewer);
 
        void set_analysis (std::shared_ptr<AudioAnalysis>);
        void set_channel_visible (int c, bool v);
@@ -77,7 +77,7 @@ private:
        void mouse_moved (wxMouseEvent& ev);
        void mouse_leave (wxMouseEvent& ev);
 
-       std::weak_ptr<FilmViewer> _viewer;
+       FilmViewer& _viewer;
        std::shared_ptr<AudioAnalysis> _analysis;
        bool _channel_visible[MAX_DCP_AUDIO_CHANNELS];
        bool _type_visible[AudioPoint::COUNT];
index a80a5fc82e1dffda4a3a0019e5ddf02d186d68fc..6c4864239223e06e58fa842f4fe9cf5ac4364957 100644 (file)
@@ -86,7 +86,7 @@ enum {
 };
 
 
-ContentMenu::ContentMenu (wxWindow* p, weak_ptr<FilmViewer> viewer)
+ContentMenu::ContentMenu(wxWindow* p, FilmViewer& viewer)
        : _menu (new wxMenu)
        , _parent (p)
        , _pop_up_open (false)
@@ -501,17 +501,13 @@ ContentMenu::auto_crop ()
 
        auto film = _film.lock ();
        DCPOMATIC_ASSERT (film);
-       auto viewer = _viewer.lock ();
-       DCPOMATIC_ASSERT (viewer);
 
        auto update_viewer = [this](Crop crop) {
                auto film = _film.lock();
                DCPOMATIC_ASSERT (film);
-               auto viewer = _viewer.lock ();
-               DCPOMATIC_ASSERT (viewer);
                auto const content = _content.front();
                auto const current_crop = content->video->actual_crop();
-               viewer->set_crop_guess (
+               _viewer.set_crop_guess(
                        dcpomatic::Rect<float>(
                                static_cast<float>(std::max(0, crop.left - current_crop.left)) / content->video->size().width,
                                static_cast<float>(std::max(0, crop.top - current_crop.top)) / content->video->size().height,
@@ -520,8 +516,8 @@ ContentMenu::auto_crop ()
                                ));
        };
 
-       auto guess_crop_for_content = [this, film, viewer]() {
-               auto position = viewer->position_in_content(_content.front()).get_value_or(
+       auto guess_crop_for_content = [this, film]() {
+               auto position = _viewer.position_in_content(_content.front()).get_value_or(
                        ContentTime::from_frames(_content.front()->video->length(), _content.front()->video_frame_rate().get_value_or(24))
                        );
                return guess_crop(film, _content.front(), Config::instance()->auto_crop_threshold(), position);
@@ -551,21 +547,21 @@ ContentMenu::auto_crop ()
        });
 
        /* Also update the dialog and view when we're looking at a different frame */
-       _auto_crop_viewer_connection = viewer->ImageChanged.connect([this, guess_crop_for_content, update_viewer](shared_ptr<PlayerVideo>) {
+       _auto_crop_viewer_connection = _viewer.ImageChanged.connect([this, guess_crop_for_content, update_viewer](shared_ptr<PlayerVideo>) {
                auto const crop = guess_crop_for_content();
                _auto_crop_dialog->set(crop);
                update_viewer(crop);
        });
 
        /* Handle the user closing the dialog (with OK or cancel) */
-       _auto_crop_dialog->Bind (wxEVT_BUTTON, [this, viewer](wxCommandEvent& ev) {
+       _auto_crop_dialog->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev) {
                _auto_crop_config_connection.disconnect ();
                _auto_crop_viewer_connection.disconnect ();
                if (ev.GetId() == wxID_OK) {
                        _content.front()->video->set_crop(_auto_crop_dialog->get());
                }
                _auto_crop_dialog->Show (false);
-               viewer->unset_crop_guess ();
+               _viewer.unset_crop_guess ();
        });
 
        /* Update the view when something in the dialog is changed */
index ebbdf5b60e254021165eaa54b53ad491fb21413b..783a5be04067c83ff524f2b35888eb8c1dc73e88 100644 (file)
@@ -42,7 +42,7 @@ class Job;
 class ContentMenu
 {
 public:
-       ContentMenu (wxWindow* parent, std::weak_ptr<FilmViewer> viewer);
+       ContentMenu(wxWindow* parent, FilmViewer& viewer);
 
        ContentMenu (ContentMenu const &) = delete;
        ContentMenu& operator= (ContentMenu const &) = delete;
@@ -69,7 +69,7 @@ private:
        std::weak_ptr<Film> _film;
        wxWindow* _parent;
        bool _pop_up_open;
-       std::weak_ptr<FilmViewer> _viewer;
+       FilmViewer& _viewer;
        ContentList _content;
        TimelineContentViewList _views;
        wxMenuItem* _repeat;
index 6e08644177343d4ac1319a850d7be59a2ba14871..637de9f0f5972d478838d14b30ed98cb390cd794 100644 (file)
@@ -118,7 +118,7 @@ private:
 };
 
 
-ContentPanel::ContentPanel (wxNotebook* n, shared_ptr<Film> film, weak_ptr<FilmViewer> viewer)
+ContentPanel::ContentPanel(wxNotebook* n, shared_ptr<Film> film, FilmViewer& viewer)
        : _parent (n)
        , _film (film)
        , _film_viewer (viewer)
@@ -371,9 +371,7 @@ ContentPanel::check_selection ()
        }
 
        if (go_to && Config::instance()->jump_to_selected() && signal_manager) {
-               auto fv = _film_viewer.lock ();
-               DCPOMATIC_ASSERT (fv);
-               signal_manager->when_idle(boost::bind(&FilmViewer::seek, fv.get(), go_to.get().ceil(_film->video_frame_rate()), true));
+               signal_manager->when_idle(boost::bind(&FilmViewer::seek, &_film_viewer, go_to.get().ceil(_film->video_frame_rate()), true));
        }
 
        if (_timeline_dialog) {
index 896c81880c29a6aa4f832ae49f8793b54c5296d4..3aeb9db17328475984f04bab805cbee9e62b6dbb 100644 (file)
@@ -71,7 +71,7 @@ private:
 class ContentPanel
 {
 public:
-       ContentPanel (wxNotebook *, std::shared_ptr<Film>, std::weak_ptr<FilmViewer> viewer);
+       ContentPanel(wxNotebook *, std::shared_ptr<Film>, FilmViewer& viewer);
 
        ContentPanel (ContentPanel const&) = delete;
        ContentPanel& operator= (ContentPanel const&) = delete;
@@ -109,7 +109,7 @@ public:
        bool remove_clicked (bool hotkey);
        void timeline_clicked ();
 
-       std::weak_ptr<FilmViewer> film_viewer () const {
+       FilmViewer& film_viewer() const {
                return _film_viewer;
        }
 
@@ -158,7 +158,7 @@ private:
        wxWindow* _last_selected_tab = nullptr;
 
        std::shared_ptr<Film> _film;
-       std::weak_ptr<FilmViewer> _film_viewer;
+       FilmViewer& _film_viewer;
        bool _generally_sensitive;
        bool _ignore_deselect;
        bool _no_check_selection;
index c02581cc0ec3ad3dff7833481ea5bc1cf89394ba..61c671788cacb2f328b31775e434b664c15f6d6e 100644 (file)
@@ -64,7 +64,7 @@ using namespace boost::placeholders;
 using namespace dcpomatic;
 
 
-Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor_controls)
+Controls::Controls(wxWindow* parent, FilmViewer& viewer, bool editor_controls)
        : wxPanel (parent)
        , _markers (new MarkersPanel(this, viewer))
        , _slider (new wxSlider(this, wxID_ANY, 0, 0, 4096))
@@ -154,13 +154,13 @@ Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor
                _jump_to_selected->SetValue (Config::instance()->jump_to_selected ());
        }
 
-       viewer->Started.connect (boost::bind(&Controls::started, this));
-       viewer->Stopped.connect (boost::bind(&Controls::stopped, this));
+       viewer.Started.connect (boost::bind(&Controls::started, this));
+       viewer.Stopped.connect (boost::bind(&Controls::stopped, this));
 
        Bind (wxEVT_TIMER, boost::bind(&Controls::update_position, this));
        _timer.Start (80, wxTIMER_CONTINUOUS);
 
-       set_film (viewer->film());
+       set_film(viewer.film());
 
        setup_sensitivity ();
 
@@ -196,12 +196,7 @@ Controls::stopped ()
 void
 Controls::update_position ()
 {
-       auto viewer = _viewer.lock ();
-       if (!viewer) {
-               return;
-       }
-
-       if (!_slider_being_moved && !viewer->pending_idle_get()) {
+       if (!_slider_being_moved && !_viewer.pending_idle_get()) {
                update_position_label ();
                update_position_slider ();
        }
@@ -211,24 +206,14 @@ Controls::update_position ()
 void
 Controls::eye_changed ()
 {
-       auto viewer = _viewer.lock ();
-       if (!viewer) {
-               return;
-       }
-
-       viewer->set_eyes (_eye->GetSelection() == 0 ? Eyes::LEFT : Eyes::RIGHT);
+       _viewer.set_eyes(_eye->GetSelection() == 0 ? Eyes::LEFT : Eyes::RIGHT);
 }
 
 
 void
 Controls::outline_content_changed ()
 {
-       auto viewer = _viewer.lock ();
-       if (!viewer) {
-               return;
-       }
-
-       viewer->set_outline_content (_outline_content->GetValue());
+       _viewer.set_outline_content(_outline_content->GetValue());
 }
 
 
@@ -236,14 +221,13 @@ Controls::outline_content_changed ()
 void
 Controls::slider_moved (bool page)
 {
-       auto viewer = _viewer.lock ();
-       if (!_film || !viewer) {
+       if (!_film) {
                return;
        }
 
        if (!page && !_slider_being_moved) {
                /* This is the first event of a drag; stop playback for the duration of the drag */
-               viewer->suspend ();
+               _viewer.suspend();
                _slider_being_moved = true;
        }
 
@@ -254,10 +238,10 @@ Controls::slider_moved (bool page)
        */
        bool accurate = false;
        if (t >= _film->length ()) {
-               t = _film->length() - viewer->one_video_frame();
+               t = _film->length() - _viewer.one_video_frame();
                accurate = true;
        }
-       viewer->seek (t, accurate);
+       _viewer.seek(t, accurate);
        update_position_label ();
 }
 
@@ -265,13 +249,8 @@ Controls::slider_moved (bool page)
 void
 Controls::slider_released ()
 {
-       auto viewer = _viewer.lock ();
-       if (!viewer) {
-               return;
-       }
-
        /* Restart after a drag */
-       viewer->resume ();
+       _viewer.resume();
        _slider_being_moved = false;
 }
 
@@ -284,15 +263,10 @@ Controls::update_position_slider ()
                return;
        }
 
-       auto viewer = _viewer.lock ();
-       if (!viewer) {
-               return;
-       }
-
        auto const len = _film->length ();
 
        if (len.get ()) {
-               int const new_slider_position = 4096 * viewer->position().get() / len.get();
+               int const new_slider_position = 4096 * _viewer.position().get() / len.get();
                if (new_slider_position != _slider->GetValue()) {
                        _slider->SetValue (new_slider_position);
                }
@@ -309,15 +283,10 @@ Controls::update_position_label ()
                return;
        }
 
-       auto viewer = _viewer.lock ();
-       if (!viewer) {
-               return;
-       }
-
        double const fps = _film->video_frame_rate ();
        /* Count frame number from 1 ... not sure if this is the best idea */
-       checked_set (_frame_number, wxString::Format (wxT("%ld"), lrint (viewer->position().seconds() * fps) + 1));
-       checked_set (_timecode, time_to_timecode (viewer->position(), fps));
+       checked_set(_frame_number, wxString::Format (wxT("%ld"), lrint(_viewer.position().seconds() * fps) + 1));
+       checked_set(_timecode, time_to_timecode(_viewer.position(), fps));
 }
 
 
@@ -332,12 +301,7 @@ Controls::active_jobs_changed (optional<string> j)
 DCPTime
 Controls::nudge_amount (wxKeyboardState& ev)
 {
-       auto viewer = _viewer.lock ();
-       if (!viewer) {
-               return {};
-       }
-
-       auto amount = viewer->one_video_frame ();
+       auto amount = _viewer.one_video_frame();
 
        if (ev.ShiftDown() && !ev.ControlDown()) {
                amount = DCPTime::from_seconds (1);
@@ -354,10 +318,7 @@ Controls::nudge_amount (wxKeyboardState& ev)
 void
 Controls::rewind_clicked (wxMouseEvent& ev)
 {
-       auto viewer = _viewer.lock ();
-       if (viewer) {
-               viewer->seek (DCPTime(), true);
-       }
+       _viewer.seek(DCPTime(), true);
        ev.Skip();
 }
 
@@ -365,40 +326,28 @@ Controls::rewind_clicked (wxMouseEvent& ev)
 void
 Controls::back_frame ()
 {
-       auto viewer = _viewer.lock ();
-       if (viewer) {
-               viewer->seek_by (-viewer->one_video_frame(), true);
-       }
+       _viewer.seek_by(-_viewer.one_video_frame(), true);
 }
 
 
 void
 Controls::forward_frame ()
 {
-       auto viewer = _viewer.lock ();
-       if (viewer) {
-               viewer->seek_by (viewer->one_video_frame(), true);
-       }
+       _viewer.seek_by(_viewer.one_video_frame(), true);
 }
 
 
 void
 Controls::back_clicked (wxKeyboardState& ev)
 {
-       auto viewer = _viewer.lock ();
-       if (viewer) {
-               viewer->seek_by (-nudge_amount(ev), true);
-       }
+       _viewer.seek_by(-nudge_amount(ev), true);
 }
 
 
 void
 Controls::forward_clicked (wxKeyboardState& ev)
 {
-       auto viewer = _viewer.lock ();
-       if (viewer) {
-               viewer->seek_by (nudge_amount(ev), true);
-       }
+       _viewer.seek_by(nudge_amount(ev), true);
 }
 
 
@@ -431,14 +380,9 @@ Controls::setup_sensitivity ()
 void
 Controls::timecode_clicked ()
 {
-       auto viewer = _viewer.lock ();
-       if (!viewer) {
-               return;
-       }
-
-       auto dialog = new PlayheadToTimecodeDialog (this, viewer->position(), _film->video_frame_rate());
+       auto dialog = new PlayheadToTimecodeDialog(this, _viewer.position(), _film->video_frame_rate());
        if (dialog->ShowModal() == wxID_OK) {
-               viewer->seek (dialog->get(), true);
+               _viewer.seek(dialog->get(), true);
        }
        dialog->Destroy ();
 }
@@ -447,14 +391,9 @@ Controls::timecode_clicked ()
 void
 Controls::frame_number_clicked ()
 {
-       auto viewer = _viewer.lock ();
-       if (!viewer) {
-               return;
-       }
-
-       auto dialog = new PlayheadToFrameDialog (this, viewer->position(), _film->video_frame_rate());
+       auto dialog = new PlayheadToFrameDialog(this, _viewer.position(), _film->video_frame_rate());
        if (dialog->ShowModal() == wxID_OK) {
-               viewer->seek (dialog->get(), true);
+               _viewer.seek(dialog->get(), true);
        }
        dialog->Destroy ();
 }
index 5f7dc387a252e549c38ecce3f1ca6c3330f624b3..a7e32179c33d4830c39e0891e0e8cf5bb89f94cb 100644 (file)
@@ -55,7 +55,7 @@ class Controls : public wxPanel
 public:
        Controls (
                wxWindow* parent,
-               std::shared_ptr<FilmViewer>,
+               FilmViewer &,
                bool editor_controls = true
                );
 
@@ -81,7 +81,7 @@ protected:
        std::shared_ptr<Film> _film;
        MarkersPanel* _markers;
        wxSlider* _slider;
-       std::weak_ptr<FilmViewer> _viewer;
+       FilmViewer& _viewer;
        boost::optional<std::string> _active_job;
 
 private:
index ea1dd6d612ab9221014eef9e02e23e25edca1dcf..95c375819cf92f0c7b7f4dc06217e5443e1dcc75 100644 (file)
@@ -70,7 +70,7 @@ using namespace boost::placeholders;
 using dcp::locale_convert;
 
 
-DCPPanel::DCPPanel (wxNotebook* n, shared_ptr<Film> film, weak_ptr<FilmViewer> viewer)
+DCPPanel::DCPPanel(wxNotebook* n, shared_ptr<Film> film, FilmViewer& viewer)
        : _film (film)
        , _viewer (viewer)
        , _generally_sensitive (true)
index 470f98fc8b54afbd1bac1f2b0d4fa6983d107ccb..31d58e1f88ed527c188476a67e7ff346e9cc84f3 100644 (file)
@@ -48,7 +48,7 @@ class SMPTEMetadataDialog;
 class DCPPanel
 {
 public:
-       DCPPanel (wxNotebook *, std::shared_ptr<Film>, std::weak_ptr<FilmViewer> viewer);
+       DCPPanel(wxNotebook *, std::shared_ptr<Film>, FilmViewer& viewer);
 
        DCPPanel (DCPPanel const&) = delete;
        DCPPanel& operator= (DCPPanel const&) = delete;
@@ -165,6 +165,6 @@ private:
        SMPTEMetadataDialog* _smpte_metadata_dialog = nullptr;
 
        std::shared_ptr<Film> _film;
-       std::weak_ptr<FilmViewer> _viewer;
+       FilmViewer& _viewer;
        bool _generally_sensitive;
 };
index 00b260919859e430df45b897405e5a67758091a0..70c4a7b24b3e3c5d14b60dab68d28e406e6ae5ba 100644 (file)
@@ -49,7 +49,7 @@ using namespace boost::placeholders;
 #endif
 
 
-FilmEditor::FilmEditor (wxWindow* parent, weak_ptr<FilmViewer> viewer)
+FilmEditor::FilmEditor(wxWindow* parent, FilmViewer& viewer)
        : wxPanel (parent)
 {
        auto s = new wxBoxSizer (wxVERTICAL);
index d78c9c5af87c4192f374bb77c024e6c5e39d75c8..296058c212e55ee7496ec589e53ac2eaca51e4d0 100644 (file)
@@ -45,7 +45,7 @@ class FilmViewer;
 class FilmEditor : public wxPanel
 {
 public:
-       FilmEditor (wxWindow *, std::weak_ptr<FilmViewer> viewer);
+       FilmEditor(wxWindow *, FilmViewer& viewer);
 
        void set_film (std::shared_ptr<Film>);
        void first_shown ();
index c8561ad743581ee6435ce2cbde3e1398c574f0cf..9c9850af00839d30e1d1ed930fbc6b02cc0c9e44 100644 (file)
@@ -47,7 +47,7 @@ using dcpomatic::DCPTime;
 class Marker
 {
 public:
-       Marker (wxWindow* parent, wxGridBagSizer* grid, int row, weak_ptr<Film> film_, weak_ptr<FilmViewer> viewer_, wxString name, dcp::Marker type_)
+       Marker(wxWindow* parent, wxGridBagSizer* grid, int row, weak_ptr<Film> film_, FilmViewer const& viewer_, wxString name, dcp::Marker type_)
                : film (film_)
                , viewer (viewer_)
                , type (type_)
@@ -92,9 +92,7 @@ private:
        {
                auto f = film.lock ();
                DCPOMATIC_ASSERT (f);
-               auto v = viewer.lock ();
-               DCPOMATIC_ASSERT (v);
-               timecode->set (v->position(), f->video_frame_rate());
+               timecode->set(viewer.position(), f->video_frame_rate());
                changed ();
        }
 
@@ -116,7 +114,7 @@ private:
        }
 
        weak_ptr<Film> film;
-       weak_ptr<FilmViewer> viewer;
+       FilmViewer const& viewer;
        dcp::Marker type;
        CheckBox* checkbox;
        Timecode<dcpomatic::DCPTime>* timecode;
@@ -124,7 +122,7 @@ private:
 };
 
 
-MarkersDialog::MarkersDialog (wxWindow* parent, weak_ptr<Film> film, weak_ptr<FilmViewer> viewer)
+MarkersDialog::MarkersDialog(wxWindow* parent, weak_ptr<Film> film, FilmViewer const& viewer)
        : wxDialog (parent, wxID_ANY, _("Markers"))
        , _film (film)
 {
index 22af7126e29d348d1559b6cb3bd38a02020e8809..e962d44631e9fc28193b3b06f567db5f26485579 100644 (file)
@@ -34,7 +34,7 @@ class FilmViewer;
 class MarkersDialog : public wxDialog
 {
 public:
-       MarkersDialog (wxWindow* parent, std::weak_ptr<Film> film, std::weak_ptr<FilmViewer> viewer);
+       MarkersDialog (wxWindow* parent, std::weak_ptr<Film> film, FilmViewer const& viewer);
 
 private:
        std::list<std::shared_ptr<Marker>> _markers;
index a110da105f5cb36318365b4119f2408e6b1af710..9942dca8993d9d61d7beafc2733b059bd68bcf78 100644 (file)
@@ -53,7 +53,7 @@ enum {
 static constexpr auto line_to_label_gap = 2;
 
 
-MarkersPanel::MarkersPanel (wxWindow* parent, weak_ptr<FilmViewer> viewer)
+MarkersPanel::MarkersPanel(wxWindow* parent, FilmViewer& viewer)
        : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxSize(-1, 16))
        , _viewer (viewer)
 {
@@ -222,9 +222,7 @@ void
 MarkersPanel::mouse_left_down ()
 {
        if (_over) {
-               auto viewer = _viewer.lock ();
-               DCPOMATIC_ASSERT (viewer);
-               viewer->seek (_markers[*_over].time, true);
+               _viewer.seek(_markers[*_over].time, true);
        }
 }
 
@@ -253,12 +251,11 @@ void
 MarkersPanel::move_marker_to_current_position ()
 {
        auto film = _film.lock ();
-       auto viewer = _viewer.lock ();
-       if (!film || !viewer || !_menu_marker) {
+       if (!film || !_menu_marker) {
                return;
        }
 
-       film->set_marker (*_menu_marker, viewer->position());
+       film->set_marker(*_menu_marker, _viewer.position());
 }
 
 
@@ -266,12 +263,11 @@ void
 MarkersPanel::remove_marker ()
 {
        auto film = _film.lock ();
-       auto viewer = _viewer.lock ();
-       if (!film || !viewer || !_menu_marker) {
+       if (!film || !_menu_marker) {
                return;
        }
 
-       film->unset_marker (*_menu_marker);
+       film->unset_marker(*_menu_marker);
 }
 
 
@@ -279,12 +275,11 @@ void
 MarkersPanel::add_marker (wxCommandEvent& ev)
 {
        auto film = _film.lock ();
-       auto viewer = _viewer.lock ();
-       if (!film || !viewer) {
+       if (!film) {
                return;
        }
 
        auto marker = static_cast<dcp::Marker>(ev.GetId() - ID_add_base);
-       film->set_marker (marker, viewer->position());
+       film->set_marker(marker, _viewer.position());
 }
 
index 23cc860c1dbcc74bb6e7144b8e8ecdb9c731a15c..e34008a41fc5c0e4c29c9ef355ef1496e5fd2216 100644 (file)
@@ -34,7 +34,7 @@ class wxTipWindow;
 class MarkersPanel : public wxPanel
 {
 public:
-       MarkersPanel (wxWindow* parent, std::weak_ptr<FilmViewer> viewer);
+       MarkersPanel(wxWindow* parent, FilmViewer& viewer);
 
        void set_film (std::weak_ptr<Film> film);
 
@@ -69,7 +69,7 @@ private:
        std::weak_ptr<Film> _film;
        std::map<dcp::Marker, Marker> _markers;
        boost::optional<dcp::Marker> _over;
-       std::weak_ptr<FilmViewer> _viewer;
+       FilmViewer& _viewer;
        boost::optional<dcp::Marker> _menu_marker;
 };
 
index 058f66764f025d1f476837050c88dff09697fba9..279ff08609b97b9ecd5b12510f5878603690fdb1 100644 (file)
@@ -42,7 +42,7 @@ using boost::optional;
 static int const dcp_lines = 6;
 
 
-PlayerInformation::PlayerInformation (wxWindow* parent, weak_ptr<FilmViewer> viewer)
+PlayerInformation::PlayerInformation(wxWindow* parent, FilmViewer const& viewer)
        : wxPanel (parent)
        , _viewer (viewer)
        , _sizer (new wxBoxSizer (wxHORIZONTAL))
@@ -107,30 +107,22 @@ PlayerInformation::PlayerInformation (wxWindow* parent, weak_ptr<FilmViewer> vie
 void
 PlayerInformation::periodic_update ()
 {
-       auto fv = _viewer.lock ();
-       if (fv) {
-               auto s = wxString::Format(_("Dropped frames: %d"), fv->dropped() + fv->errored());
-               if (fv->errored() == 1) {
-                       s += wxString::Format(_(" (%d error)"), fv->errored());
-               } else if (fv->errored() > 1) {
-                       s += wxString::Format(_(" (%d errors)"), fv->errored());
-               }
-               checked_set (_dropped, s);
+       auto s = wxString::Format(_("Dropped frames: %d"), _viewer.dropped() + _viewer.errored());
+       if (_viewer.errored() == 1) {
+               s += wxString::Format(_(" (%d error)"), _viewer.errored());
+       } else if (_viewer.errored() > 1) {
+               s += wxString::Format(_(" (%d errors)"), _viewer.errored());
        }
+       checked_set (_dropped, s);
 }
 
 
 void
 PlayerInformation::triggered_update ()
 {
-       auto fv = _viewer.lock ();
-       if (!fv) {
-               return;
-       }
-
        shared_ptr<DCPContent> dcp;
-       if (fv->film()) {
-               auto content = fv->film()->content();
+       if (_viewer.film()) {
+               auto content = _viewer.film()->content();
                if (content.size() == 1) {
                        dcp = dynamic_pointer_cast<DCPContent>(content.front());
                }
@@ -180,14 +172,14 @@ PlayerInformation::triggered_update ()
 
        auto const len = String::compose(
                wx_to_std(_("Length: %1 (%2 frames)")),
-               time_to_hmsf(dcp->full_length(fv->film()), lrint(*vfr)),
-               dcp->full_length(fv->film()).frames_round(*vfr)
+               time_to_hmsf(dcp->full_length(_viewer.film()), lrint(*vfr)),
+               dcp->full_length(_viewer.film()).frames_round(*vfr)
                );
 
        checked_set (_dcp[r++], std_to_wx(len));
 
        auto decode = dcp->video->size();
-       auto reduction = fv->dcp_decode_reduction();
+       auto reduction = _viewer.dcp_decode_reduction();
        if (reduction) {
                decode.width /= pow(2, *reduction);
                decode.height /= pow(2, *reduction);
index b311847cb17be9a6c638eff14e71be36ad081848..2ce49371431e3f6e8162aedd66105918e22a40d2 100644 (file)
@@ -32,7 +32,7 @@ class FilmViewer;
 class PlayerInformation : public wxPanel
 {
 public:
-       PlayerInformation (wxWindow* parent, std::weak_ptr<FilmViewer> viewer);
+       PlayerInformation(wxWindow* parent, FilmViewer const& viewer);
 
        void triggered_update ();
 
@@ -40,7 +40,7 @@ private:
 
        void periodic_update ();
 
-       std::weak_ptr<FilmViewer> _viewer;
+       FilmViewer const& _viewer;
        wxPanel* _kdm_panel;
        wxSizer* _sizer;
        wxStaticText** _dcp;
index 5023cad929e51898cacda40883c8e46aad83b0b9..ad5fda862c0012b2c24f052e430f652a9cf4cd98 100644 (file)
@@ -51,7 +51,7 @@ using boost::optional;
 using namespace dcpomatic;
 
 
-PlaylistControls::PlaylistControls (wxWindow* parent, shared_ptr<FilmViewer> viewer)
+PlaylistControls::PlaylistControls(wxWindow* parent, FilmViewer& viewer)
        : Controls (parent, viewer, false)
        , _play_button (new Button(this, _("Play")))
        , _pause_button (new Button(this, _("Pause")))
@@ -115,7 +115,7 @@ PlaylistControls::PlaylistControls (wxWindow* parent, shared_ptr<FilmViewer> vie
        _previous_button->Bind (wxEVT_BUTTON, boost::bind(&PlaylistControls::previous_clicked,  this));
        _spl_view->Bind        (wxEVT_LIST_ITEM_SELECTED,   boost::bind(&PlaylistControls::spl_selection_changed, this));
        _spl_view->Bind        (wxEVT_LIST_ITEM_DESELECTED, boost::bind(&PlaylistControls::spl_selection_changed, this));
-       viewer->Finished.connect (boost::bind(&PlaylistControls::viewer_finished, this));
+       _viewer.Finished.connect(boost::bind(&PlaylistControls::viewer_finished, this));
        _refresh_spl_view->Bind (wxEVT_BUTTON, boost::bind(&PlaylistControls::update_playlist_directory, this));
        _refresh_content_view->Bind (wxEVT_BUTTON, boost::bind(&ContentView::update, _content_view));
 
@@ -148,32 +148,24 @@ PlaylistControls::deselect_playlist ()
                _selected_playlist = boost::none;
                _spl_view->SetItemState (selected, 0, wxLIST_STATE_SELECTED);
        }
-       ResetFilm (shared_ptr<Film>(new Film(optional<boost::filesystem::path>())));
+       ResetFilm(std::make_shared<Film>(optional<boost::filesystem::path>()));
 }
 
 void
 PlaylistControls::play_clicked ()
 {
-       auto viewer = _viewer.lock ();
-       if (viewer) {
-               viewer->start ();
-       }
+       _viewer.start();
 }
 
 void
 PlaylistControls::setup_sensitivity ()
 {
-       auto viewer = _viewer.lock ();
-       if (!viewer) {
-               return;
-       }
-
        Controls::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 (viewer->playing());
-       _spl_view->Enable (!viewer->playing());
+       _play_button->Enable(c && !_viewer.playing());
+       _pause_button->Enable(_viewer.playing());
+       _spl_view->Enable(!_viewer.playing());
        _next_button->Enable (can_do_next());
        _previous_button->Enable (can_do_previous());
 }
@@ -181,22 +173,14 @@ PlaylistControls::setup_sensitivity ()
 void
 PlaylistControls::pause_clicked ()
 {
-       auto viewer = _viewer.lock ();
-       if (viewer) {
-               viewer->stop ();
-       }
+       _viewer.stop();
 }
 
 void
 PlaylistControls::stop_clicked ()
 {
-       auto viewer = _viewer.lock ();
-       if (!viewer) {
-               return;
-       }
-
-       viewer->stop ();
-       viewer->seek (DCPTime(), true);
+       _viewer.stop();
+       _viewer.seek(DCPTime(), true);
        if (_selected_playlist) {
                _selected_playlist_position = 0;
                update_current_content ();
@@ -434,8 +418,7 @@ PlaylistControls::update_current_content ()
 void
 PlaylistControls::viewer_finished ()
 {
-       auto viewer = _viewer.lock ();
-       if (!_selected_playlist || !viewer) {
+       if (!_selected_playlist) {
                return;
        }
 
@@ -443,11 +426,11 @@ PlaylistControls::viewer_finished ()
        if (_selected_playlist_position < int(_playlists[*_selected_playlist].get().size())) {
                /* Next piece of content on the SPL */
                update_current_content ();
-               viewer->start ();
+               _viewer.start();
        } else {
                /* Finished the whole SPL */
                _selected_playlist_position = 0;
-               ResetFilm (shared_ptr<Film>(new Film(optional<boost::filesystem::path>())));
+               ResetFilm(std::make_shared<Film>(optional<boost::filesystem::path>()));
                _play_button->Enable (true);
                _pause_button->Enable (false);
        }
index bc283f288db3936fa6dd5b740c5a52b4863571f8..e1b834054b2918e3e8f0511995cd99f2d2f60192 100644 (file)
@@ -29,7 +29,7 @@ class DCPContent;
 class PlaylistControls : public Controls
 {
 public:
-       PlaylistControls (wxWindow* parent, std::shared_ptr<FilmViewer> viewer);
+       PlaylistControls(wxWindow* parent, FilmViewer& viewer);
 
        void set_film (std::shared_ptr<Film> film) override;
 
index a2914d77ba0727f866bf1b874e63e9babd2b50a2..de63c2fce8da83ab32e74aa6708ff3eca3c07960 100644 (file)
@@ -31,7 +31,7 @@ LIBDCP_ENABLE_WARNINGS
 using std::shared_ptr;
 
 
-StandardControls::StandardControls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor_controls)
+StandardControls::StandardControls(wxWindow* parent, FilmViewer& viewer, bool editor_controls)
        : Controls (parent, viewer, editor_controls)
        , _play_button (new wxToggleButton(this, wxID_ANY, _("Play")))
 {
@@ -66,15 +66,14 @@ StandardControls::play_clicked ()
 void
 StandardControls::check_play_state ()
 {
-       auto viewer = _viewer.lock ();
-       if (!_film || _film->video_frame_rate() == 0 || !viewer) {
+       if (!_film || _film->video_frame_rate() == 0) {
                return;
        }
 
        if (_play_button->GetValue()) {
-               viewer->start ();
+               _viewer.start();
        } else {
-               viewer->stop ();
+               _viewer.stop();
        }
 }
 
index 4e0e836e86cf14be571ddc6153f0c0414eaec7cd..1b8618763313eedc264694b4eb95acd3eb747718 100644 (file)
@@ -25,7 +25,7 @@
 class StandardControls : public Controls
 {
 public:
-       StandardControls (wxWindow* parent, std::shared_ptr<FilmViewer> viewer, bool editor_controls);
+       StandardControls(wxWindow* parent, FilmViewer& viewer, bool editor_controls);
 
        void play () override;
        void stop () override;
index addb89da4c7ab7d64882905b830b1f6651a23312..79a7f735acb0d878334c48a750a940a631262c1e 100644 (file)
@@ -41,20 +41,15 @@ using std::shared_ptr;
 
 #if wxCHECK_VERSION(3, 1, 0)
 
-SystemInformationDialog::SystemInformationDialog (wxWindow* parent, weak_ptr<FilmViewer> weak_viewer)
+SystemInformationDialog::SystemInformationDialog(wxWindow* parent, FilmViewer const& viewer)
        : TableDialog (parent, _("System information"), 2, 1, false)
 {
-       auto viewer = weak_viewer.lock ();
-       shared_ptr<const GLVideoView> gl;
-       if (viewer) {
-               gl = std::dynamic_pointer_cast<const GLVideoView>(viewer->video_view());
-       }
+       auto gl = std::dynamic_pointer_cast<const GLVideoView>(viewer.video_view());
 
        if (!gl) {
                add (_("OpenGL version"), true);
                add (_("unknown (OpenGL not enabled in DCP-o-matic)"), false);
        } else {
-
                auto information = gl->information();
                auto add_string = [this, &information](GLenum name, wxString label) {
                        add (label, true);
@@ -80,7 +75,7 @@ SystemInformationDialog::SystemInformationDialog (wxWindow* parent, weak_ptr<Fil
 
 #else
 
-SystemInformationDialog::SystemInformationDialog (wxWindow* parent, weak_ptr<FilmViewer>)
+SystemInformationDialog::SystemInformationDialog(wxWindow* parent, FilmViewer&)
        : TableDialog (parent, _("System information"), 2, 1, false)
 {
        add (_("OpenGL version"), true);
index 49e617a6eb2b89a816125704ab129a9317fd9db2..48674eecb198a852cbf1cca7d2a86f1ee2851f4e 100644 (file)
@@ -29,5 +29,5 @@ class FilmViewer;
 class SystemInformationDialog : public TableDialog
 {
 public:
-       SystemInformationDialog (wxWindow* parent, std::weak_ptr<FilmViewer> viewer);
+       SystemInformationDialog(wxWindow* parent, FilmViewer const& viewer);
 };
index a9a3f142dd60ce3773f5f2d0f8acb7965052f415..19bac8e8e40b7d5424d70bba9d392888be200466 100644 (file)
@@ -863,10 +863,7 @@ TextPanel::try_to_load_analysis ()
 void
 TextPanel::update_outline_subtitles_in_viewer ()
 {
-       auto fv = _parent->film_viewer().lock();
-       if (!fv) {
-               return;
-       }
+       auto& fv = _parent->film_viewer();
 
        if (_analysis) {
                auto rect = _analysis->bounding_box ();
@@ -876,9 +873,9 @@ TextPanel::update_outline_subtitles_in_viewer ()
                        rect->x += content->text.front()->x_offset() - _analysis->analysis_x_offset();
                        rect->y += content->text.front()->y_offset() - _analysis->analysis_y_offset();
                }
-               fv->set_outline_subtitles (rect);
+               fv.set_outline_subtitles(rect);
        } else {
-               fv->set_outline_subtitles ({});
+               fv.set_outline_subtitles({});
        }
 }
 
index 4a39b913976eba1476bc3a5bb123a006e37928ed..7e526788651794a717e38c75deba15741f249418 100644 (file)
@@ -35,7 +35,6 @@
 using std::dynamic_pointer_cast;
 using std::list;
 using std::shared_ptr;
-using std::weak_ptr;
 using boost::bind;
 using namespace dcpomatic;
 #if BOOST_VERSION >= 106100
@@ -44,7 +43,7 @@ using namespace boost::placeholders;
 
 
 TextView::TextView (
-       wxWindow* parent, shared_ptr<Film> film, shared_ptr<Content> content, shared_ptr<TextContent> text, shared_ptr<Decoder> decoder, weak_ptr<FilmViewer> viewer
+       wxWindow* parent, shared_ptr<Film> film, shared_ptr<Content> content, shared_ptr<TextContent> text, shared_ptr<Decoder> decoder, FilmViewer& viewer
        )
        : wxDialog (parent, wxID_ANY, _("Captions"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
        , _content (content)
@@ -148,8 +147,6 @@ TextView::subtitle_selected (wxListEvent& ev)
        DCPOMATIC_ASSERT (ev.GetIndex() < int(_start_times.size()));
        auto lc = _content.lock ();
        DCPOMATIC_ASSERT (lc);
-       auto fv = _film_viewer.lock ();
-       DCPOMATIC_ASSERT (fv);
        /* Add on a frame here to work around any rounding errors and make sure land in the subtitle */
-       fv->seek (lc, _start_times[ev.GetIndex()] + ContentTime::from_frames(1, _frc->source), true);
+       _film_viewer.seek(lc, _start_times[ev.GetIndex()] + ContentTime::from_frames(1, _frc->source), true);
 }
index f8aba8ffd23a893793e56b467a9e226e8a52c5e6..8cf3c78bbf580480270810723f06878204f50a47 100644 (file)
@@ -38,7 +38,7 @@ public:
                std::shared_ptr<Content> content,
                std::shared_ptr<TextContent> caption,
                std::shared_ptr<Decoder>,
-               std::weak_ptr<FilmViewer> viewer
+               FilmViewer& viewer
                );
 
 private:
@@ -52,5 +52,5 @@ private:
        boost::optional<int> _last_count;
        std::vector<dcpomatic::ContentTime> _start_times;
        std::weak_ptr<Content> _content;
-       std::weak_ptr<FilmViewer> _film_viewer;
+       FilmViewer& _film_viewer;
 };
index f6ede297db3a809408c1a2f7dad9b68437760ed8..6886daa42771e6686fadb96b38890e7949a511b9 100644 (file)
@@ -67,7 +67,7 @@ double const Timeline::_minimum_pixels_per_second = 640.0 / (60 * 60 * 3);
 int const Timeline::_minimum_pixels_per_track = 16;
 
 
-Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr<Film> film, weak_ptr<FilmViewer> viewer)
+Timeline::Timeline(wxWindow* parent, ContentPanel* cp, shared_ptr<Film> film, FilmViewer& viewer)
        : wxPanel (parent, wxID_ANY)
        , _labels_canvas (new wxScrolledCanvas (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE))
        , _main_canvas (new wxScrolledCanvas (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE))
@@ -219,12 +219,9 @@ Timeline::paint_main ()
 
        /* Playhead */
 
-       auto vp = _viewer.lock ();
-       DCPOMATIC_ASSERT (vp);
-
        gc->SetPen (*wxRED_PEN);
        auto path = gc->CreatePath ();
-       double const ph = vp->position().seconds() * pixels_per_second().get_value_or(0);
+       double const ph = _viewer.position().seconds() * pixels_per_second().get_value_or(0);
        path.MoveToPoint (ph, 0);
        path.AddLineToPoint (ph, pixels_per_track() * _tracks + 32);
        gc->StrokePath (path);
index 24c046a6a2faaabebb85400972fcb339ff0e36fe..797b32a55e831623aa0e43e1cfd4ac8483b118ac 100644 (file)
@@ -42,7 +42,7 @@ class TimelineView;
 class Timeline : public wxPanel
 {
 public:
-       Timeline (wxWindow *, ContentPanel *, std::shared_ptr<Film>, std::weak_ptr<FilmViewer> viewer);
+       Timeline (wxWindow *, ContentPanel *, std::shared_ptr<Film>, FilmViewer& viewer);
 
        std::shared_ptr<const Film> film () const;
 
@@ -118,7 +118,7 @@ private:
        wxScrolledCanvas* _main_canvas;
        ContentPanel* _content_panel;
        std::weak_ptr<Film> _film;
-       std::weak_ptr<FilmViewer> _viewer;
+       FilmViewer& _viewer;
        TimelineViewList _views;
        std::shared_ptr<TimelineTimeAxisView> _time_axis_view;
        std::shared_ptr<TimelineReelsView> _reels_view;
index 1c67622c2bffb21858dc405a17afb15fc3fd343d..91737f204db7352085c8fc841ab83359358c005a 100644 (file)
@@ -42,7 +42,7 @@ using namespace boost::placeholders;
 #endif
 
 
-TimelineDialog::TimelineDialog (ContentPanel* cp, shared_ptr<Film> film, weak_ptr<FilmViewer> viewer)
+TimelineDialog::TimelineDialog(ContentPanel* cp, shared_ptr<Film> film, FilmViewer& viewer)
        : wxDialog (
                cp->window(),
                wxID_ANY,
index 8796f2bbfc41add263dfb0ca328d960e95527053..f5dea4eef3c54ab2eae034282f9fb91de281e274 100644 (file)
@@ -32,7 +32,7 @@ class Playlist;
 class TimelineDialog : public wxDialog
 {
 public:
-       TimelineDialog (ContentPanel *, std::shared_ptr<Film>, std::weak_ptr<FilmViewer> viewer);
+       TimelineDialog(ContentPanel *, std::shared_ptr<Film>, FilmViewer& viewer);
 
        void set_selection (ContentList selection);
 
index 494d415eca1742b10cddd0cbb16d6ab77026aeb5..a78e3bdd4fe04f82bf027360cb13074b6777d48b 100644 (file)
@@ -60,7 +60,7 @@ using dcp::locale_convert;
 using namespace dcpomatic;
 
 
-TimingPanel::TimingPanel (ContentPanel* p, weak_ptr<FilmViewer> viewer)
+TimingPanel::TimingPanel (ContentPanel* p, FilmViewer& viewer)
        /* horrid hack for apparent lack of context support with wxWidgets i18n code */
        /// TRANSLATORS: translate the word "Timing" here; do not include the "Timing|" prefix
        : ContentSubPanel (p, S_("Timing|Timing"))
@@ -125,9 +125,7 @@ TimingPanel::create ()
        _trim_end_to_playhead->Bind   (wxEVT_BUTTON, boost::bind (&TimingPanel::trim_end_to_playhead_clicked, this));
        _play_length->Changed.connect (boost::bind (&TimingPanel::play_length_changed, this));
 
-       shared_ptr<FilmViewer> fv = _viewer.lock ();
-       DCPOMATIC_ASSERT (fv);
-       fv->ImageChanged.connect (boost::bind (&TimingPanel::setup_sensitivity, this));
+       _viewer.ImageChanged.connect(boost::bind(&TimingPanel::setup_sensitivity, this));
 
        setup_sensitivity ();
        add_to_grid ();
@@ -346,14 +344,9 @@ TimingPanel::full_length_changed ()
 void
 TimingPanel::trim_start_changed ()
 {
-       shared_ptr<FilmViewer> fv = _viewer.lock ();
-       if (!fv) {
-               return;
-       }
-
-       DCPTime const ph = fv->position ();
+       DCPTime const ph = _viewer.position();
 
-       fv->set_coalesce_player_changes (true);
+       _viewer.set_coalesce_player_changes(true);
 
        shared_ptr<Content> ref;
        optional<FrameRateChange> ref_frc;
@@ -376,21 +369,16 @@ TimingPanel::trim_start_changed ()
        }
 
        if (ref) {
-               fv->seek (max(DCPTime(), ref_ph.get() + ref->position() - DCPTime(ref->trim_start(), ref_frc.get())), true);
+               _viewer.seek(max(DCPTime(), ref_ph.get() + ref->position() - DCPTime(ref->trim_start(), ref_frc.get())), true);
        }
 
-       fv->set_coalesce_player_changes (false);
+       _viewer.set_coalesce_player_changes(false);
 }
 
 void
 TimingPanel::trim_end_changed ()
 {
-       shared_ptr<FilmViewer> fv = _viewer.lock ();
-       if (!fv) {
-               return;
-       }
-
-       fv->set_coalesce_player_changes (true);
+       _viewer.set_coalesce_player_changes(true);
 
        Suspender::Block bl = _film_content_changed_suspender.block ();
        for (auto i: _parent->selected()) {
@@ -399,11 +387,11 @@ TimingPanel::trim_end_changed ()
        }
 
        /* XXX: maybe playhead-off-the-end-of-the-film should be handled elsewhere */
-       if (fv->position() >= _parent->film()->length()) {
-               fv->seek (_parent->film()->length() - DCPTime::from_frames(1, _parent->film()->video_frame_rate()), true);
+       if (_viewer.position() >= _parent->film()->length()) {
+               _viewer.seek(_parent->film()->length() - DCPTime::from_frames(1, _parent->film()->video_frame_rate()), true);
        }
 
-       fv->set_coalesce_player_changes (false);
+       _viewer.set_coalesce_player_changes(false);
 }
 
 void
@@ -443,16 +431,11 @@ TimingPanel::film_changed (Film::Property p)
 void
 TimingPanel::trim_start_to_playhead_clicked ()
 {
-       shared_ptr<FilmViewer> fv = _viewer.lock ();
-       if (!fv) {
-               return;
-       }
-
-       shared_ptr<const Film> film = _parent->film ();
-       DCPTime const ph = fv->position().floor (film->video_frame_rate ());
+       auto film = _parent->film ();
+       DCPTime const ph = _viewer.position().floor(film->video_frame_rate());
        optional<DCPTime> new_ph;
 
-       fv->set_coalesce_player_changes (true);
+       _viewer.set_coalesce_player_changes(true);
 
        for (auto i: _parent->selected()) {
                if (i->position() < ph && ph < i->end(film)) {
@@ -462,23 +445,18 @@ TimingPanel::trim_start_to_playhead_clicked ()
                }
        }
 
-       fv->set_coalesce_player_changes (false);
+       _viewer.set_coalesce_player_changes(false);
 
        if (new_ph) {
-               fv->seek (new_ph.get(), true);
+               _viewer.seek(new_ph.get(), true);
        }
 }
 
 void
 TimingPanel::trim_end_to_playhead_clicked ()
 {
-       shared_ptr<FilmViewer> fv = _viewer.lock ();
-       if (!fv) {
-               return;
-       }
-
-       shared_ptr<const Film> film = _parent->film ();
-       DCPTime const ph = fv->position().floor (film->video_frame_rate ());
+       auto film = _parent->film ();
+       auto const ph = _viewer.position().floor(film->video_frame_rate());
        for (auto i: _parent->selected()) {
                if (i->position() < ph && ph < i->end(film)) {
                        FrameRateChange const frc = film->active_frame_rate_change (i->position ());
@@ -499,9 +477,7 @@ TimingPanel::setup_sensitivity ()
        _trim_end->Enable (e);
        _play_length->Enable (e);
 
-       shared_ptr<FilmViewer> fv = _viewer.lock ();
-       DCPOMATIC_ASSERT (fv);
-       DCPTime const ph = fv->position ();
+       auto const ph = _viewer.position();
        bool any_over_ph = false;
        for (auto i: _parent->selected()) {
                if (i->position() <= ph && ph < i->end(_parent->film())) {
@@ -530,7 +506,7 @@ TimingPanel::move_to_start_of_reel_clicked ()
                }
        }
 
-       MoveToDialog* d = new MoveToDialog (this, position, _parent->film());
+       auto d = new MoveToDialog(this, position, _parent->film());
 
        if (d->ShowModal() == wxID_OK) {
                for (auto i: _parent->selected()) {
index f5c9893dea25b125268e85cfe3e8329307ba10fe..1edaeb27192b18da2f4195b9639676ab878b170b 100644 (file)
@@ -27,7 +27,7 @@ class FilmViewer;
 class TimingPanel : public ContentSubPanel
 {
 public:
-       TimingPanel (ContentPanel *, std::weak_ptr<FilmViewer> viewer);
+       TimingPanel(ContentPanel *, FilmViewer& viewer);
 
        void create () override;
        void film_changed (Film::Property) override;
@@ -48,7 +48,7 @@ private:
        void setup_sensitivity ();
        void add_to_grid () override;
 
-       std::weak_ptr<FilmViewer> _viewer;
+       FilmViewer& _viewer;
 
        wxStaticText* _h_label;
        wxStaticText* _m_label;
index 3177f48cb9009aff7ac5703035ac66b23524fe39..73ccc82df67abb80b6054d7584b289bd65c45aed 100644 (file)
@@ -35,7 +35,7 @@ using namespace boost::placeholders;
 #endif
 
 
-VideoWaveformDialog::VideoWaveformDialog (wxWindow* parent, weak_ptr<const Film> film, weak_ptr<FilmViewer> viewer)
+VideoWaveformDialog::VideoWaveformDialog(wxWindow* parent, weak_ptr<const Film> film, FilmViewer& viewer)
        : wxDialog (
                parent,
                wxID_ANY,
@@ -112,9 +112,7 @@ VideoWaveformDialog::shown (wxShowEvent& ev)
 {
        _plot->set_enabled (ev.IsShown ());
        if (ev.IsShown ()) {
-               shared_ptr<FilmViewer> fv = _viewer.lock ();
-               DCPOMATIC_ASSERT (fv);
-               fv->slow_refresh ();
+               _viewer.slow_refresh();
        }
 }
 
index 99a9a566acdc5b1541881188658a57959e27544d..e524dc92148c0d58f3ffa4a6a4cdc2e39406ec77 100644 (file)
@@ -34,7 +34,7 @@ class Film;
 class VideoWaveformDialog : public wxDialog
 {
 public:
-       VideoWaveformDialog (wxWindow* parent, std::weak_ptr<const Film> film, std::weak_ptr<FilmViewer> viewer);
+       VideoWaveformDialog(wxWindow* parent, std::weak_ptr<const Film> film, FilmViewer& viewer);
 
 private:
        void shown (wxShowEvent &);
@@ -42,7 +42,7 @@ private:
        void contrast_changed ();
        void mouse_moved (int x1, int x2, int y1, int y2);
 
-       std::weak_ptr<FilmViewer> _viewer;
+       FilmViewer& _viewer;
        VideoWaveformPlot* _plot;
        wxChoice* _component;
        wxSlider* _contrast;
index 8e3284682485833dc7395c65b75e1c1edeb3be14..826e173597d31038ec92cdbd421b2123be430b45 100644 (file)
@@ -53,7 +53,7 @@ int const VideoWaveformPlot::_pixel_values = 4096;
 int const VideoWaveformPlot::_x_axis_width = 52;
 
 
-VideoWaveformPlot::VideoWaveformPlot (wxWindow* parent, weak_ptr<const Film> film, weak_ptr<FilmViewer> viewer)
+VideoWaveformPlot::VideoWaveformPlot(wxWindow* parent, weak_ptr<const Film> film, FilmViewer& viewer)
        : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
        , _film (film)
 {
@@ -61,10 +61,7 @@ VideoWaveformPlot::VideoWaveformPlot (wxWindow* parent, weak_ptr<const Film> fil
        SetDoubleBuffered (true);
 #endif
 
-       auto fv = viewer.lock ();
-       DCPOMATIC_ASSERT (fv);
-
-       _viewer_connection = fv->ImageChanged.connect (boost::bind(&VideoWaveformPlot::set_image, this, _1));
+       _viewer_connection = viewer.ImageChanged.connect(boost::bind(&VideoWaveformPlot::set_image, this, _1));
 
        Bind (wxEVT_PAINT, boost::bind(&VideoWaveformPlot::paint, this));
        Bind (wxEVT_SIZE,  boost::bind(&VideoWaveformPlot::sized, this, _1));
index 362efa2acae5b535724c843ddbe4e9359b2d9b2e..f482da8f8a2d75cb2876071abbfcf5aed0c11519 100644 (file)
@@ -39,7 +39,7 @@ class FilmViewer;
 class VideoWaveformPlot : public wxPanel
 {
 public:
-       VideoWaveformPlot (wxWindow* parent, std::weak_ptr<const Film> film, std::weak_ptr<FilmViewer> viewer);
+       VideoWaveformPlot(wxWindow* parent, std::weak_ptr<const Film> film, FilmViewer& viewer);
 
        void set_enabled (bool e);
        void set_component (int c);