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 "lib/audio_analysis.h"
23 #include "audio_dialog.h"
24 #include "audio_plot.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 | wxFULL_REPAINT_ON_RESIZE)
35 wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
37 _plot = new AudioPlot (this);
38 sizer->Add (_plot, 1, wxALL | wxEXPAND, 12);
40 wxBoxSizer* side = new wxBoxSizer (wxVERTICAL);
43 wxStaticText* m = new wxStaticText (this, wxID_ANY, _("Channels"));
44 side->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 16);
47 for (int i = 0; i < MAX_AUDIO_CHANNELS; ++i) {
48 _channel_checkbox[i] = new wxCheckBox (this, wxID_ANY, std_to_wx (audio_channel_name (i)));
49 side->Add (_channel_checkbox[i], 1, wxEXPAND | wxALL, 3);
50 _channel_checkbox[i]->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (AudioDialog::channel_clicked), 0, this);
54 wxStaticText* m = new wxStaticText (this, wxID_ANY, _("Type"));
55 side->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 16);
58 wxString const types[] = {
63 for (int i = 0; i < AudioPoint::COUNT; ++i) {
64 _type_checkbox[i] = new wxCheckBox (this, wxID_ANY, types[i]);
65 side->Add (_type_checkbox[i], 1, wxEXPAND | wxALL, 3);
66 _type_checkbox[i]->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (AudioDialog::type_clicked), 0, this);
70 wxStaticText* m = new wxStaticText (this, wxID_ANY, _("Smoothing"));
71 side->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 16);
74 _smoothing = new wxSlider (this, wxID_ANY, AudioPlot::max_smoothing / 2, 1, AudioPlot::max_smoothing);
75 _smoothing->Connect (wxID_ANY, wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler (AudioDialog::smoothing_changed), 0, this);
76 side->Add (_smoothing, 1, wxEXPAND);
78 sizer->Add (side, 0, wxALL, 12);
82 sizer->SetSizeHints (this);
86 AudioDialog::set_film (shared_ptr<Film> f)
88 _film_changed_connection.disconnect ();
89 _film_audio_analysis_succeeded_connection.disconnect ();
93 for (int i = 0; i < MAX_AUDIO_CHANNELS; ++i) {
94 _channel_checkbox[i]->Show (!_film->audio_mapping().dcp_to_content (static_cast<libdcp::Channel> (i)).empty());
97 try_to_load_analysis ();
98 _plot->set_gain (_film->audio_gain ());
100 _film_changed_connection = _film->Changed.connect (bind (&AudioDialog::film_changed, this, _1));
101 _film_audio_analysis_succeeded_connection = _film->AudioAnalysisSucceeded.connect (bind (&AudioDialog::try_to_load_analysis, this));
103 SetTitle (wxString::Format (_("DCP-o-matic audio - %s"), std_to_wx(_film->name()).data()));
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 if (_channel_checkbox[0]) {
123 _channel_checkbox[0]->SetValue (true);
125 _plot->set_channel_visible (0, true);
127 for (int i = 0; i < AudioPoint::COUNT; ++i) {
128 _type_checkbox[i]->SetValue (true);
129 _plot->set_type_visible (i, true);
134 AudioDialog::channel_clicked (wxCommandEvent& ev)
137 while (c < MAX_AUDIO_CHANNELS && ev.GetEventObject() != _channel_checkbox[c]) {
141 assert (c < MAX_AUDIO_CHANNELS);
143 _plot->set_channel_visible (c, _channel_checkbox[c]->GetValue ());
147 AudioDialog::film_changed (Film::Property p)
150 case Film::AUDIO_GAIN:
151 _plot->set_gain (_film->audio_gain ());
159 AudioDialog::type_clicked (wxCommandEvent& ev)
162 while (t < AudioPoint::COUNT && ev.GetEventObject() != _type_checkbox[t]) {
166 assert (t < AudioPoint::COUNT);
168 _plot->set_type_visible (t, _type_checkbox[t]->GetValue ());
172 AudioDialog::smoothing_changed (wxScrollEvent &)
174 _plot->set_smoothing (_smoothing->GetValue ());