summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-11-23 00:24:09 +0000
committerCarl Hetherington <cth@carlh.net>2018-11-23 00:24:09 +0000
commite13e5cd4cfda39b0a0b77ed8036e14e15f93ec2e (patch)
tree7580c93f98c2afbebdc0915b5ed9a000be533cbb /src/lib
parentdf30165f29beb41078b1a17894ee1ef5327abc20 (diff)
Move make_default into AudioMapping.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/audio_mapping.cc50
-rw-r--r--src/lib/audio_mapping.h3
-rw-r--r--src/lib/dcp_content.cc2
-rw-r--r--src/lib/ffmpeg_content.cc2
-rw-r--r--src/lib/film.cc49
-rw-r--r--src/lib/film.h5
6 files changed, 54 insertions, 57 deletions
diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc
index bf454b5e5..86add09f4 100644
--- a/src/lib/audio_mapping.cc
+++ b/src/lib/audio_mapping.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -21,9 +21,11 @@
#include "audio_mapping.h"
#include "util.h"
#include "digester.h"
+#include "audio_processor.h"
#include <dcp/raw_convert.h>
#include <libcxml/cxml.h>
#include <libxml++/libxml++.h>
+#include <boost/regex.hpp>
#include <iostream>
using std::list;
@@ -36,6 +38,7 @@ using std::vector;
using std::abs;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
+using boost::optional;
using dcp::raw_convert;
AudioMapping::AudioMapping ()
@@ -78,6 +81,51 @@ AudioMapping::make_zero ()
}
}
+void
+AudioMapping::make_default (AudioProcessor const * processor, optional<boost::filesystem::path> filename)
+{
+ static string const regex[] = {
+ ".*[\\._-]L[\\._-].*",
+ ".*[\\._-]R[\\._-].*",
+ ".*[\\._-]C[\\._-].*",
+ ".*[\\._-]Lfe[\\._-].*",
+ ".*[\\._-]Ls[\\._-].*",
+ ".*[\\._-]Rs[\\._-].*"
+ };
+
+ static int const regexes = sizeof(regex) / sizeof(*regex);
+
+ if (processor) {
+ processor->make_audio_mapping_default (*this);
+ } else {
+ make_zero ();
+ if (input_channels() == 1) {
+ bool guessed = false;
+
+ /* See if we can guess where this stream should go */
+ if (filename) {
+ for (int i = 0; i < regexes; ++i) {
+ boost::regex e (regex[i], boost::regex::icase);
+ if (boost::regex_match(filename->string(), e) && i < output_channels()) {
+ set (0, i, 1);
+ guessed = true;
+ }
+ }
+ }
+
+ if (!guessed) {
+ /* If we have no idea, just put it on centre */
+ set (0, static_cast<int>(dcp::CENTRE), 1);
+ }
+ } else {
+ /* 1:1 mapping */
+ for (int i = 0; i < min (input_channels(), output_channels()); ++i) {
+ set (i, i, 1);
+ }
+ }
+ }
+}
+
AudioMapping::AudioMapping (cxml::ConstNodePtr node, int state_version)
{
if (state_version < 32) {
diff --git a/src/lib/audio_mapping.h b/src/lib/audio_mapping.h
index 1a3c16ef9..8add0ec83 100644
--- a/src/lib/audio_mapping.h
+++ b/src/lib/audio_mapping.h
@@ -32,6 +32,8 @@ namespace xmlpp {
class Node;
}
+class AudioProcessor;
+
/** @class AudioMapping.
* @brief A many-to-many mapping of audio channels.
*/
@@ -47,6 +49,7 @@ public:
void as_xml (xmlpp::Node *) const;
void make_zero ();
+ void make_default (AudioProcessor const * processor, boost::optional<boost::filesystem::path> filename = boost::optional<boost::filesystem::path>());
void set (int input_channel, int output_channel, float);
float get (int input_channel, int output_channel) const;
diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc
index b455e7f7f..c89eadc3c 100644
--- a/src/lib/dcp_content.cc
+++ b/src/lib/dcp_content.cc
@@ -212,7 +212,7 @@ DCPContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
AudioStreamPtr as (new AudioStream (examiner->audio_frame_rate(), examiner->audio_length(), examiner->audio_channels()));
audio->set_stream (as);
AudioMapping m = as->mapping ();
- film->make_audio_mapping_default (m);
+ m.make_default (film->audio_processor());
as->set_mapping (m);
}
diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc
index 34a6e1444..919200679 100644
--- a/src/lib/ffmpeg_content.cc
+++ b/src/lib/ffmpeg_content.cc
@@ -307,7 +307,7 @@ FFmpegContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
AudioStreamPtr as = audio->streams().front();
AudioMapping m = as->mapping ();
- film->make_audio_mapping_default (m, first_path);
+ m.make_default (film->audio_processor(), first_path);
as->set_mapping (m);
}
diff --git a/src/lib/film.cc b/src/lib/film.cc
index 60b80d052..d27b15a65 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -1438,55 +1438,6 @@ Film::subtitle_language () const
return all;
}
-/** Change the gains of the supplied AudioMapping to make it a default
- * for this film. The defaults are guessed based on what processor (if any)
- * is in use, the number of input channels and any filename supplied.
- */
-void
-Film::make_audio_mapping_default (AudioMapping& mapping, optional<boost::filesystem::path> filename) const
-{
- static string const regex[] = {
- ".*[\\._-]L[\\._-].*",
- ".*[\\._-]R[\\._-].*",
- ".*[\\._-]C[\\._-].*",
- ".*[\\._-]Lfe[\\._-].*",
- ".*[\\._-]Ls[\\._-].*",
- ".*[\\._-]Rs[\\._-].*"
- };
-
- static int const regexes = sizeof(regex) / sizeof(*regex);
-
- if (audio_processor ()) {
- audio_processor()->make_audio_mapping_default (mapping);
- } else {
- mapping.make_zero ();
- if (mapping.input_channels() == 1) {
- bool guessed = false;
-
- /* See if we can guess where this stream should go */
- if (filename) {
- for (int i = 0; i < regexes; ++i) {
- boost::regex e (regex[i], boost::regex::icase);
- if (boost::regex_match (filename->string(), e) && i < mapping.output_channels()) {
- mapping.set (0, i, 1);
- guessed = true;
- }
- }
- }
-
- if (!guessed) {
- /* If we have no idea, just put it on centre */
- mapping.set (0, static_cast<int> (dcp::CENTRE), 1);
- }
- } else {
- /* 1:1 mapping */
- for (int i = 0; i < min (mapping.input_channels(), mapping.output_channels()); ++i) {
- mapping.set (i, i, 1);
- }
- }
- }
-}
-
/** @return The names of the channels that audio contents' outputs are passed into;
* this is either the DCP or a AudioProcessor.
*/
diff --git a/src/lib/film.h b/src/lib/film.h
index 4656da9de..3fb24af93 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -155,11 +155,6 @@ public:
std::string subtitle_language () const;
- void make_audio_mapping_default (
- AudioMapping & mapping,
- boost::optional<boost::filesystem::path> filename = boost::optional<boost::filesystem::path> ()
- ) const;
-
std::vector<std::string> audio_output_names () const;
void repeat_content (ContentList, int);