Merge branch 'master' of ssh://main.carlh.net/home/carl/git/dcpomatic
[dcpomatic.git] / src / lib / audio_mapping.cc
index ae7702998498902717b43df546c069a3e07475e3..b1810c97349e0652767e0940084b3db0b7add927 100644 (file)
@@ -17,9 +17,9 @@
 
 */
 
-#include <boost/lexical_cast.hpp>
 #include <libxml++/libxml++.h>
 #include <libcxml/cxml.h>
+#include <libdcp/raw_convert.h>
 #include "audio_mapping.h"
 #include "util.h"
 
@@ -28,9 +28,10 @@ using std::cout;
 using std::make_pair;
 using std::pair;
 using std::string;
+using std::min;
 using boost::shared_ptr;
-using boost::lexical_cast;
 using boost::dynamic_pointer_cast;
+using libdcp::raw_convert;
 
 AudioMapping::AudioMapping ()
        : _content_channels (0)
@@ -53,7 +54,7 @@ AudioMapping::setup (int c)
        
        _gain.resize (_content_channels);
        for (int i = 0; i < _content_channels; ++i) {
-               _gain[i].resize (MAX_AUDIO_CHANNELS);
+               _gain[i].resize (MAX_DCP_AUDIO_CHANNELS);
        }
 }
 
@@ -61,7 +62,7 @@ void
 AudioMapping::make_default ()
 {
        for (int i = 0; i < _content_channels; ++i) {
-               for (int j = 0; j < MAX_AUDIO_CHANNELS; ++j) {
+               for (int j = 0; j < MAX_DCP_AUDIO_CHANNELS; ++j) {
                        _gain[i][j] = 0;
                }
        }
@@ -71,7 +72,7 @@ AudioMapping::make_default ()
                set (0, libdcp::CENTRE, 1);
        } else {
                /* 1:1 mapping */
-               for (int i = 0; i < _content_channels; ++i) {
+               for (int i = 0; i < min (_content_channels, MAX_DCP_AUDIO_CHANNELS); ++i) {
                        set (i, static_cast<libdcp::Channel> (i), 1);
                }
        }
@@ -93,7 +94,7 @@ AudioMapping::AudioMapping (shared_ptr<const cxml::Node> node, int state_version
                        set (
                                (*i)->number_attribute<int> ("Content"),
                                static_cast<libdcp::Channel> ((*i)->number_attribute<int> ("DCP")),
-                               lexical_cast<float> ((*i)->content ())
+                               raw_convert<float> ((*i)->content ())
                                );
                }
        }
@@ -114,14 +115,14 @@ AudioMapping::get (int c, libdcp::Channel d) const
 void
 AudioMapping::as_xml (xmlpp::Node* node) const
 {
-       node->add_child ("ContentChannels")->add_child_text (lexical_cast<string> (_content_channels));
+       node->add_child ("ContentChannels")->add_child_text (raw_convert<string> (_content_channels));
 
        for (int c = 0; c < _content_channels; ++c) {
-               for (int d = 0; d < MAX_AUDIO_CHANNELS; ++d) {
+               for (int d = 0; d < MAX_DCP_AUDIO_CHANNELS; ++d) {
                        xmlpp::Element* t = node->add_child ("Gain");
-                       t->set_attribute ("Content", lexical_cast<string> (c));
-                       t->set_attribute ("DCP", lexical_cast<string> (d));
-                       t->add_child_text (lexical_cast<string> (get (c, static_cast<libdcp::Channel> (d))));
+                       t->set_attribute ("Content", raw_convert<string> (c));
+                       t->set_attribute ("DCP", raw_convert<string> (d));
+                       t->add_child_text (raw_convert<string> (get (c, static_cast<libdcp::Channel> (d))));
                }
        }
 }