2 Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "text_view.h"
22 #include "film_viewer.h"
24 #include "lib/string_text_file_decoder.h"
25 #include "lib/content_text.h"
26 #include "lib/video_decoder.h"
27 #include "lib/audio_decoder.h"
29 #include "lib/config.h"
30 #include "lib/string_text_file_content.h"
31 #include "lib/text_decoder.h"
34 using boost::shared_ptr;
35 using boost::weak_ptr;
37 using boost::dynamic_pointer_cast;
38 using namespace dcpomatic;
39 #if BOOST_VERSION >= 106100
40 using namespace boost::placeholders;
44 wxWindow* parent, shared_ptr<Film> film, shared_ptr<Content> content, shared_ptr<TextContent> text, shared_ptr<Decoder> decoder, weak_ptr<FilmViewer> viewer
46 : wxDialog (parent, wxID_ANY, _("Captions"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
48 , _film_viewer (viewer)
50 _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
55 ip.SetText (_("Start"));
57 _list->InsertColumn (0, ip);
63 ip.SetText (_("End"));
65 _list->InsertColumn (1, ip);
71 ip.SetText (_("Caption"));
73 _list->InsertColumn (2, ip);
76 wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
77 sizer->Add (_list, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
79 _list->Bind (wxEVT_LIST_ITEM_SELECTED, boost::bind (&TextView::subtitle_selected, this, _1));
81 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
83 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
87 decoder->video->set_ignore (true);
90 decoder->audio->set_ignore (true);
94 _frc = film->active_frame_rate_change (content->position());
96 /* Find the decoder that is being used for our TextContent and attach to it */
97 BOOST_FOREACH (shared_ptr<TextDecoder> i, decoder->text) {
98 if (i->content() == text) {
99 i->PlainStart.connect (bind (&TextView::data_start, this, _1));
100 i->Stop.connect (bind (&TextView::data_stop, this, _1));
103 while (!decoder->pass ()) {}
104 SetSizerAndFit (sizer);
108 TextView::data_start (ContentStringText cts)
110 BOOST_FOREACH (dcp::SubtitleString const & i, cts.subs) {
111 wxListItem list_item;
112 list_item.SetId (_subs);
113 _list->InsertItem (list_item);
114 _list->SetItem (_subs, 0, std_to_wx (cts.from().timecode (_frc->source)));
115 _list->SetItem (_subs, 2, std_to_wx (i.text ()));
116 _start_times.push_back (cts.from ());
120 _last_count = cts.subs.size ();
124 TextView::data_stop (ContentTime time)
130 for (int i = _subs - *_last_count; i < _subs; ++i) {
131 _list->SetItem (i, 1, std_to_wx (time.timecode (_frc->source)));
136 TextView::subtitle_selected (wxListEvent& ev)
138 if (!Config::instance()->jump_to_selected ()) {
142 DCPOMATIC_ASSERT (ev.GetIndex() < int(_start_times.size()));
143 shared_ptr<Content> lc = _content.lock ();
144 DCPOMATIC_ASSERT (lc);
145 shared_ptr<FilmViewer> fv = _film_viewer.lock ();
146 DCPOMATIC_ASSERT (fv);
147 fv->seek (lc, _start_times[ev.GetIndex()], true);