2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <boost/lexical_cast.hpp>
21 #include <wx/spinctrl.h>
22 #include "lib/ffmpeg_content.h"
23 #include "lib/subrip_content.h"
24 #include "lib/ffmpeg_subtitle_stream.h"
25 #include "subtitle_panel.h"
26 #include "film_editor.h"
28 #include "subtitle_view.h"
32 using boost::shared_ptr;
33 using boost::lexical_cast;
34 using boost::dynamic_pointer_cast;
36 SubtitlePanel::SubtitlePanel (FilmEditor* e)
37 : FilmEditorPanel (e, _("Subtitles"))
40 wxFlexGridSizer* grid = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
41 _sizer->Add (grid, 0, wxALL, 8);
43 _with_subtitles = new wxCheckBox (this, wxID_ANY, _("With Subtitles"));
44 grid->Add (_with_subtitles, 1);
48 add_label_to_sizer (grid, this, _("Subtitle X Offset"), true);
49 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
50 _x_offset = new wxSpinCtrl (this);
52 add_label_to_sizer (s, this, _("%"), false);
57 add_label_to_sizer (grid, this, _("Subtitle Y Offset"), true);
58 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
59 _y_offset = new wxSpinCtrl (this);
61 add_label_to_sizer (s, this, _("%"), false);
66 add_label_to_sizer (grid, this, _("Subtitle Scale"), true);
67 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
68 _scale = new wxSpinCtrl (this);
70 add_label_to_sizer (s, this, _("%"), false);
74 add_label_to_sizer (grid, this, _("Subtitle Stream"), true);
75 _stream = new wxChoice (this, wxID_ANY);
76 grid->Add (_stream, 1, wxEXPAND);
78 _view_button = new wxButton (this, wxID_ANY, _("View..."));
79 grid->Add (_view_button);
81 _x_offset->SetRange (-100, 100);
82 _y_offset->SetRange (-100, 100);
83 _scale->SetRange (1, 1000);
84 _scale->SetValue (100);
86 _with_subtitles->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&SubtitlePanel::with_subtitles_toggled, this));
87 _x_offset->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::x_offset_changed, this));
88 _y_offset->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::y_offset_changed, this));
89 _scale->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::scale_changed, this));
90 _stream->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&SubtitlePanel::stream_changed, this));
91 _view_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&SubtitlePanel::view_clicked, this));
95 SubtitlePanel::film_changed (Film::Property property)
101 case Film::WITH_SUBTITLES:
102 checked_set (_with_subtitles, _editor->film()->with_subtitles ());
103 setup_sensitivity ();
111 SubtitlePanel::film_content_changed (int property)
113 FFmpegContentList fc = _editor->selected_ffmpeg_content ();
114 SubtitleContentList sc = _editor->selected_subtitle_content ();
116 shared_ptr<FFmpegContent> fcs;
117 if (fc.size() == 1) {
121 shared_ptr<SubtitleContent> scs;
122 if (sc.size() == 1) {
126 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
129 vector<shared_ptr<FFmpegSubtitleStream> > s = fcs->subtitle_streams ();
130 for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
131 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx ((*i)->identifier ())));
134 if (fcs->subtitle_stream()) {
135 checked_set (_stream, fcs->subtitle_stream()->identifier ());
137 _stream->SetSelection (wxNOT_FOUND);
140 setup_sensitivity ();
141 } else if (property == SubtitleContentProperty::SUBTITLE_X_OFFSET) {
142 checked_set (_x_offset, scs ? (scs->subtitle_x_offset() * 100) : 0);
143 } else if (property == SubtitleContentProperty::SUBTITLE_Y_OFFSET) {
144 checked_set (_y_offset, scs ? (scs->subtitle_y_offset() * 100) : 0);
145 } else if (property == SubtitleContentProperty::SUBTITLE_SCALE) {
146 checked_set (_scale, scs ? (scs->subtitle_scale() * 100) : 100);
151 SubtitlePanel::with_subtitles_toggled ()
153 if (!_editor->film()) {
157 _editor->film()->set_with_subtitles (_with_subtitles->GetValue ());
161 SubtitlePanel::setup_sensitivity ()
165 if (_editor->film()) {
166 h = _editor->film()->has_subtitles ();
167 j = _editor->film()->with_subtitles ();
170 _with_subtitles->Enable (h);
171 _x_offset->Enable (j);
172 _y_offset->Enable (j);
176 SubtitleContentList c = _editor->selected_subtitle_content ();
177 _view_button->Enable (c.size() == 1);
181 SubtitlePanel::stream_changed ()
183 FFmpegContentList fc = _editor->selected_ffmpeg_content ();
184 if (fc.size() != 1) {
188 shared_ptr<FFmpegContent> fcs = fc.front ();
190 vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
191 vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
192 string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
193 while (i != a.end() && (*i)->identifier () != s) {
198 fcs->set_subtitle_stream (*i);
203 SubtitlePanel::x_offset_changed ()
205 SubtitleContentList c = _editor->selected_subtitle_content ();
207 c.front()->set_subtitle_x_offset (_x_offset->GetValue() / 100.0);
212 SubtitlePanel::y_offset_changed ()
214 SubtitleContentList c = _editor->selected_subtitle_content ();
216 c.front()->set_subtitle_y_offset (_y_offset->GetValue() / 100.0);
221 SubtitlePanel::scale_changed ()
223 SubtitleContentList c = _editor->selected_subtitle_content ();
225 c.front()->set_subtitle_scale (_scale->GetValue() / 100.0);
230 SubtitlePanel::content_selection_changed ()
232 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
233 film_content_changed (SubtitleContentProperty::SUBTITLE_X_OFFSET);
234 film_content_changed (SubtitleContentProperty::SUBTITLE_Y_OFFSET);
235 film_content_changed (SubtitleContentProperty::SUBTITLE_SCALE);
239 SubtitlePanel::view_clicked ()
246 SubtitleContentList c = _editor->selected_subtitle_content ();
247 assert (c.size() == 1);
248 shared_ptr<SubRipContent> sr = dynamic_pointer_cast<SubRipContent> (c.front ());
250 _view = new SubtitleView (this, sr);