Add load button for SPL.
[dcpomatic.git] / src / wx / controls.cc
1 /*
2     Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "controls.h"
22 #include "film_viewer.h"
23 #include "wx_util.h"
24 #include "playhead_to_timecode_dialog.h"
25 #include "playhead_to_frame_dialog.h"
26 #include "lib/job_manager.h"
27 #include "lib/player_video.h"
28 #include "lib/dcp_content.h"
29 #include "lib/spl_entry.h"
30 #include <dcp/dcp.h>
31 #include <dcp/cpl.h>
32 #include <dcp/reel.h>
33 #include <dcp/reel_picture_asset.h>
34 #include <wx/wx.h>
35 #include <wx/tglbtn.h>
36 #include <wx/listctrl.h>
37
38 using std::string;
39 using std::list;
40 using std::make_pair;
41 using boost::optional;
42 using boost::shared_ptr;
43 using boost::weak_ptr;
44 using boost::dynamic_pointer_cast;
45
46 Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor_controls)
47         : wxPanel (parent)
48         , _viewer (viewer)
49         , _slider_being_moved (false)
50         , _was_running_before_slider (false)
51         , _outline_content (0)
52         , _eye (0)
53         , _jump_to_selected (0)
54         , _slider (new wxSlider (this, wxID_ANY, 0, 0, 4096))
55         , _rewind_button (new wxButton (this, wxID_ANY, wxT("|<")))
56         , _back_button (new wxButton (this, wxID_ANY, wxT("<")))
57         , _forward_button (new wxButton (this, wxID_ANY, wxT(">")))
58         , _frame_number (new wxStaticText (this, wxID_ANY, wxT("")))
59         , _timecode (new wxStaticText (this, wxID_ANY, wxT("")))
60 #ifdef DCPOMATIC_VARIANT_SWAROOP
61         , _play_button (new wxButton(this, wxID_ANY, _("Play")))
62         , _pause_button (new wxButton(this, wxID_ANY, _("Pause")))
63         , _stop_button (new wxButton(this, wxID_ANY, _("Stop")))
64 #else
65         , _play_button (new wxToggleButton(this, wxID_ANY, _("Play")))
66 #endif
67 {
68         _v_sizer = new wxBoxSizer (wxVERTICAL);
69         SetSizer (_v_sizer);
70
71         wxBoxSizer* view_options = new wxBoxSizer (wxHORIZONTAL);
72         if (editor_controls) {
73                 _outline_content = new wxCheckBox (this, wxID_ANY, _("Outline content"));
74                 view_options->Add (_outline_content, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
75                 _eye = new wxChoice (this, wxID_ANY);
76                 _eye->Append (_("Left"));
77                 _eye->Append (_("Right"));
78                 _eye->SetSelection (0);
79                 view_options->Add (_eye, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
80                 _jump_to_selected = new wxCheckBox (this, wxID_ANY, _("Jump to selected content"));
81                 view_options->Add (_jump_to_selected, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
82         }
83
84         _v_sizer->Add (view_options, 0, wxALL, DCPOMATIC_SIZER_GAP);
85
86         wxBoxSizer* e_sizer = new wxBoxSizer (wxHORIZONTAL);
87
88         _cpl = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER);
89         /* time */
90         _cpl->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 80);
91         /* type */
92         _cpl->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 80);
93         /* annotation text */
94         _cpl->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 580);
95         e_sizer->Add (_cpl, 1, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
96
97         _spl_view = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER);
98         _spl_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 80);
99         _spl_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 80);
100         _spl_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 580);
101         e_sizer->Add (_spl_view, 1, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
102
103         wxBoxSizer* buttons_sizer = new wxBoxSizer (wxVERTICAL);
104         _add_button = new wxButton(this, wxID_ANY, _("Add"));
105         buttons_sizer->Add (_add_button);
106         _save_button = new wxButton(this, wxID_ANY, _("Save..."));
107         buttons_sizer->Add (_save_button);
108         _load_button = new wxButton(this, wxID_ANY, _("Load..."));
109         buttons_sizer->Add (_load_button);
110         e_sizer->Add (buttons_sizer, 0, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
111
112         _v_sizer->Add (e_sizer, 1, wxEXPAND);
113
114         _log = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(-1, 200), wxTE_READONLY | wxTE_MULTILINE);
115         _v_sizer->Add (_log, 0, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
116
117         _cpl->Show (false);
118         _spl_view->Show (false);
119         _add_button->Show (false);
120         _save_button->Show (false);
121         _load_button->Show (false);
122         _log->Show (false);
123
124         wxBoxSizer* h_sizer = new wxBoxSizer (wxHORIZONTAL);
125
126         wxBoxSizer* time_sizer = new wxBoxSizer (wxVERTICAL);
127         time_sizer->Add (_frame_number, 0, wxEXPAND);
128         time_sizer->Add (_timecode, 0, wxEXPAND);
129
130         h_sizer->Add (_rewind_button, 0, wxALL, 2);
131         h_sizer->Add (_back_button, 0, wxALL, 2);
132         h_sizer->Add (time_sizer, 0, wxEXPAND);
133         h_sizer->Add (_forward_button, 0, wxALL, 2);
134         h_sizer->Add (_play_button, 0, wxEXPAND);
135 #ifdef DCPOMATIC_VARIANT_SWAROOP
136         h_sizer->Add (_pause_button, 0, wxEXPAND);
137         h_sizer->Add (_stop_button, 0, wxEXPAND);
138 #endif
139         h_sizer->Add (_slider, 1, wxEXPAND);
140
141         _v_sizer->Add (h_sizer, 0, wxEXPAND | wxALL, 6);
142
143         _frame_number->SetMinSize (wxSize (84, -1));
144         _rewind_button->SetMinSize (wxSize (32, -1));
145         _back_button->SetMinSize (wxSize (32, -1));
146         _forward_button->SetMinSize (wxSize (32, -1));
147
148         if (_eye) {
149                 _eye->Bind (wxEVT_CHOICE, boost::bind (&Controls::eye_changed, this));
150         }
151         if (_outline_content) {
152                 _outline_content->Bind (wxEVT_CHECKBOX, boost::bind (&Controls::outline_content_changed, this));
153         }
154
155         _slider->Bind           (wxEVT_SCROLL_THUMBTRACK,    boost::bind(&Controls::slider_moved,    this, false));
156         _slider->Bind           (wxEVT_SCROLL_PAGEUP,        boost::bind(&Controls::slider_moved,    this, true));
157         _slider->Bind           (wxEVT_SCROLL_PAGEDOWN,      boost::bind(&Controls::slider_moved,    this, true));
158         _slider->Bind           (wxEVT_SCROLL_CHANGED,       boost::bind(&Controls::slider_released, this));
159 #ifdef DCPOMATIC_VARIANT_SWAROOP
160         _play_button->Bind      (wxEVT_BUTTON,               boost::bind(&Controls::play_clicked,    this));
161         _pause_button->Bind     (wxEVT_BUTTON,               boost::bind(&Controls::pause_clicked,   this));
162         _stop_button->Bind      (wxEVT_BUTTON,               boost::bind(&Controls::stop_clicked,    this));
163 #else
164         _play_button->Bind      (wxEVT_TOGGLEBUTTON,         boost::bind(&Controls::play_clicked,    this));
165 #endif
166         _rewind_button->Bind    (wxEVT_LEFT_DOWN,            boost::bind(&Controls::rewind_clicked,  this, _1));
167         _back_button->Bind      (wxEVT_LEFT_DOWN,            boost::bind(&Controls::back_clicked,    this, _1));
168         _forward_button->Bind   (wxEVT_LEFT_DOWN,            boost::bind(&Controls::forward_clicked, this, _1));
169         _frame_number->Bind     (wxEVT_LEFT_DOWN,            boost::bind(&Controls::frame_number_clicked, this));
170         _timecode->Bind         (wxEVT_LEFT_DOWN,            boost::bind(&Controls::timecode_clicked, this));
171         _cpl->Bind              (wxEVT_LIST_ITEM_SELECTED,   boost::bind(&Controls::setup_sensitivity, this));
172         _cpl->Bind              (wxEVT_LIST_ITEM_DESELECTED, boost::bind(&Controls::setup_sensitivity, this));
173         if (_jump_to_selected) {
174                 _jump_to_selected->Bind (wxEVT_CHECKBOX, boost::bind (&Controls::jump_to_selected_clicked, this));
175                 _jump_to_selected->SetValue (Config::instance()->jump_to_selected ());
176         }
177         _add_button->Bind       (wxEVT_BUTTON,              boost::bind(&Controls::add_clicked, this));
178         _save_button->Bind      (wxEVT_BUTTON,              boost::bind(&Controls::save_clicked, this));
179         _load_button->Bind      (wxEVT_BUTTON,              boost::bind(&Controls::load_clicked, this));
180
181         _viewer->PositionChanged.connect (boost::bind(&Controls::position_changed, this));
182         _viewer->Started.connect (boost::bind(&Controls::started, this));
183         _viewer->Stopped.connect (boost::bind(&Controls::stopped, this));
184         _viewer->FilmChanged.connect (boost::bind(&Controls::film_changed, this));
185         _viewer->ImageChanged.connect (boost::bind(&Controls::image_changed, this, _1));
186
187         film_changed ();
188
189         setup_sensitivity ();
190         update_dcp_directory ();
191
192         JobManager::instance()->ActiveJobsChanged.connect (
193                 bind (&Controls::active_jobs_changed, this, _2)
194                 );
195
196         _config_changed_connection = Config::instance()->Changed.connect (bind(&Controls::config_changed, this, _1));
197         config_changed (Config::OTHER);
198 }
199
200 void
201 Controls::add_clicked ()
202 {
203         optional<CPL> sel = selected_cpl ();
204         DCPOMATIC_ASSERT (sel);
205         _spl.playlist.push_back (SPLEntry(sel->first, sel->second));
206         add_cpl_to_list (sel->first, _spl_view);
207         SPLChanged (_spl);
208         setup_sensitivity ();
209 }
210
211 void
212 Controls::save_clicked ()
213 {
214         wxFileDialog* d = new wxFileDialog (
215                 this, _("Select playlist file"), wxEmptyString, wxEmptyString, wxT ("XML files (*.xml)|*.xml"),
216                 wxFD_SAVE | wxFD_OVERWRITE_PROMPT
217                 );
218
219         if (d->ShowModal() == wxID_OK) {
220                 _spl.as_xml (boost::filesystem::path(wx_to_std(d->GetPath())));
221         }
222
223         d->Destroy ();
224 }
225
226 void
227 Controls::load_clicked ()
228 {
229         wxFileDialog* d = new wxFileDialog (
230                 this, _("Select playlist file"), wxEmptyString, wxEmptyString, wxT ("XML files (*.xml)|*.xml")
231                 );
232
233         if (d->ShowModal() == wxID_OK) {
234                 _spl = SPL (boost::filesystem::path(wx_to_std(d->GetPath())));
235                 _spl_view->DeleteAllItems ();
236                 BOOST_FOREACH (SPLEntry i, _spl.playlist) {
237                         add_cpl_to_list (i.cpl, _spl_view);
238                 }
239                 SPLChanged (_spl);
240         }
241
242         d->Destroy ();
243 }
244
245 void
246 Controls::config_changed (int property)
247 {
248         if (property == Config::PLAYER_DCP_DIRECTORY) {
249                 update_dcp_directory ();
250         } else {
251                 setup_sensitivity ();
252         }
253 }
254
255 void
256 Controls::started ()
257 {
258 #ifdef DCPOMATIC_VARIANT_SWAROOP
259         _play_button->Enable (false);
260         _pause_button->Enable (true);
261 #else
262         _play_button->SetValue (true);
263 #endif
264         setup_sensitivity ();
265 }
266
267 void
268 Controls::stopped ()
269 {
270 #ifdef DCPOMATIC_VARIANT_SWAROOP
271         _play_button->Enable (true);
272         _pause_button->Enable (false);
273 #else
274         _play_button->SetValue (false);
275 #endif
276         setup_sensitivity ();
277 }
278
279 void
280 Controls::position_changed ()
281 {
282         if (!_slider_being_moved) {
283                 update_position_label ();
284                 update_position_slider ();
285         }
286 }
287
288 void
289 Controls::eye_changed ()
290 {
291         _viewer->set_eyes (_eye->GetSelection() == 0 ? EYES_LEFT : EYES_RIGHT);
292 }
293
294 void
295 Controls::outline_content_changed ()
296 {
297         _viewer->set_outline_content (_outline_content->GetValue());
298 }
299
300 void
301 Controls::film_change (ChangeType type, Film::Property p)
302 {
303         if (type != CHANGE_TYPE_DONE) {
304                 return;
305         }
306
307         if (p == Film::CONTENT || p == Film::THREE_D) {
308                 setup_sensitivity ();
309         }
310 }
311
312 /** @param page true if this was a PAGEUP/PAGEDOWN event for which we won't receive a THUMBRELEASE */
313 void
314 Controls::slider_moved (bool page)
315 {
316         if (!_film) {
317                 return;
318         }
319
320         if (!page && !_slider_being_moved) {
321                 /* This is the first event of a drag; stop playback for the duration of the drag */
322                 _was_running_before_slider = _viewer->stop ();
323                 _slider_being_moved = true;
324         }
325
326         DCPTime t (_slider->GetValue() * _film->length().get() / 4096);
327         t = t.round (_film->video_frame_rate());
328         /* Ensure that we hit the end of the film at the end of the slider */
329         if (t >= _film->length ()) {
330                 t = _film->length() - _viewer->one_video_frame();
331         }
332         _viewer->seek (t, false);
333         update_position_label ();
334 }
335
336 void
337 Controls::slider_released ()
338 {
339         if (_was_running_before_slider) {
340                 /* Restart after a drag */
341                 _viewer->start ();
342         }
343         _slider_being_moved = false;
344 }
345
346 void
347 Controls::play_clicked ()
348 {
349 #ifdef DCPOMATIC_VARIANT_SWAROOP
350         _viewer->start ();
351 #else
352         check_play_state ();
353 #endif
354 }
355
356
357 #ifndef DCPOMATIC_VARIANT_SWAROOP
358 void
359 Controls::check_play_state ()
360 {
361         if (!_film || _film->video_frame_rate() == 0) {
362                 return;
363         }
364
365         if (_play_button->GetValue()) {
366                 _viewer->start ();
367         } else {
368                 _viewer->stop ();
369         }
370 }
371 #endif
372
373 void
374 Controls::update_position_slider ()
375 {
376         if (!_film) {
377                 _slider->SetValue (0);
378                 return;
379         }
380
381         DCPTime const len = _film->length ();
382
383         if (len.get ()) {
384                 int const new_slider_position = 4096 * _viewer->position().get() / len.get();
385                 if (new_slider_position != _slider->GetValue()) {
386                         _slider->SetValue (new_slider_position);
387                 }
388         }
389 }
390
391 void
392 Controls::update_position_label ()
393 {
394         if (!_film) {
395                 _frame_number->SetLabel ("0");
396                 _timecode->SetLabel ("0:0:0.0");
397                 return;
398         }
399
400         double const fps = _film->video_frame_rate ();
401         /* Count frame number from 1 ... not sure if this is the best idea */
402         _frame_number->SetLabel (wxString::Format (wxT("%ld"), lrint (_viewer->position().seconds() * fps) + 1));
403         _timecode->SetLabel (time_to_timecode (_viewer->position(), fps));
404 }
405
406 void
407 Controls::active_jobs_changed (optional<string> j)
408 {
409         _active_job = j;
410         setup_sensitivity ();
411 }
412
413 DCPTime
414 Controls::nudge_amount (wxKeyboardState& ev)
415 {
416         DCPTime amount = _viewer->one_video_frame ();
417
418         if (ev.ShiftDown() && !ev.ControlDown()) {
419                 amount = DCPTime::from_seconds (1);
420         } else if (!ev.ShiftDown() && ev.ControlDown()) {
421                 amount = DCPTime::from_seconds (10);
422         } else if (ev.ShiftDown() && ev.ControlDown()) {
423                 amount = DCPTime::from_seconds (60);
424         }
425
426         return amount;
427 }
428
429 void
430 Controls::rewind_clicked (wxMouseEvent& ev)
431 {
432         _viewer->seek (DCPTime(), true);
433         ev.Skip();
434 }
435
436 void
437 Controls::back_frame ()
438 {
439         _viewer->seek_by (-_viewer->one_video_frame(), true);
440 }
441
442 void
443 Controls::forward_frame ()
444 {
445         _viewer->seek_by (_viewer->one_video_frame(), true);
446 }
447
448 void
449 Controls::back_clicked (wxKeyboardState& ev)
450 {
451         _viewer->seek_by (-nudge_amount(ev), true);
452 }
453
454 void
455 Controls::forward_clicked (wxKeyboardState& ev)
456 {
457         _viewer->seek_by (nudge_amount(ev), true);
458 }
459
460 void
461 Controls::setup_sensitivity ()
462 {
463         /* examine content is the only job which stops the viewer working */
464         bool const active_job = _active_job && *_active_job != "examine_content";
465         bool const c = ((_film && !_film->content().empty()) || !_spl.playlist.empty()) && !active_job;
466
467         _slider->Enable (c);
468         _rewind_button->Enable (c);
469         _back_button->Enable (c);
470         _forward_button->Enable (c);
471 #ifdef DCPOMATIC_VARIANT_SWAROOP
472         _play_button->Enable (c && !_viewer->playing());
473         _pause_button->Enable (c && (!_current_kind || _current_kind != dcp::ADVERTISEMENT) && _viewer->playing());
474         _stop_button->Enable (c && (!_current_kind || _current_kind != dcp::ADVERTISEMENT));
475         _slider->Enable (c && (!_current_kind || _current_kind != dcp::ADVERTISEMENT));
476 #else
477         _play_button->Enable (c);
478 #endif
479         if (_outline_content) {
480                 _outline_content->Enable (c);
481         }
482         _frame_number->Enable (c);
483         _timecode->Enable (c);
484         if (_jump_to_selected) {
485                 _jump_to_selected->Enable (c);
486         }
487
488         if (_eye) {
489                 _eye->Enable (c && _film->three_d ());
490         }
491
492         _add_button->Enable (Config::instance()->allow_spl_editing() && static_cast<bool>(selected_cpl()));
493         _save_button->Enable (Config::instance()->allow_spl_editing());
494 }
495
496 optional<Controls::CPL>
497 Controls::selected_cpl () const
498 {
499         long int s = _cpl->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
500         if (s == -1) {
501                 return optional<CPL>();
502         }
503
504         DCPOMATIC_ASSERT (s < int(_cpls.size()));
505         return _cpls[s];
506 }
507
508 void
509 Controls::timecode_clicked ()
510 {
511         PlayheadToTimecodeDialog* dialog = new PlayheadToTimecodeDialog (this, _film->video_frame_rate ());
512         if (dialog->ShowModal() == wxID_OK) {
513                 _viewer->seek (dialog->get(), true);
514         }
515         dialog->Destroy ();
516 }
517
518 void
519 Controls::frame_number_clicked ()
520 {
521         PlayheadToFrameDialog* dialog = new PlayheadToFrameDialog (this, _film->video_frame_rate ());
522         if (dialog->ShowModal() == wxID_OK) {
523                 _viewer->seek (dialog->get(), true);
524         }
525         dialog->Destroy ();
526 }
527
528 void
529 Controls::jump_to_selected_clicked ()
530 {
531         Config::instance()->set_jump_to_selected (_jump_to_selected->GetValue ());
532 }
533
534 void
535 Controls::film_changed ()
536 {
537         shared_ptr<Film> film = _viewer->film ();
538
539         if (_film == film) {
540                 return;
541         }
542
543         _film = film;
544
545         setup_sensitivity ();
546
547         update_position_slider ();
548         update_position_label ();
549
550         if (_film) {
551                 _film->Change.connect (boost::bind (&Controls::film_change, this, _1, _2));
552         }
553 }
554
555 shared_ptr<Film>
556 Controls::film () const
557 {
558         return _film;
559 }
560
561 void
562 Controls::show_extended_player_controls (bool s)
563 {
564         _cpl->Show (s);
565         if (s) {
566                 update_dcp_directory ();
567         }
568         _spl_view->Show (s);
569         _log->Show (s);
570         _add_button->Show (s);
571         _save_button->Show (s);
572         _load_button->Show (s);
573         _v_sizer->Layout ();
574 }
575
576 void
577 Controls::add_cpl_to_list (shared_ptr<dcp::CPL> cpl, wxListCtrl* ctrl)
578 {
579         list<shared_ptr<dcp::Reel> > reels = cpl->reels ();
580
581         int const N = ctrl->GetItemCount();
582
583         wxListItem it;
584         if (!reels.empty() && reels.front()->main_picture()) {
585                 it.SetId(N);
586                 it.SetColumn(0);
587                 int seconds = rint(double(cpl->duration()) / reels.front()->main_picture()->frame_rate().as_float());
588                 int minutes = seconds / 60;
589                 seconds -= minutes * 60;
590                 int hours = minutes / 60;
591                 minutes -= hours * 60;
592                 it.SetText(wxString::Format("%02d:%02d:%02d", hours, minutes, seconds));
593                 ctrl->InsertItem(it);
594         }
595
596         it.SetId(N);
597         it.SetColumn(1);
598         it.SetText(std_to_wx(dcp::content_kind_to_string(cpl->content_kind())));
599         ctrl->SetItem(it);
600
601         it.SetId(N);
602         it.SetColumn(2);
603         it.SetText(std_to_wx(cpl->annotation_text()));
604         ctrl->SetItem(it);
605 }
606
607 void
608 Controls::update_dcp_directory ()
609 {
610         if (!_cpl->IsShown()) {
611                 return;
612         }
613
614         using namespace boost::filesystem;
615
616         _cpl->DeleteAllItems ();
617         _cpls.clear ();
618         optional<path> dir = Config::instance()->player_dcp_directory();
619         if (!dir) {
620                 return;
621         }
622
623         for (directory_iterator i = directory_iterator(*dir); i != directory_iterator(); ++i) {
624                 try {
625                         if (is_directory(*i) && (is_regular_file(*i / "ASSETMAP") || is_regular_file(*i / "ASSETMAP.xml"))) {
626                                 string const x = i->path().string().substr(dir->string().length() + 1);
627                                 dcp::DCP dcp (*i);
628                                 dcp.read ();
629                                 BOOST_FOREACH (shared_ptr<dcp::CPL> j, dcp.cpls()) {
630                                         add_cpl_to_list (j, _cpl);
631                                         _cpls.push_back (make_pair(j, *i));
632                                 }
633                         }
634                 } catch (boost::filesystem::filesystem_error& e) {
635                         /* Never mind */
636                 }
637         }
638 }
639
640 #ifdef DCPOMATIC_VARIANT_SWAROOP
641 void
642 Controls::pause_clicked ()
643 {
644         _viewer->stop ();
645 }
646
647 void
648 Controls::stop_clicked ()
649 {
650         _viewer->stop ();
651         _viewer->seek (DCPTime(), true);
652 }
653 #endif
654
655 void
656 Controls::log (wxString s)
657 {
658         struct timeval time;
659         gettimeofday (&time, 0);
660         char buffer[64];
661         time_t const sec = time.tv_sec;
662         struct tm* t = localtime (&sec);
663         strftime (buffer, 64, "%c", t);
664         wxString ts = std_to_wx(string(buffer)) + N_(": ");
665         _log->SetValue(_log->GetValue() + ts + s + "\n");
666 }
667
668 void
669 Controls::image_changed (boost::weak_ptr<PlayerVideo> weak_pv)
670 {
671 #ifdef DCPOMATIC_VARIANT_SWAROOP
672         shared_ptr<PlayerVideo> pv = weak_pv.lock ();
673         if (!pv) {
674                 return;
675         }
676
677         shared_ptr<Content> c = pv->content().lock();
678         if (!c) {
679                 return;
680         }
681
682         shared_ptr<DCPContent> dc = dynamic_pointer_cast<DCPContent> (c);
683         if (!dc) {
684                 return;
685         }
686
687         if (!_current_kind || *_current_kind != dc->content_kind()) {
688                 _current_kind = dc->content_kind ();
689                 setup_sensitivity ();
690         }
691 #endif
692 }