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 "lib/string_text_file_decoder.h"
22 #include "lib/content_text.h"
23 #include "lib/video_decoder.h"
24 #include "lib/audio_decoder.h"
26 #include "lib/config.h"
27 #include "lib/string_text_file_content.h"
28 #include "lib/text_decoder.h"
29 #include "text_view.h"
30 #include "film_viewer.h"
34 using boost::shared_ptr;
36 using boost::dynamic_pointer_cast;
38 TextView::TextView (wxWindow* parent, shared_ptr<Film> film, shared_ptr<Content> content, shared_ptr<TextContent> text, shared_ptr<Decoder> decoder, FilmViewer* viewer)
39 : wxDialog (parent, wxID_ANY, _("Captions"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
41 , _film_viewer (viewer)
43 _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
48 ip.SetText (_("Start"));
50 _list->InsertColumn (0, ip);
56 ip.SetText (_("End"));
58 _list->InsertColumn (1, ip);
64 ip.SetText (_("Caption"));
66 _list->InsertColumn (2, ip);
69 wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
70 sizer->Add (_list, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
72 _list->Bind (wxEVT_LIST_ITEM_SELECTED, boost::bind (&TextView::subtitle_selected, this, _1));
74 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
76 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
80 decoder->video->set_ignore (true);
83 decoder->audio->set_ignore (true);
87 _frc = film->active_frame_rate_change (content->position());
89 /* Find the decoder that is being used for our TextContent and attach to it */
90 BOOST_FOREACH (shared_ptr<TextDecoder> i, decoder->text) {
91 if (i->content() == text) {
92 i->PlainStart.connect (bind (&TextView::data_start, this, _1));
93 i->Stop.connect (bind (&TextView::data_stop, this, _1));
96 while (!decoder->pass ()) {}
97 SetSizerAndFit (sizer);
101 TextView::data_start (ContentStringText cts)
103 BOOST_FOREACH (dcp::SubtitleString const & i, cts.subs) {
104 wxListItem list_item;
105 list_item.SetId (_subs);
106 _list->InsertItem (list_item);
107 _list->SetItem (_subs, 0, std_to_wx (cts.from().timecode (_frc->source)));
108 _list->SetItem (_subs, 2, std_to_wx (i.text ()));
109 _start_times.push_back (cts.from ());
113 _last_count = cts.subs.size ();
117 TextView::data_stop (ContentTime time)
123 for (int i = _subs - *_last_count; i < _subs; ++i) {
124 _list->SetItem (i, 1, std_to_wx (time.timecode (_frc->source)));
129 TextView::subtitle_selected (wxListEvent& ev)
131 if (!Config::instance()->jump_to_selected ()) {
135 DCPOMATIC_ASSERT (ev.GetIndex() < int(_start_times.size()));
136 shared_ptr<Content> locked = _content.lock ();
137 DCPOMATIC_ASSERT (locked);
138 _film_viewer->set_position (locked, _start_times[ev.GetIndex()]);