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/standard_controls.h"
31 #include "wx/swaroop_controls.h"
32 #include "lib/cross.h"
33 #include "lib/config.h"
35 #include "lib/internet.h"
36 #include "lib/update_checker.h"
37 #include "lib/compose.hpp"
38 #include "lib/dcp_content.h"
39 #include "lib/job_manager.h"
42 #include "lib/null_log.h"
43 #include "lib/video_content.h"
44 #include "lib/text_content.h"
45 #include "lib/ratio.h"
46 #include "lib/verify_dcp_job.h"
47 #include "lib/dcp_examiner.h"
48 #include "lib/examine_content_job.h"
49 #include "lib/server.h"
50 #include "lib/dcpomatic_socket.h"
51 #include "lib/scoped_temporary.h"
52 #include "lib/monitor_checker.h"
53 #include "lib/lock_file_checker.h"
54 #include "lib/ffmpeg_content.h"
55 #include "lib/dcpomatic_log.h"
57 #include <dcp/raw_convert.h>
58 #include <dcp/exceptions.h>
60 #include <wx/stdpaths.h>
61 #include <wx/splash.h>
62 #include <wx/cmdline.h>
63 #include <wx/preferences.h>
64 #include <wx/progdlg.h>
65 #include <wx/display.h>
67 #include <ApplicationServices/ApplicationServices.h>
69 #include <boost/bind.hpp>
83 using boost::shared_ptr;
84 using boost::weak_ptr;
85 using boost::scoped_array;
86 using boost::optional;
87 using boost::dynamic_pointer_cast;
96 /* Allow spare IDs after _history for the recent files list */
99 /* Allow spare IDs for CPLs */
100 ID_view_full_screen = 200,
102 ID_view_closed_captions,
103 ID_view_scale_appropriate,
106 ID_view_scale_quarter,
107 ID_help_report_a_problem,
109 ID_tools_check_for_updates,
110 /* IDs for shortcuts (with no associated menu item) */
116 class DOMFrame : public wxFrame
120 : wxFrame (0, -1, _("DCP-o-matic Player"))
122 , _update_news_requested (false)
124 , _mode (Config::instance()->player_mode())
128 , _history_position (0)
129 , _history_separator (0)
130 , _view_full_screen (0)
131 , _view_dual_screen (0)
133 dcpomatic_log.reset (new NullLog());
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 #ifdef DCPOMATIC_VARIANT_SWAROOP
178 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
180 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
182 _controls = new StandardControls (_overall_panel, _viewer, false);
184 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
185 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
186 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
187 _viewer->Seeked.connect (bind(&DOMFrame::playback_seeked, this, _1));
188 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
189 #ifdef DCPOMATIC_VARIANT_SWAROOP
190 _viewer->PositionChanged.connect (bind(&DOMFrame::position_changed, this));
192 _info = new PlayerInformation (_overall_panel, _viewer);
193 setup_main_sizer (Config::instance()->player_mode());
195 int accelerators = 4;
197 int accelerators = 3;
200 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
201 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
202 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
203 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
205 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
207 wxAcceleratorTable accel_table (accelerators, accel);
208 SetAcceleratorTable (accel_table);
211 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
212 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
213 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
217 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
218 #ifdef DCPOMATIC_VARIANT_SWAROOP
219 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
220 MonitorChecker::instance()->run ();
221 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
222 LockFileChecker::instance()->run ();
226 #ifdef DCPOMATIC_VARIANT_SWAROOP
228 boost::filesystem::is_regular_file(Config::path("position")) &&
229 boost::filesystem::is_regular_file(Config::path("spl.xml"))) {
231 shared_ptr<Film> film (new Film(boost::optional<boost::filesystem::path>()));
232 film->read_metadata (Config::path("spl.xml"));
234 FILE* f = fopen_boost (Config::path("position"), "r");
237 fscanf (f, "%63s", buffer);
238 _viewer->seek (DCPTime(atoi(buffer)), true);
247 void position_changed ()
249 if (!_viewer->playing() || _viewer->position().get() % DCPTime::HZ) {
253 FILE* f = fopen_boost (Config::path("position"), "w");
255 string const p = dcp::raw_convert<string> (_viewer->position().get());
256 fwrite (p.c_str(), p.length(), 1, f);
261 #ifdef DCPOMATIC_VARIANT_SWAROOP
262 void monitor_checker_state_changed ()
264 if (!MonitorChecker::instance()->ok()) {
266 error_dialog (this, _("The required display devices are not connected correctly."));
270 void lock_checker_state_changed ()
272 if (!LockFileChecker::instance()->ok()) {
274 error_dialog (this, _("The lock file is not present."));
279 void setup_main_sizer (Config::PlayerMode mode)
281 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
282 if (mode != Config::PLAYER_MODE_DUAL) {
283 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
285 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
286 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
287 _overall_panel->SetSizer (main_sizer);
288 _overall_panel->Layout ();
291 bool playback_permitted ()
293 #ifdef DCPOMATIC_VARIANT_SWAROOP
294 if (!MonitorChecker::instance()->ok()) {
295 error_dialog (this, _("The required display devices are not connected correctly."));
298 if (!LockFileChecker::instance()->ok()) {
299 error_dialog (this, _("The lock file is not present."));
303 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
308 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
309 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
310 if (d && !d->kdm_timing_window_valid()) {
316 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
322 void playback_started (DCPTime time)
324 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
329 FILE* f = fopen_boost(*log, "a");
331 /* XXX: this only logs the first piece of content; probably should be each piece? */
333 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
335 DCPExaminer ex (dcp);
336 shared_ptr<dcp::CPL> playing_cpl;
337 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
338 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
342 DCPOMATIC_ASSERT (playing_cpl);
346 "%s playback-started %s %s %s\n",
347 dcp::LocalTime().as_string().c_str(),
348 time.timecode(_film->video_frame_rate()).c_str(),
349 dcp->directories().front().string().c_str(),
350 playing_cpl->annotation_text().c_str()
354 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
358 "%s playback-started %s %s\n",
359 dcp::LocalTime().as_string().c_str(),
360 time.timecode(_film->video_frame_rate()).c_str(),
361 ffmpeg->path(0).string().c_str()
368 void playback_seeked (DCPTime time)
370 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
375 FILE* f = fopen_boost(*log, "a");
376 fprintf (f, "%s playback-seeked %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
380 void playback_stopped (DCPTime time)
382 #ifdef DCPOMATIC_VARIANT_SWAROOP
384 boost::filesystem::remove (Config::path("position"));
390 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
395 FILE* f = fopen_boost(*log, "a");
396 fprintf (f, "%s playback-stopped %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
400 void set_decode_reduction (optional<int> reduction)
402 _viewer->set_dcp_decode_reduction (reduction);
403 _info->triggered_update ();
404 Config::instance()->set_decode_reduction (reduction);
407 void load_dcp (boost::filesystem::path dir)
409 DCPOMATIC_ASSERT (_film);
413 shared_ptr<DCPContent> dcp (new DCPContent(dir));
414 _film->examine_and_add_content (dcp, true);
415 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
416 if (!ok || !report_errors_from_last_job(this)) {
419 Config::instance()->add_to_player_history (dir);
420 } catch (dcp::DCPReadError& e) {
421 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
425 #ifdef DCPOMATIC_VARIANT_SWAROOP
426 optional<dcp::EncryptedKDM> get_kdm_from_url (shared_ptr<DCPContent> dcp)
428 ScopedTemporary temp;
429 string url = Config::instance()->kdm_server_url();
430 boost::algorithm::replace_all (url, "{CPL}", *dcp->cpl());
431 optional<dcp::EncryptedKDM> kdm;
432 if (dcp->cpl() && !get_from_url(url, false, temp)) {
434 kdm = dcp::EncryptedKDM (dcp::file_to_string(temp.file()));
435 if (kdm->cpl_id() != dcp->cpl()) {
438 } catch (std::exception& e) {
446 optional<dcp::EncryptedKDM> get_kdm_from_directory (shared_ptr<DCPContent> dcp)
448 using namespace boost::filesystem;
449 optional<path> kdm_dir = Config::instance()->player_kdm_directory();
451 return optional<dcp::EncryptedKDM>();
453 for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) {
455 if (file_size(i->path()) < MAX_KDM_SIZE) {
456 dcp::EncryptedKDM kdm (dcp::file_to_string(i->path()));
457 if (kdm.cpl_id() == dcp->cpl()) {
461 } catch (std::exception& e) {
465 return optional<dcp::EncryptedKDM>();
468 void reset_film_weak (weak_ptr<Film> weak_film)
470 shared_ptr<Film> film = weak_film.lock ();
476 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
479 _viewer->set_film (_film);
480 _controls->set_film (_film);
481 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
482 _info->triggered_update ();
485 void film_changed (ChangeType type, Film::Property property)
487 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
491 _film->write_metadata (Config::path("spl.xml"));
493 if (_viewer->playing ()) {
497 /* Start off as Flat */
498 _film->set_container (Ratio::from_id("185"));
500 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
501 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
502 if (dcp && dcp->needs_kdm()) {
503 optional<dcp::EncryptedKDM> kdm;
504 #ifdef DCPOMATIC_VARIANT_SWAROOP
505 kdm = get_kdm_from_url (dcp);
508 kdm = get_kdm_from_directory (dcp);
513 dcp->examine (_film, shared_ptr<Job>());
517 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
522 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
523 if (r->id() == "239") {
524 /* Any scope content means we use scope */
525 _film->set_container(r);
529 /* Any 3D content means we use 3D mode */
530 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
531 _film->set_three_d (true);
535 _viewer->seek (DCPTime(), true);
536 _info->triggered_update ();
538 set_menu_sensitivity ();
540 wxMenuItemList old = _cpl_menu->GetMenuItems();
541 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
542 _cpl_menu->Remove (*i);
545 if (_film->content().size() == 1) {
546 /* Offer a CPL menu */
547 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
549 DCPExaminer ex (first);
550 int id = ID_view_cpl;
551 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
552 wxMenuItem* j = _cpl_menu->AppendRadioItem(
554 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
556 j->Check(!first->cpl() || i->id() == *first->cpl());
565 void setup_menu (wxMenuBar* m)
567 _file_menu = new wxMenu;
568 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
569 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
570 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
572 _history_position = _file_menu->GetMenuItems().GetCount();
574 _file_menu->AppendSeparator ();
575 _file_menu->Append (ID_file_close, _("&Close"));
576 _file_menu->AppendSeparator ();
579 _file_menu->Append (wxID_EXIT, _("&Exit"));
581 _file_menu->Append (wxID_EXIT, _("&Quit"));
585 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
587 wxMenu* edit = new wxMenu;
588 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
591 prefs->Enable (Config::instance()->have_write_permission());
593 _cpl_menu = new wxMenu;
595 wxMenu* view = new wxMenu;
596 optional<int> c = Config::instance()->decode_reduction();
597 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
598 view->AppendSeparator();
599 #ifndef DCPOMATIC_VARIANT_SWAROOP
600 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
601 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
604 view->AppendSeparator();
605 view->Append(ID_view_closed_captions, _("Closed captions..."));
606 view->AppendSeparator();
607 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
608 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
609 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
610 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
612 wxMenu* tools = new wxMenu;
613 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
614 tools->AppendSeparator ();
615 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
617 wxMenu* help = new wxMenu;
619 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
621 help->Append (wxID_ABOUT, _("About"));
623 help->Append (ID_help_report_a_problem, _("Report a problem..."));
625 m->Append (_file_menu, _("&File"));
627 m->Append (edit, _("&Edit"));
629 m->Append (view, _("&View"));
630 m->Append (tools, _("&Tools"));
631 m->Append (help, _("&Help"));
636 wxString d = wxStandardPaths::Get().GetDocumentsDir();
637 if (Config::instance()->last_player_load_directory()) {
638 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
641 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
646 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
647 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
654 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
656 Config::instance()->set_last_player_load_directory (dcp.parent_path());
664 wxDirDialog* c = new wxDirDialog (
666 _("Select DCP to open as OV"),
667 wxStandardPaths::Get().GetDocumentsDir(),
668 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
674 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
675 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
682 DCPOMATIC_ASSERT (_film);
683 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
684 DCPOMATIC_ASSERT (dcp);
685 dcp->add_ov (wx_to_std(c->GetPath()));
686 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
687 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
688 if (!ok || !report_errors_from_last_job(this)) {
691 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
695 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
697 _film->set_container(r);
703 _info->triggered_update ();
708 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
710 if (d->ShowModal() == wxID_OK) {
711 DCPOMATIC_ASSERT (_film);
712 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
713 DCPOMATIC_ASSERT (dcp);
715 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
716 dcp->examine (_film, shared_ptr<Job>());
717 } catch (exception& e) {
718 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
725 _info->triggered_update ();
728 void file_history (wxCommandEvent& event)
730 vector<boost::filesystem::path> history = Config::instance()->player_history ();
731 int n = event.GetId() - ID_file_history;
732 if (n >= 0 && n < static_cast<int> (history.size ())) {
733 load_dcp (history[n]);
740 _info->triggered_update ();
741 set_menu_sensitivity ();
749 void edit_preferences ()
751 if (!Config::instance()->have_write_permission()) {
755 if (!_config_dialog) {
756 _config_dialog = create_player_config_dialog ();
758 _config_dialog->Show (this);
761 void view_cpl (wxCommandEvent& ev)
763 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
764 DCPOMATIC_ASSERT (dcp);
765 DCPExaminer ex (dcp);
766 int id = ev.GetId() - ID_view_cpl;
767 DCPOMATIC_ASSERT (id >= 0);
768 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
769 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
770 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
776 dcp->set_cpl ((*i)->id());
777 dcp->examine (_film, shared_ptr<Job>());
780 void view_full_screen ()
782 if (_mode == Config::PLAYER_MODE_FULL) {
783 _mode = Config::PLAYER_MODE_WINDOW;
785 _mode = Config::PLAYER_MODE_FULL;
791 void view_dual_screen ()
793 if (_mode == Config::PLAYER_MODE_DUAL) {
794 _mode = Config::PLAYER_MODE_WINDOW;
796 _mode = Config::PLAYER_MODE_DUAL;
804 if (_view_full_screen) {
805 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
807 if (_view_dual_screen) {
808 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
814 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
815 _info->Show (_mode != Config::PLAYER_MODE_FULL);
816 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
817 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
818 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
820 if (_mode == Config::PLAYER_MODE_DUAL) {
821 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
822 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
823 _dual_screen->ShowFullScreen (true);
824 _viewer->panel()->Reparent (_dual_screen);
825 _dual_screen->Show ();
826 if (wxDisplay::GetCount() > 1) {
827 switch (Config::instance()->image_display()) {
829 _dual_screen->Move (0, 0);
830 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
833 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
834 // (0, 0) doesn't seem to work for some strange reason
841 _viewer->panel()->Reparent (_overall_panel);
842 _dual_screen->Destroy ();
847 setup_main_sizer (_mode);
850 void view_closed_captions ()
852 _viewer->show_closed_captions ();
857 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
858 DCPOMATIC_ASSERT (dcp);
860 JobManager* jm = JobManager::instance ();
861 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
862 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
867 DCPOMATIC_ASSERT (!jm->get().empty());
868 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
869 DCPOMATIC_ASSERT (last);
871 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
876 void tools_check_for_updates ()
878 UpdateChecker::instance()->run ();
879 _update_news_requested = true;
884 AboutDialog* d = new AboutDialog (this);
889 void help_report_a_problem ()
891 ReportProblemDialog* d = new ReportProblemDialog (this);
892 if (d->ShowModal () == wxID_OK) {
898 void update_checker_state_changed ()
900 UpdateChecker* uc = UpdateChecker::instance ();
902 bool const announce =
903 _update_news_requested ||
904 (uc->stable() && Config::instance()->check_for_updates()) ||
905 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
907 _update_news_requested = false;
913 if (uc->state() == UpdateChecker::YES) {
914 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
915 dialog->ShowModal ();
917 } else if (uc->state() == UpdateChecker::FAILED) {
918 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
920 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
923 _update_news_requested = false;
926 void config_changed (Config::Property prop)
928 /* Instantly save any config changes when using the player GUI */
930 Config::instance()->write_config();
931 } catch (FileError& e) {
932 if (prop != Config::HISTORY) {
936 _("Could not write to config file at %s. Your changes have not been saved."),
937 std_to_wx(e.file().string())
941 } catch (exception& e) {
944 _("Could not write to config file. Your changes have not been saved.")
948 update_from_config ();
951 void update_from_config ()
953 for (int i = 0; i < _history_items; ++i) {
954 delete _file_menu->Remove (ID_file_history + i);
957 if (_history_separator) {
958 _file_menu->Remove (_history_separator);
960 delete _history_separator;
961 _history_separator = 0;
963 int pos = _history_position;
965 vector<boost::filesystem::path> history = Config::instance()->player_history ();
967 if (!history.empty ()) {
968 _history_separator = _file_menu->InsertSeparator (pos++);
971 for (size_t i = 0; i < history.size(); ++i) {
974 s = String::compose ("&%1 %2", i + 1, history[i].string());
976 s = history[i].string();
978 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
981 _history_items = history.size ();
984 void set_menu_sensitivity ()
986 _tools_verify->Enable (static_cast<bool>(_film));
987 _file_add_ov->Enable (static_cast<bool>(_film));
988 _file_add_kdm->Enable (static_cast<bool>(_film));
989 _view_cpl->Enable (static_cast<bool>(_film));
992 void start_stop_pressed ()
994 if (_viewer->playing()) {
1003 _viewer->seek_by (-_viewer->one_video_frame(), true);
1006 void forward_frame ()
1008 _viewer->seek_by (_viewer->one_video_frame(), true);
1013 wxFrame* _dual_screen;
1014 bool _update_news_requested;
1015 PlayerInformation* _info;
1016 Config::PlayerMode _mode;
1017 wxPreferencesEditor* _config_dialog;
1018 wxPanel* _overall_panel;
1020 wxMenuItem* _view_cpl;
1023 int _history_position;
1024 wxMenuItem* _history_separator;
1025 shared_ptr<FilmViewer> _viewer;
1026 Controls* _controls;
1027 boost::shared_ptr<Film> _film;
1028 boost::signals2::scoped_connection _config_changed_connection;
1029 wxMenuItem* _file_add_ov;
1030 wxMenuItem* _file_add_kdm;
1031 wxMenuItem* _tools_verify;
1032 wxMenuItem* _view_full_screen;
1033 wxMenuItem* _view_dual_screen;
1036 static const wxCmdLineEntryDesc command_line_description[] = {
1037 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1038 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1041 class PlayServer : public Server
1044 explicit PlayServer (DOMFrame* frame)
1045 : Server (PLAYER_PLAY_PORT)
1049 void handle (shared_ptr<Socket> socket)
1052 int const length = socket->read_uint32 ();
1053 scoped_array<char> buffer (new char[length]);
1054 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1055 string s (buffer.get());
1056 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1057 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1068 * @brief The magic App class for wxWidgets.
1070 class App : public wxApp
1083 wxInitAllImageHandlers ();
1085 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1086 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1088 wxSplashScreen* splash = maybe_show_splash ();
1090 SetAppName (_("DCP-o-matic Player"));
1092 if (!wxApp::OnInit()) {
1096 #ifdef DCPOMATIC_LINUX
1097 unsetenv ("UBUNTU_MENUPROXY");
1101 ProcessSerialNumber serial;
1102 GetCurrentProcess (&serial);
1103 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1106 dcpomatic_setup_path_encoding ();
1108 /* Enable i18n; this will create a Config object
1109 to look for a force-configured language. This Config
1110 object will be wrong, however, because dcpomatic_setup
1111 hasn't yet been called and there aren't any filters etc.
1114 dcpomatic_setup_i18n ();
1116 /* Set things up, including filters etc.
1117 which will now be internationalised correctly.
1121 /* Force the configuration to be re-loaded correctly next
1126 signal_manager = new wxSignalManager (this);
1128 _frame = new DOMFrame ();
1129 SetTopWindow (_frame);
1130 _frame->Maximize ();
1136 PlayServer* server = new PlayServer (_frame);
1137 new thread (boost::bind (&PlayServer::run, server));
1139 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1141 _frame->load_dcp (_dcp_to_load);
1142 } catch (exception& e) {
1143 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1147 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1149 if (Config::instance()->check_for_updates ()) {
1150 UpdateChecker::instance()->run ();
1155 catch (exception& e)
1157 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1161 void OnInitCmdLine (wxCmdLineParser& parser)
1163 parser.SetDesc (command_line_description);
1164 parser.SetSwitchChars (wxT ("-"));
1167 bool OnCmdLineParsed (wxCmdLineParser& parser)
1169 if (parser.GetParamCount() > 0) {
1170 _dcp_to_load = wx_to_std (parser.GetParam (0));
1176 void report_exception ()
1180 } catch (FileError& e) {
1184 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1185 std_to_wx (e.what()),
1186 std_to_wx (e.file().string().c_str ())
1189 } catch (exception& e) {
1193 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1194 std_to_wx (e.what ())
1198 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1202 /* An unhandled exception has occurred inside the main event loop */
1203 bool OnExceptionInMainLoop ()
1205 report_exception ();
1206 /* This will terminate the program */
1210 void OnUnhandledException ()
1212 report_exception ();
1217 signal_manager->ui_idle ();
1220 void config_failed_to_load ()
1222 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1225 void config_warning (string m)
1227 message_dialog (_frame, std_to_wx (m));
1231 string _dcp_to_load;