diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-06-29 22:02:19 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-06-29 22:02:19 +0100 |
| commit | e00b9850a7336b7db0aee058fe12f576db5f84a3 (patch) | |
| tree | 390f055e9b70fc41a4e9eff851f931e1a8a2609f /src | |
| parent | 362443f12f6614404fe668b309f91099e3a83d51 (diff) | |
Basic jump to selected subtitle (#1200).
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/player.cc | 17 | ||||
| -rw-r--r-- | src/lib/player.h | 2 | ||||
| -rw-r--r-- | src/wx/content_panel.h | 4 | ||||
| -rw-r--r-- | src/wx/film_viewer.cc | 6 | ||||
| -rw-r--r-- | src/wx/film_viewer.h | 1 | ||||
| -rw-r--r-- | src/wx/subtitle_panel.cc | 2 | ||||
| -rw-r--r-- | src/wx/subtitle_view.cc | 26 | ||||
| -rw-r--r-- | src/wx/subtitle_view.h | 7 |
8 files changed, 60 insertions, 5 deletions
diff --git a/src/lib/player.cc b/src/lib/player.cc index 5515b70e8..df58ed223 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -1089,3 +1089,20 @@ Player::set_dcp_decode_reduction (optional<int> reduction) _have_valid_pieces = false; Changed (PlayerProperty::DCP_DECODE_REDUCTION, false); } + +DCPTime +Player::content_time_to_dcp (shared_ptr<Content> content, ContentTime t) +{ + if (_have_valid_pieces) { + setup_pieces (); + } + + BOOST_FOREACH (shared_ptr<Piece> i, _pieces) { + if (i->content == content) { + return content_time_to_dcp (i, t); + } + } + + DCPOMATIC_ASSERT (false); + return DCPTime (); +} diff --git a/src/lib/player.h b/src/lib/player.h index fc7117ba2..54fa074c0 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -84,6 +84,8 @@ public: void set_play_referenced (); void set_dcp_decode_reduction (boost::optional<int> reduction); + DCPTime content_time_to_dcp (boost::shared_ptr<Content> content, ContentTime t); + /** Emitted when something has changed such that if we went back and emitted * the last frame again it would look different. This is not emitted after * a seek. diff --git a/src/wx/content_panel.h b/src/wx/content_panel.h index 15e0fb6e1..c5378fc36 100644 --- a/src/wx/content_panel.h +++ b/src/wx/content_panel.h @@ -71,6 +71,10 @@ public: bool remove_clicked (bool hotkey); void timeline_clicked (); + FilmViewer* film_viewer () const { + return _film_viewer; + } + boost::signals2::signal<void (void)> SelectionChanged; private: diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index a7e040bb5..9f42aaad2 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -758,6 +758,12 @@ FilmViewer::set_position (DCPTime p) } void +FilmViewer::set_position (shared_ptr<Content> content, ContentTime t) +{ + set_position (_player->content_time_to_dcp (content, t)); +} + +void FilmViewer::set_coalesce_player_changes (bool c) { _coalesce_player_changes = c; diff --git a/src/wx/film_viewer.h b/src/wx/film_viewer.h index eed6c283d..11d06cc46 100644 --- a/src/wx/film_viewer.h +++ b/src/wx/film_viewer.h @@ -55,6 +55,7 @@ public: } void set_position (DCPTime p); + void set_position (boost::shared_ptr<Content> content, ContentTime p); void set_coalesce_player_changes (bool c); void set_dcp_decode_reduction (boost::optional<int> reduction); boost::optional<int> dcp_decode_reduction () const; diff --git a/src/wx/subtitle_panel.cc b/src/wx/subtitle_panel.cc index ff215c31d..1a42c1f57 100644 --- a/src/wx/subtitle_panel.cc +++ b/src/wx/subtitle_panel.cc @@ -409,7 +409,7 @@ SubtitlePanel::subtitle_view_clicked () shared_ptr<Decoder> decoder = decoder_factory (c.front(), _parent->film()->log(), false); if (decoder) { - _subtitle_view = new SubtitleView (this, _parent->film(), decoder, c.front()->position ()); + _subtitle_view = new SubtitleView (this, _parent->film(), c.front(), decoder, _parent->film_viewer()); _subtitle_view->Show (); } } diff --git a/src/wx/subtitle_view.cc b/src/wx/subtitle_view.cc index bf8391371..cedf273d4 100644 --- a/src/wx/subtitle_view.cc +++ b/src/wx/subtitle_view.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -24,7 +24,9 @@ #include "lib/audio_decoder.h" #include "lib/film.h" #include "lib/text_subtitle_content.h" +#include "lib/config.h" #include "subtitle_view.h" +#include "film_viewer.h" #include "wx_util.h" using std::list; @@ -32,8 +34,10 @@ using boost::shared_ptr; using boost::bind; using boost::dynamic_pointer_cast; -SubtitleView::SubtitleView (wxWindow* parent, shared_ptr<Film> film, shared_ptr<Decoder> decoder, DCPTime position) +SubtitleView::SubtitleView (wxWindow* parent, shared_ptr<Film> film, shared_ptr<Content> content, shared_ptr<Decoder> decoder, FilmViewer* viewer) : wxDialog (parent, wxID_ANY, _("Subtitles"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) + , _content (content) + , _film_viewer (viewer) { _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL); @@ -64,6 +68,8 @@ SubtitleView::SubtitleView (wxWindow* parent, shared_ptr<Film> film, shared_ptr< wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL); sizer->Add (_list, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP); + _list->Bind (wxEVT_LIST_ITEM_SELECTED, boost::bind (&SubtitleView::subtitle_selected, this, _1)); + wxSizer* buttons = CreateSeparatedButtonSizer (wxOK); if (buttons) { sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder()); @@ -77,7 +83,7 @@ SubtitleView::SubtitleView (wxWindow* parent, shared_ptr<Film> film, shared_ptr< } _subs = 0; - _frc = film->active_frame_rate_change (position); + _frc = film->active_frame_rate_change (content->position()); decoder->subtitle->TextStart.connect (bind (&SubtitleView::data_start, this, _1)); decoder->subtitle->Stop.connect (bind (&SubtitleView::data_stop, this, _1)); while (!decoder->pass ()) {} @@ -93,6 +99,7 @@ SubtitleView::data_start (ContentTextSubtitle cts) _list->InsertItem (list_item); _list->SetItem (_subs, 0, std_to_wx (cts.from().timecode (_frc->source))); _list->SetItem (_subs, 2, std_to_wx (i.text ())); + _start_times.push_back (cts.from ()); ++_subs; } @@ -110,3 +117,16 @@ SubtitleView::data_stop (ContentTime time) _list->SetItem (i, 1, std_to_wx (time.timecode (_frc->source))); } } + +void +SubtitleView::subtitle_selected (wxListEvent& ev) +{ + if (!Config::instance()->jump_to_selected ()) { + return; + } + + DCPOMATIC_ASSERT (ev.GetIndex() < int(_start_times.size())); + shared_ptr<Content> locked = _content.lock (); + DCPOMATIC_ASSERT (locked); + _film_viewer->set_position (locked, _start_times[ev.GetIndex()]); +} diff --git a/src/wx/subtitle_view.h b/src/wx/subtitle_view.h index 43a622705..94ef52171 100644 --- a/src/wx/subtitle_view.h +++ b/src/wx/subtitle_view.h @@ -24,18 +24,23 @@ #include <wx/listctrl.h> class Decoder; +class FilmViewer; class SubtitleView : public wxDialog { public: - SubtitleView (wxWindow *, boost::shared_ptr<Film>, boost::shared_ptr<Decoder>, DCPTime position); + SubtitleView (wxWindow *, boost::shared_ptr<Film>, boost::shared_ptr<Content> content, boost::shared_ptr<Decoder>, FilmViewer* viewer); private: void data_start (ContentTextSubtitle cts); void data_stop (ContentTime time); + void subtitle_selected (wxListEvent &); wxListCtrl* _list; int _subs; boost::optional<FrameRateChange> _frc; boost::optional<int> _last_count; + std::vector<ContentTime> _start_times; + boost::weak_ptr<Content> _content; + FilmViewer* _film_viewer; }; |
