#include <sstream>
+#include <libxml/uri.h>
+
#include <lrdf.h>
+#include <glibmm/miscutils.h>
+
+#include <glibmm/convert.h>
-#include <pbd/compose.h>
+#include "pbd/compose.h"
-#include <ardour/audio_library.h>
-#include <ardour/utils.h>
+#include "ardour/audio_library.h"
+#include "ardour/utils.h"
+#include "ardour/filesystem_paths.h"
#include "i18n.h"
using namespace std;
+using namespace PBD;
using namespace ARDOUR;
-static char* TAG = "http://ardour.org/ontology/Tag";
+namespace {
+ const char* const sfdb_file_name = "sfdb";
+} // anonymous namespace
+
+static const char* TAG = "http://ardour.org/ontology/Tag";
AudioLibrary::AudioLibrary ()
{
- src = "file:" + get_user_ardour_path() + "sfdb";
+ sys::path sfdb_file_path(user_config_directory ());
+
+ sfdb_file_path /= sfdb_file_name;
+
+ src = Glib::filename_to_uri (sfdb_file_path.to_string ());
// workaround for possible bug in raptor that crashes when saving to a
// non-existant file.
- touch_file(get_user_ardour_path() + "sfdb");
+
+ touch_file(sfdb_file_path.to_string());
lrdf_read_file(src.c_str());
}
}
}
-string
-AudioLibrary::path2uri (string path)
-{
- stringstream uri;
- uri << "file:" << path;
- return uri.str();
-}
-
void
AudioLibrary::set_tags (string member, vector<string> tags)
{
sort (tags.begin(), tags.end());
tags.erase (unique(tags.begin(), tags.end()), tags.end());
-
- string file_uri(path2uri(member));
-
+
+ const string file_uri(Glib::filename_to_uri (member));
+
lrdf_remove_uri_matches (file_uri.c_str());
-
+
for (vector<string>::iterator i = tags.begin(); i != tags.end(); ++i) {
lrdf_add_triple (src.c_str(), file_uri.c_str(), TAG, (*i).c_str(), lrdf_literal);
}
AudioLibrary::get_tags (string member)
{
vector<string> tags;
-
+
lrdf_statement pattern;
- pattern.subject = strdup(path2uri(member).c_str());
- pattern.predicate = TAG;
+ pattern.subject = strdup(Glib::filename_to_uri(member).c_str());
+ pattern.predicate = (char*)TAG;
pattern.object = 0;
pattern.object_type = lrdf_literal;
-
+
lrdf_statement* matches = lrdf_matches (&pattern);
free (pattern.subject);
-
+
lrdf_statement* current = matches;
while (current != 0) {
tags.push_back (current->object);
-
+
current = current->next;
}
-
+
lrdf_free_statements (matches);
-
+
sort (tags.begin(), tags.end());
-
+
return tags;
}
void
-AudioLibrary::search_members_and (vector<string>& members, const vector<string> tags)
+AudioLibrary::search_members_and (vector<string>& members, const vector<string>& tags)
{
lrdf_statement **head;
lrdf_statement* pattern = 0;
vector<string>::const_iterator i;
for (i = tags.begin(); i != tags.end(); ++i){
pattern = new lrdf_statement;
- pattern->subject = "?";
- pattern->predicate = TAG;
+ pattern->subject = (char*)"?";
+ pattern->predicate = (char*)TAG;
pattern->object = strdup((*i).c_str());
pattern->next = old;
if (*head != 0) {
lrdf_uris* ulist = lrdf_match_multi(*head);
for (uint32_t j = 0; ulist && j < ulist->count; ++j) {
-// printf("AND: %s\n", ulist->items[j]);
- members.push_back(ulist->items[j]);
+ members.push_back(Glib::filename_from_uri(ulist->items[j]));
}
lrdf_free_uris(ulist);
// memory clean up
pattern = *head;
while(pattern){
- free(pattern->predicate);
free(pattern->object);
old = pattern;
pattern = pattern->next;
delete old;
}
}
-
-bool
-AudioLibrary::safe_file_extension(string file)
-{
- return !(file.rfind(".wav") == string::npos &&
- file.rfind(".aiff")== string::npos &&
- file.rfind(".aif") == string::npos &&
- file.rfind(".snd") == string::npos &&
- file.rfind(".au") == string::npos &&
- file.rfind(".raw") == string::npos &&
- file.rfind(".sf") == string::npos &&
- file.rfind(".cdr") == string::npos &&
- file.rfind(".smp") == string::npos &&
- file.rfind(".maud")== string::npos &&
- file.rfind(".vwe") == string::npos &&
- file.rfind(".paf") == string::npos &&
-#ifdef HAVE_COREAUDIO
- file.rfind(".mp3") == string::npos &&
- file.rfind(".aac") == string::npos &&
- file.rfind(".mp4") == string::npos &&
-#endif // HAVE_COREAUDIO
- file.rfind(".voc") == string::npos);
-}