2 Copyright (C) 2017-2020 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/>.
21 #include "wx/wx_signal_manager.h"
22 #include "wx/wx_util.h"
23 #include "wx/about_dialog.h"
24 #include "wx/report_problem_dialog.h"
25 #include "wx/film_viewer.h"
26 #include "wx/player_information.h"
27 #include "wx/update_dialog.h"
28 #include "wx/player_config_dialog.h"
29 #include "wx/verify_dcp_dialog.h"
30 #include "wx/standard_controls.h"
31 #include "wx/playlist_controls.h"
32 #include "wx/timer_display.h"
33 #include "wx/system_information_dialog.h"
34 #include "wx/player_stress_tester.h"
35 #include "wx/verify_dcp_progress_dialog.h"
36 #include "lib/cross.h"
37 #include "lib/config.h"
39 #include "lib/internet.h"
40 #include "lib/update_checker.h"
41 #include "lib/compose.hpp"
42 #include "lib/dcp_content.h"
43 #include "lib/job_manager.h"
46 #include "lib/null_log.h"
47 #include "lib/video_content.h"
48 #include "lib/text_content.h"
49 #include "lib/ratio.h"
50 #include "lib/verify_dcp_job.h"
51 #include "lib/dcp_examiner.h"
52 #include "lib/examine_content_job.h"
53 #include "lib/server.h"
54 #include "lib/dcpomatic_socket.h"
55 #include "lib/scoped_temporary.h"
56 #include "lib/ffmpeg_content.h"
57 #include "lib/dcpomatic_log.h"
58 #include "lib/file_log.h"
60 #include <dcp/raw_convert.h>
61 #include <dcp/exceptions.h>
63 #include <wx/stdpaths.h>
64 #include <wx/splash.h>
65 #include <wx/cmdline.h>
66 #include <wx/preferences.h>
67 #include <wx/progdlg.h>
68 #include <wx/display.h>
72 #include <boost/bind/bind.hpp>
73 #include <boost/algorithm/string.hpp>
87 using std::shared_ptr;
89 using boost::scoped_array;
90 using boost::optional;
91 using std::dynamic_pointer_cast;
94 #if BOOST_VERSION >= 106100
95 using namespace boost::placeholders;
97 using dcp::raw_convert;
98 using namespace dcpomatic;
105 /* Allow spare IDs after _history for the recent files list */
108 /* Allow spare IDs for CPLs */
109 ID_view_full_screen = 200,
111 ID_view_closed_captions,
112 ID_view_scale_appropriate,
115 ID_view_scale_quarter,
116 ID_help_report_a_problem,
118 ID_tools_check_for_updates,
120 ID_tools_system_information,
121 /* IDs for shortcuts (with no associated menu item) */
125 ID_go_back_small_amount,
126 ID_go_forward_small_amount,
127 ID_go_back_medium_amount,
128 ID_go_forward_medium_amount,
129 ID_go_back_large_amount,
130 ID_go_forward_large_amount,
135 class DOMFrame : public wxFrame
139 : wxFrame (0, -1, _("DCP-o-matic Player"))
141 , _update_news_requested (false)
143 , _mode (Config::instance()->player_mode())
147 , _history_position (0)
148 , _history_separator (0)
149 , _system_information_dialog (0)
150 , _view_full_screen (0)
151 , _view_dual_screen (0)
152 , _main_sizer (new wxBoxSizer (wxVERTICAL))
154 dcpomatic_log.reset (new NullLog());
156 #if defined(DCPOMATIC_WINDOWS)
157 maybe_open_console ();
158 cout << "DCP-o-matic Player is starting." << "\n";
161 wxMenuBar* bar = new wxMenuBar;
163 set_menu_sensitivity ();
166 #ifdef DCPOMATIC_WINDOWS
167 SetIcon (wxIcon (std_to_wx ("id")));
170 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
171 update_from_config (Config::PLAYER_DEBUG_LOG);
173 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
174 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
175 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
176 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
177 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
178 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
179 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
180 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
181 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
182 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
183 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
184 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
185 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
186 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
187 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
188 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
189 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
190 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
191 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
192 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
194 /* Use a panel as the only child of the Frame so that we avoid
195 the dark-grey background on Windows.
197 _overall_panel = new wxPanel (this, wxID_ANY);
199 _viewer.reset (new FilmViewer (_overall_panel));
200 if (Config::instance()->player_mode() == Config::PLAYER_MODE_DUAL) {
201 PlaylistControls* pc = new PlaylistControls (_overall_panel, _viewer);
203 pc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
205 _controls = new StandardControls (_overall_panel, _viewer, false);
207 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
208 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
209 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
210 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
211 _info = new PlayerInformation (_overall_panel, _viewer);
212 setup_main_sizer (Config::instance()->player_mode());
214 int accelerators = 12;
216 int accelerators = 11;
219 _stress.setup (this, _controls);
221 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
222 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
223 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_go_back_frame);
224 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_go_forward_frame);
225 accel[3].Set(wxACCEL_SHIFT, WXK_LEFT, ID_go_back_small_amount);
226 accel[4].Set(wxACCEL_SHIFT, WXK_RIGHT, ID_go_forward_small_amount);
227 accel[5].Set(wxACCEL_CTRL, WXK_LEFT, ID_go_back_medium_amount);
228 accel[6].Set(wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_medium_amount);
229 accel[7].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_LEFT, ID_go_back_large_amount);
230 accel[8].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_large_amount);
231 accel[9].Set(wxACCEL_NORMAL, WXK_HOME, ID_go_to_start);
232 accel[10].Set(wxACCEL_NORMAL, WXK_END, ID_go_to_end);
234 accel[11].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
236 wxAcceleratorTable accel_table (accelerators, accel);
237 SetAcceleratorTable (accel_table);
240 Bind (wxEVT_MENU, boost::bind(&DOMFrame::start_stop_pressed, this), ID_start_stop);
241 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_back_frame, this), ID_go_back_frame);
242 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_forward_frame, this), ID_go_forward_frame);
243 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -60), ID_go_back_small_amount);
244 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 60), ID_go_forward_small_amount);
245 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -600), ID_go_back_medium_amount);
246 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 600), ID_go_forward_medium_amount);
247 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -3600), ID_go_back_large_amount);
248 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 3600), ID_go_forward_large_amount);
249 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_start, this), ID_go_to_start);
250 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_end, this), ID_go_to_end);
254 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
257 _stress.LoadDCP.connect (boost::bind(&DOMFrame::load_dcp, this, _1));
260 void setup_main_sizer (Config::PlayerMode mode)
262 _main_sizer->Detach (_viewer->panel());
263 _main_sizer->Detach (_controls);
264 _main_sizer->Detach (_info);
265 if (mode != Config::PLAYER_MODE_DUAL) {
266 _main_sizer->Add (_viewer->panel(), 1, wxEXPAND);
268 _main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
269 _main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
270 _overall_panel->SetSizer (_main_sizer);
271 _overall_panel->Layout ();
274 bool playback_permitted ()
276 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
281 for (auto i: _film->content()) {
282 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
283 if (d && !d->kdm_timing_window_valid()) {
289 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
295 void playback_started (DCPTime time)
297 /* XXX: this only logs the first piece of content; probably should be each piece? */
298 if (_film->content().empty()) {
302 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
304 DCPExaminer ex (dcp, true);
305 shared_ptr<dcp::CPL> playing_cpl;
306 for (auto i: ex.cpls()) {
307 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
311 DCPOMATIC_ASSERT (playing_cpl);
315 "playback-started %s %s %s",
316 time.timecode(_film->video_frame_rate()).c_str(),
317 dcp->directories().front().string().c_str(),
318 playing_cpl->annotation_text().get_value_or("").c_str()
323 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
327 "playback-started %s %s",
328 time.timecode(_film->video_frame_rate()).c_str(),
329 ffmpeg->path(0).string().c_str()
335 void playback_stopped (DCPTime time)
337 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
340 void set_decode_reduction (optional<int> reduction)
342 _viewer->set_dcp_decode_reduction (reduction);
343 _info->triggered_update ();
344 Config::instance()->set_decode_reduction (reduction);
347 void load_dcp (boost::filesystem::path dir)
349 DCPOMATIC_ASSERT (_film);
353 _stress.set_suspended (true);
354 shared_ptr<DCPContent> dcp (new DCPContent(dir));
355 shared_ptr<Job> job (new ExamineContentJob(_film, dcp));
356 _examine_job_connection = job->Finished.connect(bind(&DOMFrame::add_dcp_to_film, this, weak_ptr<Job>(job), weak_ptr<Content>(dcp)));
357 JobManager::instance()->add (job);
358 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
359 if (!ok || !report_errors_from_last_job(this)) {
362 Config::instance()->add_to_player_history (dir);
363 } catch (dcp::ReadError& e) {
364 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
365 } catch (DCPError& e) {
366 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
370 void add_dcp_to_film (weak_ptr<Job> weak_job, weak_ptr<Content> weak_content)
372 shared_ptr<Job> job = weak_job.lock ();
373 if (!job || !job->finished_ok()) {
377 shared_ptr<Content> content = weak_content.lock ();
382 _film->add_content (content);
383 _stress.set_suspended (false);
386 void reset_film_weak (weak_ptr<Film> weak_film)
388 shared_ptr<Film> film = weak_film.lock ();
394 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
397 _film->set_tolerant (true);
398 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
399 _viewer->set_film (_film);
400 _controls->set_film (_film);
401 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
402 _info->triggered_update ();
405 void film_changed (ChangeType type, Film::Property property)
407 if (type != ChangeType::DONE || property != Film::CONTENT) {
411 if (_viewer->playing ()) {
415 /* Start off as Flat */
416 _film->set_container (Ratio::from_id("185"));
418 for (auto i: _film->content()) {
419 auto dcp = dynamic_pointer_cast<DCPContent>(i);
421 for (auto j: i->text) {
426 auto const r = Ratio::nearest_from_ratio(i->video->size().ratio());
427 if (r->id() == "239") {
428 /* Any scope content means we use scope */
429 _film->set_container(r);
433 /* Any 3D content means we use 3D mode */
434 if (i->video && i->video->frame_type() != VideoFrameType::TWO_D) {
435 _film->set_three_d (true);
439 _viewer->seek (DCPTime(), true);
440 _info->triggered_update ();
442 set_menu_sensitivity ();
444 auto old = _cpl_menu->GetMenuItems();
445 for (auto const& i: old) {
446 _cpl_menu->Remove (i);
449 if (_film->content().size() == 1) {
450 /* Offer a CPL menu */
451 auto first = dynamic_pointer_cast<DCPContent>(_film->content().front());
453 DCPExaminer ex (first, true);
454 int id = ID_view_cpl;
455 for (auto i: ex.cpls()) {
456 auto j = _cpl_menu->AppendRadioItem(
458 wxString::Format("%s (%s)", std_to_wx(i->annotation_text().get_value_or("")).data(), std_to_wx(i->id()).data())
460 j->Check(!first->cpl() || i->id() == *first->cpl());
467 void load_stress_script (boost::filesystem::path path)
469 _stress.load_script (path);
474 bool report_errors_from_last_job (wxWindow* parent) const
476 auto jm = JobManager::instance ();
478 DCPOMATIC_ASSERT (!jm->get().empty());
480 auto last = jm->get().back();
481 if (last->finished_in_error()) {
482 error_dialog(parent, wxString::Format(_("Could not load DCP.\n\n%s."), std_to_wx(last->error_summary()).data()), std_to_wx(last->error_details()));
489 void setup_menu (wxMenuBar* m)
491 _file_menu = new wxMenu;
492 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
493 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
494 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
496 _history_position = _file_menu->GetMenuItems().GetCount();
498 _file_menu->AppendSeparator ();
499 _file_menu->Append (ID_file_close, _("&Close"));
500 _file_menu->AppendSeparator ();
503 _file_menu->Append (wxID_EXIT, _("&Exit"));
505 _file_menu->Append (wxID_EXIT, _("&Quit"));
509 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
511 wxMenu* edit = new wxMenu;
512 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
515 prefs->Enable (Config::instance()->have_write_permission());
517 _cpl_menu = new wxMenu;
519 wxMenu* view = new wxMenu;
520 optional<int> c = Config::instance()->decode_reduction();
521 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
522 view->AppendSeparator();
523 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
524 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
526 view->AppendSeparator();
527 view->Append(ID_view_closed_captions, _("Closed captions..."));
528 view->AppendSeparator();
529 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
530 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
531 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
532 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
534 wxMenu* tools = new wxMenu;
535 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP..."));
536 tools->AppendSeparator ();
537 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
538 tools->Append (ID_tools_timing, _("Timing..."));
539 tools->Append (ID_tools_system_information, _("System information..."));
541 wxMenu* help = new wxMenu;
543 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
545 help->Append (wxID_ABOUT, _("About"));
547 help->Append (ID_help_report_a_problem, _("Report a problem..."));
549 m->Append (_file_menu, _("&File"));
551 m->Append (edit, _("&Edit"));
553 m->Append (view, _("&View"));
554 m->Append (tools, _("&Tools"));
555 m->Append (help, _("&Help"));
560 wxString d = wxStandardPaths::Get().GetDocumentsDir();
561 if (Config::instance()->last_player_load_directory()) {
562 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
565 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
570 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
571 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
578 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
580 Config::instance()->set_last_player_load_directory (dcp.parent_path());
588 wxDirDialog* c = new wxDirDialog (
590 _("Select DCP to open as OV"),
591 wxStandardPaths::Get().GetDocumentsDir(),
592 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
598 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
599 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
606 DCPOMATIC_ASSERT (_film);
607 shared_ptr<DCPContent> dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
608 DCPOMATIC_ASSERT (dcp);
609 dcp->add_ov (wx_to_std(c->GetPath()));
610 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
611 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
612 if (!ok || !report_errors_from_last_job(this)) {
615 for (auto i: dcp->text) {
619 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
621 _film->set_container(r);
627 _info->triggered_update ();
632 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
634 if (d->ShowModal() == wxID_OK) {
635 DCPOMATIC_ASSERT (_film);
636 shared_ptr<DCPContent> dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
637 DCPOMATIC_ASSERT (dcp);
640 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
641 dcp->examine (_film, shared_ptr<Job>());
643 } catch (exception& e) {
644 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
651 _info->triggered_update ();
654 void file_history (wxCommandEvent& event)
656 vector<boost::filesystem::path> history = Config::instance()->player_history ();
657 int n = event.GetId() - ID_file_history;
658 if (n >= 0 && n < static_cast<int> (history.size ())) {
660 load_dcp (history[n]);
661 } catch (exception& e) {
662 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
670 _info->triggered_update ();
671 set_menu_sensitivity ();
679 void edit_preferences ()
681 if (!Config::instance()->have_write_permission()) {
685 if (!_config_dialog) {
686 _config_dialog = create_player_config_dialog ();
688 _config_dialog->Show (this);
691 void view_cpl (wxCommandEvent& ev)
693 shared_ptr<DCPContent> dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
694 DCPOMATIC_ASSERT (dcp);
695 DCPExaminer ex (dcp, true);
696 int id = ev.GetId() - ID_view_cpl;
697 DCPOMATIC_ASSERT (id >= 0);
698 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
699 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
700 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
706 dcp->set_cpl ((*i)->id());
707 dcp->examine (_film, shared_ptr<Job>());
708 _info->triggered_update ();
711 void view_full_screen ()
713 if (_mode == Config::PLAYER_MODE_FULL) {
714 _mode = Config::PLAYER_MODE_WINDOW;
716 _mode = Config::PLAYER_MODE_FULL;
722 void view_dual_screen ()
724 if (_mode == Config::PLAYER_MODE_DUAL) {
725 _mode = Config::PLAYER_MODE_WINDOW;
727 _mode = Config::PLAYER_MODE_DUAL;
735 if (_view_full_screen) {
736 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
738 if (_view_dual_screen) {
739 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
745 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
746 _info->Show (_mode != Config::PLAYER_MODE_FULL);
747 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
748 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
749 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
751 if (_mode == Config::PLAYER_MODE_DUAL) {
752 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
753 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
754 _dual_screen->ShowFullScreen (true);
755 _viewer->panel()->Reparent (_dual_screen);
756 _dual_screen->Show ();
757 if (wxDisplay::GetCount() > 1) {
758 switch (Config::instance()->image_display()) {
760 _dual_screen->Move (0, 0);
761 Move (wxDisplay(0U).GetClientArea().GetWidth(), 0);
764 _dual_screen->Move (wxDisplay(0U).GetClientArea().GetWidth(), 0);
765 // (0, 0) doesn't seem to work for some strange reason
772 _viewer->panel()->Reparent (_overall_panel);
773 _dual_screen->Destroy ();
778 setup_main_sizer (_mode);
781 void view_closed_captions ()
783 _viewer->show_closed_captions ();
788 shared_ptr<DCPContent> dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
789 DCPOMATIC_ASSERT (dcp);
791 shared_ptr<VerifyDCPJob> job (new VerifyDCPJob(dcp->directories()));
792 VerifyDCPProgressDialog* progress = new VerifyDCPProgressDialog(this, _("DCP-o-matic Player"));
793 bool const completed = progress->run (job);
794 progress->Destroy ();
799 VerifyDCPDialog* d = new VerifyDCPDialog (this, job);
804 void tools_check_for_updates ()
806 UpdateChecker::instance()->run ();
807 _update_news_requested = true;
812 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
817 void tools_system_information ()
819 if (!_system_information_dialog) {
820 _system_information_dialog = new SystemInformationDialog (this, _viewer);
823 _system_information_dialog->Show ();
828 AboutDialog* d = new AboutDialog (this);
833 void help_report_a_problem ()
835 ReportProblemDialog* d = new ReportProblemDialog (this);
836 if (d->ShowModal () == wxID_OK) {
842 void update_checker_state_changed ()
844 UpdateChecker* uc = UpdateChecker::instance ();
846 bool const announce =
847 _update_news_requested ||
848 (uc->stable() && Config::instance()->check_for_updates()) ||
849 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
851 _update_news_requested = false;
857 if (uc->state() == UpdateChecker::YES) {
858 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
859 dialog->ShowModal ();
861 } else if (uc->state() == UpdateChecker::FAILED) {
862 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
864 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
867 _update_news_requested = false;
870 void config_changed (Config::Property prop)
872 /* Instantly save any config changes when using the player GUI */
874 Config::instance()->write_config();
875 } catch (FileError& e) {
876 if (prop != Config::HISTORY) {
880 _("Could not write to config file at %s. Your changes have not been saved."),
881 std_to_wx(e.file().string())
885 } catch (exception& e) {
888 _("Could not write to config file. Your changes have not been saved.")
892 update_from_config (prop);
895 void update_from_config (Config::Property prop)
897 for (int i = 0; i < _history_items; ++i) {
898 delete _file_menu->Remove (ID_file_history + i);
901 if (_history_separator) {
902 _file_menu->Remove (_history_separator);
904 delete _history_separator;
905 _history_separator = 0;
907 int pos = _history_position;
909 /* Clear out non-existant history items before we re-build the menu */
910 Config::instance()->clean_player_history ();
911 vector<boost::filesystem::path> history = Config::instance()->player_history ();
913 if (!history.empty ()) {
914 _history_separator = _file_menu->InsertSeparator (pos++);
917 for (size_t i = 0; i < history.size(); ++i) {
920 s = String::compose ("&%1 %2", i + 1, history[i].string());
922 s = history[i].string();
924 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
927 _history_items = history.size ();
929 if (prop == Config::PLAYER_DEBUG_LOG) {
930 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
932 dcpomatic_log.reset (new FileLog(*p));
934 dcpomatic_log.reset (new NullLog());
936 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_VIDEO_VIEW);
940 void set_menu_sensitivity ()
942 _tools_verify->Enable (static_cast<bool>(_film));
943 _file_add_ov->Enable (static_cast<bool>(_film));
944 _file_add_kdm->Enable (static_cast<bool>(_film));
945 _view_cpl->Enable (static_cast<bool>(_film));
948 void start_stop_pressed ()
950 if (_viewer->playing()) {
957 void go_back_frame ()
959 _viewer->seek_by (-_viewer->one_video_frame(), true);
962 void go_forward_frame ()
964 _viewer->seek_by (_viewer->one_video_frame(), true);
967 void go_seconds (int s)
969 _viewer->seek_by (DCPTime::from_seconds(s), true);
974 _viewer->seek (DCPTime(), true);
979 _viewer->seek (_film->length() - _viewer->one_video_frame(), true);
982 wxFrame* _dual_screen;
983 bool _update_news_requested;
984 PlayerInformation* _info;
985 Config::PlayerMode _mode;
986 wxPreferencesEditor* _config_dialog;
987 wxPanel* _overall_panel;
989 wxMenuItem* _view_cpl;
992 int _history_position;
993 wxMenuItem* _history_separator;
994 shared_ptr<FilmViewer> _viewer;
996 SystemInformationDialog* _system_information_dialog;
997 std::shared_ptr<Film> _film;
998 boost::signals2::scoped_connection _config_changed_connection;
999 boost::signals2::scoped_connection _examine_job_connection;
1000 wxMenuItem* _file_add_ov;
1001 wxMenuItem* _file_add_kdm;
1002 wxMenuItem* _tools_verify;
1003 wxMenuItem* _view_full_screen;
1004 wxMenuItem* _view_dual_screen;
1005 wxSizer* _main_sizer;
1006 PlayerStressTester _stress;
1009 static const wxCmdLineEntryDesc command_line_description[] = {
1010 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1011 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1012 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1013 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1016 class PlayServer : public Server
1019 explicit PlayServer (DOMFrame* frame)
1020 : Server (PLAYER_PLAY_PORT)
1024 void handle (shared_ptr<Socket> socket)
1027 int const length = socket->read_uint32 ();
1028 scoped_array<char> buffer (new char[length]);
1029 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1030 string s (buffer.get());
1031 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1032 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1043 * @brief The magic App class for wxWidgets.
1045 class App : public wxApp
1052 #ifdef DCPOMATIC_LINUX
1061 wxSplashScreen* splash = 0;
1063 wxInitAllImageHandlers ();
1065 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1066 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1068 splash = maybe_show_splash ();
1070 SetAppName (_("DCP-o-matic Player"));
1072 if (!wxApp::OnInit()) {
1076 #ifdef DCPOMATIC_LINUX
1077 unsetenv ("UBUNTU_MENUPROXY");
1080 #ifdef DCPOMATIC_OSX
1081 make_foreground_application ();
1084 dcpomatic_setup_path_encoding ();
1086 /* Enable i18n; this will create a Config object
1087 to look for a force-configured language. This Config
1088 object will be wrong, however, because dcpomatic_setup
1089 hasn't yet been called and there aren't any filters etc.
1092 dcpomatic_setup_i18n ();
1094 /* Set things up, including filters etc.
1095 which will now be internationalised correctly.
1099 /* Force the configuration to be re-loaded correctly next
1104 signal_manager = new wxSignalManager (this);
1106 _frame = new DOMFrame ();
1107 SetTopWindow (_frame);
1108 _frame->Maximize ();
1115 PlayServer* server = new PlayServer (_frame);
1116 new thread (boost::bind (&PlayServer::run, server));
1118 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1120 _frame->load_dcp (_dcp_to_load);
1121 } catch (exception& e) {
1122 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1128 _frame->load_stress_script (*_stress);
1129 } catch (exception& e) {
1130 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1134 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1136 if (Config::instance()->check_for_updates ()) {
1137 UpdateChecker::instance()->run ();
1140 catch (exception& e)
1145 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1151 void OnInitCmdLine (wxCmdLineParser& parser)
1153 parser.SetDesc (command_line_description);
1154 parser.SetSwitchChars (wxT ("-"));
1157 bool OnCmdLineParsed (wxCmdLineParser& parser)
1159 if (parser.GetParamCount() > 0) {
1160 _dcp_to_load = wx_to_std (parser.GetParam (0));
1164 if (parser.Found("c", &config)) {
1165 Config::override_path = wx_to_std (config);
1168 if (parser.Found("s", &stress)) {
1169 _stress = wx_to_std (stress);
1175 void report_exception ()
1179 } catch (FileError& e) {
1183 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1184 std_to_wx (e.what()),
1185 std_to_wx (e.file().string().c_str ())
1188 } catch (exception& e) {
1192 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1193 std_to_wx (e.what ())
1197 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1201 /* An unhandled exception has occurred inside the main event loop */
1202 bool OnExceptionInMainLoop ()
1204 report_exception ();
1205 /* This will terminate the program */
1209 void OnUnhandledException ()
1211 report_exception ();
1216 signal_manager->ui_idle ();
1219 void config_failed_to_load ()
1221 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1224 void config_warning (string m)
1226 message_dialog (_frame, std_to_wx (m));
1230 string _dcp_to_load;
1231 boost::optional<string> _stress;