2 #include "film_viewer.h"
4 #include "playhead_to_timecode_dialog.h"
5 #include "playhead_to_frame_dialog.h"
6 #include "lib/job_manager.h"
11 using boost::optional;
12 using boost::shared_ptr;
13 using boost::weak_ptr;
15 /** @param outline_content true if viewer should present an "outline content" checkbox.
16 * @param jump_to_selected true if viewer should present a "jump to selected" checkbox.
18 Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool outline_content, bool jump_to_selected)
21 , _slider_being_moved (false)
22 , _was_running_before_slider (false)
23 , _outline_content (0)
25 , _jump_to_selected (0)
26 , _slider (new wxSlider (this, wxID_ANY, 0, 0, 4096))
27 , _rewind_button (new wxButton (this, wxID_ANY, wxT("|<")))
28 , _back_button (new wxButton (this, wxID_ANY, wxT("<")))
29 , _forward_button (new wxButton (this, wxID_ANY, wxT(">")))
30 , _frame_number (new wxStaticText (this, wxID_ANY, wxT("")))
31 , _timecode (new wxStaticText (this, wxID_ANY, wxT("")))
32 , _play_button (new wxToggleButton (this, wxID_ANY, _("Play")))
34 _v_sizer = new wxBoxSizer (wxVERTICAL);
37 wxBoxSizer* view_options = new wxBoxSizer (wxHORIZONTAL);
38 if (outline_content) {
39 _outline_content = new wxCheckBox (this, wxID_ANY, _("Outline content"));
40 view_options->Add (_outline_content, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
43 _eye = new wxChoice (this, wxID_ANY);
44 _eye->Append (_("Left"));
45 _eye->Append (_("Right"));
46 _eye->SetSelection (0);
47 view_options->Add (_eye, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
49 if (jump_to_selected) {
50 _jump_to_selected = new wxCheckBox (this, wxID_ANY, _("Jump to selected content"));
51 view_options->Add (_jump_to_selected, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
54 _v_sizer->Add (view_options, 0, wxALL, DCPOMATIC_SIZER_GAP);
56 wxBoxSizer* h_sizer = new wxBoxSizer (wxHORIZONTAL);
58 wxBoxSizer* time_sizer = new wxBoxSizer (wxVERTICAL);
59 time_sizer->Add (_frame_number, 0, wxEXPAND);
60 time_sizer->Add (_timecode, 0, wxEXPAND);
62 h_sizer->Add (_rewind_button, 0, wxALL, 2);
63 h_sizer->Add (_back_button, 0, wxALL, 2);
64 h_sizer->Add (time_sizer, 0, wxEXPAND);
65 h_sizer->Add (_forward_button, 0, wxALL, 2);
66 h_sizer->Add (_play_button, 0, wxEXPAND);
67 h_sizer->Add (_slider, 1, wxEXPAND);
69 _v_sizer->Add (h_sizer, 0, wxEXPAND | wxALL, 6);
71 _frame_number->SetMinSize (wxSize (84, -1));
72 _rewind_button->SetMinSize (wxSize (32, -1));
73 _back_button->SetMinSize (wxSize (32, -1));
74 _forward_button->SetMinSize (wxSize (32, -1));
76 _eye->Bind (wxEVT_CHOICE, boost::bind (&Controls::eye_changed, this));
77 if (_outline_content) {
78 _outline_content->Bind (wxEVT_CHECKBOX, boost::bind (&Controls::outline_content_changed, this));
81 _slider->Bind (wxEVT_SCROLL_THUMBTRACK, boost::bind (&Controls::slider_moved, this, false));
82 _slider->Bind (wxEVT_SCROLL_PAGEUP, boost::bind (&Controls::slider_moved, this, true));
83 _slider->Bind (wxEVT_SCROLL_PAGEDOWN, boost::bind (&Controls::slider_moved, this, true));
84 _slider->Bind (wxEVT_SCROLL_THUMBRELEASE, boost::bind (&Controls::slider_released, this));
85 _play_button->Bind (wxEVT_TOGGLEBUTTON, boost::bind (&Controls::play_clicked, this));
86 _rewind_button->Bind (wxEVT_LEFT_DOWN, boost::bind (&Controls::rewind_clicked, this, _1));
87 _back_button->Bind (wxEVT_LEFT_DOWN, boost::bind (&Controls::back_clicked, this, _1));
88 _forward_button->Bind (wxEVT_LEFT_DOWN, boost::bind (&Controls::forward_clicked, this, _1));
89 _frame_number->Bind (wxEVT_LEFT_DOWN, boost::bind (&Controls::frame_number_clicked, this));
90 _timecode->Bind (wxEVT_LEFT_DOWN, boost::bind (&Controls::timecode_clicked, this));
91 if (_jump_to_selected) {
92 _jump_to_selected->Bind (wxEVT_CHECKBOX, boost::bind (&Controls::jump_to_selected_clicked, this));
93 _jump_to_selected->SetValue (Config::instance()->jump_to_selected ());
96 _viewer->PositionChanged.connect (boost::bind(&Controls::position_changed, this));
97 _viewer->Started.connect (boost::bind(&Controls::started, this));
98 _viewer->Stopped.connect (boost::bind(&Controls::stopped, this));
99 _viewer->FilmChanged.connect (boost::bind(&Controls::film_changed, this));
103 setup_sensitivity ();
105 JobManager::instance()->ActiveJobsChanged.connect (
106 bind (&Controls::active_jobs_changed, this, _2)
113 _play_button->SetValue (true);
119 _play_button->SetValue (false);
123 Controls::position_changed ()
125 update_position_label ();
126 update_position_slider ();
130 Controls::eye_changed ()
132 _viewer->set_eyes (_eye->GetSelection() == 0 ? EYES_LEFT : EYES_RIGHT);
136 Controls::outline_content_changed ()
138 _viewer->set_outline_content (_outline_content->GetValue());
142 Controls::film_change (ChangeType type, Film::Property p)
144 if (type != CHANGE_TYPE_DONE) {
148 if (p == Film::CONTENT || p == Film::THREE_D) {
149 setup_sensitivity ();
153 /** @param page true if this was a PAGEUP/PAGEDOWN event for which we won't receive a THUMBRELEASE */
155 Controls::slider_moved (bool page)
161 if (!page && !_slider_being_moved) {
162 /* This is the first event of a drag; stop playback for the duration of the drag */
163 _was_running_before_slider = _viewer->stop ();
164 _slider_being_moved = true;
167 DCPTime t (_slider->GetValue() * _film->length().get() / 4096);
168 t = t.round (_film->video_frame_rate());
169 /* Ensure that we hit the end of the film at the end of the slider */
170 if (t >= _film->length ()) {
171 t = _film->length() - _viewer->one_video_frame();
173 _viewer->seek (t, false);
174 update_position_label ();
178 Controls::slider_released ()
180 if (_was_running_before_slider) {
181 /* Restart after a drag */
184 _slider_being_moved = false;
188 Controls::play_clicked ()
194 Controls::check_play_state ()
196 if (!_film || _film->video_frame_rate() == 0) {
200 if (_play_button->GetValue()) {
208 Controls::update_position_slider ()
211 _slider->SetValue (0);
215 DCPTime const len = _film->length ();
218 int const new_slider_position = 4096 * _viewer->video_position().get() / len.get();
219 if (new_slider_position != _slider->GetValue()) {
220 _slider->SetValue (new_slider_position);
226 Controls::update_position_label ()
229 _frame_number->SetLabel ("0");
230 _timecode->SetLabel ("0:0:0.0");
234 double const fps = _film->video_frame_rate ();
235 /* Count frame number from 1 ... not sure if this is the best idea */
236 _frame_number->SetLabel (wxString::Format (wxT("%ld"), lrint (_viewer->video_position().seconds() * fps) + 1));
237 _timecode->SetLabel (time_to_timecode (_viewer->video_position(), fps));
241 Controls::active_jobs_changed (optional<string> j)
243 /* examine content is the only job which stops the viewer working */
244 bool const a = !j || *j != "examine_content";
246 _play_button->Enable (a);
250 Controls::nudge_amount (wxKeyboardState& ev)
252 DCPTime amount = _viewer->one_video_frame ();
254 if (ev.ShiftDown() && !ev.ControlDown()) {
255 amount = DCPTime::from_seconds (1);
256 } else if (!ev.ShiftDown() && ev.ControlDown()) {
257 amount = DCPTime::from_seconds (10);
258 } else if (ev.ShiftDown() && ev.ControlDown()) {
259 amount = DCPTime::from_seconds (60);
266 Controls::rewind_clicked (wxMouseEvent& ev)
268 _viewer->go_to (DCPTime());
273 Controls::back_frame ()
275 _viewer->move (-_viewer->one_video_frame());
279 Controls::forward_frame ()
281 _viewer->move (_viewer->one_video_frame());
285 Controls::back_clicked (wxKeyboardState& ev)
287 _viewer->move (-nudge_amount(ev));
291 Controls::forward_clicked (wxKeyboardState& ev)
293 _viewer->move (nudge_amount(ev));
297 Controls::setup_sensitivity ()
299 bool const c = _film && !_film->content().empty ();
302 _rewind_button->Enable (c);
303 _back_button->Enable (c);
304 _forward_button->Enable (c);
305 _play_button->Enable (c);
306 if (_outline_content) {
307 _outline_content->Enable (c);
309 _frame_number->Enable (c);
310 _timecode->Enable (c);
311 if (_jump_to_selected) {
312 _jump_to_selected->Enable (c);
315 _eye->Enable (c && _film->three_d ());
319 Controls::timecode_clicked ()
321 PlayheadToTimecodeDialog* dialog = new PlayheadToTimecodeDialog (this, _film->video_frame_rate ());
322 if (dialog->ShowModal() == wxID_OK) {
323 _viewer->go_to (dialog->get ());
329 Controls::frame_number_clicked ()
331 PlayheadToFrameDialog* dialog = new PlayheadToFrameDialog (this, _film->video_frame_rate ());
332 if (dialog->ShowModal() == wxID_OK) {
333 _viewer->go_to (dialog->get ());
339 Controls::jump_to_selected_clicked ()
341 Config::instance()->set_jump_to_selected (_jump_to_selected->GetValue ());
345 Controls::film_changed ()
347 shared_ptr<Film> film = _viewer->film ();
355 setup_sensitivity ();
357 update_position_slider ();
358 update_position_label ();
360 _film->Change.connect (boost::bind (&Controls::film_change, this, _1, _2));
364 Controls::film () const