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 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
44 _sizer->Add (grid, 0, wxALL, 8);
48 _show = new wxButton (this, wxID_ANY, _("Show Audio..."));
49 grid->Add (_show, wxGBPosition (r, 0));
52 add_label_to_grid_bag_sizer (grid, this, _("Audio Gain"), true, wxGBPosition (r, 0));
53 _gain = new ContentSpinCtrl<AudioContent> (
55 new wxSpinCtrl (this),
56 AudioContentProperty::AUDIO_GAIN,
57 boost::mem_fn (&AudioContent::audio_gain),
58 boost::mem_fn (&AudioContent::set_audio_gain)
61 _gain->add (grid, wxGBPosition (r, 1));
62 add_label_to_grid_bag_sizer (grid, this, _("dB"), false, wxGBPosition (r, 2));
63 _gain_calculate_button = new wxButton (this, wxID_ANY, _("Calculate..."));
64 grid->Add (_gain_calculate_button, wxGBPosition (r, 3));
67 add_label_to_grid_bag_sizer (grid, this, _("Audio Delay"), false, wxGBPosition (r, 0));
68 _delay = new ContentSpinCtrl<AudioContent> (
70 new wxSpinCtrl (this),
71 AudioContentProperty::AUDIO_DELAY,
72 boost::mem_fn (&AudioContent::audio_delay),
73 boost::mem_fn (&AudioContent::set_audio_delay)
76 _delay->add (grid, wxGBPosition (r,1 ));
77 /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time
78 add_label_to_grid_bag_sizer (grid, this, _("ms"), false, wxGBPosition (r, 2));
81 add_label_to_grid_bag_sizer (grid, this, _("Audio Stream"), true, wxGBPosition (r, 0));
82 _stream = new wxChoice (this, wxID_ANY);
83 grid->Add (_stream, wxGBPosition (r, 1));
86 _description = new wxStaticText (this, wxID_ANY, wxT (""));
87 grid->Add (_description, wxGBPosition (r, 0));
90 _mapping = new AudioMappingView (this);
91 _sizer->Add (_mapping, 1, wxEXPAND | wxALL, 6);
93 _gain->wrapped()->SetRange (-60, 60);
94 _delay->wrapped()->SetRange (-1000, 1000);
96 _stream->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&AudioPanel::stream_changed, this));
97 _show->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&AudioPanel::show_clicked, this));
98 _gain_calculate_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&AudioPanel::gain_calculate_button_clicked, this));
100 _mapping->Changed.connect (boost::bind (&AudioPanel::mapping_changed, this, _1));
105 AudioPanel::film_changed (Film::Property property)
108 case Film::AUDIO_CHANNELS:
109 _mapping->set_channels (_editor->film()->audio_channels ());
118 AudioPanel::film_content_changed (int property)
120 AudioContentList ac = _editor->selected_audio_content ();
121 shared_ptr<AudioContent> acs;
122 shared_ptr<FFmpegContent> fcs;
123 if (ac.size() == 1) {
125 fcs = dynamic_pointer_cast<FFmpegContent> (acs);
128 if (_audio_dialog && acs) {
129 _audio_dialog->set_content (acs);
132 if (property == AudioContentProperty::AUDIO_MAPPING) {
133 _mapping->set (acs ? acs->audio_mapping () : AudioMapping ());
135 } else if (property == FFmpegContentProperty::AUDIO_STREAM) {
136 setup_stream_description ();
137 _mapping->set (acs ? acs->audio_mapping () : AudioMapping ());
138 } else if (property == FFmpegContentProperty::AUDIO_STREAMS) {
141 vector<shared_ptr<FFmpegAudioStream> > a = fcs->audio_streams ();
142 for (vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin(); i != a.end(); ++i) {
143 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
146 if (fcs->audio_stream()) {
147 checked_set (_stream, lexical_cast<string> (fcs->audio_stream()->id));
148 setup_stream_description ();
155 AudioPanel::gain_calculate_button_clicked ()
157 GainCalculatorDialog* d = new GainCalculatorDialog (this);
160 if (d->wanted_fader() == 0 || d->actual_fader() == 0) {
165 _gain->wrapped()->SetValue (
166 Config::instance()->sound_processor()->db_for_fader_change (
172 /* This appears to be necessary, as the change is not signalled,
175 _gain->update_from_model ();
181 AudioPanel::show_clicked ()
184 _audio_dialog->Destroy ();
188 AudioContentList ac = _editor->selected_audio_content ();
189 if (ac.size() != 1) {
193 _audio_dialog = new AudioDialog (this);
194 _audio_dialog->Show ();
195 _audio_dialog->set_content (ac.front ());
199 AudioPanel::stream_changed ()
201 FFmpegContentList fc = _editor->selected_ffmpeg_content ();
202 if (fc.size() != 1) {
206 shared_ptr<FFmpegContent> fcs = fc.front ();
208 if (_stream->GetSelection() == -1) {
212 vector<shared_ptr<FFmpegAudioStream> > a = fcs->audio_streams ();
213 vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin ();
214 string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
215 while (i != a.end() && lexical_cast<string> ((*i)->id) != s) {
220 fcs->set_audio_stream (*i);
223 setup_stream_description ();
227 AudioPanel::setup_stream_description ()
229 FFmpegContentList fc = _editor->selected_ffmpeg_content ();
230 if (fc.size() != 1) {
234 shared_ptr<FFmpegContent> fcs = fc.front ();
236 if (!fcs->audio_stream ()) {
237 _description->SetLabel (wxT (""));
240 if (fcs->audio_channels() == 1) {
243 s << fcs->audio_channels() << wxT (" ") << _("channels");
245 s << wxT (", ") << fcs->content_audio_frame_rate() << _("Hz");
246 _description->SetLabel (s);
251 AudioPanel::mapping_changed (AudioMapping m)
253 AudioContentList c = _editor->selected_audio_content ();
255 c.front()->set_audio_mapping (m);
260 AudioPanel::content_selection_changed ()
262 AudioContentList sel = _editor->selected_audio_content ();
264 _gain->set_content (sel);
265 _delay->set_content (sel);
267 _show->Enable (sel.size() == 1);
268 _stream->Enable (sel.size() == 1);
269 _mapping->Enable (sel.size() == 1);
271 film_content_changed (AudioContentProperty::AUDIO_MAPPING);
272 film_content_changed (FFmpegContentProperty::AUDIO_STREAM);
273 film_content_changed (FFmpegContentProperty::AUDIO_STREAMS);