Potential fix for crash on loading a new film after starting an audio analysis.
[dcpomatic.git] / src / wx / audio_panel.cc
index a41e428ece43fd9881fd0d9e9670de1d7e529e06..ab26329a4b878a564ecf9cd96e9eed8890f674db 100644 (file)
@@ -1,19 +1,20 @@
 /*
     Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
 
-    This program is free software; you can redistribute it and/or modify
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
+    DCP-o-matic is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 
@@ -24,6 +25,7 @@
 #include "content_panel.h"
 #include "audio_dialog.h"
 #include "lib/config.h"
+#include "lib/ffmpeg_audio_stream.h"
 #include "lib/ffmpeg_content.h"
 #include "lib/cinema_sound_processor.h"
 #include "lib/job_manager.h"
@@ -65,10 +67,10 @@ AudioPanel::AudioPanel (ContentPanel* p)
        _gain = new ContentSpinCtrlDouble<AudioContent> (
                this,
                new wxSpinCtrlDouble (this),
-               AudioContentProperty::AUDIO_GAIN,
+               AudioContentProperty::GAIN,
                &Content::audio,
-               boost::mem_fn (&AudioContent::audio_gain),
-               boost::mem_fn (&AudioContent::set_audio_gain)
+               boost::mem_fn (&AudioContent::gain),
+               boost::mem_fn (&AudioContent::set_gain)
                );
 
        _gain->add (grid, wxGBPosition (r, 1));
@@ -81,10 +83,10 @@ AudioPanel::AudioPanel (ContentPanel* p)
        _delay = new ContentSpinCtrl<AudioContent> (
                this,
                new wxSpinCtrl (this),
-               AudioContentProperty::AUDIO_DELAY,
+               AudioContentProperty::DELAY,
                &Content::audio,
-               boost::mem_fn (&AudioContent::audio_delay),
-               boost::mem_fn (&AudioContent::set_audio_delay)
+               boost::mem_fn (&AudioContent::delay),
+               boost::mem_fn (&AudioContent::set_delay)
                );
 
        _delay->add (grid, wxGBPosition (r, 1));
@@ -149,17 +151,34 @@ void
 AudioPanel::film_content_changed (int property)
 {
        ContentList ac = _parent->selected_audio ();
-       if (property == AudioContentProperty::AUDIO_STREAMS) {
+       if (property == AudioContentProperty::STREAMS) {
                if (ac.size() == 1) {
-                       _mapping->set (ac.front()->audio->audio_mapping());
-                       _mapping->set_input_channels (ac.front()->audio->audio_channel_names ());
+                       _mapping->set (ac.front()->audio->mapping());
+                       _mapping->set_input_channels (ac.front()->audio->channel_names ());
+
+                       vector<AudioMappingView::Group> groups;
+                       int c = 0;
+                       BOOST_FOREACH (shared_ptr<const AudioStream> i, ac.front()->audio->streams()) {
+                               shared_ptr<const FFmpegAudioStream> f = dynamic_pointer_cast<const FFmpegAudioStream> (i);
+                               string name = "";
+                               if (f) {
+                                       name = f->name;
+                                       if (f->codec_name) {
+                                               name += " (" + f->codec_name.get() + ")";
+                                       }
+                               }
+                               groups.push_back (AudioMappingView::Group (c, c + i->channels() - 1, name));
+                               c += i->channels ();
+                       }
+                       _mapping->set_input_groups (groups);
+
                } else {
                        _mapping->set (AudioMapping ());
                }
                setup_description ();
                setup_peak ();
                _sizer->Layout ();
-       } else if (property == AudioContentProperty::AUDIO_GAIN) {
+       } else if (property == AudioContentProperty::GAIN) {
                setup_peak ();
        } else if (property == DCPContentProperty::REFERENCE_AUDIO) {
                if (ac.size() == 1) {
@@ -170,7 +189,7 @@ AudioPanel::film_content_changed (int property)
                }
 
                setup_sensitivity ();
-       } else if (property == AudioContentProperty::AUDIO_VIDEO_FRAME_RATE) {
+       } else if (property == ContentProperty::VIDEO_FRAME_RATE) {
                setup_description ();
        }
 }
@@ -218,7 +237,7 @@ AudioPanel::mapping_changed (AudioMapping m)
 {
        ContentList c = _parent->selected_audio ();
        if (c.size() == 1) {
-               c.front()->audio->set_audio_mapping (m);
+               c.front()->audio->set_mapping (m);
        }
 }
 
@@ -230,7 +249,7 @@ AudioPanel::content_selection_changed ()
        _gain->set_content (sel);
        _delay->set_content (sel);
 
-       film_content_changed (AudioContentProperty::AUDIO_STREAMS);
+       film_content_changed (AudioContentProperty::STREAMS);
        film_content_changed (DCPContentProperty::REFERENCE_AUDIO);
 
        setup_sensitivity ();
@@ -343,3 +362,13 @@ AudioPanel::reference_clicked ()
 
        d->set_reference_audio (_reference->GetValue ());
 }
+
+void
+AudioPanel::set_film (shared_ptr<Film>)
+{
+       /* We are changing film, so destroy any audio dialog for the old one */
+       if (_audio_dialog) {
+               _audio_dialog->Destroy ();
+               _audio_dialog = 0;
+       }
+}