Prepare session-metadata export to external command
authorRobin Gareus <robin@gareus.org>
Tue, 20 Nov 2018 22:56:12 +0000 (23:56 +0100)
committerRobin Gareus <robin@gareus.org>
Tue, 20 Nov 2018 22:56:12 +0000 (23:56 +0100)
libs/ardour/ardour/session_metadata.h
libs/ardour/session_metadata.cc
libs/pbd/pbd/system_exec.h
libs/pbd/system_exec.cc

index c0bfdb4003866bf32cbe40934c5913cd2160dc2f..7232d9ec5dfe41609e3318b0bb1a2a3b9d2d11a8 100644 (file)
@@ -132,6 +132,10 @@ class LIBARDOUR_API SessionMetadata : public PBD::StatefulDestructible
        void set_organization (const std::string &);
        void set_country (const std::string &);
 
+       /*** Export ***/
+       typedef std::map<std::string,std::string> MetaDataMap;
+       void av_export_tag (MetaDataMap&) const;
+
        /*** Serialization ***/
        XMLNode & get_state ();  //serializes stuff in the map, to be stored in session file
        XMLNode & get_user_state ();  //serializes stuff in the user_map, to be stored in user's config file
index 61818422cf93ed2ccf749f9bbbc1f4f85b72cd1f..fbe5222552318407caea07e1a78a72c4bce899ec 100644 (file)
@@ -647,3 +647,29 @@ SessionMetadata::set_country (const string & v)
 {
        set_value ("user_country", v);
 }
+
+void
+SessionMetadata::av_export_tag (MetaDataMap& meta) const
+{
+       if (year() > 0) {
+               std::ostringstream osstream; osstream << year();
+               meta["year"] = osstream.str();
+       }
+       if (track_number() > 0) {
+               std::ostringstream osstream; osstream << track_number();
+               meta["track"] = osstream.str();
+       }
+       if (disc_number() > 0) {
+               std::ostringstream osstream; osstream << disc_number();
+               meta["disc"] = osstream.str();
+       }
+       if (!title().empty())        { meta["title"] = title(); }
+       if (!artist().empty())       { meta["author"] = artist(); }
+       if (!album_artist().empty()) { meta["album_artist"] = album_artist(); }
+       if (!album().empty())        { meta["album"] = album(); }
+       if (!genre().empty())        { meta["genre"] = genre(); }
+       if (!composer().empty())     { meta["composer"] = composer(); }
+       if (!comment().empty())      { meta["comment"] = comment(); }
+       if (!copyright().empty())    { meta["copyright"] = copyright(); }
+       if (!subtitle().empty())     { meta["description"] = subtitle(); }
+}
index c5fb58315284e52a015821e66d1eaad88e19206f..5e543e76ae2bc7182a6e950add3942b7eb062aad 100644 (file)
@@ -118,6 +118,8 @@ class LIBPBD_API SystemExec
 
                virtual ~SystemExec ();
 
+               static char* format_key_value_parameter (std::string, std::string);
+
                std::string to_s() const;
 
                /** fork and execute the given program
index cc5d8d99fef132c9b5ec10b145c98ad0101e7a45..26f50146c8b8a2f76bbb144fece4ca600b760ea8 100644 (file)
@@ -236,6 +236,39 @@ SystemExec::SystemExec (std::string command, const std::map<char, std::string> s
        make_envp();
 }
 
+char*
+SystemExec::format_key_value_parameter (std::string key, std::string value)
+{
+       size_t start_pos = 0;
+       std::string v1 = value;
+       while((start_pos = v1.find_first_not_of(
+                       "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789(),.\"'",
+                       start_pos)) != std::string::npos)
+       {
+               v1.replace(start_pos, 1, "_");
+               start_pos += 1;
+       }
+
+       start_pos = 0;
+       while((start_pos = v1.find("\"", start_pos)) != std::string::npos) {
+               v1.replace(start_pos, 1, "\\\"");
+               start_pos += 2;
+       }
+
+       size_t len = key.length() + v1.length() + 4;
+       char *mds = (char*) calloc(len, sizeof(char));
+#ifdef PLATFORM_WINDOWS
+       /* SystemExec::make_wargs() adds quotes around the complete argument
+        * windows uses CreateProcess() with a parameter string
+        * (and not an array list of separate arguments)
+        */
+       snprintf(mds, len, "%s=%s", key.c_str(), v1.c_str());
+#else
+       snprintf(mds, len, "%s=\"%s\"", key.c_str(), v1.c_str());
+#endif
+       return mds;
+}
+
 void
 SystemExec::make_argp_escaped(std::string command, const std::map<char, std::string> subs)
 {