2 Copyright (C) 2018-2021 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/>.
22 #include "check_box.h"
23 #include "content_view.h"
25 #include "dcpomatic_button.h"
26 #include "film_viewer.h"
27 #include "markers_panel.h"
28 #include "playhead_to_frame_dialog.h"
29 #include "playhead_to_timecode_dialog.h"
30 #include "static_text.h"
32 #include "lib/content_factory.h"
33 #include "lib/cross.h"
34 #include "lib/dcp_content.h"
35 #include "lib/examine_content_job.h"
38 #include "lib/job_manager.h"
39 #include "lib/player_video.h"
43 #include <dcp/reel_picture_asset.h>
44 #include <dcp/warnings.h>
45 LIBDCP_DISABLE_WARNINGS
46 #include <wx/listctrl.h>
47 #include <wx/progdlg.h>
48 #include <wx/tglbtn.h>
50 LIBDCP_ENABLE_WARNINGS
54 using std::dynamic_pointer_cast;
58 using std::shared_ptr;
61 using boost::optional;
62 #if BOOST_VERSION >= 106100
63 using namespace boost::placeholders;
65 using namespace dcpomatic;
68 Controls::Controls(wxWindow* parent, FilmViewer& viewer, bool editor_controls)
70 , _markers (new MarkersPanel(this, viewer))
71 , _slider (new wxSlider(this, wxID_ANY, 0, 0, 4096))
73 , _rewind_button (new Button(this, wxT("|<")))
74 , _back_button (new Button(this, wxT("<")))
75 , _forward_button (new Button(this, wxT(">")))
76 , _frame_number (new StaticText(this, wxT("")))
77 , _timecode (new StaticText(this, wxT("")))
80 _v_sizer = new wxBoxSizer (wxVERTICAL);
83 auto view_options = new wxBoxSizer (wxHORIZONTAL);
84 if (editor_controls) {
85 _outline_content = new CheckBox (this, _("Outline content"));
86 view_options->Add (_outline_content, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
87 _eye = new wxChoice (this, wxID_ANY);
88 _eye->Append (_("Left"));
89 _eye->Append (_("Right"));
90 _eye->SetSelection (0);
91 view_options->Add (_eye, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
92 _jump_to_selected = new CheckBox (this, _("Jump to selected content"));
93 view_options->Add (_jump_to_selected, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
96 _v_sizer->Add (view_options, 0, wxALL, DCPOMATIC_SIZER_GAP);
98 auto h_sizer = new wxBoxSizer (wxHORIZONTAL);
100 auto time_sizer = new wxBoxSizer (wxVERTICAL);
101 time_sizer->Add (_frame_number, 0, wxEXPAND);
102 time_sizer->Add (_timecode, 0, wxEXPAND);
104 h_sizer->Add (_rewind_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
105 h_sizer->Add (time_sizer, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
106 h_sizer->Add (_back_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
107 h_sizer->Add (_forward_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
109 _button_sizer = new wxBoxSizer (wxHORIZONTAL);
110 h_sizer->Add(_button_sizer, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
113 auto box = new wxBoxSizer (wxVERTICAL);
114 box->Add (_markers, 0, wxEXPAND);
115 box->Add (_slider, 0, wxEXPAND);
116 h_sizer->Add (box, 1, wxEXPAND);
119 _v_sizer->Add (h_sizer, 0, wxEXPAND | wxALL, 6);
122 _frame_number->SetMinSize (wxSize(100, -1));
123 _rewind_button->SetMinSize (wxSize(48, -1));
124 _back_button->SetMinSize (wxSize(48, -1));
125 _forward_button->SetMinSize (wxSize(48, -1));
127 _frame_number->SetMinSize (wxSize (84, -1));
128 _rewind_button->SetMinSize (wxSize (32, -1));
129 _back_button->SetMinSize (wxSize (32, -1));
130 _forward_button->SetMinSize (wxSize (32, -1));
134 _eye->Bind (wxEVT_CHOICE, boost::bind (&Controls::eye_changed, this));
136 if (_outline_content) {
137 _outline_content->bind(&Controls::outline_content_changed, this);
140 _slider->Bind (wxEVT_SCROLL_THUMBTRACK, boost::bind(&Controls::slider_moved, this, false));
141 _slider->Bind (wxEVT_SCROLL_PAGEUP, boost::bind(&Controls::slider_moved, this, true));
142 _slider->Bind (wxEVT_SCROLL_PAGEDOWN, boost::bind(&Controls::slider_moved, this, true));
143 _slider->Bind (wxEVT_SCROLL_THUMBRELEASE, boost::bind(&Controls::slider_released, this));
144 _rewind_button->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::rewind_clicked, this, _1));
145 _back_button->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::back_clicked, this, _1));
146 _forward_button->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::forward_clicked, this, _1));
147 _frame_number->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::frame_number_clicked, this));
148 _timecode->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::timecode_clicked, this));
149 if (_jump_to_selected) {
150 _jump_to_selected->bind(&Controls::jump_to_selected_clicked, this);
151 _jump_to_selected->SetValue (Config::instance()->jump_to_selected ());
154 viewer.Started.connect (boost::bind(&Controls::started, this));
155 viewer.Stopped.connect (boost::bind(&Controls::stopped, this));
157 Bind (wxEVT_TIMER, boost::bind(&Controls::update_position, this));
158 _timer.Start (80, wxTIMER_CONTINUOUS);
160 set_film(viewer.film());
162 JobManager::instance()->ActiveJobsChanged.connect (
163 bind (&Controls::active_jobs_changed, this, _2)
166 _config_changed_connection = Config::instance()->Changed.connect (bind(&Controls::config_changed, this, _1));
170 Controls::config_changed (int)
172 setup_sensitivity ();
179 setup_sensitivity ();
186 setup_sensitivity ();
191 Controls::update_position ()
193 if (!_slider_being_moved && !_viewer.pending_idle_get()) {
194 update_position_label ();
195 update_position_slider ();
201 Controls::eye_changed ()
203 _viewer.set_eyes(_eye->GetSelection() == 0 ? Eyes::LEFT : Eyes::RIGHT);
208 Controls::outline_content_changed ()
210 _viewer.set_outline_content(_outline_content->GetValue());
214 /** @param page true if this was a PAGEUP/PAGEDOWN event for which we won't receive a THUMBRELEASE */
216 Controls::slider_moved (bool page)
222 if (!page && !_slider_being_moved) {
223 /* This is the first event of a drag; stop playback for the duration of the drag */
225 _slider_being_moved = true;
228 DCPTime t (_slider->GetValue() * _film->length().get() / 4096);
229 t = t.round (_film->video_frame_rate());
230 /* Ensure that we hit the end of the film at the end of the slider. In particular, we
231 need to do an accurate seek in case there isn't a keyframe near the end.
233 bool accurate = false;
234 if (t >= _film->length ()) {
235 t = _film->length() - _viewer.one_video_frame();
238 _viewer.seek(t, accurate);
239 update_position_label ();
244 Controls::slider_released ()
246 /* Restart after a drag */
248 _slider_being_moved = false;
253 Controls::update_position_slider ()
256 _slider->SetValue (0);
260 auto const len = _film->length ();
263 int const new_slider_position = 4096 * _viewer.position().get() / len.get();
264 if (new_slider_position != _slider->GetValue()) {
265 _slider->SetValue (new_slider_position);
272 Controls::update_position_label ()
275 checked_set (_frame_number, wxT("0"));
276 checked_set (_timecode, wxT("0:0:0.0"));
280 double const fps = _film->video_frame_rate ();
281 /* Count frame number from 1 ... not sure if this is the best idea */
282 checked_set(_frame_number, wxString::Format (wxT("%ld"), lrint(_viewer.position().seconds() * fps) + 1));
283 checked_set(_timecode, time_to_timecode(_viewer.position(), fps));
288 Controls::active_jobs_changed (optional<string> j)
291 setup_sensitivity ();
296 Controls::nudge_amount (wxKeyboardState& ev)
298 auto amount = _viewer.one_video_frame();
300 if (ev.ShiftDown() && !ev.ControlDown()) {
301 amount = DCPTime::from_seconds (1);
302 } else if (!ev.ShiftDown() && ev.ControlDown()) {
303 amount = DCPTime::from_seconds (10);
304 } else if (ev.ShiftDown() && ev.ControlDown()) {
305 amount = DCPTime::from_seconds (60);
313 Controls::rewind_clicked (wxMouseEvent& ev)
315 _viewer.seek(DCPTime(), true);
321 Controls::back_frame ()
323 _viewer.seek_by(-_viewer.one_video_frame(), true);
328 Controls::forward_frame ()
330 _viewer.seek_by(_viewer.one_video_frame(), true);
335 Controls::back_clicked (wxKeyboardState& ev)
337 _viewer.seek_by(-nudge_amount(ev), true);
342 Controls::forward_clicked (wxKeyboardState& ev)
344 _viewer.seek_by(nudge_amount(ev), true);
349 Controls::setup_sensitivity ()
351 /* examine content is the only job which stops the viewer working */
352 bool const active_job = _active_job && *_active_job != "examine_content";
353 bool const c = _film && !_film->content().empty() && !active_job;
356 _rewind_button->Enable (c);
357 _back_button->Enable (c);
358 _forward_button->Enable (c);
359 if (_outline_content) {
360 _outline_content->Enable (c);
362 _frame_number->Enable (c);
363 _timecode->Enable (c);
364 if (_jump_to_selected) {
365 _jump_to_selected->Enable (c);
369 _eye->Enable (c && _film->three_d ());
375 Controls::timecode_clicked ()
377 auto dialog = make_wx<PlayheadToTimecodeDialog>(this, _viewer.position(), _film->video_frame_rate());
379 if (dialog->ShowModal() == wxID_OK) {
380 _viewer.seek(dialog->get(), true);
386 Controls::frame_number_clicked ()
388 auto dialog = make_wx<PlayheadToFrameDialog>(this, _viewer.position(), _film->video_frame_rate());
390 if (dialog->ShowModal() == wxID_OK) {
391 _viewer.seek(dialog->get(), true);
397 Controls::jump_to_selected_clicked ()
399 Config::instance()->set_jump_to_selected (_jump_to_selected->GetValue ());
404 Controls::set_film (shared_ptr<Film> film)
412 _markers->set_film (_film);
415 _film_change_connection = _film->Change.connect (boost::bind(&Controls::film_change, this, _1, _2));
418 setup_sensitivity ();
420 update_position_slider ();
421 update_position_label ();
426 Controls::film () const
433 Controls::film_change(ChangeType type, FilmProperty p)
435 if (type == ChangeType::DONE) {
436 if (p == FilmProperty::CONTENT) {
437 setup_sensitivity ();
438 update_position_label ();
439 update_position_slider ();
440 } else if (p == FilmProperty::THREE_D) {
441 setup_sensitivity ();
448 Controls::seek (int slider)
450 _slider->SetValue (slider);
451 slider_moved (false);