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/plain_text_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/plain_text_content.h"
28 #include "subtitle_view.h"
29 #include "film_viewer.h"
33 using boost::shared_ptr;
35 using boost::dynamic_pointer_cast;
37 SubtitleView::SubtitleView (wxWindow* parent, shared_ptr<Film> film, shared_ptr<Content> content, shared_ptr<Decoder> decoder, FilmViewer* viewer)
38 : wxDialog (parent, wxID_ANY, _("Subtitles"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
40 , _film_viewer (viewer)
42 _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
47 ip.SetText (_("Start"));
49 _list->InsertColumn (0, ip);
55 ip.SetText (_("End"));
57 _list->InsertColumn (1, ip);
63 ip.SetText (_("Subtitle"));
65 _list->InsertColumn (2, ip);
68 wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
69 sizer->Add (_list, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
71 _list->Bind (wxEVT_LIST_ITEM_SELECTED, boost::bind (&SubtitleView::subtitle_selected, this, _1));
73 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
75 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
79 decoder->video->set_ignore (true);
82 decoder->audio->set_ignore (true);
86 _frc = film->active_frame_rate_change (content->position());
87 decoder->subtitle->PlainStart.connect (bind (&SubtitleView::data_start, this, _1));
88 decoder->subtitle->Stop.connect (bind (&SubtitleView::data_stop, this, _1));
89 while (!decoder->pass ()) {}
90 SetSizerAndFit (sizer);
94 SubtitleView::data_start (ContentPlainText cts)
96 BOOST_FOREACH (dcp::SubtitleString const & i, cts.subs) {
98 list_item.SetId (_subs);
99 _list->InsertItem (list_item);
100 _list->SetItem (_subs, 0, std_to_wx (cts.from().timecode (_frc->source)));
101 _list->SetItem (_subs, 2, std_to_wx (i.text ()));
102 _start_times.push_back (cts.from ());
106 _last_count = cts.subs.size ();
110 SubtitleView::data_stop (ContentTime time)
116 for (int i = _subs - *_last_count; i < _subs; ++i) {
117 _list->SetItem (i, 1, std_to_wx (time.timecode (_frc->source)));
122 SubtitleView::subtitle_selected (wxListEvent& ev)
124 if (!Config::instance()->jump_to_selected ()) {
128 DCPOMATIC_ASSERT (ev.GetIndex() < int(_start_times.size()));
129 shared_ptr<Content> locked = _content.lock ();
130 DCPOMATIC_ASSERT (locked);
131 _film_viewer->set_position (locked, _start_times[ev.GetIndex()]);