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/cinema_sound_processor.h"
23 #include "audio_dialog.h"
24 #include "audio_panel.h"
25 #include "audio_mapping_view.h"
27 #include "gain_calculator_dialog.h"
28 #include "content_panel.h"
29 #include <wx/spinctrl.h>
30 #include <boost/lexical_cast.hpp>
31 #include <boost/foreach.hpp>
38 using boost::dynamic_pointer_cast;
39 using boost::lexical_cast;
40 using boost::shared_ptr;
42 AudioPanel::AudioPanel (ContentPanel* p)
43 : ContentSubPanel (p, _("Audio"))
46 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
47 _sizer->Add (grid, 0, wxALL, 8);
51 _show = new wxButton (this, wxID_ANY, _("Show Audio..."));
52 grid->Add (_show, wxGBPosition (r, 0));
55 add_label_to_grid_bag_sizer (grid, this, _("Gain"), true, wxGBPosition (r, 0));
56 _gain = new ContentSpinCtrlDouble<AudioContent> (
58 new wxSpinCtrlDouble (this),
59 AudioContentProperty::AUDIO_GAIN,
60 boost::mem_fn (&AudioContent::audio_gain),
61 boost::mem_fn (&AudioContent::set_audio_gain)
64 _gain->add (grid, wxGBPosition (r, 1));
65 add_label_to_grid_bag_sizer (grid, this, _("dB"), false, wxGBPosition (r, 2));
66 _gain_calculate_button = new wxButton (this, wxID_ANY, _("Calculate..."));
67 grid->Add (_gain_calculate_button, wxGBPosition (r, 3));
70 add_label_to_grid_bag_sizer (grid, this, _("Delay"), true, wxGBPosition (r, 0));
71 _delay = new ContentSpinCtrl<AudioContent> (
73 new wxSpinCtrl (this),
74 AudioContentProperty::AUDIO_DELAY,
75 boost::mem_fn (&AudioContent::audio_delay),
76 boost::mem_fn (&AudioContent::set_audio_delay)
79 _delay->add (grid, wxGBPosition (r, 1));
80 /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time
81 add_label_to_grid_bag_sizer (grid, this, _("ms"), false, wxGBPosition (r, 2));
84 _mapping = new AudioMappingView (this);
85 _sizer->Add (_mapping, 1, wxEXPAND | wxALL, 6);
88 _description = new wxStaticText (this, wxID_ANY, wxT (" \n"), wxDefaultPosition, wxDefaultSize);
89 _sizer->Add (_description, 0, wxALL, 12);
90 wxFont font = _description->GetFont();
91 font.SetStyle (wxFONTSTYLE_ITALIC);
92 font.SetPointSize (font.GetPointSize() - 1);
93 _description->SetFont (font);
96 _gain->wrapped()->SetRange (-60, 60);
97 _gain->wrapped()->SetDigits (1);
98 _gain->wrapped()->SetIncrement (0.5);
99 _delay->wrapped()->SetRange (-1000, 1000);
101 _show->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&AudioPanel::show_clicked, this));
102 _gain_calculate_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&AudioPanel::gain_calculate_button_clicked, this));
104 _mapping_connection = _mapping->Changed.connect (boost::bind (&AudioPanel::mapping_changed, this, _1));
109 AudioPanel::film_changed (Film::Property property)
112 case Film::AUDIO_CHANNELS:
113 case Film::AUDIO_PROCESSOR:
114 _mapping->set_output_channels (_parent->film()->audio_output_names ());
116 case Film::VIDEO_FRAME_RATE:
117 setup_description ();
125 AudioPanel::film_content_changed (int property)
127 if (property == AudioContentProperty::AUDIO_STREAMS) {
128 AudioContentList ac = _parent->selected_audio ();
129 if (ac.size() == 1) {
130 _mapping->set (ac.front()->audio_mapping());
131 _mapping->set_input_channels (ac.front()->audio_channel_names ());
133 _mapping->set (AudioMapping ());
135 setup_description ();
140 AudioPanel::gain_calculate_button_clicked ()
142 GainCalculatorDialog* d = new GainCalculatorDialog (this);
143 int const r = d->ShowModal ();
145 if (r == wxID_CANCEL || d->wanted_fader() == 0 || d->actual_fader() == 0) {
150 _gain->wrapped()->SetValue (
151 Config::instance()->cinema_sound_processor()->db_for_fader_change (
157 /* This appears to be necessary, as the change is not signalled,
160 _gain->view_changed ();
166 AudioPanel::show_clicked ()
169 _audio_dialog->Destroy ();
173 AudioContentList ac = _parent->selected_audio ();
174 if (ac.size() != 1) {
178 _audio_dialog = new AudioDialog (this, _parent->film ());
179 _audio_dialog->Show ();
180 _audio_dialog->set_content (ac.front ());
184 AudioPanel::setup_description ()
186 AudioContentList ac = _parent->selected_audio ();
187 if (ac.size () != 1) {
188 checked_set (_description, wxT (""));
192 checked_set (_description, ac.front()->processing_description ());
196 AudioPanel::mapping_changed (AudioMapping m)
198 AudioContentList c = _parent->selected_audio ();
200 c.front()->set_audio_mapping (m);
205 AudioPanel::content_selection_changed ()
207 AudioContentList sel = _parent->selected_audio ();
209 if (_audio_dialog && sel.size() == 1) {
210 _audio_dialog->set_content (sel.front ());
213 _gain->set_content (sel);
214 _delay->set_content (sel);
216 _gain_calculate_button->Enable (sel.size() == 1);
217 _show->Enable (sel.size() == 1);
218 _mapping->Enable (sel.size() == 1);
220 film_content_changed (AudioContentProperty::AUDIO_STREAMS);