2 Copyright (C) 2017-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/>.
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"
61 #include <dcp/raw_convert.h>
62 #include <dcp/exceptions.h>
64 #include <wx/stdpaths.h>
65 #include <wx/splash.h>
66 #include <wx/cmdline.h>
67 #include <wx/preferences.h>
68 #include <wx/progdlg.h>
69 #include <wx/display.h>
73 #include <boost/bind/bind.hpp>
74 #include <boost/algorithm/string.hpp>
84 using std::dynamic_pointer_cast;
87 using std::make_shared;
88 using std::shared_ptr;
92 using boost::scoped_array;
93 using boost::optional;
96 #if BOOST_VERSION >= 106100
97 using namespace boost::placeholders;
99 using dcp::raw_convert;
100 using namespace dcpomatic;
107 /* Allow spare IDs after _history for the recent files list */
110 /* Allow spare IDs for CPLs */
111 ID_view_full_screen = 200,
113 ID_view_closed_captions,
114 ID_view_scale_appropriate,
117 ID_view_scale_quarter,
118 ID_help_report_a_problem,
120 ID_tools_check_for_updates,
122 ID_tools_system_information,
123 /* IDs for shortcuts (with no associated menu item) */
127 ID_go_back_small_amount,
128 ID_go_forward_small_amount,
129 ID_go_back_medium_amount,
130 ID_go_forward_medium_amount,
131 ID_go_back_large_amount,
132 ID_go_forward_large_amount,
137 class DOMFrame : public wxFrame
141 : wxFrame (0, -1, _("DCP-o-matic Player"))
143 , _update_news_requested (false)
145 , _mode (Config::instance()->player_mode())
149 , _history_position (0)
150 , _history_separator (0)
151 , _system_information_dialog (0)
152 , _view_full_screen (0)
153 , _view_dual_screen (0)
154 , _main_sizer (new wxBoxSizer (wxVERTICAL))
156 dcpomatic_log = make_shared<NullLog>();
158 #if defined(DCPOMATIC_WINDOWS)
159 maybe_open_console ();
160 cout << "DCP-o-matic Player is starting." << "\n";
163 auto bar = new wxMenuBar;
165 set_menu_sensitivity ();
168 #ifdef DCPOMATIC_WINDOWS
169 SetIcon (wxIcon (std_to_wx ("id")));
172 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
173 update_from_config (Config::PLAYER_DEBUG_LOG);
175 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
176 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
177 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
178 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
179 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
180 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
181 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
182 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
183 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
184 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
185 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
186 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
187 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
188 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
189 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
190 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
191 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
192 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
193 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
194 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
196 /* Use a panel as the only child of the Frame so that we avoid
197 the dark-grey background on Windows.
199 _overall_panel = new wxPanel (this, wxID_ANY);
201 _viewer.reset (new FilmViewer (_overall_panel));
202 if (Config::instance()->player_mode() == Config::PLAYER_MODE_DUAL) {
203 auto pc = new PlaylistControls (_overall_panel, _viewer);
205 pc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
207 _controls = new StandardControls (_overall_panel, _viewer, false);
209 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
210 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
211 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
212 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
213 _info = new PlayerInformation (_overall_panel, _viewer);
214 setup_main_sizer (Config::instance()->player_mode());
216 int accelerators = 12;
218 int accelerators = 11;
221 _stress.setup (this, _controls);
223 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
224 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
225 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_go_back_frame);
226 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_go_forward_frame);
227 accel[3].Set(wxACCEL_SHIFT, WXK_LEFT, ID_go_back_small_amount);
228 accel[4].Set(wxACCEL_SHIFT, WXK_RIGHT, ID_go_forward_small_amount);
229 accel[5].Set(wxACCEL_CTRL, WXK_LEFT, ID_go_back_medium_amount);
230 accel[6].Set(wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_medium_amount);
231 accel[7].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_LEFT, ID_go_back_large_amount);
232 accel[8].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_large_amount);
233 accel[9].Set(wxACCEL_NORMAL, WXK_HOME, ID_go_to_start);
234 accel[10].Set(wxACCEL_NORMAL, WXK_END, ID_go_to_end);
236 accel[11].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
238 wxAcceleratorTable accel_table (accelerators, accel);
239 SetAcceleratorTable (accel_table);
242 Bind (wxEVT_MENU, boost::bind(&DOMFrame::start_stop_pressed, this), ID_start_stop);
243 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_back_frame, this), ID_go_back_frame);
244 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_forward_frame, this), ID_go_forward_frame);
245 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -60), ID_go_back_small_amount);
246 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 60), ID_go_forward_small_amount);
247 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -600), ID_go_back_medium_amount);
248 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 600), ID_go_forward_medium_amount);
249 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -3600), ID_go_back_large_amount);
250 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 3600), ID_go_forward_large_amount);
251 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_start, this), ID_go_to_start);
252 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_end, this), ID_go_to_end);
256 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
259 _stress.LoadDCP.connect (boost::bind(&DOMFrame::load_dcp, this, _1));
264 /* It's important that this is stopped before our frame starts destroying its children,
265 * otherwise UI elements that it depends on will disappear from under it.
270 void setup_main_sizer (Config::PlayerMode mode)
272 _main_sizer->Detach (_viewer->panel());
273 _main_sizer->Detach (_controls);
274 _main_sizer->Detach (_info);
275 if (mode != Config::PLAYER_MODE_DUAL) {
276 _main_sizer->Add (_viewer->panel(), 1, wxEXPAND);
278 _main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
279 _main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
280 _overall_panel->SetSizer (_main_sizer);
281 _overall_panel->Layout ();
284 bool playback_permitted ()
286 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
291 for (auto i: _film->content()) {
292 auto d = dynamic_pointer_cast<DCPContent>(i);
293 if (d && !d->kdm_timing_window_valid()) {
299 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
305 void playback_started (DCPTime time)
307 /* XXX: this only logs the first piece of content; probably should be each piece? */
308 if (_film->content().empty()) {
312 auto dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
314 DCPExaminer ex (dcp, true);
315 shared_ptr<dcp::CPL> playing_cpl;
316 for (auto i: ex.cpls()) {
317 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
321 DCPOMATIC_ASSERT (playing_cpl);
325 "playback-started %s %s %s",
326 time.timecode(_film->video_frame_rate()).c_str(),
327 dcp->directories().front().string().c_str(),
328 playing_cpl->annotation_text().get_value_or("").c_str()
333 auto ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
337 "playback-started %s %s",
338 time.timecode(_film->video_frame_rate()).c_str(),
339 ffmpeg->path(0).string().c_str()
345 void playback_stopped (DCPTime time)
347 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
350 void set_decode_reduction (optional<int> reduction)
352 _viewer->set_dcp_decode_reduction (reduction);
353 _info->triggered_update ();
354 Config::instance()->set_decode_reduction (reduction);
357 void load_dcp (boost::filesystem::path dir)
359 DCPOMATIC_ASSERT (_film);
363 _stress.set_suspended (true);
365 auto dcp = make_shared<DCPContent>(dir);
366 auto job = make_shared<ExamineContentJob>(_film, dcp);
367 _examine_job_connection = job->Finished.connect(bind(&DOMFrame::add_dcp_to_film, this, weak_ptr<Job>(job), weak_ptr<Content>(dcp)));
368 JobManager::instance()->add (job);
369 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
370 if (!ok || !report_errors_from_last_job(this)) {
373 Config::instance()->add_to_player_history (dir);
374 } catch (ProjectFolderError &) {
377 wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())),
379 "This looks like a DCP-o-matic project folder, which cannot be loaded into the player. "
380 "Choose the DCP directory inside the DCP-o-matic project folder if that's what you want to play."
383 } catch (dcp::ReadError& e) {
384 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
385 } catch (DCPError& e) {
386 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
390 void add_dcp_to_film (weak_ptr<Job> weak_job, weak_ptr<Content> weak_content)
392 auto job = weak_job.lock ();
393 if (!job || !job->finished_ok()) {
397 auto content = weak_content.lock ();
402 _film->add_content (content);
403 _stress.set_suspended (false);
406 void reset_film_weak (weak_ptr<Film> weak_film)
408 auto film = weak_film.lock ();
414 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
417 _film->set_tolerant (true);
418 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
419 _viewer->set_film (_film);
420 _controls->set_film (_film);
421 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
422 _info->triggered_update ();
425 void film_changed (ChangeType type, Film::Property property)
427 if (type != ChangeType::DONE || property != Film::Property::CONTENT) {
431 if (_viewer->playing ()) {
435 /* Start off as Flat */
436 _film->set_container (Ratio::from_id("185"));
438 for (auto i: _film->content()) {
439 auto dcp = dynamic_pointer_cast<DCPContent>(i);
441 for (auto j: i->text) {
446 auto const r = Ratio::nearest_from_ratio(i->video->size().ratio());
447 if (r->id() == "239") {
448 /* Any scope content means we use scope */
449 _film->set_container(r);
453 /* Any 3D content means we use 3D mode */
454 if (i->video && i->video->frame_type() != VideoFrameType::TWO_D) {
455 _film->set_three_d (true);
459 _viewer->seek (DCPTime(), true);
460 _info->triggered_update ();
462 set_menu_sensitivity ();
464 auto old = _cpl_menu->GetMenuItems();
465 for (auto const& i: old) {
466 _cpl_menu->Remove (i);
469 if (_film->content().size() == 1) {
470 /* Offer a CPL menu */
471 auto first = dynamic_pointer_cast<DCPContent>(_film->content().front());
473 DCPExaminer ex (first, true);
474 int id = ID_view_cpl;
475 for (auto i: ex.cpls()) {
476 auto j = _cpl_menu->AppendRadioItem(
478 wxString::Format("%s (%s)", std_to_wx(i->annotation_text().get_value_or("")).data(), std_to_wx(i->id()).data())
480 j->Check(!first->cpl() || i->id() == *first->cpl());
487 void load_stress_script (boost::filesystem::path path)
489 _stress.load_script (path);
494 void examine_content ()
496 DCPOMATIC_ASSERT (_film);
497 auto dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
498 DCPOMATIC_ASSERT (dcp);
499 dcp->examine (_film, shared_ptr<Job>());
501 /* Examining content re-creates the TextContent objects, so we must re-enable them */
502 for (auto i: dcp->text) {
507 bool report_errors_from_last_job (wxWindow* parent) const
509 auto jm = JobManager::instance ();
511 DCPOMATIC_ASSERT (!jm->get().empty());
513 auto last = jm->get().back();
514 if (last->finished_in_error()) {
515 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()));
522 void setup_menu (wxMenuBar* m)
524 _file_menu = new wxMenu;
525 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
526 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
527 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
529 _history_position = _file_menu->GetMenuItems().GetCount();
531 _file_menu->AppendSeparator ();
532 _file_menu->Append (ID_file_close, _("&Close"));
533 _file_menu->AppendSeparator ();
536 _file_menu->Append (wxID_EXIT, _("&Exit"));
538 _file_menu->Append (wxID_EXIT, _("&Quit"));
542 auto prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
544 auto edit = new wxMenu;
545 auto prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
548 prefs->Enable (Config::instance()->have_write_permission());
550 _cpl_menu = new wxMenu;
552 auto view = new wxMenu;
553 auto c = Config::instance()->decode_reduction();
554 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
555 view->AppendSeparator();
556 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
557 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
559 view->AppendSeparator();
560 view->Append(ID_view_closed_captions, _("Closed captions..."));
561 view->AppendSeparator();
562 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
563 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
564 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
565 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
567 auto tools = new wxMenu;
568 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP..."));
569 tools->AppendSeparator ();
570 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
571 tools->Append (ID_tools_timing, _("Timing..."));
572 tools->Append (ID_tools_system_information, _("System information..."));
574 auto help = new wxMenu;
576 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
578 help->Append (wxID_ABOUT, _("About"));
580 help->Append (ID_help_report_a_problem, _("Report a problem..."));
582 m->Append (_file_menu, _("&File"));
584 m->Append (edit, _("&Edit"));
586 m->Append (view, _("&View"));
587 m->Append (tools, _("&Tools"));
588 m->Append (help, _("&Help"));
593 auto d = wxStandardPaths::Get().GetDocumentsDir();
594 if (Config::instance()->last_player_load_directory()) {
595 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
598 auto c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
603 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
604 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
611 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
613 Config::instance()->set_last_player_load_directory (dcp.parent_path());
621 auto c = new wxDirDialog (
623 _("Select DCP to open as OV"),
624 wxStandardPaths::Get().GetDocumentsDir(),
625 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
631 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
632 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
639 DCPOMATIC_ASSERT (_film);
640 auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
641 DCPOMATIC_ASSERT (dcp);
642 dcp->add_ov (wx_to_std(c->GetPath()));
643 JobManager::instance()->add(make_shared<ExamineContentJob>(_film, dcp));
644 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
645 if (!ok || !report_errors_from_last_job(this)) {
648 for (auto i: dcp->text) {
652 auto const r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
654 _film->set_container(r);
660 _info->triggered_update ();
665 auto d = new wxFileDialog (this, _("Select KDM"));
667 if (d->ShowModal() == wxID_OK) {
668 DCPOMATIC_ASSERT (_film);
669 auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
670 DCPOMATIC_ASSERT (dcp);
673 _viewer->set_coalesce_player_changes (true);
674 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
676 _viewer->set_coalesce_player_changes (false);
678 } catch (exception& e) {
679 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
686 _info->triggered_update ();
689 void file_history (wxCommandEvent& event)
691 auto history = Config::instance()->player_history ();
692 int n = event.GetId() - ID_file_history;
693 if (n >= 0 && n < static_cast<int> (history.size ())) {
695 load_dcp (history[n]);
696 } catch (exception& e) {
697 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
705 _info->triggered_update ();
706 set_menu_sensitivity ();
714 void edit_preferences ()
716 if (!Config::instance()->have_write_permission()) {
720 if (!_config_dialog) {
721 _config_dialog = create_player_config_dialog ();
723 _config_dialog->Show (this);
726 void view_cpl (wxCommandEvent& ev)
728 auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
729 DCPOMATIC_ASSERT (dcp);
730 DCPExaminer ex (dcp, true);
731 int id = ev.GetId() - ID_view_cpl;
732 DCPOMATIC_ASSERT (id >= 0);
733 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
734 auto cpls = ex.cpls();
735 auto i = cpls.begin();
741 _viewer->set_coalesce_player_changes (true);
742 dcp->set_cpl ((*i)->id());
744 _viewer->set_coalesce_player_changes (false);
746 _info->triggered_update ();
749 void view_full_screen ()
751 if (_mode == Config::PLAYER_MODE_FULL) {
752 _mode = Config::PLAYER_MODE_WINDOW;
754 _mode = Config::PLAYER_MODE_FULL;
760 void view_dual_screen ()
762 if (_mode == Config::PLAYER_MODE_DUAL) {
763 _mode = Config::PLAYER_MODE_WINDOW;
765 _mode = Config::PLAYER_MODE_DUAL;
773 if (_view_full_screen) {
774 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
776 if (_view_dual_screen) {
777 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
783 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
784 _info->Show (_mode != Config::PLAYER_MODE_FULL);
785 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
786 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
787 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
789 if (_mode == Config::PLAYER_MODE_DUAL) {
790 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
791 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
792 _dual_screen->ShowFullScreen (true);
793 _viewer->panel()->Reparent (_dual_screen);
794 _dual_screen->Show ();
795 if (wxDisplay::GetCount() > 1) {
796 switch (Config::instance()->image_display()) {
798 _dual_screen->Move (0, 0);
799 Move (wxDisplay(0U).GetClientArea().GetWidth(), 0);
802 _dual_screen->Move (wxDisplay(0U).GetClientArea().GetWidth(), 0);
803 // (0, 0) doesn't seem to work for some strange reason
810 _viewer->panel()->Reparent (_overall_panel);
811 _dual_screen->Destroy ();
816 setup_main_sizer (_mode);
819 void view_closed_captions ()
821 _viewer->show_closed_captions ();
826 auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
827 DCPOMATIC_ASSERT (dcp);
829 auto job = make_shared<VerifyDCPJob>(dcp->directories());
830 auto progress = new VerifyDCPProgressDialog(this, _("DCP-o-matic Player"));
831 bool const completed = progress->run (job);
832 progress->Destroy ();
837 auto d = new VerifyDCPDialog (this, job);
842 void tools_check_for_updates ()
844 UpdateChecker::instance()->run ();
845 _update_news_requested = true;
850 auto d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
855 void tools_system_information ()
857 if (!_system_information_dialog) {
858 _system_information_dialog = new SystemInformationDialog (this, _viewer);
861 _system_information_dialog->Show ();
866 auto d = new AboutDialog (this);
871 void help_report_a_problem ()
873 auto d = new ReportProblemDialog (this);
874 if (d->ShowModal () == wxID_OK) {
880 void update_checker_state_changed ()
882 auto uc = UpdateChecker::instance ();
884 bool const announce =
885 _update_news_requested ||
886 (uc->stable() && Config::instance()->check_for_updates()) ||
887 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
889 _update_news_requested = false;
895 if (uc->state() == UpdateChecker::State::YES) {
896 auto dialog = new UpdateDialog (this, uc->stable (), uc->test ());
897 dialog->ShowModal ();
899 } else if (uc->state() == UpdateChecker::State::FAILED) {
900 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
902 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
905 _update_news_requested = false;
908 void config_changed (Config::Property prop)
910 /* Instantly save any config changes when using the player GUI */
912 Config::instance()->write_config();
913 } catch (FileError& e) {
914 if (prop != Config::HISTORY) {
918 _("Could not write to config file at %s. Your changes have not been saved."),
919 std_to_wx(e.file().string())
923 } catch (exception& e) {
926 _("Could not write to config file. Your changes have not been saved.")
930 update_from_config (prop);
933 void update_from_config (Config::Property prop)
935 for (int i = 0; i < _history_items; ++i) {
936 delete _file_menu->Remove (ID_file_history + i);
939 if (_history_separator) {
940 _file_menu->Remove (_history_separator);
942 delete _history_separator;
943 _history_separator = nullptr;
945 int pos = _history_position;
947 /* Clear out non-existant history items before we re-build the menu */
948 Config::instance()->clean_player_history ();
949 auto history = Config::instance()->player_history ();
951 if (!history.empty ()) {
952 _history_separator = _file_menu->InsertSeparator (pos++);
955 for (size_t i = 0; i < history.size(); ++i) {
958 s = String::compose ("&%1 %2", i + 1, history[i].string());
960 s = history[i].string();
962 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
965 _history_items = history.size ();
967 if (prop == Config::PLAYER_DEBUG_LOG) {
968 auto p = Config::instance()->player_debug_log_file();
970 dcpomatic_log = make_shared<FileLog>(*p);
972 dcpomatic_log = make_shared<NullLog>();
974 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_VIDEO_VIEW);
978 void set_menu_sensitivity ()
980 _tools_verify->Enable (static_cast<bool>(_film));
981 _file_add_ov->Enable (static_cast<bool>(_film));
982 _file_add_kdm->Enable (static_cast<bool>(_film));
983 _view_cpl->Enable (static_cast<bool>(_film));
986 void start_stop_pressed ()
988 if (_viewer->playing()) {
995 void go_back_frame ()
997 _viewer->seek_by (-_viewer->one_video_frame(), true);
1000 void go_forward_frame ()
1002 _viewer->seek_by (_viewer->one_video_frame(), true);
1005 void go_seconds (int s)
1007 _viewer->seek_by (DCPTime::from_seconds(s), true);
1012 _viewer->seek (DCPTime(), true);
1017 _viewer->seek (_film->length() - _viewer->one_video_frame(), true);
1020 wxFrame* _dual_screen;
1021 bool _update_news_requested;
1022 PlayerInformation* _info;
1023 Config::PlayerMode _mode;
1024 wxPreferencesEditor* _config_dialog;
1025 wxPanel* _overall_panel;
1027 wxMenuItem* _view_cpl;
1030 int _history_position;
1031 wxMenuItem* _history_separator;
1032 shared_ptr<FilmViewer> _viewer;
1033 Controls* _controls;
1034 SystemInformationDialog* _system_information_dialog;
1035 std::shared_ptr<Film> _film;
1036 boost::signals2::scoped_connection _config_changed_connection;
1037 boost::signals2::scoped_connection _examine_job_connection;
1038 wxMenuItem* _file_add_ov;
1039 wxMenuItem* _file_add_kdm;
1040 wxMenuItem* _tools_verify;
1041 wxMenuItem* _view_full_screen;
1042 wxMenuItem* _view_dual_screen;
1043 wxSizer* _main_sizer;
1044 PlayerStressTester _stress;
1047 static const wxCmdLineEntryDesc command_line_description[] = {
1048 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1049 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1050 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1051 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1054 class PlayServer : public Server
1057 explicit PlayServer (DOMFrame* frame)
1058 : Server (PLAYER_PLAY_PORT)
1062 void handle (shared_ptr<Socket> socket)
1065 int const length = socket->read_uint32 ();
1066 scoped_array<char> buffer (new char[length]);
1067 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1068 string s (buffer.get());
1069 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1070 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1081 * @brief The magic App class for wxWidgets.
1083 class App : public wxApp
1090 #ifdef DCPOMATIC_LINUX
1099 wxSplashScreen* splash = 0;
1101 wxInitAllImageHandlers ();
1103 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1104 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1106 splash = maybe_show_splash ();
1108 SetAppName (_("DCP-o-matic Player"));
1110 if (!wxApp::OnInit()) {
1114 #ifdef DCPOMATIC_LINUX
1115 unsetenv ("UBUNTU_MENUPROXY");
1118 #ifdef DCPOMATIC_OSX
1119 make_foreground_application ();
1122 dcpomatic_setup_path_encoding ();
1124 /* Enable i18n; this will create a Config object
1125 to look for a force-configured language. This Config
1126 object will be wrong, however, because dcpomatic_setup
1127 hasn't yet been called and there aren't any filters etc.
1130 dcpomatic_setup_i18n ();
1132 /* Set things up, including filters etc.
1133 which will now be internationalised correctly.
1137 /* Force the configuration to be re-loaded correctly next
1142 signal_manager = new wxSignalManager (this);
1144 _frame = new DOMFrame ();
1145 SetTopWindow (_frame);
1146 _frame->Maximize ();
1153 PlayServer* server = new PlayServer (_frame);
1154 new thread (boost::bind (&PlayServer::run, server));
1156 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1158 _frame->load_dcp (_dcp_to_load);
1159 } catch (exception& e) {
1160 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1166 _frame->load_stress_script (*_stress);
1167 } catch (exception& e) {
1168 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1172 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1174 if (Config::instance()->check_for_updates ()) {
1175 UpdateChecker::instance()->run ();
1178 catch (exception& e)
1183 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1189 void OnInitCmdLine (wxCmdLineParser& parser)
1191 parser.SetDesc (command_line_description);
1192 parser.SetSwitchChars (wxT ("-"));
1195 bool OnCmdLineParsed (wxCmdLineParser& parser)
1197 if (parser.GetParamCount() > 0) {
1198 _dcp_to_load = wx_to_std (parser.GetParam (0));
1202 if (parser.Found("c", &config)) {
1203 Config::override_path = wx_to_std (config);
1206 if (parser.Found("s", &stress)) {
1207 _stress = wx_to_std (stress);
1213 void report_exception ()
1217 } catch (FileError& e) {
1221 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1222 std_to_wx (e.what()),
1223 std_to_wx (e.file().string().c_str ())
1226 } catch (exception& e) {
1230 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1231 std_to_wx (e.what ())
1235 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1239 /* An unhandled exception has occurred inside the main event loop */
1240 bool OnExceptionInMainLoop ()
1242 report_exception ();
1243 /* This will terminate the program */
1247 void OnUnhandledException ()
1249 report_exception ();
1254 signal_manager->ui_idle ();
1257 void config_failed_to_load ()
1259 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1262 void config_warning (string m)
1264 message_dialog (_frame, std_to_wx (m));
1268 string _dcp_to_load;
1269 boost::optional<string> _stress;