1 #include "control_film_viewer.h"
2 #include "film_viewer.h"
10 ControlFilmViewer::ControlFilmViewer (wxWindow* parent, bool outline_content, bool jump_to_selected)
12 , _viewer (new FilmViewer(this, outline_content, jump_to_selected))
13 , _slider (new wxSlider (this, wxID_ANY, 0, 0, 4096))
14 , _rewind_button (new wxButton (this, wxID_ANY, wxT("|<")))
15 , _back_button (new wxButton (this, wxID_ANY, wxT("<")))
16 , _forward_button (new wxButton (this, wxID_ANY, wxT(">")))
17 , _frame_number (new wxStaticText (this, wxID_ANY, wxT("")))
18 , _timecode (new wxStaticText (this, wxID_ANY, wxT("")))
19 , _play_button (new wxToggleButton (this, wxID_ANY, _("Play")))
21 _v_sizer = new wxBoxSizer (wxVERTICAL);
23 _v_sizer->Add (_viewer->panel(), 1, wxEXPAND);
25 wxBoxSizer* view_options = new wxBoxSizer (wxHORIZONTAL);
26 if (outline_content) {
27 _outline_content = new wxCheckBox (this, wxID_ANY, _("Outline content"));
28 view_options->Add (_outline_content, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
31 _eye = new wxChoice (this, wxID_ANY);
32 _eye->Append (_("Left"));
33 _eye->Append (_("Right"));
34 _eye->SetSelection (0);
35 view_options->Add (_eye, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
37 if (jump_to_selected) {
38 _jump_to_selected = new wxCheckBox (this, wxID_ANY, _("Jump to selected content"));
39 view_options->Add (_jump_to_selected, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
42 _v_sizer->Add (view_options, 0, wxALL, DCPOMATIC_SIZER_GAP);
44 wxBoxSizer* h_sizer = new wxBoxSizer (wxHORIZONTAL);
46 wxBoxSizer* time_sizer = new wxBoxSizer (wxVERTICAL);
47 time_sizer->Add (_frame_number, 0, wxEXPAND);
48 time_sizer->Add (_timecode, 0, wxEXPAND);
50 h_sizer->Add (_rewind_button, 0, wxALL, 2);
51 h_sizer->Add (_back_button, 0, wxALL, 2);
52 h_sizer->Add (time_sizer, 0, wxEXPAND);
53 h_sizer->Add (_forward_button, 0, wxALL, 2);
54 h_sizer->Add (_play_button, 0, wxEXPAND);
55 h_sizer->Add (_slider, 1, wxEXPAND);
57 _v_sizer->Add (h_sizer, 0, wxEXPAND | wxALL, 6);
59 _frame_number->SetMinSize (wxSize (84, -1));
60 _rewind_button->SetMinSize (wxSize (32, -1));
61 _back_button->SetMinSize (wxSize (32, -1));
62 _forward_button->SetMinSize (wxSize (32, -1));
64 _eye->Bind (wxEVT_CHOICE, boost::bind (&FilmViewer::slow_refresh, _viewer.get()));
65 _slider->Bind (wxEVT_SCROLL_THUMBTRACK, boost::bind (&ControlFilmViewer::slider_moved, this, false));
66 _slider->Bind (wxEVT_SCROLL_PAGEUP, boost::bind (&ControlFilmViewer::slider_moved, this, true));
67 _slider->Bind (wxEVT_SCROLL_PAGEDOWN, boost::bind (&ControlFilmViewer::slider_moved, this, true));
68 _slider->Bind (wxEVT_SCROLL_THUMBRELEASE, boost::bind (&ControlFilmViewer::slider_released, this));
69 _play_button->Bind (wxEVT_TOGGLEBUTTON, boost::bind (&ControlFilmViewer::play_clicked, this));
70 _rewind_button->Bind (wxEVT_LEFT_DOWN, boost::bind (&ControlFilmViewer::rewind_clicked, this, _1));
71 _back_button->Bind (wxEVT_LEFT_DOWN, boost::bind (&ControlFilmViewer::back_clicked, this, _1));
72 _forward_button->Bind (wxEVT_LEFT_DOWN, boost::bind (&ControlFilmViewer::forward_clicked, this, _1));
73 _frame_number->Bind (wxEVT_LEFT_DOWN, boost::bind (&ControlFilmViewer::frame_number_clicked, this));
74 _timecode->Bind (wxEVT_LEFT_DOWN, boost::bind (&ControlFilmViewer::timecode_clicked, this));
75 if (_jump_to_selected) {
76 _jump_to_selected->Bind (wxEVT_CHECKBOX, boost::bind (&ControlFilmViewer::jump_to_selected_clicked, this));
77 _jump_to_selected->SetValue (Config::instance()->jump_to_selected ());
81 /** @param page true if this was a PAGEUP/PAGEDOWN event for which we won't receive a THUMBRELEASE */
83 ControlFilmViewer::slider_moved (bool page)
89 if (!page && !_slider_being_moved) {
90 /* This is the first event of a drag; stop playback for the duration of the drag */
91 _was_running_before_slider = stop ();
92 _slider_being_moved = true;
95 DCPTime t (_slider->GetValue() * _film->length().get() / 4096);
96 t = t.round (_film->video_frame_rate());
97 /* Ensure that we hit the end of the film at the end of the slider */
98 if (t >= _film->length ()) {
99 t = _film->length() - _viewer->one_video_frame();
101 _viewer->seek (t, false);
102 update_position_label ();
106 ControlFilmViewer::slider_released ()
108 if (_was_running_before_slider) {
109 /* Restart after a drag */
112 _slider_being_moved = false;
116 ControlFilmViewer::play_clicked ()
122 ControlFilmViewer::check_play_state ()
124 if (!_film || _film->video_frame_rate() == 0) {
128 if (_play_button->GetValue()) {
136 ControlFilmViewer::update_position_slider ()
139 _slider->SetValue (0);
143 DCPTime const len = _film->length ();
146 int const new_slider_position = 4096 * _viewer->video_position().get() / len.get();
147 if (new_slider_position != _slider->GetValue()) {
148 _slider->SetValue (new_slider_position);
154 ControlFilmViewer::update_position_label ()
157 _frame_number->SetLabel ("0");
158 _timecode->SetLabel ("0:0:0.0");
162 double const fps = _film->video_frame_rate ();
163 /* Count frame number from 1 ... not sure if this is the best idea */
164 _frame_number->SetLabel (wxString::Format (wxT("%ld"), lrint (_viewer->video_position().seconds() * fps) + 1));
165 _timecode->SetLabel (time_to_timecode (_viewer->video_position(), fps));
169 ControlFilmViewer::active_jobs_changed (optional<string> j)
171 /* examine content is the only job which stops the viewer working */
172 bool const a = !j || *j != "examine_content";
174 _play_button->Enable (a);
178 ControlFilmViewer::nudge_amount (wxKeyboardState& ev)
180 DCPTime amount = _viewer->one_video_frame ();
182 if (ev.ShiftDown() && !ev.ControlDown()) {
183 amount = DCPTime::from_seconds (1);
184 } else if (!ev.ShiftDown() && ev.ControlDown()) {
185 amount = DCPTime::from_seconds (10);
186 } else if (ev.ShiftDown() && ev.ControlDown()) {
187 amount = DCPTime::from_seconds (60);
194 ControlFilmViewer::rewind_clicked (wxMouseEvent& ev)
196 _viewer->go_to (DCPTime());
201 ControlFilmViewer::back_frame ()
203 _viewer->move (-_viewer->one_video_frame());
207 ControlFilmViewer::forward_frame ()
209 _viewer->move (_viewer->one_video_frame());
213 ControlFilmViewer::back_clicked (wxKeyboardState& ev)
215 _viewer->move (-nudge_amount(ev));
219 ControlFilmViewer::forward_clicked (wxKeyboardState& ev)
221 _viewer->move (nudge_amount(ev));
225 ControlFilmViewer::setup_sensitivity ()
227 bool const c = _film && !_film->content().empty ();
230 _rewind_button->Enable (c);
231 _back_button->Enable (c);
232 _forward_button->Enable (c);
233 _play_button->Enable (c);
234 if (_outline_content) {
235 _outline_content->Enable (c);
237 _frame_number->Enable (c);
238 _timecode->Enable (c);
239 if (_jump_to_selected) {
240 _jump_to_selected->Enable (c);
243 _eye->Enable (c && _film->three_d ());
247 ControlFilmViewer::timecode_clicked ()
249 PlayheadToTimecodeDialog* dialog = new PlayheadToTimecodeDialog (this, _film->video_frame_rate ());
250 if (dialog->ShowModal() == wxID_OK) {
251 _viewer->go_to (dialog->get ());
257 ControlFilmViewer::frame_number_clicked ()
259 PlayheadToFrameDialog* dialog = new PlayheadToFrameDialog (this, _film->video_frame_rate ());
260 if (dialog->ShowModal() == wxID_OK) {
261 _viewer->go_to (dialog->get ());
267 ControlFilmViewer::jump_to_selected_clicked ()
269 Config::instance()->set_jump_to_selected (_jump_to_selected->GetValue ());
273 ControlFilmViewer::set_film (shared_ptr<Film> film)
275 _viewer->set_film (film);
283 update_position_slider ();
284 update_position_label ();
288 ControlFilmViewer::set_position (DCPTime p)
290 _viewer->set_position (p);
294 ControlFilmViewer::set_position (shared_ptr<Content> content, ContentTime t)
296 _viewer->set_position (content, t);
300 ControlFilmViewer::set_dcp_decode_reduction (boost::optional<int> reduction)
302 _viewer->set_dcp_decode_reduction (reduction);
306 ControlFilmViewer::show_closed_captions ()
308 _viewer->show_closed_captions ();
312 ControlFilmViewer::start ()
318 ControlFilmViewer::stop ()
320 return _viewer->stop ();
324 ControlFilmViewer::playing () const
326 return _viewer->playing ();