2 Copyright (C) 2017-2018 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/controls.h"
31 #include "lib/cross.h"
32 #include "lib/config.h"
34 #include "lib/internet.h"
35 #include "lib/update_checker.h"
36 #include "lib/compose.hpp"
37 #include "lib/dcp_content.h"
38 #include "lib/job_manager.h"
41 #include "lib/null_log.h"
42 #include "lib/video_content.h"
43 #include "lib/text_content.h"
44 #include "lib/ratio.h"
45 #include "lib/verify_dcp_job.h"
46 #include "lib/dcp_examiner.h"
47 #include "lib/examine_content_job.h"
48 #include "lib/server.h"
49 #include "lib/dcpomatic_socket.h"
50 #include "lib/scoped_temporary.h"
51 #include "lib/monitor_checker.h"
52 #include "lib/lock_file_checker.h"
53 #include "lib/ffmpeg_content.h"
54 #include "lib/dcpomatic_log.h"
56 #include <dcp/raw_convert.h>
57 #include <dcp/exceptions.h>
59 #include <wx/stdpaths.h>
60 #include <wx/splash.h>
61 #include <wx/cmdline.h>
62 #include <wx/preferences.h>
63 #include <wx/progdlg.h>
64 #include <wx/display.h>
66 #include <ApplicationServices/ApplicationServices.h>
68 #include <boost/bind.hpp>
82 using boost::shared_ptr;
83 using boost::scoped_array;
84 using boost::optional;
85 using boost::dynamic_pointer_cast;
94 /* Allow spare IDs after _history for the recent files list */
97 /* Allow spare IDs for CPLs */
98 ID_view_full_screen = 200,
100 ID_view_closed_captions,
101 ID_view_scale_appropriate,
104 ID_view_scale_quarter,
105 ID_help_report_a_problem,
107 ID_tools_check_for_updates,
108 /* IDs for shortcuts (with no associated menu item) */
114 class DOMFrame : public wxFrame
118 : wxFrame (0, -1, _("DCP-o-matic Player"))
120 , _update_news_requested (false)
122 , _mode (Config::instance()->player_mode())
126 , _history_position (0)
127 , _history_separator (0)
128 , _view_full_screen (0)
129 , _view_dual_screen (0)
132 dcpomatic_log.reset (new NullLog());
133 cout << "here's the log " << dcpomatic_log.get() << "\n";
135 #if defined(DCPOMATIC_WINDOWS)
136 maybe_open_console ();
137 cout << "DCP-o-matic Player is starting." << "\n";
140 wxMenuBar* bar = new wxMenuBar;
142 set_menu_sensitivity ();
145 #ifdef DCPOMATIC_WINDOWS
146 SetIcon (wxIcon (std_to_wx ("id")));
149 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
150 update_from_config ();
152 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
153 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
154 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
155 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
156 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
157 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
158 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
159 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
160 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
161 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
162 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
163 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
164 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
165 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
166 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
167 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
168 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
169 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
171 /* Use a panel as the only child of the Frame so that we avoid
172 the dark-grey background on Windows.
174 _overall_panel = new wxPanel (this, wxID_ANY);
176 _viewer.reset (new FilmViewer (_overall_panel));
177 _controls = new Controls (_overall_panel, _viewer, false);
178 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
179 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
180 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
181 _viewer->Seeked.connect (bind(&DOMFrame::playback_seeked, this, _1));
182 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
183 #ifdef DCPOMATIC_VARIANT_SWAROOP
184 _viewer->PositionChanged.connect (bind(&DOMFrame::position_changed, this));
186 _info = new PlayerInformation (_overall_panel, _viewer);
187 setup_main_sizer (Config::instance()->player_mode());
189 int accelerators = 4;
191 int accelerators = 3;
194 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
195 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
196 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
197 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
199 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
201 wxAcceleratorTable accel_table (accelerators, accel);
202 SetAcceleratorTable (accel_table);
205 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
206 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
207 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
211 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
212 #ifdef DCPOMATIC_VARIANT_SWAROOP
213 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
214 MonitorChecker::instance()->run ();
215 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
216 LockFileChecker::instance()->run ();
220 #ifdef DCPOMATIC_VARIANT_SWAROOP
222 boost::filesystem::is_regular_file(Config::path("position")) &&
223 boost::filesystem::is_regular_file(Config::path("spl.xml"))) {
225 shared_ptr<Film> film (new Film(boost::optional<boost::filesystem::path>()));
226 film->read_metadata (Config::path("spl.xml"));
228 FILE* f = fopen_boost (Config::path("position"), "r");
231 fscanf (f, "%63s", buffer);
232 _viewer->seek (DCPTime(atoi(buffer)), true);
241 void position_changed ()
243 if (!_viewer->playing() || _viewer->position().get() % DCPTime::HZ) {
247 FILE* f = fopen_boost (Config::path("position"), "w");
249 string const p = dcp::raw_convert<string> (_viewer->position().get());
250 fwrite (p.c_str(), p.length(), 1, f);
255 #ifdef DCPOMATIC_VARIANT_SWAROOP
256 void monitor_checker_state_changed ()
258 if (!MonitorChecker::instance()->ok()) {
260 error_dialog (this, _("The required display devices are not connected correctly."));
264 void lock_checker_state_changed ()
266 if (!LockFileChecker::instance()->ok()) {
268 error_dialog (this, _("The lock file is not present."));
273 void setup_main_sizer (Config::PlayerMode mode)
275 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
276 if (mode != Config::PLAYER_MODE_DUAL) {
277 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
279 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
280 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
281 _overall_panel->SetSizer (main_sizer);
282 _overall_panel->Layout ();
285 bool playback_permitted ()
287 #ifdef DCPOMATIC_VARIANT_SWAROOP
288 if (!MonitorChecker::instance()->ok()) {
289 error_dialog (this, _("The required display devices are not connected correctly."));
292 if (!LockFileChecker::instance()->ok()) {
293 error_dialog (this, _("The lock file is not present."));
297 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
302 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
303 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
304 if (d && !d->kdm_timing_window_valid()) {
310 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
316 void playback_started (DCPTime time)
318 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
323 FILE* f = fopen_boost(*log, "a");
325 /* XXX: this only logs the first piece of content; probably should be each piece? */
327 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
329 DCPExaminer ex (dcp);
330 shared_ptr<dcp::CPL> playing_cpl;
331 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
332 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
336 DCPOMATIC_ASSERT (playing_cpl);
340 "%s playback-started %s %s %s\n",
341 dcp::LocalTime().as_string().c_str(),
342 time.timecode(_film->video_frame_rate()).c_str(),
343 dcp->directories().front().string().c_str(),
344 playing_cpl->annotation_text().c_str()
348 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
352 "%s playback-started %s %s\n",
353 dcp::LocalTime().as_string().c_str(),
354 time.timecode(_film->video_frame_rate()).c_str(),
355 ffmpeg->path(0).string().c_str()
362 void playback_seeked (DCPTime time)
364 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
369 FILE* f = fopen_boost(*log, "a");
370 fprintf (f, "%s playback-seeked %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
374 void playback_stopped (DCPTime time)
376 #ifdef DCPOMATIC_VARIANT_SWAROOP
378 boost::filesystem::remove (Config::path("position"));
384 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
389 FILE* f = fopen_boost(*log, "a");
390 fprintf (f, "%s playback-stopped %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
394 void set_decode_reduction (optional<int> reduction)
396 _viewer->set_dcp_decode_reduction (reduction);
397 _info->triggered_update ();
398 Config::instance()->set_decode_reduction (reduction);
401 void load_dcp (boost::filesystem::path dir)
403 DCPOMATIC_ASSERT (_film);
407 shared_ptr<DCPContent> dcp (new DCPContent(dir));
408 _film->examine_and_add_content (dcp);
409 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
410 if (!ok || !report_errors_from_last_job(this)) {
413 Config::instance()->add_to_player_history (dir);
414 } catch (dcp::DCPReadError& e) {
415 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
419 #ifdef DCPOMATIC_VARIANT_SWAROOP
420 optional<dcp::EncryptedKDM> get_kdm_from_url (shared_ptr<DCPContent> dcp)
422 ScopedTemporary temp;
423 string url = Config::instance()->kdm_server_url();
424 boost::algorithm::replace_all (url, "{CPL}", *dcp->cpl());
425 optional<dcp::EncryptedKDM> kdm;
426 if (dcp->cpl() && !get_from_url(url, false, temp)) {
428 kdm = dcp::EncryptedKDM (dcp::file_to_string(temp.file()));
429 if (kdm->cpl_id() != dcp->cpl()) {
432 } catch (std::exception& e) {
440 optional<dcp::EncryptedKDM> get_kdm_from_directory (shared_ptr<DCPContent> dcp)
442 using namespace boost::filesystem;
443 optional<path> kdm_dir = Config::instance()->player_kdm_directory();
445 return optional<dcp::EncryptedKDM>();
447 for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) {
449 if (file_size(i->path()) < MAX_KDM_SIZE) {
450 dcp::EncryptedKDM kdm (dcp::file_to_string(i->path()));
451 if (kdm.cpl_id() == dcp->cpl()) {
455 } catch (std::exception& e) {
459 return optional<dcp::EncryptedKDM>();
462 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
465 _viewer->set_film (_film);
466 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
469 void film_changed (ChangeType type, Film::Property property)
471 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
475 _film->write_metadata (Config::path("spl.xml"));
477 if (_viewer->playing ()) {
481 /* Start off as Flat */
482 _film->set_container (Ratio::from_id("185"));
484 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
485 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
486 if (dcp && dcp->needs_kdm()) {
487 optional<dcp::EncryptedKDM> kdm;
488 #ifdef DCPOMATIC_VARIANT_SWAROOP
489 kdm = get_kdm_from_url (dcp);
492 kdm = get_kdm_from_directory (dcp);
497 dcp->examine (_film, shared_ptr<Job>());
501 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
506 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
507 if (r->id() == "239") {
508 /* Any scope content means we use scope */
509 _film->set_container(r);
513 /* Any 3D content means we use 3D mode */
514 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
515 _film->set_three_d (true);
519 _viewer->seek (DCPTime(), true);
520 _info->triggered_update ();
522 set_menu_sensitivity ();
524 wxMenuItemList old = _cpl_menu->GetMenuItems();
525 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
526 _cpl_menu->Remove (*i);
529 if (_film->content().size() == 1) {
530 /* Offer a CPL menu */
531 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
533 DCPExaminer ex (first);
534 int id = ID_view_cpl;
535 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
536 wxMenuItem* j = _cpl_menu->AppendRadioItem(
538 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
540 j->Check(!first->cpl() || i->id() == *first->cpl());
549 void setup_menu (wxMenuBar* m)
551 _file_menu = new wxMenu;
552 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
553 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
554 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
556 _history_position = _file_menu->GetMenuItems().GetCount();
558 _file_menu->AppendSeparator ();
559 _file_menu->Append (ID_file_close, _("&Close"));
560 _file_menu->AppendSeparator ();
563 _file_menu->Append (wxID_EXIT, _("&Exit"));
565 _file_menu->Append (wxID_EXIT, _("&Quit"));
569 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
571 wxMenu* edit = new wxMenu;
572 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
575 prefs->Enable (Config::instance()->have_write_permission());
577 _cpl_menu = new wxMenu;
579 wxMenu* view = new wxMenu;
580 optional<int> c = Config::instance()->decode_reduction();
581 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
582 view->AppendSeparator();
583 #ifndef DCPOMATIC_VARIANT_SWAROOP
584 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
585 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
588 view->AppendSeparator();
589 view->Append(ID_view_closed_captions, _("Closed captions..."));
590 view->AppendSeparator();
591 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
592 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
593 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
594 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
596 wxMenu* tools = new wxMenu;
597 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
598 tools->AppendSeparator ();
599 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
601 wxMenu* help = new wxMenu;
603 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
605 help->Append (wxID_ABOUT, _("About"));
607 help->Append (ID_help_report_a_problem, _("Report a problem..."));
609 m->Append (_file_menu, _("&File"));
611 m->Append (edit, _("&Edit"));
613 m->Append (view, _("&View"));
614 m->Append (tools, _("&Tools"));
615 m->Append (help, _("&Help"));
620 wxString d = wxStandardPaths::Get().GetDocumentsDir();
621 if (Config::instance()->last_player_load_directory()) {
622 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
625 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
630 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
631 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
638 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
640 Config::instance()->set_last_player_load_directory (dcp.parent_path());
648 wxDirDialog* c = new wxDirDialog (
650 _("Select DCP to open as OV"),
651 wxStandardPaths::Get().GetDocumentsDir(),
652 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
658 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
659 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
666 DCPOMATIC_ASSERT (_film);
667 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
668 DCPOMATIC_ASSERT (dcp);
669 dcp->add_ov (wx_to_std(c->GetPath()));
670 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
671 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
672 if (!ok || !report_errors_from_last_job(this)) {
675 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
679 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
681 _film->set_container(r);
687 _info->triggered_update ();
692 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
694 if (d->ShowModal() == wxID_OK) {
695 DCPOMATIC_ASSERT (_film);
696 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
697 DCPOMATIC_ASSERT (dcp);
699 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
700 dcp->examine (_film, shared_ptr<Job>());
701 } catch (exception& e) {
702 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
709 _info->triggered_update ();
712 void file_history (wxCommandEvent& event)
714 vector<boost::filesystem::path> history = Config::instance()->player_history ();
715 int n = event.GetId() - ID_file_history;
716 if (n >= 0 && n < static_cast<int> (history.size ())) {
717 load_dcp (history[n]);
724 _info->triggered_update ();
725 set_menu_sensitivity ();
733 void edit_preferences ()
735 if (!Config::instance()->have_write_permission()) {
739 if (!_config_dialog) {
740 _config_dialog = create_player_config_dialog ();
742 _config_dialog->Show (this);
745 void view_cpl (wxCommandEvent& ev)
747 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
748 DCPOMATIC_ASSERT (dcp);
749 DCPExaminer ex (dcp);
750 int id = ev.GetId() - ID_view_cpl;
751 DCPOMATIC_ASSERT (id >= 0);
752 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
753 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
754 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
760 dcp->set_cpl ((*i)->id());
761 dcp->examine (_film, shared_ptr<Job>());
764 void view_full_screen ()
766 if (_mode == Config::PLAYER_MODE_FULL) {
767 _mode = Config::PLAYER_MODE_WINDOW;
769 _mode = Config::PLAYER_MODE_FULL;
775 void view_dual_screen ()
777 if (_mode == Config::PLAYER_MODE_DUAL) {
778 _mode = Config::PLAYER_MODE_WINDOW;
780 _mode = Config::PLAYER_MODE_DUAL;
788 if (_view_full_screen) {
789 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
791 if (_view_dual_screen) {
792 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
798 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
799 _controls->show_extended_player_controls (_mode == Config::PLAYER_MODE_DUAL);
800 _info->Show (_mode != Config::PLAYER_MODE_FULL);
801 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
802 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
803 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
805 if (_mode == Config::PLAYER_MODE_DUAL) {
806 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
807 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
808 _dual_screen->ShowFullScreen (true);
809 _viewer->panel()->Reparent (_dual_screen);
810 _dual_screen->Show ();
811 if (wxDisplay::GetCount() > 1) {
812 switch (Config::instance()->image_display()) {
814 _dual_screen->Move (0, 0);
815 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
818 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
819 // (0, 0) doesn't seem to work for some strange reason
826 _viewer->panel()->Reparent (_overall_panel);
827 _dual_screen->Destroy ();
832 setup_main_sizer (_mode);
835 void view_closed_captions ()
837 _viewer->show_closed_captions ();
842 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
843 DCPOMATIC_ASSERT (dcp);
845 JobManager* jm = JobManager::instance ();
846 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
847 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
852 DCPOMATIC_ASSERT (!jm->get().empty());
853 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
854 DCPOMATIC_ASSERT (last);
856 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
861 void tools_check_for_updates ()
863 UpdateChecker::instance()->run ();
864 _update_news_requested = true;
869 AboutDialog* d = new AboutDialog (this);
874 void help_report_a_problem ()
876 ReportProblemDialog* d = new ReportProblemDialog (this);
877 if (d->ShowModal () == wxID_OK) {
883 void update_checker_state_changed ()
885 UpdateChecker* uc = UpdateChecker::instance ();
887 bool const announce =
888 _update_news_requested ||
889 (uc->stable() && Config::instance()->check_for_updates()) ||
890 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
892 _update_news_requested = false;
898 if (uc->state() == UpdateChecker::YES) {
899 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
900 dialog->ShowModal ();
902 } else if (uc->state() == UpdateChecker::FAILED) {
903 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
905 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
908 _update_news_requested = false;
911 void config_changed (Config::Property prop)
913 /* Instantly save any config changes when using the player GUI */
915 Config::instance()->write_config();
916 } catch (FileError& e) {
917 if (prop != Config::HISTORY) {
921 _("Could not write to config file at %s. Your changes have not been saved."),
922 std_to_wx(e.file().string())
926 } catch (exception& e) {
929 _("Could not write to config file. Your changes have not been saved.")
933 update_from_config ();
936 void update_from_config ()
938 for (int i = 0; i < _history_items; ++i) {
939 delete _file_menu->Remove (ID_file_history + i);
942 if (_history_separator) {
943 _file_menu->Remove (_history_separator);
945 delete _history_separator;
946 _history_separator = 0;
948 int pos = _history_position;
950 vector<boost::filesystem::path> history = Config::instance()->player_history ();
952 if (!history.empty ()) {
953 _history_separator = _file_menu->InsertSeparator (pos++);
956 for (size_t i = 0; i < history.size(); ++i) {
959 s = String::compose ("&%1 %2", i + 1, history[i].string());
961 s = history[i].string();
963 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
966 _history_items = history.size ();
969 void set_menu_sensitivity ()
971 _tools_verify->Enable (static_cast<bool>(_film));
972 _file_add_ov->Enable (static_cast<bool>(_film));
973 _file_add_kdm->Enable (static_cast<bool>(_film));
974 _view_cpl->Enable (static_cast<bool>(_film));
977 void start_stop_pressed ()
979 if (_viewer->playing()) {
988 _viewer->seek_by (-_viewer->one_video_frame(), true);
991 void forward_frame ()
993 _viewer->seek_by (_viewer->one_video_frame(), true);
998 wxFrame* _dual_screen;
999 bool _update_news_requested;
1000 PlayerInformation* _info;
1001 Config::PlayerMode _mode;
1002 wxPreferencesEditor* _config_dialog;
1003 wxPanel* _overall_panel;
1005 wxMenuItem* _view_cpl;
1008 int _history_position;
1009 wxMenuItem* _history_separator;
1010 shared_ptr<FilmViewer> _viewer;
1011 Controls* _controls;
1012 boost::shared_ptr<Film> _film;
1013 boost::signals2::scoped_connection _config_changed_connection;
1014 wxMenuItem* _file_add_ov;
1015 wxMenuItem* _file_add_kdm;
1016 wxMenuItem* _tools_verify;
1017 wxMenuItem* _view_full_screen;
1018 wxMenuItem* _view_dual_screen;
1021 static const wxCmdLineEntryDesc command_line_description[] = {
1022 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1023 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1026 class PlayServer : public Server
1029 explicit PlayServer (DOMFrame* frame)
1030 : Server (PLAYER_PLAY_PORT)
1034 void handle (shared_ptr<Socket> socket)
1037 int const length = socket->read_uint32 ();
1038 scoped_array<char> buffer (new char[length]);
1039 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1040 string s (buffer.get());
1041 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1042 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1053 * @brief The magic App class for wxWidgets.
1055 class App : public wxApp
1068 wxInitAllImageHandlers ();
1070 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1071 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1073 wxSplashScreen* splash = maybe_show_splash ();
1075 SetAppName (_("DCP-o-matic Player"));
1077 if (!wxApp::OnInit()) {
1081 #ifdef DCPOMATIC_LINUX
1082 unsetenv ("UBUNTU_MENUPROXY");
1086 ProcessSerialNumber serial;
1087 GetCurrentProcess (&serial);
1088 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1091 dcpomatic_setup_path_encoding ();
1093 /* Enable i18n; this will create a Config object
1094 to look for a force-configured language. This Config
1095 object will be wrong, however, because dcpomatic_setup
1096 hasn't yet been called and there aren't any filters etc.
1099 dcpomatic_setup_i18n ();
1101 /* Set things up, including filters etc.
1102 which will now be internationalised correctly.
1106 /* Force the configuration to be re-loaded correctly next
1111 signal_manager = new wxSignalManager (this);
1113 _frame = new DOMFrame ();
1114 SetTopWindow (_frame);
1115 _frame->Maximize ();
1121 PlayServer* server = new PlayServer (_frame);
1122 new thread (boost::bind (&PlayServer::run, server));
1124 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1126 _frame->load_dcp (_dcp_to_load);
1127 } catch (exception& e) {
1128 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1132 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1134 if (Config::instance()->check_for_updates ()) {
1135 UpdateChecker::instance()->run ();
1140 catch (exception& e)
1142 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1146 void OnInitCmdLine (wxCmdLineParser& parser)
1148 parser.SetDesc (command_line_description);
1149 parser.SetSwitchChars (wxT ("-"));
1152 bool OnCmdLineParsed (wxCmdLineParser& parser)
1154 if (parser.GetParamCount() > 0) {
1155 _dcp_to_load = wx_to_std (parser.GetParam (0));
1161 void report_exception ()
1165 } catch (FileError& e) {
1169 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1170 std_to_wx (e.what()),
1171 std_to_wx (e.file().string().c_str ())
1174 } catch (exception& e) {
1178 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1179 std_to_wx (e.what ())
1183 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1187 /* An unhandled exception has occurred inside the main event loop */
1188 bool OnExceptionInMainLoop ()
1190 report_exception ();
1191 /* This will terminate the program */
1195 void OnUnhandledException ()
1197 report_exception ();
1202 signal_manager->ui_idle ();
1205 void config_failed_to_load ()
1207 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1210 void config_warning (string m)
1212 message_dialog (_frame, std_to_wx (m));
1216 string _dcp_to_load;