2 Copyright (C) 2012-2015 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 "lib/config.h"
21 #include "lib/ffmpeg_content.h"
22 #include "lib/ffmpeg_audio_stream.h"
23 #include "lib/audio_processor.h"
24 #include "lib/cinema_sound_processor.h"
25 #include "audio_dialog.h"
26 #include "audio_panel.h"
27 #include "audio_mapping_view.h"
29 #include "gain_calculator_dialog.h"
30 #include "content_panel.h"
31 #include <wx/spinctrl.h>
32 #include <boost/lexical_cast.hpp>
33 #include <boost/foreach.hpp>
40 using boost::dynamic_pointer_cast;
41 using boost::lexical_cast;
42 using boost::shared_ptr;
44 AudioPanel::AudioPanel (ContentPanel* p)
45 : ContentSubPanel (p, _("Audio"))
48 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
49 _sizer->Add (grid, 0, wxALL, 8);
53 _show = new wxButton (this, wxID_ANY, _("Show Audio..."));
54 grid->Add (_show, wxGBPosition (r, 0));
57 add_label_to_grid_bag_sizer (grid, this, _("Gain"), true, wxGBPosition (r, 0));
58 _gain = new ContentSpinCtrlDouble<AudioContent> (
60 new wxSpinCtrlDouble (this),
61 AudioContentProperty::AUDIO_GAIN,
62 boost::mem_fn (&AudioContent::audio_gain),
63 boost::mem_fn (&AudioContent::set_audio_gain)
66 _gain->add (grid, wxGBPosition (r, 1));
67 add_label_to_grid_bag_sizer (grid, this, _("dB"), false, wxGBPosition (r, 2));
68 _gain_calculate_button = new wxButton (this, wxID_ANY, _("Calculate..."));
69 grid->Add (_gain_calculate_button, wxGBPosition (r, 3));
72 add_label_to_grid_bag_sizer (grid, this, _("Delay"), true, wxGBPosition (r, 0));
73 _delay = new ContentSpinCtrl<AudioContent> (
75 new wxSpinCtrl (this),
76 AudioContentProperty::AUDIO_DELAY,
77 boost::mem_fn (&AudioContent::audio_delay),
78 boost::mem_fn (&AudioContent::set_audio_delay)
81 _delay->add (grid, wxGBPosition (r, 1));
82 /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time
83 add_label_to_grid_bag_sizer (grid, this, _("ms"), false, wxGBPosition (r, 2));
86 add_label_to_grid_bag_sizer (grid, this, _("Stream"), true, wxGBPosition (r, 0));
87 _stream = new wxChoice (this, wxID_ANY);
88 grid->Add (_stream, wxGBPosition (r, 1), wxGBSpan (1, 3), wxEXPAND);
91 add_label_to_grid_bag_sizer (grid, this, _("Process with"), true, wxGBPosition (r, 0));
92 _processor = new wxChoice (this, wxID_ANY);
94 grid->Add (_processor, wxGBPosition (r, 1), wxGBSpan (1, 3), wxEXPAND);
97 _mapping = new AudioMappingView (this);
98 _sizer->Add (_mapping, 1, wxEXPAND | wxALL, 6);
101 _description = new wxStaticText (this, wxID_ANY, wxT (" \n"), wxDefaultPosition, wxDefaultSize);
102 _sizer->Add (_description, 0, wxALL, 12);
103 wxFont font = _description->GetFont();
104 font.SetStyle (wxFONTSTYLE_ITALIC);
105 font.SetPointSize (font.GetPointSize() - 1);
106 _description->SetFont (font);
109 _gain->wrapped()->SetRange (-60, 60);
110 _gain->wrapped()->SetDigits (1);
111 _gain->wrapped()->SetIncrement (0.5);
112 _delay->wrapped()->SetRange (-1000, 1000);
114 _stream->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&AudioPanel::stream_changed, this));
115 _show->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&AudioPanel::show_clicked, this));
116 _gain_calculate_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&AudioPanel::gain_calculate_button_clicked, this));
117 _processor->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&AudioPanel::processor_changed, this));
119 _mapping_connection = _mapping->Changed.connect (boost::bind (&AudioPanel::mapping_changed, this, _1));
124 AudioPanel::film_changed (Film::Property property)
127 case Film::AUDIO_CHANNELS:
128 _mapping->set_channels (_parent->film()->audio_channels ());
131 case Film::VIDEO_FRAME_RATE:
132 setup_description ();
140 AudioPanel::film_content_changed (int property)
142 AudioContentList ac = _parent->selected_audio ();
143 shared_ptr<AudioContent> acs;
144 shared_ptr<FFmpegContent> fcs;
145 if (ac.size() == 1) {
147 fcs = dynamic_pointer_cast<FFmpegContent> (acs);
150 if (property == AudioContentProperty::AUDIO_MAPPING) {
151 _mapping->set (acs ? acs->audio_mapping () : AudioMapping ());
153 } else if (property == AudioContentProperty::AUDIO_FRAME_RATE) {
154 setup_description ();
155 } else if (property == FFmpegContentProperty::AUDIO_STREAM) {
156 _mapping->set (acs ? acs->audio_mapping () : AudioMapping ());
158 } else if (property == FFmpegContentProperty::AUDIO_STREAMS) {
160 vector<pair<string, string> > data;
161 BOOST_FOREACH (shared_ptr<FFmpegAudioStream> i, fcs->audio_streams ()) {
162 data.push_back (make_pair (i->name, i->identifier ()));
164 checked_set (_stream, data);
166 if (fcs->audio_stream()) {
167 checked_set (_stream, fcs->audio_stream()->identifier ());
172 } else if (property == AudioContentProperty::AUDIO_PROCESSOR) {
174 checked_set (_processor, acs->audio_processor() ? acs->audio_processor()->id() : N_("none"));
176 checked_set (_processor, N_("none"));
182 AudioPanel::gain_calculate_button_clicked ()
184 GainCalculatorDialog* d = new GainCalculatorDialog (this);
185 int const r = d->ShowModal ();
187 if (r == wxID_CANCEL || d->wanted_fader() == 0 || d->actual_fader() == 0) {
192 _gain->wrapped()->SetValue (
193 Config::instance()->cinema_sound_processor()->db_for_fader_change (
199 /* This appears to be necessary, as the change is not signalled,
202 _gain->view_changed ();
208 AudioPanel::show_clicked ()
211 _audio_dialog->Destroy ();
215 AudioContentList ac = _parent->selected_audio ();
216 if (ac.size() != 1) {
220 _audio_dialog = new AudioDialog (this, _parent->film ());
221 _audio_dialog->Show ();
222 _audio_dialog->set_content (ac.front ());
226 AudioPanel::stream_changed ()
228 FFmpegContentList fc = _parent->selected_ffmpeg ();
229 if (fc.size() != 1) {
233 shared_ptr<FFmpegContent> fcs = fc.front ();
235 if (_stream->GetSelection() == -1) {
239 vector<shared_ptr<FFmpegAudioStream> > a = fcs->audio_streams ();
240 vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin ();
241 string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
242 while (i != a.end() && (*i)->identifier () != s) {
247 fcs->set_audio_stream (*i);
252 AudioPanel::processor_changed ()
254 string const s = string_client_data (_processor->GetClientObject (_processor->GetSelection ()));
255 AudioProcessor const * p = 0;
256 if (s != wx_to_std (N_("none"))) {
257 p = AudioProcessor::from_id (s);
260 AudioContentList c = _parent->selected_audio ();
261 for (AudioContentList::const_iterator i = c.begin(); i != c.end(); ++i) {
262 (*i)->set_audio_processor (p);
267 AudioPanel::setup_description ()
269 AudioContentList ac = _parent->selected_audio ();
270 if (ac.size () != 1) {
271 checked_set (_description, wxT (""));
275 checked_set (_description, ac.front()->processing_description ());
279 AudioPanel::mapping_changed (AudioMapping m)
281 AudioContentList c = _parent->selected_audio ();
283 c.front()->set_audio_mapping (m);
288 AudioPanel::content_selection_changed ()
290 AudioContentList sel = _parent->selected_audio ();
292 if (_audio_dialog && sel.size() == 1) {
293 _audio_dialog->set_content (sel.front ());
296 _gain->set_content (sel);
297 _delay->set_content (sel);
299 _gain_calculate_button->Enable (sel.size() == 1);
300 _show->Enable (sel.size() == 1);
301 _stream->Enable (sel.size() == 1);
302 _processor->Enable (!sel.empty());
303 _mapping->Enable (sel.size() == 1);
307 film_content_changed (AudioContentProperty::AUDIO_MAPPING);
308 film_content_changed (AudioContentProperty::AUDIO_PROCESSOR);
309 film_content_changed (AudioContentProperty::AUDIO_FRAME_RATE);
310 film_content_changed (FFmpegContentProperty::AUDIO_STREAM);
311 film_content_changed (FFmpegContentProperty::AUDIO_STREAMS);
315 AudioPanel::setup_processors ()
317 AudioContentList sel = _parent->selected_audio ();
319 _processor->Clear ();
320 list<AudioProcessor const *> ap = AudioProcessor::all ();
321 _processor->Append (_("None"), new wxStringClientData (N_("none")));
322 for (list<AudioProcessor const *>::const_iterator i = ap.begin(); i != ap.end(); ++i) {
324 AudioContentList::const_iterator j = sel.begin();
325 while (j != sel.end() && (*i)->in_channels().includes ((*j)->audio_channels ())) {
329 if (j == sel.end ()) {
330 _processor->Append (std_to_wx ((*i)->name ()), new wxStringClientData (std_to_wx ((*i)->id ())));