From 449f383f13e5755c523db11f9adef53b58391025 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 12 Oct 2022 01:03:28 +0200 Subject: [PATCH] Cleanup: use simpler ownership for FilmViewer. --- src/tools/dcpomatic.cc | 40 +++++----- src/tools/dcpomatic_player.cc | 77 ++++++++++--------- src/wx/audio_dialog.cc | 2 +- src/wx/audio_dialog.h | 4 +- src/wx/audio_plot.cc | 6 +- src/wx/audio_plot.h | 4 +- src/wx/content_menu.cc | 18 ++--- src/wx/content_menu.h | 4 +- src/wx/content_panel.cc | 6 +- src/wx/content_panel.h | 6 +- src/wx/controls.cc | 111 +++++++--------------------- src/wx/controls.h | 4 +- src/wx/dcp_panel.cc | 2 +- src/wx/dcp_panel.h | 4 +- src/wx/film_editor.cc | 2 +- src/wx/film_editor.h | 2 +- src/wx/markers_dialog.cc | 10 +-- src/wx/markers_dialog.h | 2 +- src/wx/markers_panel.cc | 21 ++---- src/wx/markers_panel.h | 4 +- src/wx/player_information.cc | 32 +++----- src/wx/player_information.h | 4 +- src/wx/playlist_controls.cc | 43 ++++------- src/wx/playlist_controls.h | 2 +- src/wx/standard_controls.cc | 9 +-- src/wx/standard_controls.h | 2 +- src/wx/system_information_dialog.cc | 11 +-- src/wx/system_information_dialog.h | 2 +- src/wx/text_panel.cc | 9 +-- src/wx/text_view.cc | 7 +- src/wx/text_view.h | 4 +- src/wx/timeline.cc | 7 +- src/wx/timeline.h | 4 +- src/wx/timeline_dialog.cc | 2 +- src/wx/timeline_dialog.h | 2 +- src/wx/timing_panel.cc | 62 +++++----------- src/wx/timing_panel.h | 4 +- src/wx/video_waveform_dialog.cc | 6 +- src/wx/video_waveform_dialog.h | 4 +- src/wx/video_waveform_plot.cc | 7 +- src/wx/video_waveform_plot.h | 2 +- 41 files changed, 204 insertions(+), 350 deletions(-) diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index 772d90050..adc7823c5 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -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_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 _film_viewer; + wxPanel* _overall_panel; + FilmViewer _film_viewer; StandardControls* _controls; VideoWaveformDialog* _video_waveform_dialog = nullptr; SystemInformationDialog* _system_information_dialog = nullptr; diff --git a/src/tools/dcpomatic_player.cc b/src/tools/dcpomatic_player.cc index d97bdd168..ace7fd793 100644 --- a/src/tools/dcpomatic_player.cc +++ b/src/tools/dcpomatic_player.cc @@ -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(); @@ -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(_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 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(_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 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 _viewer; + FilmViewer _viewer; Controls* _controls; SystemInformationDialog* _system_information_dialog = nullptr; std::shared_ptr _film; diff --git a/src/wx/audio_dialog.cc b/src/wx/audio_dialog.cc index c64f64e31..30fe2f752 100644 --- a/src/wx/audio_dialog.cc +++ b/src/wx/audio_dialog.cc @@ -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, weak_ptr viewer, shared_ptr content) +AudioDialog::AudioDialog (wxWindow* parent, shared_ptr film, FilmViewer& viewer, shared_ptr content) : wxDialog ( parent, wxID_ANY, diff --git a/src/wx/audio_dialog.h b/src/wx/audio_dialog.h index a202ad65b..746b23f40 100644 --- a/src/wx/audio_dialog.h +++ b/src/wx/audio_dialog.h @@ -37,7 +37,7 @@ class Film; class AudioDialog : public wxDialog { public: - AudioDialog (wxWindow* parent, std::shared_ptr film, std::weak_ptr viewer, std::shared_ptr content = std::shared_ptr()); + AudioDialog(wxWindow* parent, std::shared_ptr film, FilmViewer& viewer, std::shared_ptr content = std::shared_ptr()); bool Show (bool show = true) override; @@ -56,7 +56,7 @@ private: std::shared_ptr _analysis; std::weak_ptr _film; - std::weak_ptr _viewer; + FilmViewer& _viewer; /** content to analyse, or 0 to analyse all the film's content */ std::weak_ptr _content; int _channels; diff --git a/src/wx/audio_plot.cc b/src/wx/audio_plot.cc index fbcd9047f..59df0425b 100644 --- a/src/wx/audio_plot.cc +++ b/src/wx/audio_plot.cc @@ -54,7 +54,7 @@ int const AudioPlot::_cursor_size = 8; int const AudioPlot::max_smoothing = 128; -AudioPlot::AudioPlot (wxWindow* parent, weak_ptr 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); } } diff --git a/src/wx/audio_plot.h b/src/wx/audio_plot.h index b2ffd5ad5..8755053f5 100644 --- a/src/wx/audio_plot.h +++ b/src/wx/audio_plot.h @@ -33,7 +33,7 @@ class FilmViewer; class AudioPlot : public wxPanel { public: - explicit AudioPlot (wxWindow *, std::weak_ptr viewer); + explicit AudioPlot (wxWindow *, FilmViewer& viewer); void set_analysis (std::shared_ptr); 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 _viewer; + FilmViewer& _viewer; std::shared_ptr _analysis; bool _channel_visible[MAX_DCP_AUDIO_CHANNELS]; bool _type_visible[AudioPoint::COUNT]; diff --git a/src/wx/content_menu.cc b/src/wx/content_menu.cc index a80a5fc82..6c4864239 100644 --- a/src/wx/content_menu.cc +++ b/src/wx/content_menu.cc @@ -86,7 +86,7 @@ enum { }; -ContentMenu::ContentMenu (wxWindow* p, weak_ptr 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( static_cast(std::max(0, crop.left - current_crop.left)) / content->video->size().width, static_cast(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) { + _auto_crop_viewer_connection = _viewer.ImageChanged.connect([this, guess_crop_for_content, update_viewer](shared_ptr) { 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 */ diff --git a/src/wx/content_menu.h b/src/wx/content_menu.h index ebbdf5b60..783a5be04 100644 --- a/src/wx/content_menu.h +++ b/src/wx/content_menu.h @@ -42,7 +42,7 @@ class Job; class ContentMenu { public: - ContentMenu (wxWindow* parent, std::weak_ptr viewer); + ContentMenu(wxWindow* parent, FilmViewer& viewer); ContentMenu (ContentMenu const &) = delete; ContentMenu& operator= (ContentMenu const &) = delete; @@ -69,7 +69,7 @@ private: std::weak_ptr _film; wxWindow* _parent; bool _pop_up_open; - std::weak_ptr _viewer; + FilmViewer& _viewer; ContentList _content; TimelineContentViewList _views; wxMenuItem* _repeat; diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index 6e0864417..637de9f0f 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -118,7 +118,7 @@ private: }; -ContentPanel::ContentPanel (wxNotebook* n, shared_ptr film, weak_ptr viewer) +ContentPanel::ContentPanel(wxNotebook* n, shared_ptr 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) { diff --git a/src/wx/content_panel.h b/src/wx/content_panel.h index 896c81880..3aeb9db17 100644 --- a/src/wx/content_panel.h +++ b/src/wx/content_panel.h @@ -71,7 +71,7 @@ private: class ContentPanel { public: - ContentPanel (wxNotebook *, std::shared_ptr, std::weak_ptr viewer); + ContentPanel(wxNotebook *, std::shared_ptr, 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 film_viewer () const { + FilmViewer& film_viewer() const { return _film_viewer; } @@ -158,7 +158,7 @@ private: wxWindow* _last_selected_tab = nullptr; std::shared_ptr _film; - std::weak_ptr _film_viewer; + FilmViewer& _film_viewer; bool _generally_sensitive; bool _ignore_deselect; bool _no_check_selection; diff --git a/src/wx/controls.cc b/src/wx/controls.cc index c02581cc0..61c671788 100644 --- a/src/wx/controls.cc +++ b/src/wx/controls.cc @@ -64,7 +64,7 @@ using namespace boost::placeholders; using namespace dcpomatic; -Controls::Controls (wxWindow* parent, shared_ptr 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 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 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 (); } diff --git a/src/wx/controls.h b/src/wx/controls.h index 5f7dc387a..a7e32179c 100644 --- a/src/wx/controls.h +++ b/src/wx/controls.h @@ -55,7 +55,7 @@ class Controls : public wxPanel public: Controls ( wxWindow* parent, - std::shared_ptr, + FilmViewer &, bool editor_controls = true ); @@ -81,7 +81,7 @@ protected: std::shared_ptr _film; MarkersPanel* _markers; wxSlider* _slider; - std::weak_ptr _viewer; + FilmViewer& _viewer; boost::optional _active_job; private: diff --git a/src/wx/dcp_panel.cc b/src/wx/dcp_panel.cc index ea1dd6d61..95c375819 100644 --- a/src/wx/dcp_panel.cc +++ b/src/wx/dcp_panel.cc @@ -70,7 +70,7 @@ using namespace boost::placeholders; using dcp::locale_convert; -DCPPanel::DCPPanel (wxNotebook* n, shared_ptr film, weak_ptr viewer) +DCPPanel::DCPPanel(wxNotebook* n, shared_ptr film, FilmViewer& viewer) : _film (film) , _viewer (viewer) , _generally_sensitive (true) diff --git a/src/wx/dcp_panel.h b/src/wx/dcp_panel.h index 470f98fc8..31d58e1f8 100644 --- a/src/wx/dcp_panel.h +++ b/src/wx/dcp_panel.h @@ -48,7 +48,7 @@ class SMPTEMetadataDialog; class DCPPanel { public: - DCPPanel (wxNotebook *, std::shared_ptr, std::weak_ptr viewer); + DCPPanel(wxNotebook *, std::shared_ptr, 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; - std::weak_ptr _viewer; + FilmViewer& _viewer; bool _generally_sensitive; }; diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc index 00b260919..70c4a7b24 100644 --- a/src/wx/film_editor.cc +++ b/src/wx/film_editor.cc @@ -49,7 +49,7 @@ using namespace boost::placeholders; #endif -FilmEditor::FilmEditor (wxWindow* parent, weak_ptr viewer) +FilmEditor::FilmEditor(wxWindow* parent, FilmViewer& viewer) : wxPanel (parent) { auto s = new wxBoxSizer (wxVERTICAL); diff --git a/src/wx/film_editor.h b/src/wx/film_editor.h index d78c9c5af..296058c21 100644 --- a/src/wx/film_editor.h +++ b/src/wx/film_editor.h @@ -45,7 +45,7 @@ class FilmViewer; class FilmEditor : public wxPanel { public: - FilmEditor (wxWindow *, std::weak_ptr viewer); + FilmEditor(wxWindow *, FilmViewer& viewer); void set_film (std::shared_ptr); void first_shown (); diff --git a/src/wx/markers_dialog.cc b/src/wx/markers_dialog.cc index c8561ad74..9c9850af0 100644 --- a/src/wx/markers_dialog.cc +++ b/src/wx/markers_dialog.cc @@ -47,7 +47,7 @@ using dcpomatic::DCPTime; class Marker { public: - Marker (wxWindow* parent, wxGridBagSizer* grid, int row, weak_ptr film_, weak_ptr viewer_, wxString name, dcp::Marker type_) + Marker(wxWindow* parent, wxGridBagSizer* grid, int row, weak_ptr 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; - weak_ptr viewer; + FilmViewer const& viewer; dcp::Marker type; CheckBox* checkbox; Timecode* timecode; @@ -124,7 +122,7 @@ private: }; -MarkersDialog::MarkersDialog (wxWindow* parent, weak_ptr film, weak_ptr viewer) +MarkersDialog::MarkersDialog(wxWindow* parent, weak_ptr film, FilmViewer const& viewer) : wxDialog (parent, wxID_ANY, _("Markers")) , _film (film) { diff --git a/src/wx/markers_dialog.h b/src/wx/markers_dialog.h index 22af7126e..e962d4463 100644 --- a/src/wx/markers_dialog.h +++ b/src/wx/markers_dialog.h @@ -34,7 +34,7 @@ class FilmViewer; class MarkersDialog : public wxDialog { public: - MarkersDialog (wxWindow* parent, std::weak_ptr film, std::weak_ptr viewer); + MarkersDialog (wxWindow* parent, std::weak_ptr film, FilmViewer const& viewer); private: std::list> _markers; diff --git a/src/wx/markers_panel.cc b/src/wx/markers_panel.cc index a110da105..9942dca89 100644 --- a/src/wx/markers_panel.cc +++ b/src/wx/markers_panel.cc @@ -53,7 +53,7 @@ enum { static constexpr auto line_to_label_gap = 2; -MarkersPanel::MarkersPanel (wxWindow* parent, weak_ptr 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(ev.GetId() - ID_add_base); - film->set_marker (marker, viewer->position()); + film->set_marker(marker, _viewer.position()); } diff --git a/src/wx/markers_panel.h b/src/wx/markers_panel.h index 23cc860c1..e34008a41 100644 --- a/src/wx/markers_panel.h +++ b/src/wx/markers_panel.h @@ -34,7 +34,7 @@ class wxTipWindow; class MarkersPanel : public wxPanel { public: - MarkersPanel (wxWindow* parent, std::weak_ptr viewer); + MarkersPanel(wxWindow* parent, FilmViewer& viewer); void set_film (std::weak_ptr film); @@ -69,7 +69,7 @@ private: std::weak_ptr _film; std::map _markers; boost::optional _over; - std::weak_ptr _viewer; + FilmViewer& _viewer; boost::optional _menu_marker; }; diff --git a/src/wx/player_information.cc b/src/wx/player_information.cc index 058f66764..279ff0860 100644 --- a/src/wx/player_information.cc +++ b/src/wx/player_information.cc @@ -42,7 +42,7 @@ using boost::optional; static int const dcp_lines = 6; -PlayerInformation::PlayerInformation (wxWindow* parent, weak_ptr 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 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 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(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); diff --git a/src/wx/player_information.h b/src/wx/player_information.h index b311847cb..2ce493714 100644 --- a/src/wx/player_information.h +++ b/src/wx/player_information.h @@ -32,7 +32,7 @@ class FilmViewer; class PlayerInformation : public wxPanel { public: - PlayerInformation (wxWindow* parent, std::weak_ptr viewer); + PlayerInformation(wxWindow* parent, FilmViewer const& viewer); void triggered_update (); @@ -40,7 +40,7 @@ private: void periodic_update (); - std::weak_ptr _viewer; + FilmViewer const& _viewer; wxPanel* _kdm_panel; wxSizer* _sizer; wxStaticText** _dcp; diff --git a/src/wx/playlist_controls.cc b/src/wx/playlist_controls.cc index 5023cad92..ad5fda862 100644 --- a/src/wx/playlist_controls.cc +++ b/src/wx/playlist_controls.cc @@ -51,7 +51,7 @@ using boost::optional; using namespace dcpomatic; -PlaylistControls::PlaylistControls (wxWindow* parent, shared_ptr 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 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(new Film(optional()))); + ResetFilm(std::make_shared(optional())); } 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(new Film(optional()))); + ResetFilm(std::make_shared(optional())); _play_button->Enable (true); _pause_button->Enable (false); } diff --git a/src/wx/playlist_controls.h b/src/wx/playlist_controls.h index bc283f288..e1b834054 100644 --- a/src/wx/playlist_controls.h +++ b/src/wx/playlist_controls.h @@ -29,7 +29,7 @@ class DCPContent; class PlaylistControls : public Controls { public: - PlaylistControls (wxWindow* parent, std::shared_ptr viewer); + PlaylistControls(wxWindow* parent, FilmViewer& viewer); void set_film (std::shared_ptr film) override; diff --git a/src/wx/standard_controls.cc b/src/wx/standard_controls.cc index a2914d77b..de63c2fce 100644 --- a/src/wx/standard_controls.cc +++ b/src/wx/standard_controls.cc @@ -31,7 +31,7 @@ LIBDCP_ENABLE_WARNINGS using std::shared_ptr; -StandardControls::StandardControls (wxWindow* parent, shared_ptr 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(); } } diff --git a/src/wx/standard_controls.h b/src/wx/standard_controls.h index 4e0e836e8..1b8618763 100644 --- a/src/wx/standard_controls.h +++ b/src/wx/standard_controls.h @@ -25,7 +25,7 @@ class StandardControls : public Controls { public: - StandardControls (wxWindow* parent, std::shared_ptr viewer, bool editor_controls); + StandardControls(wxWindow* parent, FilmViewer& viewer, bool editor_controls); void play () override; void stop () override; diff --git a/src/wx/system_information_dialog.cc b/src/wx/system_information_dialog.cc index addb89da4..79a7f735a 100644 --- a/src/wx/system_information_dialog.cc +++ b/src/wx/system_information_dialog.cc @@ -41,20 +41,15 @@ using std::shared_ptr; #if wxCHECK_VERSION(3, 1, 0) -SystemInformationDialog::SystemInformationDialog (wxWindow* parent, weak_ptr weak_viewer) +SystemInformationDialog::SystemInformationDialog(wxWindow* parent, FilmViewer const& viewer) : TableDialog (parent, _("System information"), 2, 1, false) { - auto viewer = weak_viewer.lock (); - shared_ptr gl; - if (viewer) { - gl = std::dynamic_pointer_cast(viewer->video_view()); - } + auto gl = std::dynamic_pointer_cast(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) +SystemInformationDialog::SystemInformationDialog(wxWindow* parent, FilmViewer&) : TableDialog (parent, _("System information"), 2, 1, false) { add (_("OpenGL version"), true); diff --git a/src/wx/system_information_dialog.h b/src/wx/system_information_dialog.h index 49e617a6e..48674eecb 100644 --- a/src/wx/system_information_dialog.h +++ b/src/wx/system_information_dialog.h @@ -29,5 +29,5 @@ class FilmViewer; class SystemInformationDialog : public TableDialog { public: - SystemInformationDialog (wxWindow* parent, std::weak_ptr viewer); + SystemInformationDialog(wxWindow* parent, FilmViewer const& viewer); }; diff --git a/src/wx/text_panel.cc b/src/wx/text_panel.cc index a9a3f142d..19bac8e8e 100644 --- a/src/wx/text_panel.cc +++ b/src/wx/text_panel.cc @@ -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({}); } } diff --git a/src/wx/text_view.cc b/src/wx/text_view.cc index 4a39b9139..7e5267886 100644 --- a/src/wx/text_view.cc +++ b/src/wx/text_view.cc @@ -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, shared_ptr content, shared_ptr text, shared_ptr decoder, weak_ptr viewer + wxWindow* parent, shared_ptr film, shared_ptr content, shared_ptr text, shared_ptr 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); } diff --git a/src/wx/text_view.h b/src/wx/text_view.h index f8aba8ffd..8cf3c78bb 100644 --- a/src/wx/text_view.h +++ b/src/wx/text_view.h @@ -38,7 +38,7 @@ public: std::shared_ptr content, std::shared_ptr caption, std::shared_ptr, - std::weak_ptr viewer + FilmViewer& viewer ); private: @@ -52,5 +52,5 @@ private: boost::optional _last_count; std::vector _start_times; std::weak_ptr _content; - std::weak_ptr _film_viewer; + FilmViewer& _film_viewer; }; diff --git a/src/wx/timeline.cc b/src/wx/timeline.cc index f6ede297d..6886daa42 100644 --- a/src/wx/timeline.cc +++ b/src/wx/timeline.cc @@ -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, weak_ptr viewer) +Timeline::Timeline(wxWindow* parent, ContentPanel* cp, shared_ptr 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); diff --git a/src/wx/timeline.h b/src/wx/timeline.h index 24c046a6a..797b32a55 100644 --- a/src/wx/timeline.h +++ b/src/wx/timeline.h @@ -42,7 +42,7 @@ class TimelineView; class Timeline : public wxPanel { public: - Timeline (wxWindow *, ContentPanel *, std::shared_ptr, std::weak_ptr viewer); + Timeline (wxWindow *, ContentPanel *, std::shared_ptr, FilmViewer& viewer); std::shared_ptr film () const; @@ -118,7 +118,7 @@ private: wxScrolledCanvas* _main_canvas; ContentPanel* _content_panel; std::weak_ptr _film; - std::weak_ptr _viewer; + FilmViewer& _viewer; TimelineViewList _views; std::shared_ptr _time_axis_view; std::shared_ptr _reels_view; diff --git a/src/wx/timeline_dialog.cc b/src/wx/timeline_dialog.cc index 1c67622c2..91737f204 100644 --- a/src/wx/timeline_dialog.cc +++ b/src/wx/timeline_dialog.cc @@ -42,7 +42,7 @@ using namespace boost::placeholders; #endif -TimelineDialog::TimelineDialog (ContentPanel* cp, shared_ptr film, weak_ptr viewer) +TimelineDialog::TimelineDialog(ContentPanel* cp, shared_ptr film, FilmViewer& viewer) : wxDialog ( cp->window(), wxID_ANY, diff --git a/src/wx/timeline_dialog.h b/src/wx/timeline_dialog.h index 8796f2bbf..f5dea4eef 100644 --- a/src/wx/timeline_dialog.h +++ b/src/wx/timeline_dialog.h @@ -32,7 +32,7 @@ class Playlist; class TimelineDialog : public wxDialog { public: - TimelineDialog (ContentPanel *, std::shared_ptr, std::weak_ptr viewer); + TimelineDialog(ContentPanel *, std::shared_ptr, FilmViewer& viewer); void set_selection (ContentList selection); diff --git a/src/wx/timing_panel.cc b/src/wx/timing_panel.cc index 494d415ec..a78e3bdd4 100644 --- a/src/wx/timing_panel.cc +++ b/src/wx/timing_panel.cc @@ -60,7 +60,7 @@ using dcp::locale_convert; using namespace dcpomatic; -TimingPanel::TimingPanel (ContentPanel* p, weak_ptr 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 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 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 ref; optional 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 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 fv = _viewer.lock (); - if (!fv) { - return; - } - - shared_ptr 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 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 fv = _viewer.lock (); - if (!fv) { - return; - } - - shared_ptr 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 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()) { diff --git a/src/wx/timing_panel.h b/src/wx/timing_panel.h index f5c9893de..1edaeb271 100644 --- a/src/wx/timing_panel.h +++ b/src/wx/timing_panel.h @@ -27,7 +27,7 @@ class FilmViewer; class TimingPanel : public ContentSubPanel { public: - TimingPanel (ContentPanel *, std::weak_ptr 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 _viewer; + FilmViewer& _viewer; wxStaticText* _h_label; wxStaticText* _m_label; diff --git a/src/wx/video_waveform_dialog.cc b/src/wx/video_waveform_dialog.cc index 3177f48cb..73ccc82df 100644 --- a/src/wx/video_waveform_dialog.cc +++ b/src/wx/video_waveform_dialog.cc @@ -35,7 +35,7 @@ using namespace boost::placeholders; #endif -VideoWaveformDialog::VideoWaveformDialog (wxWindow* parent, weak_ptr film, weak_ptr viewer) +VideoWaveformDialog::VideoWaveformDialog(wxWindow* parent, weak_ptr 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 fv = _viewer.lock (); - DCPOMATIC_ASSERT (fv); - fv->slow_refresh (); + _viewer.slow_refresh(); } } diff --git a/src/wx/video_waveform_dialog.h b/src/wx/video_waveform_dialog.h index 99a9a566a..e524dc921 100644 --- a/src/wx/video_waveform_dialog.h +++ b/src/wx/video_waveform_dialog.h @@ -34,7 +34,7 @@ class Film; class VideoWaveformDialog : public wxDialog { public: - VideoWaveformDialog (wxWindow* parent, std::weak_ptr film, std::weak_ptr viewer); + VideoWaveformDialog(wxWindow* parent, std::weak_ptr 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 _viewer; + FilmViewer& _viewer; VideoWaveformPlot* _plot; wxChoice* _component; wxSlider* _contrast; diff --git a/src/wx/video_waveform_plot.cc b/src/wx/video_waveform_plot.cc index 8e3284682..826e17359 100644 --- a/src/wx/video_waveform_plot.cc +++ b/src/wx/video_waveform_plot.cc @@ -53,7 +53,7 @@ int const VideoWaveformPlot::_pixel_values = 4096; int const VideoWaveformPlot::_x_axis_width = 52; -VideoWaveformPlot::VideoWaveformPlot (wxWindow* parent, weak_ptr film, weak_ptr viewer) +VideoWaveformPlot::VideoWaveformPlot(wxWindow* parent, weak_ptr 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 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)); diff --git a/src/wx/video_waveform_plot.h b/src/wx/video_waveform_plot.h index 362efa2ac..f482da8f8 100644 --- a/src/wx/video_waveform_plot.h +++ b/src/wx/video_waveform_plot.h @@ -39,7 +39,7 @@ class FilmViewer; class VideoWaveformPlot : public wxPanel { public: - VideoWaveformPlot (wxWindow* parent, std::weak_ptr film, std::weak_ptr viewer); + VideoWaveformPlot(wxWindow* parent, std::weak_ptr film, FilmViewer& viewer); void set_enabled (bool e); void set_component (int c); -- 2.30.2