2 Copyright (C) 2022 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/>.
22 #include "wx/about_dialog.h"
23 #include "wx/editable_list.h"
24 #include "wx/wx_signal_manager.h"
25 #include "wx/wx_util.h"
26 #include "lib/constants.h"
27 #include "lib/cross.h"
28 #include "lib/dcpomatic_log.h"
29 #include "lib/null_log.h"
33 #include <dcp/reel_picture_asset.h>
34 #include <dcp/reel_sound_asset.h>
35 #include <dcp/reel_subtitle_asset.h>
36 #include <dcp/warnings.h>
37 LIBDCP_DISABLE_WARNINGS
38 #include <wx/cmdline.h>
39 #include <wx/notebook.h>
40 #include <wx/spinctrl.h>
41 #include <wx/splash.h>
42 #include <wx/stdpaths.h>
44 LIBDCP_ENABLE_WARNINGS
52 using std::make_shared;
53 using std::shared_ptr;
55 using boost::optional;
56 #if BOOST_VERSION >= 106100
57 using namespace boost::placeholders;
67 class AssetPanel : public wxPanel
70 AssetPanel(wxWindow* parent, shared_ptr<dcp::ReelAsset> asset)
71 : wxPanel(parent, wxID_ANY)
74 auto sizer = new wxGridBagSizer(DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
78 add_label_to_sizer(sizer, this, _("Annotation text"), true, wxGBPosition(r, 0));
79 _annotation_text = new wxTextCtrl(this, wxID_ANY, std_to_wx(asset->annotation_text().get_value_or("")), wxDefaultPosition, wxSize(600, -1));
80 sizer->Add(_annotation_text, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
83 add_label_to_sizer(sizer, this, _("Entry point"), true, wxGBPosition(r, 0));
84 _entry_point = new wxSpinCtrl(this, wxID_ANY);
85 sizer->Add(_entry_point, wxGBPosition(r, 1), wxDefaultSpan);
88 add_label_to_sizer(sizer, this, _("Duration"), true, wxGBPosition(r, 0));
89 _duration = new wxSpinCtrl(this, wxID_ANY);
90 sizer->Add(_duration, wxGBPosition(r, 1), wxDefaultSpan);
93 add_label_to_sizer(sizer, this, _("Intrinsic duration"), true, wxGBPosition(r, 0));
94 auto intrinsic_duration = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
95 sizer->Add(intrinsic_duration, wxGBPosition(r, 1), wxDefaultSpan);
98 auto space = new wxBoxSizer(wxVERTICAL);
99 space->Add(sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
100 SetSizerAndFit(space);
102 _entry_point->SetRange(0, 259200);
103 _entry_point->SetValue(asset->entry_point().get_value_or(0));
105 _duration->SetRange(0, 259200);
106 _duration->SetValue(asset->duration().get_value_or(0));
108 intrinsic_duration->SetValue(wxString::Format("%ld", asset->intrinsic_duration()));
110 _annotation_text->Bind(wxEVT_TEXT, boost::bind(&AssetPanel::annotation_text_changed, this));
111 _entry_point->Bind(wxEVT_SPINCTRL, boost::bind(&AssetPanel::entry_point_changed, this));
112 _duration->Bind(wxEVT_SPINCTRL, boost::bind(&AssetPanel::duration_changed, this));
116 void annotation_text_changed()
118 _asset->set_annotation_text(wx_to_std(_annotation_text->GetValue()));
121 void entry_point_changed()
123 _asset->set_entry_point(_entry_point->GetValue());
124 auto const fixed_duration = std::min(_asset->intrinsic_duration() - _asset->entry_point().get_value_or(0LL), _asset->duration().get_value_or(_asset->intrinsic_duration()));
125 _duration->SetValue(fixed_duration);
126 _asset->set_duration(fixed_duration);
129 void duration_changed()
131 _asset->set_duration(_duration->GetValue());
132 auto const fixed_entry_point = std::min(_asset->intrinsic_duration() - _asset->duration().get_value_or(_asset->intrinsic_duration()), _asset->entry_point().get_value_or(0LL));
133 _entry_point->SetValue(fixed_entry_point);
134 _asset->set_entry_point(fixed_entry_point);
137 wxTextCtrl* _annotation_text = nullptr;
138 wxSpinCtrl* _entry_point = nullptr;
139 wxSpinCtrl* _duration = nullptr;
140 shared_ptr<dcp::ReelAsset> _asset;
144 class ReelEditor : public wxDialog
147 ReelEditor(wxWindow* parent)
148 : wxDialog(parent, wxID_ANY, _("Edit reel"))
150 _sizer = new wxBoxSizer(wxVERTICAL);
151 _notebook = new wxNotebook(this, wxID_ANY);
152 _sizer->Add(_notebook, wxEXPAND | wxALL, 1, DCPOMATIC_DIALOG_BORDER);
153 SetSizerAndFit(_sizer);
156 optional<shared_ptr<dcp::Reel>> get() {
160 void set(shared_ptr<dcp::Reel> reel)
164 _notebook->DeleteAllPages();
165 if (_reel->main_picture()) {
166 _notebook->AddPage(new AssetPanel(_notebook, _reel->main_picture()), _("Picture"));
168 if (_reel->main_sound()) {
169 _notebook->AddPage(new AssetPanel(_notebook, _reel->main_sound()), _("Sound"));
171 if (_reel->main_subtitle()) {
172 _notebook->AddPage(new AssetPanel(_notebook, _reel->main_subtitle()), _("Subtitle"));
176 _sizer->SetSizeHints(this);
180 wxNotebook* _notebook = nullptr;
181 wxSizer* _sizer = nullptr;
182 shared_ptr<dcp::Reel> _reel;
186 class CPLPanel : public wxPanel
189 CPLPanel(wxWindow* parent, shared_ptr<dcp::CPL> cpl)
190 : wxPanel(parent, wxID_ANY)
193 auto sizer = new wxGridBagSizer(DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
197 add_label_to_sizer(sizer, this, _("Annotation text"), true, wxGBPosition(r, 0));
198 _annotation_text = new wxTextCtrl(this, wxID_ANY, std_to_wx(cpl->annotation_text().get_value_or("")), wxDefaultPosition, wxSize(600, -1));
199 sizer->Add(_annotation_text, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
202 add_label_to_sizer(sizer, this, _("Issuer"), true, wxGBPosition(r, 0));
203 _issuer = new wxTextCtrl(this, wxID_ANY, std_to_wx(cpl->issuer()), wxDefaultPosition, wxSize(600, -1));
204 sizer->Add(_issuer, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
207 add_label_to_sizer(sizer, this, _("Creator"), true, wxGBPosition(r, 0));
208 _creator = new wxTextCtrl(this, wxID_ANY, std_to_wx(cpl->creator()), wxDefaultPosition, wxSize(600, -1));
209 sizer->Add(_creator, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
212 add_label_to_sizer(sizer, this, _("Content title text"), true, wxGBPosition(r, 0));
213 _content_title_text = new wxTextCtrl(this, wxID_ANY, std_to_wx(cpl->content_title_text()), wxDefaultPosition, wxSize(600, -1));
214 sizer->Add(_content_title_text, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
217 add_label_to_sizer(sizer, this, _("Reels"), true, wxGBPosition(r, 0));
218 _reels = new EditableList<shared_ptr<dcp::Reel>, ReelEditor>(
220 { EditableListColumn("Name", 600, true) },
221 [this]() { return _cpl->reels(); },
222 [this](vector<shared_ptr<dcp::Reel>> reels) {
225 [](shared_ptr<dcp::Reel> reel, int) {
228 EditableListTitle::INVISIBLE,
229 EditableListButton::EDIT
231 sizer->Add(_reels, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
233 auto space = new wxBoxSizer(wxVERTICAL);
234 space->Add(sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
235 SetSizerAndFit(space);
237 _annotation_text->Bind(wxEVT_TEXT, boost::bind(&CPLPanel::annotation_text_changed, this));
238 _issuer->Bind(wxEVT_TEXT, boost::bind(&CPLPanel::issuer_changed, this));
239 _creator->Bind(wxEVT_TEXT, boost::bind(&CPLPanel::creator_changed, this));
240 _content_title_text->Bind(wxEVT_TEXT, boost::bind(&CPLPanel::content_title_text_changed, this));
244 void annotation_text_changed()
246 _cpl->set_annotation_text(wx_to_std(_annotation_text->GetValue()));
249 void issuer_changed()
251 _cpl->set_issuer(wx_to_std(_issuer->GetValue()));
254 void creator_changed()
256 _cpl->set_creator(wx_to_std(_creator->GetValue()));
259 void content_title_text_changed()
261 _cpl->set_content_title_text(wx_to_std(_content_title_text->GetValue()));
264 std::shared_ptr<dcp::CPL> _cpl;
265 wxTextCtrl* _annotation_text = nullptr;
266 wxTextCtrl* _issuer = nullptr;
267 wxTextCtrl* _creator = nullptr;
268 wxTextCtrl* _content_title_text = nullptr;
269 EditableList<shared_ptr<dcp::Reel>, ReelEditor>* _reels;
273 class DummyPanel : public wxPanel
276 DummyPanel(wxWindow* parent)
277 : wxPanel(parent, wxID_ANY)
279 auto sizer = new wxBoxSizer(wxVERTICAL);
280 add_label_to_sizer(sizer, this, _("Open a DCP using File -> Open"), false);
281 auto space = new wxBoxSizer(wxVERTICAL);
282 space->Add(sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
283 SetSizerAndFit(space);
288 class DOMFrame : public wxFrame
292 : wxFrame(nullptr, -1, _("DCP-o-matic Editor"))
293 , _main_sizer(new wxBoxSizer(wxVERTICAL))
295 dcpomatic_log = make_shared<NullLog>();
297 #if defined(DCPOMATIC_WINDOWS)
298 maybe_open_console();
299 std::cout << "DCP-o-matic Editor is starting." << "\n";
302 auto bar = new wxMenuBar;
306 #ifdef DCPOMATIC_WINDOWS
307 SetIcon(wxIcon(std_to_wx("id")));
310 Bind(wxEVT_MENU, boost::bind(&DOMFrame::file_open, this), ID_file_open);
311 Bind(wxEVT_MENU, boost::bind(&DOMFrame::file_save, this), ID_file_save);
312 Bind(wxEVT_MENU, boost::bind(&DOMFrame::file_exit, this), wxID_EXIT);
313 Bind(wxEVT_MENU, boost::bind(&DOMFrame::help_about, this), wxID_ABOUT);
315 /* Use a panel as the only child of the Frame so that we avoid
316 the dark-grey background on Windows.
318 _overall_panel = new wxPanel (this, wxID_ANY);
320 auto sizer = new wxBoxSizer(wxVERTICAL);
322 _notebook = new wxNotebook(_overall_panel, wxID_ANY);
323 _notebook->AddPage(new DummyPanel(_notebook), _("CPL"));
325 sizer->Add(_notebook, 1, wxEXPAND);
326 _overall_panel->SetSizerAndFit(sizer);
329 void load_dcp (boost::filesystem::path path)
332 _dcp = dcp::DCP(path);
334 } catch (std::runtime_error& e) {
335 error_dialog(this, _("Could not load DCP"), std_to_wx(e.what()));
339 _notebook->DeleteAllPages();
340 for (auto cpl: _dcp->cpls()) {
341 _notebook->AddPage(new CPLPanel(_notebook, cpl), wx_to_std(cpl->annotation_text().get_value_or(cpl->id())));
347 void setup_menu (wxMenuBar* m)
349 _file_menu = new wxMenu;
350 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
351 _file_menu->AppendSeparator ();
352 _file_menu->Append (ID_file_save, _("&Save\tCtrl-S"));
353 _file_menu->AppendSeparator ();
355 _file_menu->Append (wxID_EXIT, _("&Exit"));
357 _file_menu->Append (wxID_EXIT, _("&Quit"));
360 auto help = new wxMenu;
362 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
364 help->Append (wxID_ABOUT, _("About"));
367 m->Append (_file_menu, _("&File"));
368 m->Append (help, _("&Help"));
373 auto d = wxStandardPaths::Get().GetDocumentsDir();
374 wxDirDialog dialog(this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
378 r = dialog.ShowModal();
379 if (r == wxID_OK && dialog.GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
380 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
387 boost::filesystem::path const dcp(wx_to_std(dialog.GetPath()));
404 AboutDialog dialog(this);
408 wxPanel* _overall_panel = nullptr;
409 wxMenu* _file_menu = nullptr;
410 wxSizer* _main_sizer = nullptr;
411 wxNotebook* _notebook = nullptr;
412 optional<dcp::DCP> _dcp;
416 static const wxCmdLineEntryDesc command_line_description[] = {
417 { wxCMD_LINE_PARAM, 0, 0, "DCP to edit", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
418 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
423 * @brief The magic App class for wxWidgets.
425 class App : public wxApp
431 #ifdef DCPOMATIC_LINUX
438 bool OnInit () override
440 wxSplashScreen* splash;
442 wxInitAllImageHandlers ();
444 splash = maybe_show_splash ();
446 SetAppName (_("DCP-o-matic Editor"));
448 if (!wxApp::OnInit()) {
452 #ifdef DCPOMATIC_LINUX
453 unsetenv ("UBUNTU_MENUPROXY");
457 make_foreground_application ();
460 dcpomatic_setup_path_encoding ();
462 /* Enable i18n; this will create a Config object
463 to look for a force-configured language. This Config
464 object will be wrong, however, because dcpomatic_setup
465 hasn't yet been called and there aren't any filters etc.
468 dcpomatic_setup_i18n ();
470 /* Set things up, including filters etc.
471 which will now be internationalised correctly.
475 signal_manager = new wxSignalManager (this);
477 _frame = new DOMFrame ();
478 SetTopWindow (_frame);
487 _frame->load_dcp(*_dcp_to_load);
490 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
497 error_dialog (0, _("DCP-o-matic Editor could not start."), std_to_wx(e.what()));
503 void OnInitCmdLine (wxCmdLineParser& parser) override
505 parser.SetDesc (command_line_description);
506 parser.SetSwitchChars (wxT ("-"));
509 bool OnCmdLineParsed (wxCmdLineParser& parser) override
511 if (parser.GetParamCount() > 0) {
512 _dcp_to_load = wx_to_std(parser.GetParam(0));
518 void report_exception ()
522 } catch (FileError& e) {
526 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
527 std_to_wx (e.what()),
528 std_to_wx (e.file().string().c_str ())
531 } catch (exception& e) {
535 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
536 std_to_wx (e.what ())
540 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
544 /* An unhandled exception has occurred inside the main event loop */
545 bool OnExceptionInMainLoop () override
548 /* This will terminate the program */
552 void OnUnhandledException () override
559 signal_manager->ui_idle ();
562 DOMFrame* _frame = nullptr;
563 optional<boost::filesystem::path> _dcp_to_load;