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_panel.h"
24 #include "audio_mapping_view.h"
26 #include "gain_calculator_dialog.h"
27 #include "content_panel.h"
28 #include <wx/spinctrl.h>
29 #include <boost/lexical_cast.hpp>
30 #include <boost/foreach.hpp>
37 using boost::dynamic_pointer_cast;
38 using boost::lexical_cast;
39 using boost::shared_ptr;
41 AudioPanel::AudioPanel (ContentPanel* p)
42 : ContentSubPanel (p, _("Audio"))
44 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
45 _sizer->Add (grid, 0, wxALL, 8);
49 add_label_to_grid_bag_sizer (grid, this, _("Gain"), true, wxGBPosition (r, 0));
50 _gain = new ContentSpinCtrlDouble<AudioContent> (
52 new wxSpinCtrlDouble (this),
53 AudioContentProperty::AUDIO_GAIN,
54 boost::mem_fn (&AudioContent::audio_gain),
55 boost::mem_fn (&AudioContent::set_audio_gain)
58 _gain->add (grid, wxGBPosition (r, 1));
59 add_label_to_grid_bag_sizer (grid, this, _("dB"), false, wxGBPosition (r, 2));
60 _gain_calculate_button = new wxButton (this, wxID_ANY, _("Calculate..."));
61 grid->Add (_gain_calculate_button, wxGBPosition (r, 3));
64 add_label_to_grid_bag_sizer (grid, this, _("Delay"), true, wxGBPosition (r, 0));
65 _delay = new ContentSpinCtrl<AudioContent> (
67 new wxSpinCtrl (this),
68 AudioContentProperty::AUDIO_DELAY,
69 boost::mem_fn (&AudioContent::audio_delay),
70 boost::mem_fn (&AudioContent::set_audio_delay)
73 _delay->add (grid, wxGBPosition (r, 1));
74 /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time
75 add_label_to_grid_bag_sizer (grid, this, _("ms"), false, wxGBPosition (r, 2));
78 _mapping = new AudioMappingView (this);
79 _sizer->Add (_mapping, 1, wxEXPAND | wxALL, 6);
82 _description = new wxStaticText (this, wxID_ANY, wxT (" \n"), wxDefaultPosition, wxDefaultSize);
83 _sizer->Add (_description, 0, wxALL, 12);
84 wxFont font = _description->GetFont();
85 font.SetStyle (wxFONTSTYLE_ITALIC);
86 font.SetPointSize (font.GetPointSize() - 1);
87 _description->SetFont (font);
90 _gain->wrapped()->SetRange (-60, 60);
91 _gain->wrapped()->SetDigits (1);
92 _gain->wrapped()->SetIncrement (0.5);
93 _delay->wrapped()->SetRange (-1000, 1000);
95 _gain_calculate_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&AudioPanel::gain_calculate_button_clicked, this));
97 _mapping_connection = _mapping->Changed.connect (boost::bind (&AudioPanel::mapping_changed, this, _1));
102 AudioPanel::film_changed (Film::Property property)
105 case Film::AUDIO_CHANNELS:
106 case Film::AUDIO_PROCESSOR:
107 _mapping->set_output_channels (_parent->film()->audio_output_names ());
109 case Film::VIDEO_FRAME_RATE:
110 setup_description ();
118 AudioPanel::film_content_changed (int property)
120 if (property == AudioContentProperty::AUDIO_STREAMS) {
121 AudioContentList ac = _parent->selected_audio ();
122 if (ac.size() == 1) {
123 _mapping->set (ac.front()->audio_mapping());
124 _mapping->set_input_channels (ac.front()->audio_channel_names ());
126 _mapping->set (AudioMapping ());
128 setup_description ();
134 AudioPanel::gain_calculate_button_clicked ()
136 GainCalculatorDialog* d = new GainCalculatorDialog (this);
137 int const r = d->ShowModal ();
139 if (r == wxID_CANCEL || d->wanted_fader() == 0 || d->actual_fader() == 0) {
144 _gain->wrapped()->SetValue (
145 Config::instance()->cinema_sound_processor()->db_for_fader_change (
151 /* This appears to be necessary, as the change is not signalled,
154 _gain->view_changed ();
160 AudioPanel::setup_description ()
162 AudioContentList ac = _parent->selected_audio ();
163 if (ac.size () != 1) {
164 checked_set (_description, wxT (""));
168 checked_set (_description, ac.front()->processing_description ());
172 AudioPanel::mapping_changed (AudioMapping m)
174 AudioContentList c = _parent->selected_audio ();
176 c.front()->set_audio_mapping (m);
181 AudioPanel::content_selection_changed ()
183 AudioContentList sel = _parent->selected_audio ();
185 _gain->set_content (sel);
186 _delay->set_content (sel);
188 _gain_calculate_button->Enable (sel.size() == 1);
189 _mapping->Enable (sel.size() == 1);
191 film_content_changed (AudioContentProperty::AUDIO_STREAMS);