Improve audio mapping handling a bit.
authorCarl Hetherington <cth@carlh.net>
Sun, 26 May 2013 00:26:21 +0000 (01:26 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 26 May 2013 00:26:21 +0000 (01:26 +0100)
src/lib/audio_content.cc
src/lib/audio_content.h
src/lib/audio_mapping.h
src/lib/ffmpeg_content.cc
src/lib/ffmpeg_content.h
src/lib/null_content.h
src/lib/sndfile_content.cc
src/lib/sndfile_content.h
src/wx/audio_mapping_view.cc
src/wx/audio_mapping_view.h
src/wx/film_editor.cc

index 607e71c50ba6f1013f429c36d190af4e0d48380e..fb196c776d4ac82a71d87c290e0aae771f2c8b14 100644 (file)
@@ -1,5 +1,3 @@
-/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
-
 /*
     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
 
@@ -31,6 +29,7 @@ int const AudioContentProperty::AUDIO_LENGTH = 201;
 int const AudioContentProperty::AUDIO_FRAME_RATE = 202;
 int const AudioContentProperty::AUDIO_GAIN = 203;
 int const AudioContentProperty::AUDIO_DELAY = 204;
+int const AudioContentProperty::AUDIO_MAPPING = 205;
 
 AudioContent::AudioContent (shared_ptr<const Film> f, Time s)
        : Content (f, s)
index 0c5287eaf776708f61d246b16d302357edb8b8ed..8fc658a7660177eb47b46eb22f1418f38f87d0c5 100644 (file)
@@ -37,6 +37,7 @@ public:
        static int const AUDIO_FRAME_RATE;
        static int const AUDIO_GAIN;
        static int const AUDIO_DELAY;
+       static int const AUDIO_MAPPING;
 };
 
 class AudioContent : public virtual Content
@@ -54,6 +55,7 @@ public:
         virtual int content_audio_frame_rate () const = 0;
        virtual int output_audio_frame_rate () const = 0;
        virtual AudioMapping audio_mapping () const = 0;
+       virtual void set_audio_mapping (AudioMapping) = 0;
 
        void set_audio_gain (float);
        void set_audio_delay (int);
index 7d76e4f5a0643066285086522cd66d12d81ceaea..a2de8306bbf376457788bb77884d4a523bbabee0 100644 (file)
@@ -1,5 +1,3 @@
-/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
-
 /*
     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
 
index 55139ca56cd8b380265a957cb45402088d6bbabb..d912ee418d2e85e34997dfab898587e9969abe4c 100644 (file)
@@ -357,3 +357,9 @@ FFmpegContent::set_filters (vector<Filter const *> const & filters)
        signal_changed (FFmpegContentProperty::FILTERS);
 }
 
+void
+FFmpegContent::set_audio_mapping (AudioMapping m)
+{
+       audio_stream()->mapping = m;
+       signal_changed (AudioContentProperty::AUDIO_MAPPING);
+}
index 8f5c773eeb853ba7f7530268bef65d4188621969..c94b1937c7f95db1571929685b5e9dfdc5d4b274 100644 (file)
@@ -104,6 +104,7 @@ public:
         int content_audio_frame_rate () const;
         int output_audio_frame_rate () const;
        AudioMapping audio_mapping () const;
+       void set_audio_mapping (AudioMapping);
 
        void set_filters (std::vector<Filter const *> const &);
        
index f8829658c5b403aca8e6f807430c09538684dd1a..889ff7a0d326990a59e2d90af62138ad4c24231f 100644 (file)
@@ -54,6 +54,8 @@ public:
        AudioMapping audio_mapping () const {
                return AudioMapping ();
        }
+
+       void set_audio_mapping (AudioMapping) {}
        
        Time length () const {
                return _length;
index a80c7dbe511cb50de9032b813ef3444324eb4dc7..8eede89f4365241821ccf38a6db5b9c16acba08d 100644 (file)
@@ -1,5 +1,3 @@
-/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
-
 /*
     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
 
@@ -50,6 +48,7 @@ SndfileContent::SndfileContent (shared_ptr<const Film> f, shared_ptr<const cxml:
        _audio_channels = node->number_child<int> ("AudioChannels");
        _audio_length = node->number_child<ContentAudioFrame> ("AudioLength");
        _audio_frame_rate = node->number_child<int> ("AudioFrameRate");
+       _audio_mapping = AudioMapping (node->node_child ("AudioMapping"));
 }
 
 string
@@ -113,6 +112,10 @@ SndfileContent::examine (shared_ptr<Job> job)
        signal_changed (AudioContentProperty::AUDIO_CHANNELS);
        signal_changed (AudioContentProperty::AUDIO_LENGTH);
        signal_changed (AudioContentProperty::AUDIO_FRAME_RATE);
+
+       /* XXX: do this in signal_changed...? */
+       _audio_mapping = AudioMapping (_audio_channels);
+       signal_changed (AudioContentProperty::AUDIO_MAPPING);
 }
 
 void
@@ -124,6 +127,7 @@ SndfileContent::as_xml (xmlpp::Node* node) const
        node->add_child("AudioChannels")->add_child_text (lexical_cast<string> (_audio_channels));
        node->add_child("AudioLength")->add_child_text (lexical_cast<string> (_audio_length));
        node->add_child("AudioFrameRate")->add_child_text (lexical_cast<string> (_audio_frame_rate));
+       _audio_mapping.as_xml (node->add_child("AudioMapping"));
 }
 
 Time
@@ -143,3 +147,14 @@ SndfileContent::output_audio_frame_rate () const
        
        return film->dcp_audio_frame_rate ();
 }
+
+void
+SndfileContent::set_audio_mapping (AudioMapping m)
+{
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               _audio_mapping = m;
+       }
+
+       signal_changed (AudioContentProperty::AUDIO_MAPPING);
+}
index 17423b8edd76acd053f34568190a2629a220218d..30eb23a4ed38e89bea2883274306647e9568d9a5 100644 (file)
@@ -1,5 +1,3 @@
-/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
-
 /*
     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
 
@@ -67,6 +65,8 @@ public:
                boost::mutex::scoped_lock lm (_mutex);
                return _audio_mapping;
        }
+
+       void set_audio_mapping (AudioMapping);
        
        static bool valid_file (boost::filesystem::path);
 
index 43119ef4e245c69f7ff57e06382c585e563b6765..3ea0cdd1da9b72717b038ed1c6606a47f275040e 100644 (file)
@@ -1,5 +1,3 @@
-/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
-
 /*
     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
 
@@ -147,7 +145,7 @@ AudioMappingView::left_click (wxGridEvent& ev)
 }
 
 void
-AudioMappingView::set_mapping (AudioMapping map)
+AudioMappingView::set (AudioMapping map)
 {
        if (_grid->GetNumberRows ()) {
                _grid->DeleteRows (0, _grid->GetNumberRows ());
index 76e20ad9a2aef424783bdc7c9e5d7f15c770638d..824356a9f2008d5b18d2471d99c5fd652c8255a3 100644 (file)
@@ -29,7 +29,7 @@ class AudioMappingView : public wxPanel
 public:
        AudioMappingView (wxWindow *);
 
-       void set_mapping (AudioMapping);
+       void set (AudioMapping);
 
        boost::signals2::signal<void (AudioMapping)> Changed;
 
index d0522cf7360c5c5edfe299d61ea2a3fa5ea9e8f8..e6dd06472d924eaca5347ad640f43eef6fa3e957 100644 (file)
@@ -685,12 +685,15 @@ FilmEditor::film_content_changed (weak_ptr<Content> weak_content, int property)
                ffmpeg_content = dynamic_pointer_cast<FFmpegContent> (content);
        }
 
+       /* We can't use case {} here */
+       
        if (property == ContentProperty::START) {
                if (content) {
                        _start->set (content->start (), _film->dcp_video_frame_rate ());
                } else {
                        _start->set (0, 24);
                }
+
        } else if (property == VideoContentProperty::VIDEO_CROP) {
                checked_set (_left_crop,   video_content ? video_content->crop().left :   0);
                checked_set (_right_crop,  video_content ? video_content->crop().right :  0);
@@ -701,6 +704,8 @@ FilmEditor::film_content_changed (weak_ptr<Content> weak_content, int property)
                checked_set (_audio_gain, audio_content ? audio_content->audio_gain() : 0);
        } else if (property == AudioContentProperty::AUDIO_DELAY) {
                checked_set (_audio_delay, audio_content ? audio_content->audio_delay() : 0);
+       } else if (property == AudioContentProperty::AUDIO_MAPPING) {
+               _audio_mapping->set (audio_content ? audio_content->audio_mapping () : AudioMapping ());
        } else if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
                _subtitle_stream->Clear ();
                if (ffmpeg_content) {
@@ -846,6 +851,7 @@ FilmEditor::set_film (shared_ptr<Film> f)
        film_content_changed (boost::shared_ptr<Content> (), VideoContentProperty::VIDEO_CROP);
        film_content_changed (boost::shared_ptr<Content> (), AudioContentProperty::AUDIO_GAIN);
        film_content_changed (boost::shared_ptr<Content> (), AudioContentProperty::AUDIO_DELAY);
+       film_content_changed (boost::shared_ptr<Content> (), AudioContentProperty::AUDIO_MAPPING);
        film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAMS);
        film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAM);
        film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::AUDIO_STREAMS);
@@ -1168,6 +1174,7 @@ FilmEditor::content_selection_changed (wxListEvent &)
        film_content_changed (s, VideoContentProperty::VIDEO_CROP);
        film_content_changed (s, AudioContentProperty::AUDIO_GAIN);
        film_content_changed (s, AudioContentProperty::AUDIO_DELAY);
+       film_content_changed (s, AudioContentProperty::AUDIO_MAPPING);
        film_content_changed (s, FFmpegContentProperty::AUDIO_STREAM);
        film_content_changed (s, FFmpegContentProperty::AUDIO_STREAMS);
        film_content_changed (s, FFmpegContentProperty::SUBTITLE_STREAM);
@@ -1394,11 +1401,10 @@ FilmEditor::audio_mapping_changed (AudioMapping m)
                return;
        }
        
-       shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
-       if (!fc) {
+       shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> (c);
+       if (!ac) {
                return;
        }
 
-       /* XXX: should be general to audiocontent */
-       fc->audio_stream()->mapping = m;
+       ac->set_audio_mapping (m);
 }