2 Copyright (C) 2012-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/lexical_cast.hpp>
21 #include <wx/spinctrl.h>
22 #include "lib/config.h"
23 #include "lib/sound_processor.h"
24 #include "lib/ffmpeg_content.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 "film_editor.h"
35 using boost::dynamic_pointer_cast;
36 using boost::lexical_cast;
37 using boost::shared_ptr;
39 AudioPanel::AudioPanel (FilmEditor* e)
40 : FilmEditorPanel (e, _("Audio"))
43 wxFlexGridSizer* grid = new wxFlexGridSizer (3, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
44 _sizer->Add (grid, 0, wxALL, 8);
46 _show = new wxButton (this, wxID_ANY, _("Show Audio..."));
51 add_label_to_sizer (grid, this, _("Audio Gain"), true);
53 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
54 _gain = new wxSpinCtrl (this);
56 add_label_to_sizer (s, this, _("dB"), false);
60 _gain_calculate_button = new wxButton (this, wxID_ANY, _("Calculate..."));
61 grid->Add (_gain_calculate_button);
63 add_label_to_sizer (grid, this, _("Audio Delay"), false);
65 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
66 _delay = new wxSpinCtrl (this);
68 /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time
69 add_label_to_sizer (s, this, _("ms"), false);
75 add_label_to_sizer (grid, this, _("Audio Stream"), true);
76 _stream = new wxChoice (this, wxID_ANY);
77 grid->Add (_stream, 1, wxEXPAND);
78 _description = new wxStaticText (this, wxID_ANY, wxT (""));
81 grid->Add (_description, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 8);
85 _mapping = new AudioMappingView (this);
86 _sizer->Add (_mapping, 1, wxEXPAND | wxALL, 6);
88 _gain->SetRange (-60, 60);
89 _delay->SetRange (-1000, 1000);
91 _delay->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&AudioPanel::delay_changed, this));
92 _stream->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&AudioPanel::stream_changed, this));
93 _show->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&AudioPanel::show_clicked, this));
94 _gain->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&AudioPanel::gain_changed, this));
95 _gain_calculate_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&AudioPanel::gain_calculate_button_clicked, this));
97 _mapping->Changed.connect (boost::bind (&AudioPanel::mapping_changed, this, _1));
102 AudioPanel::film_changed (Film::Property property)
105 case Film::AUDIO_CHANNELS:
106 _mapping->set_channels (_editor->film()->audio_channels ());
115 AudioPanel::film_content_changed (shared_ptr<Content> c, int property)
117 shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> (c);
118 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
120 if (_audio_dialog && _editor->selected_audio_content()) {
121 _audio_dialog->set_content (_editor->selected_audio_content ());
124 if (property == AudioContentProperty::AUDIO_GAIN) {
125 checked_set (_gain, ac ? ac->audio_gain() : 0);
126 } else if (property == AudioContentProperty::AUDIO_DELAY) {
127 checked_set (_delay, ac ? ac->audio_delay() : 0);
128 } else if (property == AudioContentProperty::AUDIO_MAPPING) {
129 _mapping->set (ac ? ac->audio_mapping () : AudioMapping ());
131 } else if (property == FFmpegContentProperty::AUDIO_STREAM) {
132 setup_stream_description ();
133 _mapping->set (ac ? ac->audio_mapping () : AudioMapping ());
134 } else if (property == FFmpegContentProperty::AUDIO_STREAMS) {
137 vector<shared_ptr<FFmpegAudioStream> > a = fc->audio_streams ();
138 for (vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin(); i != a.end(); ++i) {
139 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
142 if (fc->audio_stream()) {
143 checked_set (_stream, lexical_cast<string> (fc->audio_stream()->id));
144 setup_stream_description ();
151 AudioPanel::gain_changed ()
153 shared_ptr<AudioContent> ac = _editor->selected_audio_content ();
158 ac->set_audio_gain (_gain->GetValue ());
162 AudioPanel::delay_changed ()
164 shared_ptr<AudioContent> ac = _editor->selected_audio_content ();
169 ac->set_audio_delay (_delay->GetValue ());
173 AudioPanel::gain_calculate_button_clicked ()
175 GainCalculatorDialog* d = new GainCalculatorDialog (this);
178 if (d->wanted_fader() == 0 || d->actual_fader() == 0) {
184 Config::instance()->sound_processor()->db_for_fader_change (
190 /* This appears to be necessary, as the change is not signalled,
199 AudioPanel::show_clicked ()
202 _audio_dialog->Destroy ();
206 shared_ptr<Content> c = _editor->selected_content ();
211 shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> (c);
216 _audio_dialog = new AudioDialog (this);
217 _audio_dialog->Show ();
218 _audio_dialog->set_content (ac);
222 AudioPanel::stream_changed ()
224 shared_ptr<Content> c = _editor->selected_content ();
229 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
234 if (_stream->GetSelection() == -1) {
238 vector<shared_ptr<FFmpegAudioStream> > a = fc->audio_streams ();
239 vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin ();
240 string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
241 while (i != a.end() && lexical_cast<string> ((*i)->id) != s) {
246 fc->set_audio_stream (*i);
249 setup_stream_description ();
253 AudioPanel::setup_stream_description ()
255 shared_ptr<Content> c = _editor->selected_content ();
260 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
265 if (!fc->audio_stream ()) {
266 _description->SetLabel (wxT (""));
269 if (fc->audio_channels() == 1) {
272 s << fc->audio_channels() << wxT (" ") << _("channels");
274 s << wxT (", ") << fc->content_audio_frame_rate() << _("Hz");
275 _description->SetLabel (s);
280 AudioPanel::mapping_changed (AudioMapping m)
282 shared_ptr<AudioContent> c = _editor->selected_audio_content ();
287 c->set_audio_mapping (m);