Basics of custom DCP filename components.
[dcpomatic.git] / src / lib / util.cc
index 92b3b22fd1cd72096e96d5dece3e23bea23d20b5..09f32dfda5d4b541fe5c4874a041fc47aeb6f3bf 100644 (file)
@@ -35,8 +35,8 @@
 #include "rect.h"
 #include "digester.h"
 #include "audio_processor.h"
-#include "safe_stringstream.h"
 #include "compose.hpp"
+#include <locked_sstream.h>
 #include <dcp/util.h>
 #include <dcp/picture_asset.h>
 #include <dcp/sound_asset.h>
@@ -46,6 +46,9 @@ extern "C" {
 #include <libavcodec/avcodec.h>
 }
 #include <curl/curl.h>
+#ifdef DCPOMATIC_GRAPHICS_MAGICK
+#include <Magick++.h>
+#endif
 #include <glib.h>
 #include <pangomm/init.h>
 #include <boost/algorithm/string.hpp>
@@ -112,7 +115,7 @@ seconds_to_hms (int s)
        int h = m / 60;
        m -= (h * 60);
 
-       SafeStringStream hms;
+       locked_stringstream hms;
        hms << h << N_(":");
        hms.width (2);
        hms << setfill ('0') << m << N_(":");
@@ -133,11 +136,11 @@ seconds_to_approximate_hms (int s)
        int h = m / 60;
        m -= (h * 60);
 
-       SafeStringStream ap;
+       locked_stringstream ap;
 
        bool const hours = h > 0;
-       bool const minutes = h < 10 && m > 0;
-       bool const seconds = m < 10 && s > 0;
+       bool const minutes = h < 6 && m > 0;
+       bool const seconds = h == 0 && m < 10 && s > 0;
 
        if (hours) {
                if (m > 30 && !minutes) {
@@ -148,7 +151,7 @@ seconds_to_approximate_hms (int s)
                        ap << h << _("h");
                }
 
-               if (minutes | seconds) {
+               if (minutes || seconds) {
                        ap << N_(" ");
                }
        }
@@ -346,6 +349,10 @@ dcpomatic_setup ()
 
        curl_global_init (CURL_GLOBAL_ALL);
 
+#ifdef DCPOMATIC_GRAPHICS_MAGICK
+       Magick::InitializeMagick (0);
+#endif
+
        ui_thread = boost::this_thread::get_id ();
 }
 
@@ -612,13 +619,19 @@ split_get_request (string url)
 string
 video_asset_filename (shared_ptr<dcp::PictureAsset> asset)
 {
-       return "j2c_" + asset->id() + ".mxf";
+       dcp::NameFormat::Map values;
+       values["type"] = "j2c";
+       values["id"] = asset->id();
+       return Config::instance()->dcp_filename_format().get(values) + ".mxf";
 }
 
 string
 audio_asset_filename (shared_ptr<dcp::SoundAsset> asset)
 {
-       return "pcm_" + asset->id() + ".mxf";
+       dcp::NameFormat::Map values;
+       values["type"] = "pcm";
+       values["id"] = asset->id();
+       return Config::instance()->dcp_filename_format().get(values) + ".mxf";
 }
 
 float