From 8750efb9e072cf3b42e6c3c29521c7031c0b5dfd Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 6 Apr 2013 14:42:08 +0100 Subject: Basics of content dialogs. --- src/lib/audio_mapping.cc | 103 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/lib/audio_mapping.cc (limited to 'src/lib/audio_mapping.cc') diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc new file mode 100644 index 000000000..3fc423e10 --- /dev/null +++ b/src/lib/audio_mapping.cc @@ -0,0 +1,103 @@ +/* + Copyright (C) 2013 Carl Hetherington + + This program 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, + 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. + +*/ + +#include "audio_mapping.h" + +using std::map; +using boost::optional; + +AutomaticAudioMapping::AutomaticAudioMapping (int c) + : _source_channels (c) +{ + +} + +optional +AutomaticAudioMapping::source_to_dcp (int c) const +{ + if (c >= _source_channels) { + return optional (); + } + + if (_source_channels == 1) { + /* mono sources to centre */ + return libdcp::CENTRE; + } + + return static_cast (c); +} + +optional +AutomaticAudioMapping::dcp_to_source (libdcp::Channel c) const +{ + if (_source_channels == 1) { + if (c == libdcp::CENTRE) { + return 0; + } else { + return optional (); + } + } + + if (static_cast (c) >= _source_channels) { + return optional (); + } + + return static_cast (c); +} + +int +AutomaticAudioMapping::dcp_channels () const +{ + if (_source_channels == 1) { + /* The source is mono, so to put the mono channel into + the centre we need to generate a 5.1 soundtrack. + */ + return 6; + } + + return _source_channels; +} + +optional +ConfiguredAudioMapping::dcp_to_source (libdcp::Channel c) const +{ + map::const_iterator i = _source_to_dcp.begin (); + while (i != _source_to_dcp.end() && i->second != c) { + ++i; + } + + if (i == _source_to_dcp.end ()) { + return boost::none; + } + + return i->first; +} + +optional +ConfiguredAudioMapping::source_to_dcp (int c) const +{ + map::const_iterator i = _source_to_dcp.find (c); + if (i == _source_to_dcp.end ()) { + return boost::none; + } + + return i->second; +} + + -- cgit v1.2.3