2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 #include <boost/filesystem.hpp>
21 #include "audio_dialog.h"
22 #include "audio_plot.h"
23 #include "audio_analysis.h"
27 using boost::shared_ptr;
29 using boost::optional;
31 AudioDialog::AudioDialog (wxWindow* parent)
32 : wxDialog (parent, wxID_ANY, _("Audio"), wxDefaultPosition, wxSize (640, 512), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
35 wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
37 _plot = new AudioPlot (this);
38 sizer->Add (_plot, 1, wxALL, 12);
40 wxFlexGridSizer* table = new wxFlexGridSizer (2, 6, 6);
42 for (int i = 0; i < MAX_AUDIO_CHANNELS; ++i) {
43 _channel_checkbox[i] = new wxCheckBox (this, wxID_ANY, audio_channel_name (i));
44 table->Add (_channel_checkbox[i], 1, wxEXPAND);
46 _channel_checkbox[i]->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (AudioDialog::channel_clicked), 0, this);
52 wxString const types[] = {
57 for (int i = 0; i < AudioPoint::COUNT; ++i) {
58 _type_checkbox[i] = new wxCheckBox (this, wxID_ANY, types[i]);
59 table->Add (_type_checkbox[i], 1, wxEXPAND);
61 _type_checkbox[i]->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (AudioDialog::type_clicked), 0, this);
64 sizer->Add (table, 0, wxALL, 12);
68 sizer->SetSizeHints (this);
72 AudioDialog::set_film (boost::shared_ptr<Film> f)
74 _film_changed_connection.disconnect ();
75 _film_audio_analysis_finished_connection.disconnect ();
79 try_to_load_analysis ();
81 _plot->set_gain (_film->audio_gain ());
83 _film_changed_connection = _film->Changed.connect (bind (&AudioDialog::film_changed, this, _1));
84 _film_audio_analysis_finished_connection = _film->AudioAnalysisFinished.connect (bind (&AudioDialog::try_to_load_analysis, this));
86 SetTitle (String::compose ("DVD-o-matic audio - %1", _film->name()));
90 AudioDialog::setup_channels ()
92 if (!_film->audio_stream()) {
96 AudioMapping m (_film->audio_stream()->channels ());
98 for (int i = 0; i < MAX_AUDIO_CHANNELS; ++i) {
99 if (m.dcp_to_source(static_cast<libdcp::Channel>(i))) {
100 _channel_checkbox[i]->Show ();
102 _channel_checkbox[i]->Hide ();
108 AudioDialog::try_to_load_analysis ()
110 shared_ptr<AudioAnalysis> a;
112 if (boost::filesystem::exists (_film->audio_analysis_path())) {
113 a.reset (new AudioAnalysis (_film->audio_analysis_path ()));
116 _film->analyse_audio ();
120 _plot->set_analysis (a);
122 AudioMapping m (_film->audio_stream()->channels ());
123 optional<libdcp::Channel> c = m.source_to_dcp (0);
125 _channel_checkbox[c.get()]->SetValue (true);
126 _plot->set_channel_visible (0, true);
129 for (int i = 0; i < AudioPoint::COUNT; ++i) {
130 _type_checkbox[i]->SetValue (true);
131 _plot->set_type_visible (i, true);
136 AudioDialog::channel_clicked (wxCommandEvent& ev)
139 while (c < MAX_AUDIO_CHANNELS && ev.GetEventObject() != _channel_checkbox[c]) {
143 assert (c < MAX_AUDIO_CHANNELS);
145 AudioMapping m (_film->audio_stream()->channels ());
146 optional<int> s = m.dcp_to_source (static_cast<libdcp::Channel> (c));
148 _plot->set_channel_visible (s.get(), _channel_checkbox[c]->GetValue ());
153 AudioDialog::film_changed (Film::Property p)
156 case Film::AUDIO_GAIN:
157 _plot->set_gain (_film->audio_gain ());
159 case Film::CONTENT_AUDIO_STREAM:
160 case Film::EXTERNAL_AUDIO:
161 case Film::USE_CONTENT_AUDIO:
170 AudioDialog::type_clicked (wxCommandEvent& ev)
173 while (t < AudioPoint::COUNT && ev.GetEventObject() != _type_checkbox[t]) {
177 assert (t < AudioPoint::COUNT);
179 _plot->set_type_visible (t, _type_checkbox[t]->GetValue ());