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"
37 #include "lib/job_manager.h"
38 #include "lib/player_video.h"
42 #include <dcp/reel_picture_asset.h>
43 #include <dcp/warnings.h>
44 LIBDCP_DISABLE_WARNINGS
45 #include <wx/listctrl.h>
46 #include <wx/progdlg.h>
47 #include <wx/tglbtn.h>
49 LIBDCP_ENABLE_WARNINGS
53 using std::dynamic_pointer_cast;
57 using std::shared_ptr;
60 using boost::optional;
61 #if BOOST_VERSION >= 106100
62 using namespace boost::placeholders;
64 using namespace dcpomatic;
67 Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor_controls)
69 , _markers (new MarkersPanel(this, viewer))
70 , _slider (new wxSlider(this, wxID_ANY, 0, 0, 4096))
72 , _slider_being_moved (false)
73 , _outline_content (0)
75 , _jump_to_selected (0)
76 , _rewind_button (new Button(this, wxT("|<")))
77 , _back_button (new Button(this, wxT("<")))
78 , _forward_button (new Button(this, wxT(">")))
79 , _frame_number (new StaticText(this, wxT("")))
80 , _timecode (new StaticText(this, wxT("")))
83 _v_sizer = new wxBoxSizer (wxVERTICAL);
86 auto view_options = new wxBoxSizer (wxHORIZONTAL);
87 if (editor_controls) {
88 _outline_content = new CheckBox (this, _("Outline content"));
89 view_options->Add (_outline_content, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
90 _eye = new wxChoice (this, wxID_ANY);
91 _eye->Append (_("Left"));
92 _eye->Append (_("Right"));
93 _eye->SetSelection (0);
94 view_options->Add (_eye, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
95 _jump_to_selected = new CheckBox (this, _("Jump to selected content"));
96 view_options->Add (_jump_to_selected, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
99 _v_sizer->Add (view_options, 0, wxALL, DCPOMATIC_SIZER_GAP);
101 auto h_sizer = new wxBoxSizer (wxHORIZONTAL);
103 auto time_sizer = new wxBoxSizer (wxVERTICAL);
104 time_sizer->Add (_frame_number, 0, wxEXPAND);
105 time_sizer->Add (_timecode, 0, wxEXPAND);
107 h_sizer->Add (_rewind_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
108 h_sizer->Add (time_sizer, 0, wxEXPAND);
109 h_sizer->Add (_back_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
110 h_sizer->Add (_forward_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
112 _button_sizer = new wxBoxSizer (wxHORIZONTAL);
113 h_sizer->Add (_button_sizer, 0, wxEXPAND);
116 auto box = new wxBoxSizer (wxVERTICAL);
117 box->Add (_markers, 0, wxEXPAND);
118 box->Add (_slider, 0, wxEXPAND);
119 h_sizer->Add (box, 1, wxEXPAND);
122 _v_sizer->Add (h_sizer, 0, wxEXPAND | wxALL, 6);
125 _frame_number->SetMinSize (wxSize(100, -1));
126 _rewind_button->SetMinSize (wxSize(48, -1));
127 _back_button->SetMinSize (wxSize(48, -1));
128 _forward_button->SetMinSize (wxSize(48, -1));
130 _frame_number->SetMinSize (wxSize (84, -1));
131 _rewind_button->SetMinSize (wxSize (32, -1));
132 _back_button->SetMinSize (wxSize (32, -1));
133 _forward_button->SetMinSize (wxSize (32, -1));
137 _eye->Bind (wxEVT_CHOICE, boost::bind (&Controls::eye_changed, this));
139 if (_outline_content) {
140 _outline_content->Bind (wxEVT_CHECKBOX, boost::bind (&Controls::outline_content_changed, this));
143 _slider->Bind (wxEVT_SCROLL_THUMBTRACK, boost::bind(&Controls::slider_moved, this, false));
144 _slider->Bind (wxEVT_SCROLL_PAGEUP, boost::bind(&Controls::slider_moved, this, true));
145 _slider->Bind (wxEVT_SCROLL_PAGEDOWN, boost::bind(&Controls::slider_moved, this, true));
146 _slider->Bind (wxEVT_SCROLL_THUMBRELEASE, boost::bind(&Controls::slider_released, this));
147 _rewind_button->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::rewind_clicked, this, _1));
148 _back_button->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::back_clicked, this, _1));
149 _forward_button->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::forward_clicked, this, _1));
150 _frame_number->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::frame_number_clicked, this));
151 _timecode->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::timecode_clicked, this));
152 if (_jump_to_selected) {
153 _jump_to_selected->Bind (wxEVT_CHECKBOX, boost::bind (&Controls::jump_to_selected_clicked, this));
154 _jump_to_selected->SetValue (Config::instance()->jump_to_selected ());
157 viewer->Started.connect (boost::bind(&Controls::started, this));
158 viewer->Stopped.connect (boost::bind(&Controls::stopped, this));
160 Bind (wxEVT_TIMER, boost::bind(&Controls::update_position, this));
161 _timer.Start (80, wxTIMER_CONTINUOUS);
163 set_film (viewer->film());
165 setup_sensitivity ();
167 JobManager::instance()->ActiveJobsChanged.connect (
168 bind (&Controls::active_jobs_changed, this, _2)
171 _config_changed_connection = Config::instance()->Changed.connect (bind(&Controls::config_changed, this, _1));
172 config_changed (Config::OTHER);
176 Controls::config_changed (int)
178 setup_sensitivity ();
185 setup_sensitivity ();
192 setup_sensitivity ();
197 Controls::update_position ()
199 auto viewer = _viewer.lock ();
204 if (!_slider_being_moved && !viewer->pending_idle_get()) {
205 update_position_label ();
206 update_position_slider ();
212 Controls::eye_changed ()
214 auto viewer = _viewer.lock ();
219 viewer->set_eyes (_eye->GetSelection() == 0 ? Eyes::LEFT : Eyes::RIGHT);
224 Controls::outline_content_changed ()
226 auto viewer = _viewer.lock ();
231 viewer->set_outline_content (_outline_content->GetValue());
235 /** @param page true if this was a PAGEUP/PAGEDOWN event for which we won't receive a THUMBRELEASE */
237 Controls::slider_moved (bool page)
239 auto viewer = _viewer.lock ();
240 if (!_film || !viewer) {
244 if (!page && !_slider_being_moved) {
245 /* This is the first event of a drag; stop playback for the duration of the drag */
247 _slider_being_moved = true;
250 DCPTime t (_slider->GetValue() * _film->length().get() / 4096);
251 t = t.round (_film->video_frame_rate());
252 /* Ensure that we hit the end of the film at the end of the slider. In particular, we
253 need to do an accurate seek in case there isn't a keyframe near the end.
255 bool accurate = false;
256 if (t >= _film->length ()) {
257 t = _film->length() - viewer->one_video_frame();
260 viewer->seek (t, accurate);
261 update_position_label ();
266 Controls::slider_released ()
268 auto viewer = _viewer.lock ();
273 /* Restart after a drag */
275 _slider_being_moved = false;
280 Controls::update_position_slider ()
283 _slider->SetValue (0);
287 auto viewer = _viewer.lock ();
292 auto const len = _film->length ();
295 int const new_slider_position = 4096 * viewer->position().get() / len.get();
296 if (new_slider_position != _slider->GetValue()) {
297 _slider->SetValue (new_slider_position);
304 Controls::update_position_label ()
307 checked_set (_frame_number, wxT("0"));
308 checked_set (_timecode, wxT("0:0:0.0"));
312 auto viewer = _viewer.lock ();
317 double const fps = _film->video_frame_rate ();
318 /* Count frame number from 1 ... not sure if this is the best idea */
319 checked_set (_frame_number, wxString::Format (wxT("%ld"), lrint (viewer->position().seconds() * fps) + 1));
320 checked_set (_timecode, time_to_timecode (viewer->position(), fps));
325 Controls::active_jobs_changed (optional<string> j)
328 setup_sensitivity ();
333 Controls::nudge_amount (wxKeyboardState& ev)
335 auto viewer = _viewer.lock ();
340 auto amount = viewer->one_video_frame ();
342 if (ev.ShiftDown() && !ev.ControlDown()) {
343 amount = DCPTime::from_seconds (1);
344 } else if (!ev.ShiftDown() && ev.ControlDown()) {
345 amount = DCPTime::from_seconds (10);
346 } else if (ev.ShiftDown() && ev.ControlDown()) {
347 amount = DCPTime::from_seconds (60);
355 Controls::rewind_clicked (wxMouseEvent& ev)
357 auto viewer = _viewer.lock ();
359 viewer->seek (DCPTime(), true);
366 Controls::back_frame ()
368 auto viewer = _viewer.lock ();
370 viewer->seek_by (-viewer->one_video_frame(), true);
376 Controls::forward_frame ()
378 auto viewer = _viewer.lock ();
380 viewer->seek_by (viewer->one_video_frame(), true);
386 Controls::back_clicked (wxKeyboardState& ev)
388 auto viewer = _viewer.lock ();
390 viewer->seek_by (-nudge_amount(ev), true);
396 Controls::forward_clicked (wxKeyboardState& ev)
398 auto viewer = _viewer.lock ();
400 viewer->seek_by (nudge_amount(ev), true);
406 Controls::setup_sensitivity ()
408 /* examine content is the only job which stops the viewer working */
409 bool const active_job = _active_job && *_active_job != "examine_content";
410 bool const c = _film && !_film->content().empty() && !active_job;
413 _rewind_button->Enable (c);
414 _back_button->Enable (c);
415 _forward_button->Enable (c);
416 if (_outline_content) {
417 _outline_content->Enable (c);
419 _frame_number->Enable (c);
420 _timecode->Enable (c);
421 if (_jump_to_selected) {
422 _jump_to_selected->Enable (c);
426 _eye->Enable (c && _film->three_d ());
432 Controls::timecode_clicked ()
434 auto viewer = _viewer.lock ();
439 auto dialog = new PlayheadToTimecodeDialog (this, viewer->position(), _film->video_frame_rate());
440 if (dialog->ShowModal() == wxID_OK) {
441 viewer->seek (dialog->get(), true);
448 Controls::frame_number_clicked ()
450 auto viewer = _viewer.lock ();
455 auto dialog = new PlayheadToFrameDialog (this, viewer->position(), _film->video_frame_rate());
456 if (dialog->ShowModal() == wxID_OK) {
457 viewer->seek (dialog->get(), true);
464 Controls::jump_to_selected_clicked ()
466 Config::instance()->set_jump_to_selected (_jump_to_selected->GetValue ());
471 Controls::set_film (shared_ptr<Film> film)
479 _markers->set_film (_film);
482 _film_change_connection = _film->Change.connect (boost::bind(&Controls::film_change, this, _1, _2));
485 setup_sensitivity ();
487 update_position_slider ();
488 update_position_label ();
493 Controls::film () const
500 Controls::film_change (ChangeType type, Film::Property p)
502 if (type == ChangeType::DONE) {
503 if (p == Film::Property::CONTENT) {
504 setup_sensitivity ();
505 update_position_label ();
506 update_position_slider ();
507 } else if (p == Film::Property::THREE_D) {
508 setup_sensitivity ();
515 Controls::seek (int slider)
517 _slider->SetValue (slider);
518 slider_moved (false);