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)
134 dcpomatic_log.reset (new NullLog());
135 cout << "here's the log " << dcpomatic_log.get() << "\n";
137 #if defined(DCPOMATIC_WINDOWS)
138 maybe_open_console ();
139 cout << "DCP-o-matic Player is starting." << "\n";
142 wxMenuBar* bar = new wxMenuBar;
144 set_menu_sensitivity ();
147 #ifdef DCPOMATIC_WINDOWS
148 SetIcon (wxIcon (std_to_wx ("id")));
151 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
152 update_from_config ();
154 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
155 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
156 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
157 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
158 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
159 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
160 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
161 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
162 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
163 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
164 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
165 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
166 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
167 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
168 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
169 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
170 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
171 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
173 /* Use a panel as the only child of the Frame so that we avoid
174 the dark-grey background on Windows.
176 _overall_panel = new wxPanel (this, wxID_ANY);
178 _viewer.reset (new FilmViewer (_overall_panel));
179 #ifdef DCPOMATIC_VARIANT_SWAROOP
180 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
182 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
184 _controls = new StandardControls (_overall_panel, _viewer, false);
186 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
187 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
188 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
189 _viewer->Seeked.connect (bind(&DOMFrame::playback_seeked, this, _1));
190 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
191 #ifdef DCPOMATIC_VARIANT_SWAROOP
192 _viewer->PositionChanged.connect (bind(&DOMFrame::position_changed, this));
194 _info = new PlayerInformation (_overall_panel, _viewer);
195 setup_main_sizer (Config::instance()->player_mode());
197 int accelerators = 4;
199 int accelerators = 3;
202 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
203 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
204 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
205 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
207 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
209 wxAcceleratorTable accel_table (accelerators, accel);
210 SetAcceleratorTable (accel_table);
213 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
214 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
215 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
219 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
220 #ifdef DCPOMATIC_VARIANT_SWAROOP
221 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
222 MonitorChecker::instance()->run ();
223 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
224 LockFileChecker::instance()->run ();
228 #ifdef DCPOMATIC_VARIANT_SWAROOP
230 boost::filesystem::is_regular_file(Config::path("position")) &&
231 boost::filesystem::is_regular_file(Config::path("spl.xml"))) {
233 shared_ptr<Film> film (new Film(boost::optional<boost::filesystem::path>()));
234 film->read_metadata (Config::path("spl.xml"));
236 FILE* f = fopen_boost (Config::path("position"), "r");
239 fscanf (f, "%63s", buffer);
240 _viewer->seek (DCPTime(atoi(buffer)), true);
249 void position_changed ()
251 if (!_viewer->playing() || _viewer->position().get() % DCPTime::HZ) {
255 FILE* f = fopen_boost (Config::path("position"), "w");
257 string const p = dcp::raw_convert<string> (_viewer->position().get());
258 fwrite (p.c_str(), p.length(), 1, f);
263 #ifdef DCPOMATIC_VARIANT_SWAROOP
264 void monitor_checker_state_changed ()
266 if (!MonitorChecker::instance()->ok()) {
268 error_dialog (this, _("The required display devices are not connected correctly."));
272 void lock_checker_state_changed ()
274 if (!LockFileChecker::instance()->ok()) {
276 error_dialog (this, _("The lock file is not present."));
281 void setup_main_sizer (Config::PlayerMode mode)
283 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
284 if (mode != Config::PLAYER_MODE_DUAL) {
285 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
287 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
288 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
289 _overall_panel->SetSizer (main_sizer);
290 _overall_panel->Layout ();
293 bool playback_permitted ()
295 #ifdef DCPOMATIC_VARIANT_SWAROOP
296 if (!MonitorChecker::instance()->ok()) {
297 error_dialog (this, _("The required display devices are not connected correctly."));
300 if (!LockFileChecker::instance()->ok()) {
301 error_dialog (this, _("The lock file is not present."));
305 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
310 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
311 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
312 if (d && !d->kdm_timing_window_valid()) {
318 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
324 void playback_started (DCPTime time)
326 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
331 FILE* f = fopen_boost(*log, "a");
333 /* XXX: this only logs the first piece of content; probably should be each piece? */
335 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
337 DCPExaminer ex (dcp);
338 shared_ptr<dcp::CPL> playing_cpl;
339 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
340 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
344 DCPOMATIC_ASSERT (playing_cpl);
348 "%s playback-started %s %s %s\n",
349 dcp::LocalTime().as_string().c_str(),
350 time.timecode(_film->video_frame_rate()).c_str(),
351 dcp->directories().front().string().c_str(),
352 playing_cpl->annotation_text().c_str()
356 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
360 "%s playback-started %s %s\n",
361 dcp::LocalTime().as_string().c_str(),
362 time.timecode(_film->video_frame_rate()).c_str(),
363 ffmpeg->path(0).string().c_str()
370 void playback_seeked (DCPTime time)
372 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
377 FILE* f = fopen_boost(*log, "a");
378 fprintf (f, "%s playback-seeked %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
382 void playback_stopped (DCPTime time)
384 #ifdef DCPOMATIC_VARIANT_SWAROOP
386 boost::filesystem::remove (Config::path("position"));
392 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
397 FILE* f = fopen_boost(*log, "a");
398 fprintf (f, "%s playback-stopped %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
402 void set_decode_reduction (optional<int> reduction)
404 _viewer->set_dcp_decode_reduction (reduction);
405 _info->triggered_update ();
406 Config::instance()->set_decode_reduction (reduction);
409 void load_dcp (boost::filesystem::path dir)
411 DCPOMATIC_ASSERT (_film);
415 shared_ptr<DCPContent> dcp (new DCPContent(dir));
416 _film->examine_and_add_content (dcp);
417 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
418 if (!ok || !report_errors_from_last_job(this)) {
421 Config::instance()->add_to_player_history (dir);
422 } catch (dcp::DCPReadError& e) {
423 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
427 #ifdef DCPOMATIC_VARIANT_SWAROOP
428 optional<dcp::EncryptedKDM> get_kdm_from_url (shared_ptr<DCPContent> dcp)
430 ScopedTemporary temp;
431 string url = Config::instance()->kdm_server_url();
432 boost::algorithm::replace_all (url, "{CPL}", *dcp->cpl());
433 optional<dcp::EncryptedKDM> kdm;
434 if (dcp->cpl() && !get_from_url(url, false, temp)) {
436 kdm = dcp::EncryptedKDM (dcp::file_to_string(temp.file()));
437 if (kdm->cpl_id() != dcp->cpl()) {
440 } catch (std::exception& e) {
448 optional<dcp::EncryptedKDM> get_kdm_from_directory (shared_ptr<DCPContent> dcp)
450 using namespace boost::filesystem;
451 optional<path> kdm_dir = Config::instance()->player_kdm_directory();
453 return optional<dcp::EncryptedKDM>();
455 for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) {
457 if (file_size(i->path()) < MAX_KDM_SIZE) {
458 dcp::EncryptedKDM kdm (dcp::file_to_string(i->path()));
459 if (kdm.cpl_id() == dcp->cpl()) {
463 } catch (std::exception& e) {
467 return optional<dcp::EncryptedKDM>();
470 void reset_film_weak (weak_ptr<Film> weak_film)
472 shared_ptr<Film> film = weak_film.lock ();
478 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
481 _viewer->set_film (_film);
482 _controls->set_film (_film);
483 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
484 _info->triggered_update ();
487 void film_changed (ChangeType type, Film::Property property)
489 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
493 _film->write_metadata (Config::path("spl.xml"));
495 if (_viewer->playing ()) {
499 /* Start off as Flat */
500 _film->set_container (Ratio::from_id("185"));
502 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
503 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
504 if (dcp && dcp->needs_kdm()) {
505 optional<dcp::EncryptedKDM> kdm;
506 #ifdef DCPOMATIC_VARIANT_SWAROOP
507 kdm = get_kdm_from_url (dcp);
510 kdm = get_kdm_from_directory (dcp);
515 dcp->examine (_film, shared_ptr<Job>());
519 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
524 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
525 if (r->id() == "239") {
526 /* Any scope content means we use scope */
527 _film->set_container(r);
531 /* Any 3D content means we use 3D mode */
532 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
533 _film->set_three_d (true);
537 _viewer->seek (DCPTime(), true);
538 _info->triggered_update ();
540 set_menu_sensitivity ();
542 wxMenuItemList old = _cpl_menu->GetMenuItems();
543 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
544 _cpl_menu->Remove (*i);
547 if (_film->content().size() == 1) {
548 /* Offer a CPL menu */
549 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
551 DCPExaminer ex (first);
552 int id = ID_view_cpl;
553 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
554 wxMenuItem* j = _cpl_menu->AppendRadioItem(
556 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
558 j->Check(!first->cpl() || i->id() == *first->cpl());
567 void setup_menu (wxMenuBar* m)
569 _file_menu = new wxMenu;
570 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
571 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
572 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
574 _history_position = _file_menu->GetMenuItems().GetCount();
576 _file_menu->AppendSeparator ();
577 _file_menu->Append (ID_file_close, _("&Close"));
578 _file_menu->AppendSeparator ();
581 _file_menu->Append (wxID_EXIT, _("&Exit"));
583 _file_menu->Append (wxID_EXIT, _("&Quit"));
587 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
589 wxMenu* edit = new wxMenu;
590 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
593 prefs->Enable (Config::instance()->have_write_permission());
595 _cpl_menu = new wxMenu;
597 wxMenu* view = new wxMenu;
598 optional<int> c = Config::instance()->decode_reduction();
599 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
600 view->AppendSeparator();
601 #ifndef DCPOMATIC_VARIANT_SWAROOP
602 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
603 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
606 view->AppendSeparator();
607 view->Append(ID_view_closed_captions, _("Closed captions..."));
608 view->AppendSeparator();
609 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
610 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
611 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
612 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
614 wxMenu* tools = new wxMenu;
615 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
616 tools->AppendSeparator ();
617 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
619 wxMenu* help = new wxMenu;
621 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
623 help->Append (wxID_ABOUT, _("About"));
625 help->Append (ID_help_report_a_problem, _("Report a problem..."));
627 m->Append (_file_menu, _("&File"));
629 m->Append (edit, _("&Edit"));
631 m->Append (view, _("&View"));
632 m->Append (tools, _("&Tools"));
633 m->Append (help, _("&Help"));
638 wxString d = wxStandardPaths::Get().GetDocumentsDir();
639 if (Config::instance()->last_player_load_directory()) {
640 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
643 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
648 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
649 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
656 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
658 Config::instance()->set_last_player_load_directory (dcp.parent_path());
666 wxDirDialog* c = new wxDirDialog (
668 _("Select DCP to open as OV"),
669 wxStandardPaths::Get().GetDocumentsDir(),
670 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
676 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
677 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
684 DCPOMATIC_ASSERT (_film);
685 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
686 DCPOMATIC_ASSERT (dcp);
687 dcp->add_ov (wx_to_std(c->GetPath()));
688 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
689 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
690 if (!ok || !report_errors_from_last_job(this)) {
693 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
697 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
699 _film->set_container(r);
705 _info->triggered_update ();
710 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
712 if (d->ShowModal() == wxID_OK) {
713 DCPOMATIC_ASSERT (_film);
714 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
715 DCPOMATIC_ASSERT (dcp);
717 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
718 dcp->examine (_film, shared_ptr<Job>());
719 } catch (exception& e) {
720 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
727 _info->triggered_update ();
730 void file_history (wxCommandEvent& event)
732 vector<boost::filesystem::path> history = Config::instance()->player_history ();
733 int n = event.GetId() - ID_file_history;
734 if (n >= 0 && n < static_cast<int> (history.size ())) {
735 load_dcp (history[n]);
742 _info->triggered_update ();
743 set_menu_sensitivity ();
751 void edit_preferences ()
753 if (!Config::instance()->have_write_permission()) {
757 if (!_config_dialog) {
758 _config_dialog = create_player_config_dialog ();
760 _config_dialog->Show (this);
763 void view_cpl (wxCommandEvent& ev)
765 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
766 DCPOMATIC_ASSERT (dcp);
767 DCPExaminer ex (dcp);
768 int id = ev.GetId() - ID_view_cpl;
769 DCPOMATIC_ASSERT (id >= 0);
770 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
771 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
772 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
778 dcp->set_cpl ((*i)->id());
779 dcp->examine (_film, shared_ptr<Job>());
782 void view_full_screen ()
784 if (_mode == Config::PLAYER_MODE_FULL) {
785 _mode = Config::PLAYER_MODE_WINDOW;
787 _mode = Config::PLAYER_MODE_FULL;
793 void view_dual_screen ()
795 if (_mode == Config::PLAYER_MODE_DUAL) {
796 _mode = Config::PLAYER_MODE_WINDOW;
798 _mode = Config::PLAYER_MODE_DUAL;
806 if (_view_full_screen) {
807 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
809 if (_view_dual_screen) {
810 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
816 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
817 _info->Show (_mode != Config::PLAYER_MODE_FULL);
818 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
819 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
820 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
822 if (_mode == Config::PLAYER_MODE_DUAL) {
823 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
824 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
825 _dual_screen->ShowFullScreen (true);
826 _viewer->panel()->Reparent (_dual_screen);
827 _dual_screen->Show ();
828 if (wxDisplay::GetCount() > 1) {
829 switch (Config::instance()->image_display()) {
831 _dual_screen->Move (0, 0);
832 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
835 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
836 // (0, 0) doesn't seem to work for some strange reason
843 _viewer->panel()->Reparent (_overall_panel);
844 _dual_screen->Destroy ();
849 setup_main_sizer (_mode);
852 void view_closed_captions ()
854 _viewer->show_closed_captions ();
859 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
860 DCPOMATIC_ASSERT (dcp);
862 JobManager* jm = JobManager::instance ();
863 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
864 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
869 DCPOMATIC_ASSERT (!jm->get().empty());
870 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
871 DCPOMATIC_ASSERT (last);
873 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
878 void tools_check_for_updates ()
880 UpdateChecker::instance()->run ();
881 _update_news_requested = true;
886 AboutDialog* d = new AboutDialog (this);
891 void help_report_a_problem ()
893 ReportProblemDialog* d = new ReportProblemDialog (this);
894 if (d->ShowModal () == wxID_OK) {
900 void update_checker_state_changed ()
902 UpdateChecker* uc = UpdateChecker::instance ();
904 bool const announce =
905 _update_news_requested ||
906 (uc->stable() && Config::instance()->check_for_updates()) ||
907 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
909 _update_news_requested = false;
915 if (uc->state() == UpdateChecker::YES) {
916 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
917 dialog->ShowModal ();
919 } else if (uc->state() == UpdateChecker::FAILED) {
920 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
922 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
925 _update_news_requested = false;
928 void config_changed (Config::Property prop)
930 /* Instantly save any config changes when using the player GUI */
932 Config::instance()->write_config();
933 } catch (FileError& e) {
934 if (prop != Config::HISTORY) {
938 _("Could not write to config file at %s. Your changes have not been saved."),
939 std_to_wx(e.file().string())
943 } catch (exception& e) {
946 _("Could not write to config file. Your changes have not been saved.")
950 update_from_config ();
953 void update_from_config ()
955 for (int i = 0; i < _history_items; ++i) {
956 delete _file_menu->Remove (ID_file_history + i);
959 if (_history_separator) {
960 _file_menu->Remove (_history_separator);
962 delete _history_separator;
963 _history_separator = 0;
965 int pos = _history_position;
967 vector<boost::filesystem::path> history = Config::instance()->player_history ();
969 if (!history.empty ()) {
970 _history_separator = _file_menu->InsertSeparator (pos++);
973 for (size_t i = 0; i < history.size(); ++i) {
976 s = String::compose ("&%1 %2", i + 1, history[i].string());
978 s = history[i].string();
980 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
983 _history_items = history.size ();
986 void set_menu_sensitivity ()
988 _tools_verify->Enable (static_cast<bool>(_film));
989 _file_add_ov->Enable (static_cast<bool>(_film));
990 _file_add_kdm->Enable (static_cast<bool>(_film));
991 _view_cpl->Enable (static_cast<bool>(_film));
994 void start_stop_pressed ()
996 if (_viewer->playing()) {
1005 _viewer->seek_by (-_viewer->one_video_frame(), true);
1008 void forward_frame ()
1010 _viewer->seek_by (_viewer->one_video_frame(), true);
1015 wxFrame* _dual_screen;
1016 bool _update_news_requested;
1017 PlayerInformation* _info;
1018 Config::PlayerMode _mode;
1019 wxPreferencesEditor* _config_dialog;
1020 wxPanel* _overall_panel;
1022 wxMenuItem* _view_cpl;
1025 int _history_position;
1026 wxMenuItem* _history_separator;
1027 shared_ptr<FilmViewer> _viewer;
1028 Controls* _controls;
1029 boost::shared_ptr<Film> _film;
1030 boost::signals2::scoped_connection _config_changed_connection;
1031 wxMenuItem* _file_add_ov;
1032 wxMenuItem* _file_add_kdm;
1033 wxMenuItem* _tools_verify;
1034 wxMenuItem* _view_full_screen;
1035 wxMenuItem* _view_dual_screen;
1038 static const wxCmdLineEntryDesc command_line_description[] = {
1039 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1040 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1043 class PlayServer : public Server
1046 explicit PlayServer (DOMFrame* frame)
1047 : Server (PLAYER_PLAY_PORT)
1051 void handle (shared_ptr<Socket> socket)
1054 int const length = socket->read_uint32 ();
1055 scoped_array<char> buffer (new char[length]);
1056 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1057 string s (buffer.get());
1058 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1059 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1070 * @brief The magic App class for wxWidgets.
1072 class App : public wxApp
1085 wxInitAllImageHandlers ();
1087 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1088 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1090 wxSplashScreen* splash = maybe_show_splash ();
1092 SetAppName (_("DCP-o-matic Player"));
1094 if (!wxApp::OnInit()) {
1098 #ifdef DCPOMATIC_LINUX
1099 unsetenv ("UBUNTU_MENUPROXY");
1103 ProcessSerialNumber serial;
1104 GetCurrentProcess (&serial);
1105 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1108 dcpomatic_setup_path_encoding ();
1110 /* Enable i18n; this will create a Config object
1111 to look for a force-configured language. This Config
1112 object will be wrong, however, because dcpomatic_setup
1113 hasn't yet been called and there aren't any filters etc.
1116 dcpomatic_setup_i18n ();
1118 /* Set things up, including filters etc.
1119 which will now be internationalised correctly.
1123 /* Force the configuration to be re-loaded correctly next
1128 signal_manager = new wxSignalManager (this);
1130 _frame = new DOMFrame ();
1131 SetTopWindow (_frame);
1132 _frame->Maximize ();
1138 PlayServer* server = new PlayServer (_frame);
1139 new thread (boost::bind (&PlayServer::run, server));
1141 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1143 _frame->load_dcp (_dcp_to_load);
1144 } catch (exception& e) {
1145 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1149 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1151 if (Config::instance()->check_for_updates ()) {
1152 UpdateChecker::instance()->run ();
1157 catch (exception& e)
1159 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1163 void OnInitCmdLine (wxCmdLineParser& parser)
1165 parser.SetDesc (command_line_description);
1166 parser.SetSwitchChars (wxT ("-"));
1169 bool OnCmdLineParsed (wxCmdLineParser& parser)
1171 if (parser.GetParamCount() > 0) {
1172 _dcp_to_load = wx_to_std (parser.GetParam (0));
1178 void report_exception ()
1182 } catch (FileError& e) {
1186 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1187 std_to_wx (e.what()),
1188 std_to_wx (e.file().string().c_str ())
1191 } catch (exception& e) {
1195 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1196 std_to_wx (e.what ())
1200 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1204 /* An unhandled exception has occurred inside the main event loop */
1205 bool OnExceptionInMainLoop ()
1207 report_exception ();
1208 /* This will terminate the program */
1212 void OnUnhandledException ()
1214 report_exception ();
1219 signal_manager->ui_idle ();
1222 void config_failed_to_load ()
1224 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1227 void config_warning (string m)
1229 message_dialog (_frame, std_to_wx (m));
1233 string _dcp_to_load;