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