Merge master.
[dcpomatic.git] / src / wx / film_editor.cc
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file src/film_editor.cc
21  *  @brief A wx widget to edit a film's metadata, and perform various functions.
22  */
23
24 #include <iostream>
25 #include <iomanip>
26 #include <wx/wx.h>
27 #include <wx/notebook.h>
28 #include <wx/listctrl.h>
29 #include <boost/thread.hpp>
30 #include <boost/filesystem.hpp>
31 #include <boost/lexical_cast.hpp>
32 #include "lib/film.h"
33 #include "lib/transcode_job.h"
34 #include "lib/exceptions.h"
35 #include "lib/job_manager.h"
36 #include "lib/filter.h"
37 #include "lib/ratio.h"
38 #include "lib/config.h"
39 #include "lib/image_content.h"
40 #include "lib/ffmpeg_content.h"
41 #include "lib/sndfile_content.h"
42 #include "lib/dcp_content_type.h"
43 #include "lib/scaler.h"
44 #include "lib/playlist.h"
45 #include "lib/content.h"
46 #include "lib/content_factory.h"
47 #include "lib/dcp_content.h"
48 #include "lib/safe_stringstream.h"
49 #include "timecode.h"
50 #include "wx_util.h"
51 #include "film_editor.h"
52 #include "timeline_dialog.h"
53 #include "timing_panel.h"
54 #include "subtitle_panel.h"
55 #include "audio_panel.h"
56 #include "video_panel.h"
57 #include "content_panel.h"
58 #include "dcp_panel.h"
59
60 using std::string;
61 using std::cout;
62 using std::pair;
63 using std::fixed;
64 using std::setprecision;
65 using std::list;
66 using std::vector;
67 using std::max;
68 using boost::shared_ptr;
69 using boost::weak_ptr;
70 using boost::dynamic_pointer_cast;
71 using boost::lexical_cast;
72
73 /** @param f Film to edit */
74 FilmEditor::FilmEditor (wxWindow* parent)
75         : wxPanel (parent)
76 {
77         wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
78
79         _main_notebook = new wxNotebook (this, wxID_ANY);
80         s->Add (_main_notebook, 1);
81
82         _content_panel = new ContentPanel (_main_notebook, _film);
83         _main_notebook->AddPage (_content_panel->panel (), _("Content"), true);
84         _dcp_panel = new DCPPanel (_main_notebook, _film);
85         _main_notebook->AddPage (_dcp_panel->panel (), _("DCP"), false);
86         
87         JobManager::instance()->ActiveJobsChanged.connect (
88                 bind (&FilmEditor::active_jobs_changed, this, _1)
89                 );
90
91         set_film (shared_ptr<Film> ());
92 }
93
94
95 /** Called when the metadata stored in the Film object has changed;
96  *  so that we can update the GUI.
97  *  @param p Property of the Film that has changed.
98  */
99 void
100 FilmEditor::film_changed (Film::Property p)
101 {
102         ensure_ui_thread ();
103         
104         if (!_film) {
105                 return;
106         }
107
108         _content_panel->film_changed (p);
109         _dcp_panel->film_changed (p);
110 }
111
112 void
113 FilmEditor::film_content_changed (int property)
114 {
115         ensure_ui_thread ();
116         
117         if (!_film) {
118                 /* We call this method ourselves (as well as using it as a signal handler)
119                    so _film can be 0.
120                 */
121                 return;
122         }
123
124         _content_panel->film_content_changed (property);
125         _dcp_panel->film_content_changed (property);
126 }
127
128 /** Sets the Film that we are editing */
129 void
130 FilmEditor::set_film (shared_ptr<Film> f)
131 {
132         set_general_sensitivity (f != 0);
133
134         if (_film == f) {
135                 return;
136         }
137         
138         _film = f;
139
140         _content_panel->set_film (_film);
141         _dcp_panel->set_film (_film);
142
143         if (_film) {
144                 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
145                 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _2));
146         }
147
148         if (_film) {
149                 FileChanged (_film->directory ());
150         } else {
151                 FileChanged ("");
152         }
153
154         if (!_film->content().empty ()) {
155                 _content_panel->set_selection (_film->content().front ());
156         }
157 }
158
159 void
160 FilmEditor::set_general_sensitivity (bool s)
161 {
162         _content_panel->set_general_sensitivity (s);
163         _dcp_panel->set_general_sensitivity (s);
164 }
165
166 void
167 FilmEditor::active_jobs_changed (bool a)
168 {
169         set_general_sensitivity (!a);
170 }