From: Carl Hetherington Date: Mon, 20 May 2013 15:21:55 +0000 (+0100) Subject: Some basics of AudioMapping. X-Git-Tag: v2.0.48~1337^2~371 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=0c66eaeac227d6aeb63a7a36e202ef87081dc222 Some basics of AudioMapping. --- diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc index 9968f4725..e38d9d265 100644 --- a/src/lib/audio_content.cc +++ b/src/lib/audio_content.cc @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2013 Carl Hetherington @@ -35,7 +37,6 @@ AudioContent::AudioContent (boost::filesystem::path f) AudioContent::AudioContent (shared_ptr node) : Content (node) { - } AudioContent::AudioContent (AudioContent const & o) @@ -43,3 +44,9 @@ AudioContent::AudioContent (AudioContent const & o) { } + +void +AudioContent::as_xml (xmlpp::Node* node) const +{ + +} diff --git a/src/lib/audio_content.h b/src/lib/audio_content.h index 87858488c..51f05efb0 100644 --- a/src/lib/audio_content.h +++ b/src/lib/audio_content.h @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2013 Carl Hetherington @@ -21,7 +23,7 @@ #define DCPOMATIC_AUDIO_CONTENT_H #include "content.h" -#include "util.h" +#include "audio_mapping.h" namespace cxml { class Node; @@ -42,10 +44,13 @@ public: AudioContent (boost::shared_ptr); AudioContent (AudioContent const &); + void as_xml (xmlpp::Node *) const; + virtual int audio_channels () const = 0; virtual ContentAudioFrame audio_length () const = 0; virtual int content_audio_frame_rate () const = 0; virtual int output_audio_frame_rate (boost::shared_ptr) const = 0; + virtual AudioMapping audio_mapping () const = 0; }; #endif diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index e1fa0c220..d0aa33657 100644 --- a/src/lib/audio_mapping.cc +++ b/src/lib/audio_mapping.cc @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2013 Carl Hetherington @@ -18,6 +20,7 @@ */ #include +#include #include #include "audio_mapping.h" @@ -30,23 +33,39 @@ using boost::shared_ptr; using boost::lexical_cast; using boost::dynamic_pointer_cast; -void -AudioMapping::add (int c, libdcp::Channel d) +AudioMapping::AudioMapping () { - _content_to_dcp.push_back (make_pair (c, d)); + } -/* XXX: this is grotty */ -int -AudioMapping::dcp_channels () const +/** Create a default AudioMapping for a given channel count. + * @param c Number of channels. + */ +AudioMapping::AudioMapping (int c) { - for (list >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) { - if (((int) i->second) >= 2) { - return 6; + if (c == 1) { + /* Mono -> Centre */ + add (0, libdcp::CENTRE); + } else { + /* 1:1 mapping */ + for (int i = 0; i < c; ++i) { + add (i, static_cast (i)); } } +} + +AudioMapping::AudioMapping (shared_ptr node) +{ + list > const c = node->node_children ("Map"); + for (list >::const_iterator i = c.begin(); i != c.end(); ++i) { + add ((*i)->number_child ("ContentIndex"), static_cast ((*i)->number_child ("DCP"))); + } +} - return 2; +void +AudioMapping::add (int c, libdcp::Channel d) +{ + _content_to_dcp.push_back (make_pair (c, d)); } list @@ -97,12 +116,3 @@ AudioMapping::as_xml (xmlpp::Node* node) const t->add_child ("DCP")->add_child_text (lexical_cast (i->second)); } } - -void -AudioMapping::set_from_xml (shared_ptr node) -{ - list > const c = node->node_children ("Map"); - for (list >::const_iterator i = c.begin(); i != c.end(); ++i) { - add ((*i)->number_child ("ContentIndex"), static_cast ((*i)->number_child ("DCP"))); - } -} diff --git a/src/lib/audio_mapping.h b/src/lib/audio_mapping.h index 3c471d3f4..7d76e4f5a 100644 --- a/src/lib/audio_mapping.h +++ b/src/lib/audio_mapping.h @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2013 Carl Hetherington @@ -21,20 +23,28 @@ #define DCPOMATIC_AUDIO_MAPPING_H #include -#include #include #include -#include "audio_content.h" + +namespace xmlpp { + class Node; +} + +namespace cxml { + class Node; +} class AudioMapping { public: + AudioMapping (); + AudioMapping (int); + AudioMapping (boost::shared_ptr); + void as_xml (xmlpp::Node *) const; - void set_from_xml (boost::shared_ptr); void add (int, libdcp::Channel); - int dcp_channels () const; std::list dcp_to_content (libdcp::Channel) const; std::list > content_to_dcp () const { return _content_to_dcp; diff --git a/src/lib/content.h b/src/lib/content.h index 9f465570b..8db35891a 100644 --- a/src/lib/content.h +++ b/src/lib/content.h @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2013 Carl Hetherington diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index f0df15193..d730f3ecb 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2013 Carl Hetherington @@ -88,6 +90,7 @@ FFmpegContent::as_xml (xmlpp::Node* node) const node->add_child("Type")->add_child_text ("FFmpeg"); Content::as_xml (node); VideoContent::as_xml (node); + AudioContent::as_xml (node); boost::mutex::scoped_lock lm (_mutex); @@ -263,6 +266,7 @@ operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b) } FFmpegAudioStream::FFmpegAudioStream (shared_ptr node) + : mapping (node->node_child ("Mapping")) { name = node->string_child ("Name"); id = node->number_child ("Id"); @@ -277,6 +281,7 @@ FFmpegAudioStream::as_xml (xmlpp::Node* root) const root->add_child("Id")->add_child_text (lexical_cast (id)); root->add_child("FrameRate")->add_child_text (lexical_cast (frame_rate)); root->add_child("Channels")->add_child_text (lexical_cast (channels)); + mapping.as_xml (root->add_child("Mapping")); } /** Construct a SubtitleStream from a value returned from to_string(). @@ -308,3 +313,13 @@ FFmpegContent::length (shared_ptr film) const FrameRateConversion frc (video_frame_rate (), film->dcp_video_frame_rate ()); return video_length() * frc.factor() * TIME_HZ / film->dcp_video_frame_rate (); } + +AudioMapping +FFmpegContent::audio_mapping () const +{ + if (!_audio_stream) { + return AudioMapping (); + } + + return _audio_stream->mapping; +} diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h index 540df041f..d26c73125 100644 --- a/src/lib/ffmpeg_content.h +++ b/src/lib/ffmpeg_content.h @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2013 Carl Hetherington @@ -32,6 +34,7 @@ public: , id (i) , frame_rate (f) , channels (c) + , mapping (c) {} FFmpegAudioStream (boost::shared_ptr); @@ -42,6 +45,7 @@ public: int id; int frame_rate; int channels; + AudioMapping mapping; }; extern bool operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b); @@ -96,6 +100,7 @@ public: ContentAudioFrame audio_length () const; int content_audio_frame_rate () const; int output_audio_frame_rate (boost::shared_ptr) const; + AudioMapping audio_mapping () const; std::vector subtitle_streams () const { boost::mutex::scoped_lock lm (_mutex); diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index e99a960ce..adf16c940 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -143,7 +143,7 @@ FFmpegDecoder::setup_general () _audio_streams.push_back ( FFmpegAudioStream (stream_name (s), i, s->codec->sample_rate, s->codec->channels) ); - + } else if (s->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { _subtitle_streams.push_back (FFmpegSubtitleStream (stream_name (s), i)); } diff --git a/src/lib/film.h b/src/lib/film.h index cfc55c0ac..03d472cee 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -154,7 +154,6 @@ public: J2K_BANDWIDTH, DCI_METADATA, DCP_VIDEO_FRAME_RATE, - AUDIO_MAPPING }; @@ -322,7 +321,6 @@ private: void read_metadata (); void playlist_changed (); void playlist_content_changed (boost::weak_ptr, int); - void setup_default_audio_mapping (); std::string filename_safe_name () const; /** Log to write to */ diff --git a/src/lib/sndfile_content.cc b/src/lib/sndfile_content.cc index 210ca1577..963abb58e 100644 --- a/src/lib/sndfile_content.cc +++ b/src/lib/sndfile_content.cc @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2013 Carl Hetherington @@ -48,6 +50,7 @@ SndfileContent::SndfileContent (shared_ptr node) _audio_channels = node->number_child ("AudioChannels"); _audio_length = node->number_child ("AudioLength"); _audio_frame_rate = node->number_child ("AudioFrameRate"); + _mapping = AudioMapping (node->node_child ("Mapping")); } string @@ -103,6 +106,7 @@ SndfileContent::examine (shared_ptr film, shared_ptr job, bool quick) _audio_channels = dec.audio_channels (); _audio_length = dec.audio_length (); _audio_frame_rate = dec.audio_frame_rate (); + _mapping = AudioMapping (_audio_channels); } signal_changed (AudioContentProperty::AUDIO_CHANNELS); @@ -118,6 +122,7 @@ SndfileContent::as_xml (xmlpp::Node* node) const node->add_child("AudioChannels")->add_child_text (lexical_cast (_audio_channels)); node->add_child("AudioLength")->add_child_text (lexical_cast (_audio_length)); node->add_child("AudioFrameRate")->add_child_text (lexical_cast (_audio_frame_rate)); + _mapping.as_xml (node->add_child("Mapping")); } int diff --git a/src/lib/sndfile_content.h b/src/lib/sndfile_content.h index 0623aa6f0..e0d66b992 100644 --- a/src/lib/sndfile_content.h +++ b/src/lib/sndfile_content.h @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2013 Carl Hetherington @@ -61,10 +63,16 @@ public: int output_audio_frame_rate (boost::shared_ptr) const; + AudioMapping audio_mapping () const { + boost::mutex::scoped_lock lm (_mutex); + return _mapping; + } + static bool valid_file (boost::filesystem::path); private: int _audio_channels; ContentAudioFrame _audio_length; int _audio_frame_rate; + AudioMapping _mapping; }; diff --git a/src/wx/audio_mapping_view.cc b/src/wx/audio_mapping_view.cc index 10157eb2c..8d049e05f 100644 --- a/src/wx/audio_mapping_view.cc +++ b/src/wx/audio_mapping_view.cc @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2013 Carl Hetherington diff --git a/src/wx/audio_mapping_view.h b/src/wx/audio_mapping_view.h index 36429412f..9385f492d 100644 --- a/src/wx/audio_mapping_view.h +++ b/src/wx/audio_mapping_view.h @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2013 Carl Hetherington @@ -20,6 +22,7 @@ #include #include #include +#include "lib/audio_mapping.h" class AudioMappingView : public wxPanel { diff --git a/src/wx/ffmpeg_content_dialog.cc b/src/wx/ffmpeg_content_dialog.cc index 0949d02a6..762ec3774 100644 --- a/src/wx/ffmpeg_content_dialog.cc +++ b/src/wx/ffmpeg_content_dialog.cc @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2013 Carl Hetherington @@ -21,6 +23,7 @@ #include "lib/ffmpeg_content.h" #include "ffmpeg_content_dialog.h" #include "wx_util.h" +#include "audio_mapping_view.h" using std::vector; using std::string; @@ -44,6 +47,10 @@ FFmpegContentDialog::FFmpegContentDialog (wxWindow* parent, shared_ptrAdd (_subtitle_stream, 1, wxEXPAND | wxALL, 6); grid->AddSpacer (0); + _audio_mapping = new AudioMappingView (this); + grid->Add (_audio_mapping, 1, wxEXPAND | wxALL, 6); + grid->AddSpacer (0); + _audio_stream->Clear (); vector a = content->audio_streams (); for (vector::iterator i = a.begin(); i != a.end(); ++i) { @@ -69,6 +76,8 @@ FFmpegContentDialog::FFmpegContentDialog (wxWindow* parent, shared_ptrSetSelection (wxNOT_FOUND); } + _audio_mapping->set_mapping (content->audio_mapping ()); + wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL); overall_sizer->Add (grid, 1, wxEXPAND | wxALL, 6); diff --git a/src/wx/ffmpeg_content_dialog.h b/src/wx/ffmpeg_content_dialog.h index 5251ad5da..a04645f69 100644 --- a/src/wx/ffmpeg_content_dialog.h +++ b/src/wx/ffmpeg_content_dialog.h @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2013 Carl Hetherington @@ -23,6 +25,7 @@ class wxSpinCtrl; class FFmpegContent; +class AudioMappingView; class FFmpegContentDialog : public wxDialog { @@ -37,4 +40,5 @@ private: wxChoice* _audio_stream; wxStaticText* _audio_description; wxChoice* _subtitle_stream; + AudioMappingView* _audio_mapping; }; diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc index 73c52945b..d96d146f9 100644 --- a/src/wx/film_editor.cc +++ b/src/wx/film_editor.cc @@ -53,7 +53,6 @@ #include "audio_dialog.h" #include "imagemagick_content_dialog.h" #include "ffmpeg_content_dialog.h" -#include "audio_mapping_view.h" #include "timeline_dialog.h" using std::string; @@ -401,9 +400,6 @@ FilmEditor::make_audio_panel () grid->Add (s); } - _audio_mapping = new AudioMappingView (_audio_panel); - _audio_sizer->Add (_audio_mapping, 1, wxEXPAND | wxALL, 6); - _audio_gain->SetRange (-60, 60); _audio_delay->SetRange (-1000, 1000); } @@ -864,7 +860,6 @@ FilmEditor::set_film (shared_ptr f) film_changed (Film::J2K_BANDWIDTH); film_changed (Film::DCI_METADATA); film_changed (Film::DCP_VIDEO_FRAME_RATE); - film_changed (Film::AUDIO_MAPPING); film_content_changed (boost::shared_ptr (), FFmpegContentProperty::SUBTITLE_STREAMS); film_content_changed (boost::shared_ptr (), FFmpegContentProperty::SUBTITLE_STREAM); diff --git a/src/wx/film_editor.h b/src/wx/film_editor.h index c791ad064..4bdba9979 100644 --- a/src/wx/film_editor.h +++ b/src/wx/film_editor.h @@ -33,7 +33,6 @@ class wxListCtrl; class wxListEvent; class Film; class AudioDialog; -class AudioMappingView; class TimelineDialog; /** @class FilmEditor @@ -159,7 +158,6 @@ private: wxButton* _audio_gain_calculate_button; wxButton* _show_audio; wxSpinCtrl* _audio_delay; - AudioMappingView* _audio_mapping; wxCheckBox* _with_subtitles; wxSpinCtrl* _subtitle_offset; wxSpinCtrl* _subtitle_scale; diff --git a/src/wx/properties_dialog.cc b/src/wx/properties_dialog.cc index 40527ded7..1e0641ac4 100644 --- a/src/wx/properties_dialog.cc +++ b/src/wx/properties_dialog.cc @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ + /* Copyright (C) 2012 Carl Hetherington