No-op: remove all trailing whitespace.
[dcpomatic.git] / src / wx / audio_panel.cc
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
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"
25 #include "wx_util.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>
31
32 using std::vector;
33 using std::cout;
34 using std::string;
35 using std::list;
36 using std::pair;
37 using boost::dynamic_pointer_cast;
38 using boost::lexical_cast;
39 using boost::shared_ptr;
40
41 AudioPanel::AudioPanel (ContentPanel* p)
42         : ContentSubPanel (p, _("Audio"))
43 {
44         wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
45         _sizer->Add (grid, 0, wxALL, 8);
46
47         int r = 0;
48
49         add_label_to_grid_bag_sizer (grid, this, _("Gain"), true, wxGBPosition (r, 0));
50         _gain = new ContentSpinCtrlDouble<AudioContent> (
51                 this,
52                 new wxSpinCtrlDouble (this),
53                 AudioContentProperty::AUDIO_GAIN,
54                 boost::mem_fn (&AudioContent::audio_gain),
55                 boost::mem_fn (&AudioContent::set_audio_gain)
56                 );
57
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));
62         ++r;
63
64         add_label_to_grid_bag_sizer (grid, this, _("Delay"), true, wxGBPosition (r, 0));
65         _delay = new ContentSpinCtrl<AudioContent> (
66                 this,
67                 new wxSpinCtrl (this),
68                 AudioContentProperty::AUDIO_DELAY,
69                 boost::mem_fn (&AudioContent::audio_delay),
70                 boost::mem_fn (&AudioContent::set_audio_delay)
71                 );
72
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));
76         ++r;
77
78         _mapping = new AudioMappingView (this);
79         _sizer->Add (_mapping, 1, wxEXPAND | wxALL, 6);
80         ++r;
81
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);
88         ++r;
89
90         _gain->wrapped()->SetRange (-60, 60);
91         _gain->wrapped()->SetDigits (1);
92         _gain->wrapped()->SetIncrement (0.5);
93         _delay->wrapped()->SetRange (-1000, 1000);
94
95         _gain_calculate_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED,  boost::bind (&AudioPanel::gain_calculate_button_clicked, this));
96
97         _mapping_connection = _mapping->Changed.connect (boost::bind (&AudioPanel::mapping_changed, this, _1));
98 }
99
100
101 void
102 AudioPanel::film_changed (Film::Property property)
103 {
104         switch (property) {
105         case Film::AUDIO_CHANNELS:
106         case Film::AUDIO_PROCESSOR:
107                 _mapping->set_output_channels (_parent->film()->audio_output_names ());
108                 break;
109         case Film::VIDEO_FRAME_RATE:
110                 setup_description ();
111                 break;
112         default:
113                 break;
114         }
115 }
116
117 void
118 AudioPanel::film_content_changed (int property)
119 {
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 ());
125                 } else {
126                         _mapping->set (AudioMapping ());
127                 }
128                 setup_description ();
129                 _sizer->Layout ();
130         }
131 }
132
133 void
134 AudioPanel::gain_calculate_button_clicked ()
135 {
136         GainCalculatorDialog* d = new GainCalculatorDialog (this);
137         int const r = d->ShowModal ();
138
139         if (r == wxID_CANCEL || d->wanted_fader() == 0 || d->actual_fader() == 0) {
140                 d->Destroy ();
141                 return;
142         }
143
144         _gain->wrapped()->SetValue (
145                 Config::instance()->cinema_sound_processor()->db_for_fader_change (
146                         d->wanted_fader (),
147                         d->actual_fader ()
148                         )
149                 );
150
151         /* This appears to be necessary, as the change is not signalled,
152            I think.
153         */
154         _gain->view_changed ();
155
156         d->Destroy ();
157 }
158
159 void
160 AudioPanel::setup_description ()
161 {
162         AudioContentList ac = _parent->selected_audio ();
163         if (ac.size () != 1) {
164                 checked_set (_description, wxT (""));
165                 return;
166         }
167
168         checked_set (_description, ac.front()->processing_description ());
169 }
170
171 void
172 AudioPanel::mapping_changed (AudioMapping m)
173 {
174         AudioContentList c = _parent->selected_audio ();
175         if (c.size() == 1) {
176                 c.front()->set_audio_mapping (m);
177         }
178 }
179
180 void
181 AudioPanel::content_selection_changed ()
182 {
183         AudioContentList sel = _parent->selected_audio ();
184
185         _gain->set_content (sel);
186         _delay->set_content (sel);
187
188         _gain_calculate_button->Enable (sel.size() == 1);
189         _mapping->Enable (sel.size() == 1);
190
191         film_content_changed (AudioContentProperty::AUDIO_STREAMS);
192 }