Separate out management of controls.
[dcpomatic.git] / src / tools / dcpomatic.cc
index 0fffe6cfc4aa195f062483cf4144103e1ae53173..d7862a803221278f864d1efb5ff49fefd0174593 100644 (file)
@@ -22,6 +22,7 @@
  *  @brief The main DCP-o-matic GUI.
  */
 
+#include "wx/control_film_viewer.h"
 #include "wx/film_viewer.h"
 #include "wx/film_editor.h"
 #include "wx/job_manager_view.h"
@@ -44,6 +45,8 @@
 #include "wx/nag_dialog.h"
 #include "wx/export_dialog.h"
 #include "wx/paste_dialog.h"
+#include "wx/focus_manager.h"
+#include "wx/initial_setup_dialog.h"
 #include "lib/film.h"
 #include "lib/config.h"
 #include "lib/util.h"
@@ -70,7 +73,8 @@
 #include "lib/transcode_job.h"
 #include "lib/dkdm_wrapper.h"
 #include "lib/audio_content.h"
-#include "lib/subtitle_content.h"
+#include "lib/check_content_change_job.h"
+#include "lib/text_content.h"
 #include <dcp/exceptions.h>
 #include <dcp/raw_convert.h>
 #include <wx/generic/aboutdlgg.h>
@@ -109,6 +113,7 @@ using std::exception;
 using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 using boost::optional;
+using boost::function;
 using dcp::raw_convert;
 
 class FilmChangedClosingDialog : public boost::noncopyable
@@ -209,7 +214,9 @@ enum {
        ID_jobs_export,
        ID_jobs_send_dcp_to_tms,
        ID_jobs_show_dcp,
-       ID_tools_video_waveform,
+       ID_jobs_open_dcp_in_player,
+       ID_view_closed_captions,
+       ID_view_video_waveform,
        ID_tools_hints,
        ID_tools_encoding_servers,
        ID_tools_manage_templates,
@@ -293,7 +300,9 @@ public:
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_export, this),             ID_jobs_export);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_send_dcp_to_tms, this),    ID_jobs_send_dcp_to_tms);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_show_dcp, this),           ID_jobs_show_dcp);
-               Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_video_waveform, this),    ID_tools_video_waveform);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_open_dcp_in_player, this), ID_jobs_open_dcp_in_player);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this),    ID_view_closed_captions);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_video_waveform, this),     ID_view_video_waveform);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_hints, this),             ID_tools_hints);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_encoding_servers, this),  ID_tools_encoding_servers);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_manage_templates, this),  ID_tools_manage_templates);
@@ -309,12 +318,14 @@ public:
                */
                wxPanel* overall_panel = new wxPanel (this, wxID_ANY);
 
-               _film_viewer = new FilmViewer (overall_panel);
+               _film_viewer.reset (new FilmViewer (overall_panel));
+               _controls = new Controls (overall_panel, _film_viewer);
                _film_editor = new FilmEditor (overall_panel, _film_viewer);
                JobManagerView* job_manager_view = new JobManagerView (overall_panel, false);
 
                wxBoxSizer* right_sizer = new wxBoxSizer (wxVERTICAL);
-               right_sizer->Add (_film_viewer, 2, wxEXPAND | wxALL, 6);
+               right_sizer->Add (_film_viewer->panel(), 2, wxEXPAND | wxALL, 6);
+               right_sizer->Add (_controls, 0, wxEXPAND | wxALL, 6);
                right_sizer->Add (job_manager_view, 1, wxEXPAND | wxALL, 6);
 
                wxBoxSizer* main_sizer = new wxBoxSizer (wxHORIZONTAL);
@@ -331,6 +342,15 @@ public:
 
                overall_panel->SetSizer (main_sizer);
 
+               UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
+
+               FocusManager::instance()->SetFocus.connect (boost::bind (&DOMFrame::remove_accelerators, this));
+               FocusManager::instance()->KillFocus.connect (boost::bind (&DOMFrame::add_accelerators, this));
+               add_accelerators ();
+       }
+
+       void add_accelerators ()
+       {
 #ifdef __WXOSX__
                int accelerators = 7;
 #else
@@ -355,8 +375,11 @@ public:
                wxAcceleratorTable accel_table (accelerators, accel);
                SetAcceleratorTable (accel_table);
                delete[] accel;
+       }
 
-               UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
+       void remove_accelerators ()
+       {
+               SetAcceleratorTable (wxAcceleratorTable ());
        }
 
        void remove_clicked (wxCommandEvent& ev)
@@ -396,6 +419,8 @@ public:
                }
 
                set_film (film);
+
+               JobManager::instance()->add(shared_ptr<Job>(new CheckContentChangeJob(film)));
        }
        catch (std::exception& e) {
                wxString p = std_to_wx (file.string ());
@@ -408,13 +433,15 @@ public:
                _film = film;
                _film_viewer->set_film (_film);
                _film_editor->set_film (_film);
-               delete _video_waveform_dialog;
-               _video_waveform_dialog = 0;
+               if (_video_waveform_dialog) {
+                       _video_waveform_dialog->Destroy ();
+                       _video_waveform_dialog = 0;
+               }
                set_menu_sensitivity ();
                if (_film->directory()) {
                        Config::instance()->add_to_history (_film->directory().get());
                }
-               _film->Changed.connect (boost::bind (&DOMFrame::set_menu_sensitivity, this));
+               _film->Change.connect (boost::bind (&DOMFrame::film_change, this, _1));
        }
 
        shared_ptr<Film> film () const {
@@ -423,6 +450,13 @@ public:
 
 private:
 
+       void film_change (ChangeType type)
+       {
+               if (type == CHANGE_TYPE_DONE) {
+                       set_menu_sensitivity ();
+               }
+       }
+
        void file_changed (boost::filesystem::path f)
        {
                string s = wx_to_std (_("DCP-o-matic"));
@@ -547,7 +581,7 @@ private:
        {
                DCPOMATIC_ASSERT (_clipboard);
 
-               PasteDialog* d = new PasteDialog (this, static_cast<bool>(_clipboard->video), static_cast<bool>(_clipboard->audio), static_cast<bool>(_clipboard->subtitle));
+               PasteDialog* d = new PasteDialog (this, static_cast<bool>(_clipboard->video), static_cast<bool>(_clipboard->audio), !_clipboard->text.empty());
                if (d->ShowModal() == wxID_OK) {
                        BOOST_FOREACH (shared_ptr<Content> i, _film_editor->content_panel()->selected()) {
                                if (d->video() && i->video) {
@@ -558,9 +592,15 @@ private:
                                        DCPOMATIC_ASSERT (_clipboard->audio);
                                        i->audio->take_settings_from (_clipboard->audio);
                                }
-                               if (d->subtitle() && i->subtitle) {
-                                       DCPOMATIC_ASSERT (_clipboard->subtitle);
-                                       i->subtitle->take_settings_from (_clipboard->subtitle);
+
+                               if (d->text()) {
+                                       list<shared_ptr<TextContent> >::iterator j = i->text.begin ();
+                                       list<shared_ptr<TextContent> >::const_iterator k = _clipboard->text.begin ();
+                                       while (j != i->text.end() && k != _clipboard->text.end()) {
+                                               (*j)->take_settings_from (*k);
+                                               ++j;
+                                               ++k;
+                                       }
                                }
                        }
                }
@@ -610,7 +650,7 @@ private:
                        }
                }
 
-               if (!get_hints(_film).empty() && Config::instance()->show_hints_before_make_dcp()) {
+               if (Config::instance()->show_hints_before_make_dcp()) {
                        HintsDialog* hints = new HintsDialog (this, _film, false);
                        int const r = hints->ShowModal();
                        hints->Destroy ();
@@ -667,55 +707,73 @@ private:
                _kdm_dialog->Show ();
        }
 
-       void jobs_make_dcp_batch ()
+       /** @return false if we succeeded, true if not */
+       bool send_to_other_tool (int port, function<void(boost::filesystem::path)> start, string message)
        {
-               if (!_film) {
-                       return;
-               }
-
-               if (!get_hints(_film).empty() && Config::instance()->show_hints_before_make_dcp()) {
-                       HintsDialog* hints = new HintsDialog (this, _film, false);
-                       int const r = hints->ShowModal();
-                       hints->Destroy ();
-                       if (r == wxID_CANCEL) {
-                               return;
-                       }
-               }
-
-               _film->write_metadata ();
-
                /* i = 0; try to connect via socket
-                  i = 1; try again, and then try to start the batch converter
+                  i = 1; try again, and then try to start the tool
                   i = 2 onwards; try again.
                */
                for (int i = 0; i < 8; ++i) {
                        try {
                                boost::asio::io_service io_service;
                                boost::asio::ip::tcp::resolver resolver (io_service);
-                               boost::asio::ip::tcp::resolver::query query ("127.0.0.1", raw_convert<string> (BATCH_JOB_PORT));
+                               boost::asio::ip::tcp::resolver::query query ("127.0.0.1", raw_convert<string> (port));
                                boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve (query);
                                Socket socket (5);
                                socket.connect (*endpoint_iterator);
                                DCPOMATIC_ASSERT (_film->directory ());
-                               string s = _film->directory()->string ();
-                               socket.write (s.length() + 1);
-                               socket.write ((uint8_t *) s.c_str(), s.length() + 1);
+                               socket.write (message.length() + 1);
+                               socket.write ((uint8_t *) message.c_str(), message.length() + 1);
                                /* OK\0 */
                                uint8_t ok[3];
                                socket.read (ok, 3);
-                               return;
+                               return false;
                        } catch (exception& e) {
 
                        }
 
                        if (i == 1) {
-                               start_batch_converter (wx_to_std (wxStandardPaths::Get().GetExecutablePath()));
+                               start (wx_to_std (wxStandardPaths::Get().GetExecutablePath()));
                        }
 
                        dcpomatic_sleep (1);
                }
 
-               error_dialog (this, _("Could not find batch converter."));
+               return true;
+       }
+
+       void jobs_make_dcp_batch ()
+       {
+               if (!_film) {
+                       return;
+               }
+
+               if (Config::instance()->show_hints_before_make_dcp()) {
+                       HintsDialog* hints = new HintsDialog (this, _film, false);
+                       int const r = hints->ShowModal();
+                       hints->Destroy ();
+                       if (r == wxID_CANCEL) {
+                               return;
+                       }
+               }
+
+               _film->write_metadata ();
+
+               if (send_to_other_tool (BATCH_JOB_PORT, bind (&start_batch_converter, _1), _film->directory()->string())) {
+                       error_dialog (this, _("Could not find batch converter."));
+               }
+       }
+
+       void jobs_open_dcp_in_player ()
+       {
+               if (!_film) {
+                       return;
+               }
+
+               if (send_to_other_tool (PLAYER_PLAY_PORT, bind (&start_player, _1), _film->dir(_film->dcp_name(false)).string())) {
+                       error_dialog (this, _("Could not find player."));
+               }
        }
 
        void jobs_make_self_dkdm ()
@@ -780,7 +838,11 @@ private:
                ExportDialog* d = new ExportDialog (this);
                if (d->ShowModal() == wxID_OK) {
                        shared_ptr<TranscodeJob> job (new TranscodeJob (_film));
-                       job->set_encoder (shared_ptr<FFmpegEncoder> (new FFmpegEncoder (_film, job, d->path(), d->format(), d->mixdown_to_stereo())));
+                       job->set_encoder (
+                               shared_ptr<FFmpegEncoder> (
+                                       new FFmpegEncoder (_film, job, d->path(), d->format(), d->mixdown_to_stereo(), d->split_reels(), d->x264_crf())
+                                       )
+                               );
                        JobManager::instance()->add (job);
                }
                d->Destroy ();
@@ -842,7 +904,12 @@ private:
 #endif
        }
 
-       void tools_video_waveform ()
+       void view_closed_captions ()
+       {
+               _film_viewer->show_closed_captions ();
+       }
+
+       void view_video_waveform ()
        {
                if (!_video_waveform_dialog) {
                        _video_waveform_dialog = new VideoWaveformDialog (this, _film, _film_viewer);
@@ -1099,9 +1166,13 @@ private:
                jobs_menu->AppendSeparator ();
                add_item (jobs_menu, _("&Send DCP to TMS"), ID_jobs_send_dcp_to_tms, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
                add_item (jobs_menu, _("S&how DCP"), ID_jobs_show_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
+               add_item (jobs_menu, _("Open DCP in &player"), ID_jobs_open_dcp_in_player, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
+
+               wxMenu* view = new wxMenu;
+               add_item (view, _("Closed captions..."), ID_view_closed_captions, NEEDS_FILM);
+               add_item (view, _("Video waveform..."), ID_view_video_waveform, NEEDS_FILM);
 
                wxMenu* tools = new wxMenu;
-               add_item (tools, _("Video waveform..."), ID_tools_video_waveform, NEEDS_FILM);
                add_item (tools, _("Hints..."), ID_tools_hints, 0);
                add_item (tools, _("Encoding servers..."), ID_tools_encoding_servers, 0);
                add_item (tools, _("Manage templates..."), ID_tools_manage_templates, 0);
@@ -1121,6 +1192,7 @@ private:
                m->Append (edit, _("&Edit"));
                m->Append (content, _("&Content"));
                m->Append (jobs_menu, _("&Jobs"));
+               m->Append (view, _("&View"));
                m->Append (tools, _("&Tools"));
                m->Append (help, _("&Help"));
        }
@@ -1229,16 +1301,17 @@ private:
 
        void back_frame ()
        {
-               _film_viewer->back_frame ();
+               _film_viewer->move (-_film_viewer->one_video_frame());
        }
 
        void forward_frame ()
        {
-               _film_viewer->forward_frame ();
+               _film_viewer->move (_film_viewer->one_video_frame());
        }
 
        FilmEditor* _film_editor;
-       FilmViewer* _film_viewer;
+       boost::shared_ptr<FilmViewer> _film_viewer;
+       Controls* _controls;
        VideoWaveformDialog* _video_waveform_dialog;
        HintsDialog* _hints_dialog;
        ServersListDialog* _servers_list_dialog;
@@ -1330,6 +1403,14 @@ private:
                if (splash) {
                        splash->Destroy ();
                }
+
+               if (!Config::instance()->nagged(Config::NAG_INITIAL_SETUP)) {
+                       InitialSetupDialog* d = new InitialSetupDialog ();
+                       d->ShowModal ();
+                       d->Destroy ();
+                       Config::instance()->set_nagged(Config::NAG_INITIAL_SETUP, true);
+               }
+
                _frame->Show ();
 
                if (!_film_to_load.empty() && boost::filesystem::is_directory (_film_to_load)) {