Fix mis-merge.
[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         SetSizerAndFit (s);
93 }
94
95
96 /** Called when the metadata stored in the Film object has changed;
97  *  so that we can update the GUI.
98  *  @param p Property of the Film that has changed.
99  */
100 void
101 FilmEditor::film_changed (Film::Property p)
102 {
103         ensure_ui_thread ();
104         
105         if (!_film) {
106                 return;
107         }
108
109         _content_panel->film_changed (p);
110         _dcp_panel->film_changed (p);
111 }
112
113 void
114 FilmEditor::film_content_changed (int property)
115 {
116         ensure_ui_thread ();
117         
118         if (!_film) {
119                 /* We call this method ourselves (as well as using it as a signal handler)
120                    so _film can be 0.
121                 */
122                 return;
123         }
124
125         _content_panel->film_content_changed (property);
126         _dcp_panel->film_content_changed (property);
127 }
128
129 /** Sets the Film that we are editing */
130 void
131 FilmEditor::set_film (shared_ptr<Film> f)
132 {
133         set_general_sensitivity (f != 0);
134
135         if (_film == f) {
136                 return;
137         }
138         
139         _film = f;
140
141         _content_panel->set_film (_film);
142         _dcp_panel->set_film (_film);
143
144         if (_film) {
145                 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
146                 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _2));
147         }
148
149         if (_film) {
150                 FileChanged (_film->directory ());
151         } else {
152                 FileChanged ("");
153         }
154
155         if (!_film->content().empty ()) {
156                 _content_panel->set_selection (_film->content().front ());
157         }
158 }
159
160 void
161 FilmEditor::set_general_sensitivity (bool s)
162 {
163         _content_panel->set_general_sensitivity (s);
164         _dcp_panel->set_general_sensitivity (s);
165 }
166
167 void
168 FilmEditor::active_jobs_changed (bool a)
169 {
170         set_general_sensitivity (!a);
171 }