2 * Copyright (C) 2005-2007 Taybin Rutkin <taybin@taybin.com>
3 * Copyright (C) 2005-2016 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2006-2015 Tim Mayberry <mojofunk@gmail.com>
5 * Copyright (C) 2007-2010 David Robillard <d@drobilla.net>
6 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "libardour-config.h"
29 #include <libxml/uri.h>
35 #include <glibmm/miscutils.h>
37 #include <glibmm/convert.h>
39 #include "pbd/compose.h"
40 #include "pbd/error.h"
41 #include "pbd/file_utils.h"
43 #include "ardour/audio_library.h"
44 #include "ardour/filesystem_paths.h"
50 using namespace ARDOUR;
53 const char* const sfdb_file_name = "sfdb";
54 } // anonymous namespace
56 static const char* TAG = "http://ardour.org/ontology/Tag";
58 AudioLibrary::AudioLibrary ()
60 std::string sfdb_file_path(user_config_directory ());
62 sfdb_file_path = Glib::build_filename (sfdb_file_path, sfdb_file_name);
64 src = Glib::filename_to_uri (sfdb_file_path);
66 // workaround for possible bug in raptor that crashes when saving to a
69 touch_file(sfdb_file_path);
72 lrdf_read_file(src.c_str());
76 AudioLibrary::~AudioLibrary ()
81 AudioLibrary::save_changes ()
84 #ifdef PLATFORM_WINDOWS
85 string path = Glib::locale_from_utf8 (Glib::filename_from_uri(src));
87 string path = Glib::filename_from_uri(src);
89 if (lrdf_export_by_source(src.c_str(), path.c_str())) {
90 PBD::warning << string_compose(_("Could not open %1. Audio Library not saved"), path) << endmsg;
96 AudioLibrary::set_tags (string member, vector<string> tags)
99 sort (tags.begin(), tags.end());
100 tags.erase (unique(tags.begin(), tags.end()), tags.end());
102 const string file_uri(Glib::filename_to_uri (member));
104 lrdf_remove_uri_matches (file_uri.c_str());
106 for (vector<string>::iterator i = tags.begin(); i != tags.end(); ++i) {
107 lrdf_add_triple (src.c_str(), file_uri.c_str(), TAG, (*i).c_str(), lrdf_literal);
113 AudioLibrary::get_tags (string member)
117 char * uri = strdup(Glib::filename_to_uri(member).c_str());
119 lrdf_statement pattern;
120 pattern.subject = uri;
121 pattern.predicate = const_cast<char*>(TAG);
123 pattern.object_type = lrdf_literal;
125 lrdf_statement* matches = lrdf_matches (&pattern);
127 lrdf_statement* current = matches;
128 while (current != 0) {
129 tags.push_back (current->object);
131 current = current->next;
134 lrdf_free_statements (matches);
136 sort (tags.begin(), tags.end());
143 AudioLibrary::search_members_and (vector<string>& members, const vector<string>& tags)
146 lrdf_statement **head;
147 lrdf_statement* pattern = 0;
148 lrdf_statement* old = 0;
151 vector<string>::const_iterator i;
152 for (i = tags.begin(); i != tags.end(); ++i){
153 pattern = new lrdf_statement;
154 pattern->subject = const_cast<char*>("?");
155 pattern->predicate = const_cast<char*>(TAG);
156 pattern->object = strdup((*i).c_str());
163 lrdf_uris* ulist = lrdf_match_multi(*head);
164 for (uint32_t j = 0; ulist && j < ulist->count; ++j) {
165 members.push_back(Glib::filename_from_uri(ulist->items[j]));
167 lrdf_free_uris(ulist);
169 sort (members.begin(), members.end());
170 members.erase (unique (members.begin(), members.end()), members.end());
176 free(pattern->object);
178 pattern = pattern->next;