Make "Add folder..." to accept a directory of WAV files (#942).
[dcpomatic.git] / src / lib / util.cc
index 523706deccab4d9e19072d57a74eb88297356cf2..3f0c34a15004a9da88806366bee51967278700d5 100644 (file)
@@ -53,6 +53,7 @@ extern "C" {
 #include <glib.h>
 #include <pangomm/init.h>
 #include <boost/algorithm/string.hpp>
+#include <boost/range/algorithm/replace_if.hpp>
 #include <boost/thread.hpp>
 #include <boost/filesystem.hpp>
 #ifdef DCPOMATIC_WINDOWS
@@ -515,7 +516,8 @@ short_audio_channel_name (int c)
 
        /// TRANSLATORS: these are short names of audio channels; Lfe is the low-frequency
        /// enhancement channel (sub-woofer).  HI is the hearing-impaired audio track and
-       /// VI is the visually-impaired audio track (audio describe).
+       /// VI is the visually-impaired audio track (audio describe).  DBP is the D-BOX
+       /// primary channel and DBS is the D-BOX secondary channel.
        string const channels[] = {
                _("L"),
                _("R"),
@@ -531,8 +533,8 @@ short_audio_channel_name (int c)
                _("BsR"),
                _("DBP"),
                _("DBS"),
-               _(""),
-               _("")
+               "",
+               ""
        };
 
        return channels[c];
@@ -555,6 +557,18 @@ valid_image_file (boost::filesystem::path f)
                );
 }
 
+bool
+valid_sound_file (boost::filesystem::path f)
+{
+       if (boost::starts_with (f.leaf().string(), "._")) {
+               return false;
+       }
+
+       string ext = f.extension().string();
+       transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
+       return (ext == ".wav" || ext == ".mp3" || ext == ".aif" || ext == ".aiff");
+}
+
 bool
 valid_j2k_file (boost::filesystem::path f)
 {
@@ -566,16 +580,8 @@ valid_j2k_file (boost::filesystem::path f)
 string
 tidy_for_filename (string f)
 {
-       string t;
-       for (size_t i = 0; i < f.length(); ++i) {
-               if (isalnum (f[i]) || f[i] == '_' || f[i] == '-') {
-                       t += f[i];
-               } else {
-                       t += '_';
-               }
-       }
-
-       return t;
+       boost::replace_if (f, boost::is_any_of ("\\/:"), '_');
+       return f;
 }
 
 dcp::Size
@@ -681,9 +687,3 @@ relaxed_string_to_float (string s)
                return lexical_cast<float> (s);
        }
 }
-
-bool
-string_not_empty (string s)
-{
-       return !s.empty ();
-}