Emit no audio from DCPs if none is mapped
[dcpomatic.git] / src / lib / util.cc
index 71aee88fea6330f4187103bae99c7c88370cb652..fdc647fbab8c9506bc9a2ee4cc7894b44a341982 100644 (file)
@@ -46,7 +46,6 @@
 #include "ratio.h"
 #include "rect.h"
 #include "render_text.h"
-#include "scope_guard.h"
 #include "string_text.h"
 #include "text_decoder.h"
 #include "util.h"
@@ -58,6 +57,7 @@
 #include <dcp/locale_convert.h>
 #include <dcp/picture_asset.h>
 #include <dcp/raw_convert.h>
+#include <dcp/scope_guard.h>
 #include <dcp/sound_asset.h>
 #include <dcp/subtitle_asset.h>
 #include <dcp/util.h>
@@ -470,7 +470,7 @@ LIBDCP_ENABLE_WARNINGS
        vector<StringText> subs;
        dcp::SubtitleString ss(
                optional<string>(), false, false, false, dcp::Colour(), 42, 1, dcp::Time(), dcp::Time(), 0, dcp::HAlign::CENTER, 0, dcp::VAlign::CENTER, 0, dcp::Direction::LTR,
-               "Hello dolly", dcp::Effect::NONE, dcp::Colour(), dcp::Time(), dcp::Time(), 0
+               "Hello dolly", dcp::Effect::NONE, dcp::Colour(), dcp::Time(), dcp::Time(), 0, std::vector<dcp::Ruby>()
                );
        subs.push_back(StringText(ss, 0, make_shared<dcpomatic::Font>("foo"), dcp::SubtitleStandard::SMPTE_2014));
        render_text (subs, dcp::Size(640, 480), DCPTime(), 24);
@@ -598,6 +598,7 @@ digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
 string
 simple_digest (vector<boost::filesystem::path> paths)
 {
+       DCP_ASSERT(!paths.empty());
        return digest_head_tail(paths, 1000000) + raw_convert<string>(dcp::filesystem::file_size(paths.front()));
 }
 
@@ -839,6 +840,8 @@ audio_channel_types (list<int> mapped, int channels)
                case dcp::Channel::BSR:
                        ++non_lfe;
                        break;
+               case dcp::Channel::LC:
+               case dcp::Channel::RC:
                case dcp::Channel::HI:
                case dcp::Channel::VI:
                case dcp::Channel::MOTION_DATA:
@@ -1094,7 +1097,7 @@ word_wrap(string input, int columns)
        icu::Locale locale;
        UErrorCode status = U_ZERO_ERROR;
        auto iter = icu::BreakIterator::createLineInstance(locale, status);
-       ScopeGuard sg = [iter]() { delete iter; };
+       dcp::ScopeGuard sg = [iter]() { delete iter; };
        if (U_FAILURE(status)) {
                return input;
        }
@@ -1122,3 +1125,31 @@ word_wrap(string input, int columns)
        return output;
 }
 
+
+string
+screen_names_to_string(vector<string> names)
+{
+       if (names.empty()) {
+               return {};
+       }
+
+       auto number = [](string const& s) {
+               return s.find_first_not_of("0123456789") == string::npos;
+       };
+
+       if (std::find_if(names.begin(), names.end(), [number](string const& s) { return !number(s); }) == names.end()) {
+               std::sort(names.begin(), names.end(), [](string const& a, string const& b) {
+                       return dcp::raw_convert<int>(a) < dcp::raw_convert<int>(b);
+               });
+       } else {
+               std::sort(names.begin(), names.end());
+       }
+
+       string result;
+       for (auto const& name: names) {
+               result += name + ", ";
+       }
+
+       return result.substr(0, result.length() - 2);
+}
+