2 Copyright (C) 2003-2006 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <libxml/uri.h>
26 #include <glibmm/convert.h>
28 #include <pbd/compose.h>
30 #include <ardour/audio_library.h>
31 #include <ardour/utils.h>
32 #include <ardour/filesystem_paths.h>
37 using namespace ARDOUR;
40 const char* const sfdb_file_name = "sfdb";
41 } // anonymous namespace
43 static char* TAG = "http://ardour.org/ontology/Tag";
45 AudioLibrary::AudioLibrary ()
47 sys::path sfdb_file_path(user_config_directory ());
49 sfdb_file_path /= sfdb_file_name;
51 src = Glib::filename_to_uri (sfdb_file_path.to_string ());
53 // workaround for possible bug in raptor that crashes when saving to a
55 touch_file(sfdb_file_path.to_string());
57 lrdf_read_file(src.c_str());
60 AudioLibrary::~AudioLibrary ()
65 AudioLibrary::save_changes ()
67 if (lrdf_export_by_source(src.c_str(), src.substr(5).c_str())) {
68 PBD::warning << string_compose(_("Could not open %1. Audio Library not saved"), src) << endmsg;
73 AudioLibrary::uri2path (string uri)
75 string path = xmlURIUnescapeString(uri.c_str(), 0, 0);
76 return path.substr(5);
80 AudioLibrary::set_tags (string member, vector<string> tags)
82 sort (tags.begin(), tags.end());
83 tags.erase (unique(tags.begin(), tags.end()), tags.end());
85 const string file_uri(Glib::filename_to_uri (member));
87 lrdf_remove_uri_matches (file_uri.c_str());
89 for (vector<string>::iterator i = tags.begin(); i != tags.end(); ++i) {
90 lrdf_add_triple (src.c_str(), file_uri.c_str(), TAG, (*i).c_str(), lrdf_literal);
95 AudioLibrary::get_tags (string member)
99 lrdf_statement pattern;
100 pattern.subject = strdup(Glib::filename_to_uri(member).c_str());
101 pattern.predicate = TAG;
103 pattern.object_type = lrdf_literal;
105 lrdf_statement* matches = lrdf_matches (&pattern);
106 free (pattern.subject);
108 lrdf_statement* current = matches;
109 while (current != 0) {
110 tags.push_back (current->object);
112 current = current->next;
115 lrdf_free_statements (matches);
117 sort (tags.begin(), tags.end());
123 AudioLibrary::search_members_and (vector<string>& members, const vector<string> tags)
125 lrdf_statement **head;
126 lrdf_statement* pattern = 0;
127 lrdf_statement* old = 0;
130 vector<string>::const_iterator i;
131 for (i = tags.begin(); i != tags.end(); ++i){
132 pattern = new lrdf_statement;
133 pattern->subject = "?";
134 pattern->predicate = TAG;
135 pattern->object = strdup((*i).c_str());
142 lrdf_uris* ulist = lrdf_match_multi(*head);
143 for (uint32_t j = 0; ulist && j < ulist->count; ++j) {
144 // cerr << "AND: " << uri2path(ulist->items[j]) << endl;
145 members.push_back(uri2path(ulist->items[j]));
147 lrdf_free_uris(ulist);
149 sort(members.begin(), members.end());
150 unique(members.begin(), members.end());
156 free(pattern->object);
158 pattern = pattern->next;