Primitive dropped frame count in display.
[dcpomatic.git] / src / tools / dcpomatic_player.cc
index 6dede00ca66a1a50f853341947c0676c89c5aac8..5ea341fe97718929bde1c9d880e81b2e037d48e5 100644 (file)
 #include "lib/encode_server_finder.h"
 #include "lib/dcp_content.h"
 #include "lib/job_manager.h"
+#include "lib/job.h"
+#include "lib/video_content.h"
 #include "wx/wx_signal_manager.h"
 #include "wx/wx_util.h"
 #include "wx/about_dialog.h"
 #include "wx/report_problem_dialog.h"
 #include "wx/film_viewer.h"
+#include "wx/player_information.h"
 #include "wx/update_dialog.h"
+#include "wx/config_dialog.h"
 #include <wx/wx.h>
 #include <wx/stdpaths.h>
 #include <wx/splash.h>
 #include <wx/cmdline.h>
+#include <wx/preferences.h>
 #include <boost/bind.hpp>
+#include <iostream>
 
 using std::string;
+using std::cout;
 using std::exception;
 using boost::shared_ptr;
 using boost::optional;
 
 enum {
        ID_file_open = 1,
+       ID_view_scale_appropriate,
+       ID_view_scale_full,
+       ID_view_scale_half,
+       ID_view_scale_quarter,
        ID_help_report_a_problem,
        ID_tools_check_for_updates,
 };
@@ -55,6 +66,9 @@ public:
        DOMFrame ()
                : wxFrame (0, -1, _("DCP-o-matic Player"))
                , _update_news_requested (false)
+               , _info (0)
+               , _config_dialog (0)
+               , _viewer (0)
        {
 
 #if defined(DCPOMATIC_WINDOWS)
@@ -72,6 +86,11 @@ public:
 
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>()), ID_view_scale_appropriate);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
@@ -82,13 +101,20 @@ public:
                wxPanel* overall_panel = new wxPanel (this, wxID_ANY);
 
                _viewer = new FilmViewer (overall_panel, false, false);
-               wxBoxSizer* main_sizer = new wxBoxSizer (wxHORIZONTAL);
+               _info = new PlayerInformation (overall_panel, _viewer);
+               wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
                main_sizer->Add (_viewer, 1, wxEXPAND | wxALL, 6);
+               main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
                overall_panel->SetSizer (main_sizer);
 
                UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
        }
 
+       void set_decode_reduction (optional<int> reduction)
+       {
+               _viewer->set_dcp_decode_reduction (reduction);
+       }
+
        void load_dcp (boost::filesystem::path dir)
        {
                _film.reset (new Film (optional<boost::filesystem::path>()));
@@ -102,9 +128,21 @@ public:
                        dcpomatic_sleep (1);
                }
 
-               /* XXX: report errors */
+               while (signal_manager->ui_idle ()) {}
+
+               if (jm->errors ()) {
+                       wxString errors;
+                       BOOST_FOREACH (shared_ptr<Job> i, jm->get()) {
+                               if (i->finished_in_error()) {
+                                       errors += std_to_wx (i->error_summary()) + "\n";
+                               }
+                       }
+                       error_dialog (this, errors);
+                       return;
+               }
 
                _viewer->set_film (_film);
+               _info->triggered_update ();
        }
 
 private:
@@ -114,10 +152,6 @@ private:
                wxMenu* file = new wxMenu;
                file->Append (ID_file_open, _("&Open...\tCtrl-O"));
 
-#ifndef __WXOSX__
-               file->AppendSeparator ();
-#endif
-
 #ifdef __WXOSX__
                file->Append (wxID_EXIT, _("&Exit"));
 #else
@@ -131,6 +165,12 @@ private:
                edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
 #endif
 
+               wxMenu* view = new wxMenu;
+               view->AppendRadioItem (ID_view_scale_appropriate, _("Set decode resolution to match display"));
+               view->AppendRadioItem (ID_view_scale_full, _("Decode at full resolution"));
+               view->AppendRadioItem (ID_view_scale_half, _("Decode at half resolution"));
+               view->AppendRadioItem (ID_view_scale_quarter, _("Decode at quarter resolution"));
+
                wxMenu* tools = new wxMenu;
                tools->Append (ID_tools_check_for_updates, _("Check for updates"));
 
@@ -143,6 +183,10 @@ private:
                help->Append (ID_help_report_a_problem, _("Report a problem..."));
 
                m->Append (file, _("&File"));
+#ifndef __WXOSX__
+               m->Append (edit, _("&Edit"));
+#endif
+               m->Append (view, _("&View"));
                m->Append (tools, _("&Tools"));
                m->Append (help, _("&Help"));
        }
@@ -178,6 +222,14 @@ private:
                Close ();
        }
 
+       void edit_preferences ()
+       {
+               if (!_config_dialog) {
+                       _config_dialog = create_config_dialog ();
+               }
+               _config_dialog->Show (this);
+       }
+
        void tools_check_for_updates ()
        {
                UpdateChecker::instance()->run ();
@@ -229,6 +281,8 @@ private:
        }
 
        bool _update_news_requested;
+       PlayerInformation* _info;
+       wxPreferencesEditor* _config_dialog;
        FilmViewer* _viewer;
        boost::shared_ptr<Film> _film;
 };
@@ -316,6 +370,8 @@ private:
                }
                _frame->Show ();
 
+               signal_manager = new wxSignalManager (this);
+
                if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
                        try {
                                _frame->load_dcp (_dcp_to_load);
@@ -324,7 +380,6 @@ private:
                        }
                }
 
-               signal_manager = new wxSignalManager (this);
                Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
 
                Bind (wxEVT_TIMER, boost::bind (&App::check, this));