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, 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, wxALL | wxALIGN_CENTER_VERTICAL, 2);
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(&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(&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 if (!_slider_being_moved && !_viewer.pending_idle_get()) {
200 update_position_label ();
201 update_position_slider ();
207 Controls::eye_changed ()
209 _viewer.set_eyes(_eye->GetSelection() == 0 ? Eyes::LEFT : Eyes::RIGHT);
214 Controls::outline_content_changed ()
216 _viewer.set_outline_content(_outline_content->GetValue());
220 /** @param page true if this was a PAGEUP/PAGEDOWN event for which we won't receive a THUMBRELEASE */
222 Controls::slider_moved (bool page)
228 if (!page && !_slider_being_moved) {
229 /* This is the first event of a drag; stop playback for the duration of the drag */
231 _slider_being_moved = true;
234 DCPTime t (_slider->GetValue() * _film->length().get() / 4096);
235 t = t.round (_film->video_frame_rate());
236 /* Ensure that we hit the end of the film at the end of the slider. In particular, we
237 need to do an accurate seek in case there isn't a keyframe near the end.
239 bool accurate = false;
240 if (t >= _film->length ()) {
241 t = _film->length() - _viewer.one_video_frame();
244 _viewer.seek(t, accurate);
245 update_position_label ();
250 Controls::slider_released ()
252 /* Restart after a drag */
254 _slider_being_moved = false;
259 Controls::update_position_slider ()
262 _slider->SetValue (0);
266 auto const len = _film->length ();
269 int const new_slider_position = 4096 * _viewer.position().get() / len.get();
270 if (new_slider_position != _slider->GetValue()) {
271 _slider->SetValue (new_slider_position);
278 Controls::update_position_label ()
281 checked_set (_frame_number, wxT("0"));
282 checked_set (_timecode, wxT("0:0:0.0"));
286 double const fps = _film->video_frame_rate ();
287 /* Count frame number from 1 ... not sure if this is the best idea */
288 checked_set(_frame_number, wxString::Format (wxT("%ld"), lrint(_viewer.position().seconds() * fps) + 1));
289 checked_set(_timecode, time_to_timecode(_viewer.position(), fps));
294 Controls::active_jobs_changed (optional<string> j)
297 setup_sensitivity ();
302 Controls::nudge_amount (wxKeyboardState& ev)
304 auto amount = _viewer.one_video_frame();
306 if (ev.ShiftDown() && !ev.ControlDown()) {
307 amount = DCPTime::from_seconds (1);
308 } else if (!ev.ShiftDown() && ev.ControlDown()) {
309 amount = DCPTime::from_seconds (10);
310 } else if (ev.ShiftDown() && ev.ControlDown()) {
311 amount = DCPTime::from_seconds (60);
319 Controls::rewind_clicked (wxMouseEvent& ev)
321 _viewer.seek(DCPTime(), true);
327 Controls::back_frame ()
329 _viewer.seek_by(-_viewer.one_video_frame(), true);
334 Controls::forward_frame ()
336 _viewer.seek_by(_viewer.one_video_frame(), true);
341 Controls::back_clicked (wxKeyboardState& ev)
343 _viewer.seek_by(-nudge_amount(ev), true);
348 Controls::forward_clicked (wxKeyboardState& ev)
350 _viewer.seek_by(nudge_amount(ev), true);
355 Controls::setup_sensitivity ()
357 /* examine content is the only job which stops the viewer working */
358 bool const active_job = _active_job && *_active_job != "examine_content";
359 bool const c = _film && !_film->content().empty() && !active_job;
362 _rewind_button->Enable (c);
363 _back_button->Enable (c);
364 _forward_button->Enable (c);
365 if (_outline_content) {
366 _outline_content->Enable (c);
368 _frame_number->Enable (c);
369 _timecode->Enable (c);
370 if (_jump_to_selected) {
371 _jump_to_selected->Enable (c);
375 _eye->Enable (c && _film->three_d ());
381 Controls::timecode_clicked ()
383 auto dialog = new PlayheadToTimecodeDialog(this, _viewer.position(), _film->video_frame_rate());
384 if (dialog->ShowModal() == wxID_OK) {
385 _viewer.seek(dialog->get(), true);
392 Controls::frame_number_clicked ()
394 auto dialog = new PlayheadToFrameDialog(this, _viewer.position(), _film->video_frame_rate());
395 if (dialog->ShowModal() == wxID_OK) {
396 _viewer.seek(dialog->get(), true);
403 Controls::jump_to_selected_clicked ()
405 Config::instance()->set_jump_to_selected (_jump_to_selected->GetValue ());
410 Controls::set_film (shared_ptr<Film> film)
418 _markers->set_film (_film);
421 _film_change_connection = _film->Change.connect (boost::bind(&Controls::film_change, this, _1, _2));
424 setup_sensitivity ();
426 update_position_slider ();
427 update_position_label ();
432 Controls::film () const
439 Controls::film_change (ChangeType type, Film::Property p)
441 if (type == ChangeType::DONE) {
442 if (p == Film::Property::CONTENT) {
443 setup_sensitivity ();
444 update_position_label ();
445 update_position_slider ();
446 } else if (p == Film::Property::THREE_D) {
447 setup_sensitivity ();
454 Controls::seek (int slider)
456 _slider->SetValue (slider);
457 slider_moved (false);