Merge branch 'master' into plot-audio
[dcpomatic.git] / src / wx / audio_dialog.cc
1 /*
2     Copyright (C) 2013 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 "audio_dialog.h"
21 #include "audio_plot.h"
22 #include "audio_analysis.h"
23 #include "film.h"
24 #include "wx_util.h"
25
26 using boost::shared_ptr;
27
28 AudioDialog::AudioDialog (wxWindow* parent, boost::shared_ptr<Film> film)
29         : wxDialog (parent, wxID_ANY, _("Audio"), wxDefaultPosition, wxSize (640, 512), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
30         , _plot (0)
31 {
32         wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
33
34         _plot = new AudioPlot (this);
35         sizer->Add (_plot, 1);
36
37         wxFlexGridSizer* table = new wxFlexGridSizer (2, 6, 6);
38
39         add_label_to_sizer (table, this, _("Channel"));
40         _channel = new wxChoice (this, wxID_ANY);
41         table->Add (_channel, 1, wxEXPAND | wxALL, 6);
42
43         sizer->Add (table);
44
45         set_film (film);
46
47         SetSizer (sizer);
48         sizer->Layout ();
49         sizer->SetSizeHints (this);
50
51         _channel->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (AudioDialog::channel_changed), 0, this);
52 }
53
54 void
55 AudioDialog::set_film (boost::shared_ptr<Film> f)
56 {
57         _film_connection.disconnect ();
58         _film = f;
59         
60         shared_ptr<AudioAnalysis> a;
61
62         try {
63                 a.reset (new AudioAnalysis (f->audio_analysis_path ()));
64         } catch (...) {
65
66         }
67                 
68         _plot->set_analysis (a);
69
70         _channel->Clear ();
71         for (int i = 0; i < f->audio_stream()->channels(); ++i) {
72                 _channel->Append (audio_channel_name (i));
73         }
74
75         _channel->SetSelection (0);
76
77         _film_connection = f->Changed.connect (bind (&AudioDialog::film_changed, this, _1));
78 }
79
80 void
81 AudioDialog::channel_changed (wxCommandEvent &)
82 {
83         _plot->set_channel (_channel->GetSelection ());
84 }
85
86 void
87 AudioDialog::film_changed (Film::Property p)
88 {
89         if (p == Film::AUDIO_GAIN) {
90                 _plot->set_gain (_film->audio_gain ());
91         }
92 }