From 7151de6910e6072754bd38d50efa5a36622bb5c6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 11 Sep 2018 12:29:13 +0100 Subject: [PATCH] FilmViewer API tidying. --- src/tools/dcpomatic.cc | 4 +-- src/tools/dcpomatic_player.cc | 6 ++--- src/wx/content_panel.cc | 2 +- src/wx/controls.cc | 20 +++++++-------- src/wx/film_viewer.cc | 46 ++++++++++++----------------------- src/wx/film_viewer.h | 39 +++++++++++++---------------- src/wx/text_view.cc | 2 +- src/wx/timing_panel.cc | 6 ++--- 8 files changed, 52 insertions(+), 73 deletions(-) diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index 27113eeab..aa6526311 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -1301,12 +1301,12 @@ private: void back_frame () { - _film_viewer->move (-_film_viewer->one_video_frame()); + _film_viewer->seek_by (-_film_viewer->one_video_frame(), true); } void forward_frame () { - _film_viewer->move (_film_viewer->one_video_frame()); + _film_viewer->seek_by (_film_viewer->one_video_frame(), true); } FilmEditor* _film_editor; diff --git a/src/tools/dcpomatic_player.cc b/src/tools/dcpomatic_player.cc index d8c3c59fe..a95476fc1 100644 --- a/src/tools/dcpomatic_player.cc +++ b/src/tools/dcpomatic_player.cc @@ -217,7 +217,7 @@ public: } _viewer->set_film (_film); - _viewer->set_position (DCPTime ()); + _viewer->seek (DCPTime(), true); _info->triggered_update (); Config::instance()->add_to_player_history (dir); @@ -579,12 +579,12 @@ private: void back_frame () { - _viewer->move (-_viewer->one_video_frame()); + _viewer->seek_by (-_viewer->one_video_frame(), true); } void forward_frame () { - _viewer->move (_viewer->one_video_frame()); + _viewer->seek_by (_viewer->one_video_frame(), true); } private: diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index 04e35c758..8e6c49294 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -304,7 +304,7 @@ ContentPanel::check_selection () if (go_to && Config::instance()->jump_to_selected() && signal_manager) { shared_ptr fv = _film_viewer.lock (); DCPOMATIC_ASSERT (fv); - signal_manager->when_idle(boost::bind(&FilmViewer::set_position, fv.get(), go_to.get().ceil(_film->video_frame_rate()))); + signal_manager->when_idle(boost::bind(&FilmViewer::seek, fv.get(), go_to.get().ceil(_film->video_frame_rate()), true)); } if (_timeline_dialog) { diff --git a/src/wx/controls.cc b/src/wx/controls.cc index 1bb3c4136..96bd624ac 100644 --- a/src/wx/controls.cc +++ b/src/wx/controls.cc @@ -215,7 +215,7 @@ Controls::update_position_slider () DCPTime const len = _film->length (); if (len.get ()) { - int const new_slider_position = 4096 * _viewer->video_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); } @@ -233,8 +233,8 @@ Controls::update_position_label () double const fps = _film->video_frame_rate (); /* Count frame number from 1 ... not sure if this is the best idea */ - _frame_number->SetLabel (wxString::Format (wxT("%ld"), lrint (_viewer->video_position().seconds() * fps) + 1)); - _timecode->SetLabel (time_to_timecode (_viewer->video_position(), fps)); + _frame_number->SetLabel (wxString::Format (wxT("%ld"), lrint (_viewer->position().seconds() * fps) + 1)); + _timecode->SetLabel (time_to_timecode (_viewer->position(), fps)); } void @@ -265,32 +265,32 @@ Controls::nudge_amount (wxKeyboardState& ev) void Controls::rewind_clicked (wxMouseEvent& ev) { - _viewer->go_to (DCPTime()); + _viewer->seek (DCPTime(), true); ev.Skip(); } void Controls::back_frame () { - _viewer->move (-_viewer->one_video_frame()); + _viewer->seek_by (-_viewer->one_video_frame(), true); } void Controls::forward_frame () { - _viewer->move (_viewer->one_video_frame()); + _viewer->seek_by (_viewer->one_video_frame(), true); } void Controls::back_clicked (wxKeyboardState& ev) { - _viewer->move (-nudge_amount(ev)); + _viewer->seek_by (-nudge_amount(ev), true); } void Controls::forward_clicked (wxKeyboardState& ev) { - _viewer->move (nudge_amount(ev)); + _viewer->seek_by (nudge_amount(ev), true); } void @@ -320,7 +320,7 @@ Controls::timecode_clicked () { PlayheadToTimecodeDialog* dialog = new PlayheadToTimecodeDialog (this, _film->video_frame_rate ()); if (dialog->ShowModal() == wxID_OK) { - _viewer->go_to (dialog->get ()); + _viewer->seek (dialog->get(), true); } dialog->Destroy (); } @@ -330,7 +330,7 @@ Controls::frame_number_clicked () { PlayheadToFrameDialog* dialog = new PlayheadToFrameDialog (this, _film->video_frame_rate ()); if (dialog->ShowModal() == wxID_OK) { - _viewer->go_to (dialog->get ()); + _viewer->seek (dialog->get(), true); } dialog->Destroy (); } diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index 2d53db9ef..bd83821be 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -433,21 +433,6 @@ FilmViewer::stop () return true; } -void -FilmViewer::go_to (DCPTime t) -{ - if (t < DCPTime ()) { - t = DCPTime (); - } - - if (t >= _film->length ()) { - t = _film->length (); - } - - seek (t, true); - PositionChanged (); -} - void FilmViewer::player_change (ChangeType type, int property, bool frequent) { @@ -515,19 +500,11 @@ FilmViewer::quick_refresh () } void -FilmViewer::set_position (DCPTime p) -{ - _video_position = p; - seek (p, true); - PositionChanged (); -} - -void -FilmViewer::set_position (shared_ptr content, ContentTime t) +FilmViewer::seek (shared_ptr content, ContentTime t, bool accurate) { optional dt = _player->content_time_to_dcp (content, t); if (dt) { - set_position (*dt); + seek (*dt, accurate); } } @@ -551,6 +528,14 @@ FilmViewer::seek (DCPTime t, bool accurate) return; } + if (t < DCPTime ()) { + t = DCPTime (); + } + + if (t >= _film->length ()) { + t = _film->length (); + } + bool const was_running = stop (); _closed_captions_dialog->clear (); @@ -560,6 +545,8 @@ FilmViewer::seek (DCPTime t, bool accurate) if (was_running) { start (); } + + PositionChanged (); } void @@ -696,6 +683,7 @@ FilmViewer::one_video_frame () const return DCPTime::from_frames (1, _film->video_frame_rate()); } +/** Open a dialog box showing our film's closed captions */ void FilmViewer::show_closed_captions () { @@ -703,11 +691,7 @@ FilmViewer::show_closed_captions () } void -FilmViewer::move (DCPTime by) +FilmViewer::seek_by (DCPTime by, bool accurate) { - if (!_film) { - return; - } - - go_to (_video_position + by); + seek (_video_position + by, accurate); } diff --git a/src/wx/film_viewer.h b/src/wx/film_viewer.h index 0da656fa9..d7b12703e 100644 --- a/src/wx/film_viewer.h +++ b/src/wx/film_viewer.h @@ -19,7 +19,7 @@ */ /** @file src/film_viewer.h - * @brief A wx widget to view `thumbnails' of a Film. + * @brief FilmViewer class. */ #include "lib/film.h" @@ -38,7 +38,7 @@ class Butler; class ClosedCaptionsDialog; /** @class FilmViewer - * @brief A wx widget to view a preview of a Film. + * @brief A wx widget to view a Film. */ class FilmViewer { @@ -46,25 +46,38 @@ public: FilmViewer (wxWindow *); ~FilmViewer (); + /** @return the panel showing the film's video */ wxPanel* panel () const { return _panel; } + void show_closed_captions (); + void set_film (boost::shared_ptr); boost::shared_ptr film () const { return _film; } + void seek (DCPTime t, bool accurate); + void seek (boost::shared_ptr content, ContentTime p, bool accurate); + void seek_by (DCPTime by, bool accurate); /** @return our `playhead' position; this may not lie exactly on a frame boundary */ DCPTime position () const { return _video_position; } + DCPTime one_video_frame () const; + + void start (); + bool stop (); + bool playing () const { + return _playing; + } - void set_position (DCPTime p); - void set_position (boost::shared_ptr content, ContentTime p); void set_coalesce_player_changes (bool c); void set_dcp_decode_reduction (boost::optional reduction); boost::optional dcp_decode_reduction () const; + void set_outline_content (bool o); + void set_eyes (Eyes e); void slow_refresh (); bool quick_refresh (); @@ -73,26 +86,8 @@ public: return _dropped; } - void start (); - bool stop (); - bool playing () const { - return _playing; - } - - void move (DCPTime by); - DCPTime one_video_frame () const; - void seek (DCPTime t, bool accurate); - DCPTime video_position () const { - return _video_position; - } - void go_to (DCPTime t); - void set_outline_content (bool o); - void set_eyes (Eyes e); - int audio_callback (void* out, unsigned int frames); - void show_closed_captions (); - boost::signals2::signal)> ImageChanged; boost::signals2::signal PositionChanged; boost::signals2::signal Started; diff --git a/src/wx/text_view.cc b/src/wx/text_view.cc index 16ec2213f..9b591b191 100644 --- a/src/wx/text_view.cc +++ b/src/wx/text_view.cc @@ -140,5 +140,5 @@ TextView::subtitle_selected (wxListEvent& ev) DCPOMATIC_ASSERT (lc); shared_ptr fv = _film_viewer.lock (); DCPOMATIC_ASSERT (fv); - fv->set_position (lc, _start_times[ev.GetIndex()]); + fv->seek (lc, _start_times[ev.GetIndex()], true); } diff --git a/src/wx/timing_panel.cc b/src/wx/timing_panel.cc index 4a221c650..b1d13367f 100644 --- a/src/wx/timing_panel.cc +++ b/src/wx/timing_panel.cc @@ -421,7 +421,7 @@ TimingPanel::trim_start_changed () } if (ref) { - fv->set_position (max (DCPTime(), ref_ph.get() + ref->position() - DCPTime (ref->trim_start(), ref_frc.get()))); + fv->seek (max(DCPTime(), ref_ph.get() + ref->position() - DCPTime(ref->trim_start(), ref_frc.get())), true); } fv->set_coalesce_player_changes (false); @@ -444,7 +444,7 @@ TimingPanel::trim_end_changed () /* XXX: maybe playhead-off-the-end-of-the-film should be handled elsewhere */ if (fv->position() >= _parent->film()->length()) { - fv->set_position (_parent->film()->length() - DCPTime::from_frames (1, _parent->film()->video_frame_rate())); + fv->seek (_parent->film()->length() - DCPTime::from_frames(1, _parent->film()->video_frame_rate()), true); } fv->set_coalesce_player_changes (true); @@ -530,7 +530,7 @@ TimingPanel::trim_start_to_playhead_clicked () } if (new_ph) { - fv->set_position (new_ph.get()); + fv->seek (new_ph.get(), true); } fv->set_coalesce_player_changes (false); -- 2.30.2