Peak value of audio into the audio tab.
[dcpomatic.git] / src / wx / film_editor.cc
1 /*
2     Copyright (C) 2012-2015 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/wx/film_editor.cc
21  *  @brief FilmEditor class.
22  */
23
24 #include "lib/film.h"
25 #include "lib/job_manager.h"
26 #include "lib/content.h"
27 #include "lib/dcp_content.h"
28 #include "wx_util.h"
29 #include "film_editor.h"
30 #include "dcp_panel.h"
31 #include "content_panel.h"
32 #include <wx/wx.h>
33 #include <wx/notebook.h>
34 #include <iostream>
35
36 using std::cout;
37 using std::string;
38 using boost::shared_ptr;
39 using boost::optional;
40
41 /** @param f Film to edit */
42 FilmEditor::FilmEditor (wxWindow* parent, FilmViewer* viewer)
43         : wxPanel (parent)
44 {
45         wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
46
47         _main_notebook = new wxNotebook (this, wxID_ANY);
48         s->Add (_main_notebook, 1);
49
50         _content_panel = new ContentPanel (_main_notebook, _film, viewer);
51         _main_notebook->AddPage (_content_panel->panel (), _("Content"), true);
52         _dcp_panel = new DCPPanel (_main_notebook, _film);
53         _main_notebook->AddPage (_dcp_panel->panel (), _("DCP"), false);
54
55         JobManager::instance()->ActiveJobsChanged.connect (
56                 bind (&FilmEditor::active_jobs_changed, this, _2)
57                 );
58
59         set_film (shared_ptr<Film> ());
60         SetSizerAndFit (s);
61 }
62
63
64 /** Called when the metadata stored in the Film object has changed;
65  *  so that we can update the GUI.
66  *  @param p Property of the Film that has changed.
67  */
68 void
69 FilmEditor::film_changed (Film::Property p)
70 {
71         ensure_ui_thread ();
72
73         if (!_film) {
74                 return;
75         }
76
77         _content_panel->film_changed (p);
78         _dcp_panel->film_changed (p);
79
80         if (p == Film::CONTENT && !_film->content().empty ()) {
81                 /* Select newly-added content */
82                 _content_panel->set_selection (_film->content().back ());
83         }
84 }
85
86 void
87 FilmEditor::film_content_changed (int property)
88 {
89         ensure_ui_thread ();
90
91         if (!_film) {
92                 /* We call this method ourselves (as well as using it as a signal handler)
93                    so _film can be 0.
94                 */
95                 return;
96         }
97
98         _content_panel->film_content_changed (property);
99         _dcp_panel->film_content_changed (property);
100 }
101
102 /** Sets the Film that we are editing */
103 void
104 FilmEditor::set_film (shared_ptr<Film> film)
105 {
106         set_general_sensitivity (film != 0);
107
108         if (_film == film) {
109                 return;
110         }
111
112         _film = film;
113
114         _content_panel->set_film (_film);
115         _dcp_panel->set_film (_film);
116
117         if (_film) {
118                 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
119                 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _2));
120         }
121
122         if (_film) {
123                 FileChanged (_film->directory ());
124         } else {
125                 FileChanged ("");
126         }
127
128         if (!_film->content().empty ()) {
129                 _content_panel->set_selection (_film->content().front ());
130         }
131 }
132
133 void
134 FilmEditor::set_general_sensitivity (bool s)
135 {
136         _content_panel->set_general_sensitivity (s);
137         _dcp_panel->set_general_sensitivity (s);
138 }
139
140 void
141 FilmEditor::active_jobs_changed (optional<string> j)
142 {
143         set_general_sensitivity (!j || *j == "analyse_audio");
144 }