PBD::strip_whitespace_edges() returns the empty string if the passed string is

all whitespace.  This allows for some mild code cleanup.  It's also declared in 
the PBD namespace now.

sfdb-v4 implemented.  Instead of fields that go across all files, there is now
just one tag field where you can enter comma delimited tags.  Searching for
tags to follow soon.  I recommend trashing your current ~/.ardour2/sfdb file.


git-svn-id: svn://localhost/ardour2/trunk@1182 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Taybin Rutkin 2006-12-01 06:01:30 +00:00
parent c103132ae6
commit 927553f6b8
14 changed files with 220 additions and 674 deletions

View file

@ -12,4 +12,4 @@ file) will be removed.
(2) STANDARD TEMPLATES (2) STANDARD TEMPLATES
The templates in ./templates are intended for installation in The templates in ./templates are intended for installation in
$prefix/share/ardour/templates. $prefix/share/ardour2/templates.

View file

@ -30,7 +30,6 @@
#include <pbd/error.h> #include <pbd/error.h>
#include <pbd/stl_delete.h> #include <pbd/stl_delete.h>
#include <pbd/whitespace.h>
#include <pbd/memento_command.h> #include <pbd/memento_command.h>
#include <gtkmm2ext/gtk_ui.h> #include <gtkmm2ext/gtk_ui.h>

View file

@ -20,7 +20,6 @@
#include <pbd/whitespace.h> #include <pbd/whitespace.h>
#include <ardour/audio_library.h>
#include <ardour/session.h> #include <ardour/session.h>
#include <ardour/audioengine.h> #include <ardour/audioengine.h>
#include <ardour/configuration.h> #include <ardour/configuration.h>
@ -60,7 +59,6 @@ OptionEditor::OptionEditor (ARDOUR_UI& uip, PublicEditor& ed, Mixer_UI& mixui)
/* Paths */ /* Paths */
path_table (11, 2), path_table (11, 2),
sfdb_path_view(),
/* Fades */ /* Fades */
@ -224,23 +222,9 @@ OptionEditor::setup_path_options()
path_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL); path_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
path_table.attach (session_raid_entry, 1, 3, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL); path_table.attach (session_raid_entry, 1, 3, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
label = manage(new Label(_("Soundfile Search Paths")));
label->set_name("OptionsLabel");
path_table.attach(*label, 0, 1, 2, 3, FILL|EXPAND, FILL);
path_table.attach(sfdb_path_view, 1, 3, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
sfdb_path_view.set_paths(Library->get_paths());
sfdb_path_view.PathsUpdated.connect (mem_fun(*this, &OptionEditor::sfdb_paths_changed));
path_table.show_all(); path_table.show_all();
} }
void
OptionEditor::sfdb_paths_changed ()
{
Library->set_paths (sfdb_path_view.get_paths());
}
void void
OptionEditor::add_session_paths () OptionEditor::add_session_paths ()
{ {
@ -659,12 +643,6 @@ OptionEditor::click_sound_changed ()
return; return;
} }
if (path.empty()) {
Config->set_click_sound ("");
} else {
strip_whitespace_edges (path); strip_whitespace_edges (path);
if (path == _("internal")) { if (path == _("internal")) {
@ -673,7 +651,6 @@ OptionEditor::click_sound_changed ()
Config->set_click_sound (path); Config->set_click_sound (path);
} }
} }
}
} }
void void
@ -686,12 +663,6 @@ OptionEditor::click_emphasis_sound_changed ()
return; return;
} }
if (path.empty()) {
Config->set_click_emphasis_sound ("");
} else {
strip_whitespace_edges (path); strip_whitespace_edges (path);
if (path == _("internal")) { if (path == _("internal")) {
@ -700,7 +671,6 @@ OptionEditor::click_emphasis_sound_changed ()
Config->set_click_emphasis_sound (path); Config->set_click_emphasis_sound (path);
} }
} }
}
} }
void void

View file

@ -33,8 +33,6 @@
#include <gtkmm/radiobutton.h> #include <gtkmm/radiobutton.h>
#include <gtkmm/comboboxtext.h> #include <gtkmm/comboboxtext.h>
#include <gtkmm2ext/pathlist.h>
#include <ardour/session.h> #include <ardour/session.h>
#include "ardour_dialog.h" #include "ardour_dialog.h"
@ -75,13 +73,10 @@ class OptionEditor : public Gtk::Dialog
Gtk::Table path_table; Gtk::Table path_table;
Gtk::Entry session_raid_entry; Gtk::Entry session_raid_entry;
Gtkmm2ext::PathList sfdb_path_view;
void setup_path_options(); void setup_path_options();
void add_session_paths (); void add_session_paths ();
void remove_session_paths (); void remove_session_paths ();
void raid_path_changed (); void raid_path_changed ();
void sfdb_paths_changed ();
/* fades */ /* fades */

View file

@ -1105,17 +1105,17 @@ RouteTimeAxisView::name_entry_changed ()
return; return;
} }
strip_whitespace_edges(x);
if (x.length() == 0) { if (x.length() == 0) {
name_entry.set_text (_route->name()); name_entry.set_text (_route->name());
return; return;
} }
strip_whitespace_edges(x);
if (_session.route_name_unique (x)) { if (_session.route_name_unique (x)) {
_route->set_name (x, this); _route->set_name (x, this);
} else { } else {
ARDOUR_UI::instance()->popup_error (_("a track already exists with that name")); ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
name_entry.set_text (_route->name()); name_entry.set_text (_route->name());
} }
} }

View file

@ -1,6 +1,5 @@
/* /*
Copyright (C) 2005 Paul Davis Copyright (C) 2005-2006 Paul Davis
Written by Taybin Rutkin
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -16,16 +15,17 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include <map> #include <map>
#include <cerrno> #include <cerrno>
#include <sstream>
#include <gtkmm/box.h> #include <gtkmm/box.h>
#include <gtkmm/stock.h> #include <gtkmm/stock.h>
#include <pbd/convert.h> #include <pbd/convert.h>
#include <pbd/whitespace.h>
#include <gtkmm2ext/utils.h> #include <gtkmm2ext/utils.h>
@ -52,14 +52,12 @@ SoundFileBox::SoundFileBox ()
: :
_session(0), _session(0),
current_pid(0), current_pid(0),
fields(Gtk::ListStore::create(label_columns)),
main_box (false, 3), main_box (false, 3),
top_box (true, 4), top_box (true, 4),
bottom_box (true, 4), bottom_box (true, 4),
play_btn(_("Play")), play_btn(_("Play")),
stop_btn(_("Stop")), stop_btn(_("Stop")),
add_field_btn(_("Add Field...")), apply_btn(_("Apply"))
remove_field_btn(_("Remove Field"))
{ {
set_name (X_("SoundFileBox")); set_name (X_("SoundFileBox"));
border_frame.set_label (_("Soundfile Info")); border_frame.set_label (_("Soundfile Info"));
@ -75,38 +73,21 @@ SoundFileBox::SoundFileBox ()
main_box.pack_start(channels, false, false); main_box.pack_start(channels, false, false);
main_box.pack_start(samplerate, false, false); main_box.pack_start(samplerate, false, false);
main_box.pack_start(timecode, false, false); main_box.pack_start(timecode, false, false);
main_box.pack_start(field_view, true, true); main_box.pack_start(tags_entry, true, true);
main_box.pack_start(top_box, false, false); main_box.pack_start(top_box, false, false);
main_box.pack_start(bottom_box, false, false); main_box.pack_start(bottom_box, false, false);
field_view.set_model (fields);
field_view.set_size_request(200, 150);
field_view.append_column (_("Field"), label_columns.field);
field_view.append_column_editable (_("Value"), label_columns.data);
top_box.set_homogeneous(true); top_box.set_homogeneous(true);
top_box.pack_start(add_field_btn); top_box.pack_start(apply_btn);
top_box.pack_start(remove_field_btn);
remove_field_btn.set_sensitive(false);
bottom_box.set_homogeneous(true); bottom_box.set_homogeneous(true);
bottom_box.pack_start(play_btn); bottom_box.pack_start(play_btn);
bottom_box.pack_start(stop_btn); bottom_box.pack_start(stop_btn);
// tags_entry.signal_focus_out_event().connect (mem_fun (*this, &SoundFileBox::tags_entry_left));
play_btn.signal_clicked().connect (mem_fun (*this, &SoundFileBox::play_btn_clicked)); play_btn.signal_clicked().connect (mem_fun (*this, &SoundFileBox::play_btn_clicked));
stop_btn.signal_clicked().connect (mem_fun (*this, &SoundFileBox::stop_btn_clicked)); stop_btn.signal_clicked().connect (mem_fun (*this, &SoundFileBox::stop_btn_clicked));
apply_btn.signal_clicked().connect (mem_fun (*this, &SoundFileBox::apply_btn_clicked));
add_field_btn.signal_clicked().connect
(mem_fun (*this, &SoundFileBox::add_field_clicked));
remove_field_btn.signal_clicked().connect
(mem_fun (*this, &SoundFileBox::remove_field_clicked));
Gtk::CellRendererText* cell(dynamic_cast<Gtk::CellRendererText*>(field_view.get_column_cell_renderer(1)));
cell->signal_edited().connect (mem_fun (*this, &SoundFileBox::field_edited));
field_view.get_selection()->signal_changed().connect (mem_fun (*this, &SoundFileBox::field_selected));
Library->fields_changed.connect (mem_fun (*this, &SoundFileBox::setup_fields));
show_all(); show_all();
stop_btn.hide(); stop_btn.hide();
@ -136,7 +117,7 @@ SoundFileBox::setup_labels (string filename)
} }
length.set_alignment (0.0f, 0.0f); length.set_alignment (0.0f, 0.0f);
length.set_text (string_compose(_("Length: %1"), PBD::length2string(sf_info.length, sf_info.samplerate))); length.set_text (string_compose(_("Length: %1"), length2string(sf_info.length, sf_info.samplerate)));
format.set_alignment (0.0f, 0.0f); format.set_alignment (0.0f, 0.0f);
format.set_text (sf_info.format_name); format.set_text (sf_info.format_name);
@ -148,37 +129,28 @@ SoundFileBox::setup_labels (string filename)
samplerate.set_text (string_compose(_("Samplerate: %1"), sf_info.samplerate)); samplerate.set_text (string_compose(_("Samplerate: %1"), sf_info.samplerate));
timecode.set_alignment (0.0f, 0.0f); timecode.set_alignment (0.0f, 0.0f);
timecode.set_text (string_compose (_("Timecode: %1"), PBD::length2string(sf_info.timecode, sf_info.samplerate))); timecode.set_text (string_compose (_("Timecode: %1"), length2string(sf_info.timecode, sf_info.samplerate)));
setup_fields (); vector<string> tags = Library->get_tags (filename);
stringstream tag_string;
for (vector<string>::iterator i = tags.begin(); i != tags.end(); ++i) {
if (i != tags.begin()) {
tag_string << ", ";
}
tag_string << *i;
}
tags_entry.set_text (tag_string.str());
return true; return true;
} }
void bool
SoundFileBox::setup_fields () SoundFileBox::tags_entry_left (GdkEventFocus* event)
{ {
ENSURE_GUI_THREAD(mem_fun (*this, &SoundFileBox::setup_fields)); apply_btn_clicked ();
fields->clear (); return true;
vector<string> field_list;
Library->get_fields(field_list);
vector<string>::iterator i;
Gtk::TreeModel::iterator iter;
Gtk::TreeModel::Row row;
for (i = field_list.begin(); i != field_list.end(); ++i) {
if (!(*i == _("channels") || *i == _("samplerate") ||
*i == _("resolution") || *i == _("format"))) {
iter = fields->append();
row = *iter;
string value = Library->get_field(path, *i);
row[label_columns.field] = *i;
row[label_columns.data] = value;
}
}
} }
void void
@ -228,7 +200,6 @@ SoundFileBox::play_btn_clicked ()
newpair.first = path; newpair.first = path;
newpair.second = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (srclist, 0, srclist[0]->length(), rname, 0, Region::DefaultFlags, false)); newpair.second = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (srclist, 0, srclist[0]->length(), rname, 0, Region::DefaultFlags, false));
res = region_cache.insert (newpair); res = region_cache.insert (newpair);
the_region = res.first; the_region = res.first;
} }
@ -252,56 +223,35 @@ SoundFileBox::stop_btn_clicked ()
} }
void void
SoundFileBox::add_field_clicked () SoundFileBox::apply_btn_clicked ()
{ {
ArdourPrompter prompter (true); string tag_string = tags_entry.get_text ();
string name;
prompter.set_prompt (_("Name for Field")); vector<string> tags;
prompter.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT);
prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
switch (prompter.run ()) { static const string DELIMITERS = ",";
case Gtk::RESPONSE_ACCEPT:
prompter.get_result (name); // Skip delimiters at beginning.
if (name.length()) { string::size_type last_pos = tag_string.find_first_not_of(DELIMITERS, 0);
Library->add_field (name); // Find first "non-delimiter".
Library->save_changes (); string::size_type pos = tag_string.find_first_of(DELIMITERS, last_pos);
while (string::npos != pos || string::npos != last_pos) {
string x = tag_string.substr(last_pos, pos - last_pos);
strip_whitespace_edges (x);
if (x.length()) {
tags.push_back (x);
} }
break; // Skip delimiters. Note the "not_of"
last_pos = tag_string.find_first_not_of(DELIMITERS, pos);
default: // Find next "non-delimiter"
break; pos = tag_string.find_first_of(DELIMITERS, last_pos);
} }
}
void
SoundFileBox::remove_field_clicked ()
{
field_view.get_selection()->selected_foreach_iter(mem_fun(*this, &SoundFileBox::delete_row));
Library->set_tags (path, tags);
Library->save_changes (); Library->save_changes ();
} }
void
SoundFileBox::field_edited (const Glib::ustring& str1, const Glib::ustring& str2)
{
Gtk::TreeModel::Children rows(fields->children());
Gtk::TreeModel::Row row(rows[atoi(str1.c_str())]);
Library->set_field (path, row[label_columns.field], str2);
Library->save_changes ();
}
void
SoundFileBox::delete_row (const Gtk::TreeModel::iterator& iter)
{
Gtk::TreeModel::Row row = *iter;
Library->remove_field(row[label_columns.field]);
}
void void
SoundFileBox::audition_status_changed (bool active) SoundFileBox::audition_status_changed (bool active)
{ {
@ -312,16 +262,6 @@ SoundFileBox::audition_status_changed (bool active)
} }
} }
void
SoundFileBox::field_selected ()
{
if (field_view.get_selection()->count_selected_rows()) {
remove_field_btn.set_sensitive(true);
} else {
remove_field_btn.set_sensitive(false);
}
}
// this needs to be kept in sync with the ImportMode enum defined in editing.h and editing_syms.h. // this needs to be kept in sync with the ImportMode enum defined in editing.h and editing_syms.h.
static const char *import_mode_strings[] = { static const char *import_mode_strings[] = {
N_("Add to Region list"), N_("Add to Region list"),
@ -335,6 +275,7 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s)
: ArdourDialog (title, false), : ArdourDialog (title, false),
chooser (Gtk::FILE_CHOOSER_ACTION_OPEN) chooser (Gtk::FILE_CHOOSER_ACTION_OPEN)
{ {
set_default_size (700, 500);
get_vbox()->pack_start(chooser); get_vbox()->pack_start(chooser);
chooser.set_preview_widget(preview); chooser.set_preview_widget(preview);
chooser.set_select_multiple (true); chooser.set_select_multiple (true);

View file

@ -1,6 +1,5 @@
/* /*
Copyright (C) 2005 Paul Davis Copyright (C) 2005-2006 Paul Davis
Written by Taybin Rutkin
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -16,7 +15,6 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#ifndef __ardour_sfdb_ui_h__ #ifndef __ardour_sfdb_ui_h__
@ -36,8 +34,6 @@
#include <gtkmm/comboboxtext.h> #include <gtkmm/comboboxtext.h>
#include <gtkmm/frame.h> #include <gtkmm/frame.h>
#include <gtkmm/label.h> #include <gtkmm/label.h>
#include <gtkmm/liststore.h>
#include <gtkmm/treeview.h>
#include <ardour/session.h> #include <ardour/session.h>
#include <ardour/audiofilesource.h> #include <ardour/audiofilesource.h>
@ -58,17 +54,6 @@ class SoundFileBox : public Gtk::VBox
ARDOUR::Session* _session; ARDOUR::Session* _session;
std::string path; std::string path;
struct LabelModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
Gtk::TreeModelColumn<std::string> field;
Gtk::TreeModelColumn<std::string> data;
LabelModelColumns() { add(field); add(data); }
};
LabelModelColumns label_columns;
ARDOUR::SoundFileInfo sf_info; ARDOUR::SoundFileInfo sf_info;
pid_t current_pid; pid_t current_pid;
@ -79,12 +64,10 @@ class SoundFileBox : public Gtk::VBox
Gtk::Label samplerate; Gtk::Label samplerate;
Gtk::Label timecode; Gtk::Label timecode;
Gtk::TreeView field_view;
Glib::RefPtr<Gtk::ListStore> fields;
std::string selected_field;
Gtk::Frame border_frame; Gtk::Frame border_frame;
Gtk::Entry tags_entry;
Gtk::VBox main_box; Gtk::VBox main_box;
Gtk::VBox path_box; Gtk::VBox path_box;
Gtk::HBox top_box; Gtk::HBox top_box;
@ -92,19 +75,13 @@ class SoundFileBox : public Gtk::VBox
Gtk::Button play_btn; Gtk::Button play_btn;
Gtk::Button stop_btn; Gtk::Button stop_btn;
Gtk::Button add_field_btn; Gtk::Button apply_btn;
Gtk::Button remove_field_btn;
void setup_fields ();
bool tags_entry_left (GdkEventFocus* event);
void play_btn_clicked (); void play_btn_clicked ();
void stop_btn_clicked (); void stop_btn_clicked ();
void add_field_clicked (); void apply_btn_clicked ();
void remove_field_clicked ();
void field_edited (const Glib::ustring&, const Glib::ustring&);
void delete_row (const Gtk::TreeModel::iterator& iter);
void field_selected ();
void audition_status_changed (bool state); void audition_status_changed (bool state);
}; };

View file

@ -375,17 +375,17 @@ VisualTimeAxis::name_entry_changed()
return; return;
} }
strip_whitespace_edges(x);
if (x.length() == 0) { if (x.length() == 0) {
name_entry.set_text (time_axis_name); name_entry.set_text (time_axis_name);
return; return;
} }
strip_whitespace_edges(x);
if (!editor.get_named_time_axis(x)) { if (!editor.get_named_time_axis(x)) {
set_time_axis_name(x, this); set_time_axis_name(x, this);
} else { } else {
ARDOUR_UI::instance()->popup_error (_("a track already exists with that name")); ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
name_entry.set_text(time_axis_name); name_entry.set_text(time_axis_name);
} }
} }

View file

@ -1,6 +1,5 @@
/* /*
Copyright (C) 2003 Paul Davis Copyright (C) 2003-2006 Paul Davis
Author: Taybin Rutkin
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -16,7 +15,6 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id$
*/ */
#ifndef __ardour_audio_library_h__ #ifndef __ardour_audio_library_h__
@ -26,63 +24,30 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include <sigc++/signal.h>
#include <pbd/stateful.h>
using std::vector; using std::vector;
using std::string; using std::string;
using std::map; using std::map;
namespace ARDOUR { namespace ARDOUR {
class AudioLibrary : public Stateful class AudioLibrary
{ {
public: public:
AudioLibrary (); AudioLibrary ();
~AudioLibrary (); ~AudioLibrary ();
static string state_node_name; void set_tags (string member, vector<string> tags);
vector<string> get_tags (string member);
XMLNode& get_state (void); void search_members_and (vector<string>& results, const vector<string> tags);
int set_state (const XMLNode&);
void set_paths (vector<string> paths);
vector<string> get_paths ();
void scan_paths ();
void add_member (string member);
void remove_member (string uri);
void search_members_and (vector<string>& results,
const map<string,string>& fields);
void search_members_or (vector<string>& results,
const map<string,string>& fields);
void add_field (string field);
void get_fields (vector<string>& fields);
void remove_field (string field);
string get_field (string uri, string field);
void set_field (string uri, string field, string literal);
string get_label (string uri);
void set_label (string uri, string name);
void save_changes(); void save_changes();
sigc::signal<void> fields_changed;
private: private:
vector<string> sfdb_paths;
string field_uri (string name);
bool is_rdf_type (string uri, string type);
void remove_uri (string uri);
string src; string src;
void initialize_db(); string path2uri (string);
void compact_vector (vector<string>& vec);
bool safe_file_extension (string); bool safe_file_extension (string);
}; };

View file

@ -1,6 +1,5 @@
/* /*
Copyright (C) 2003 Paul Davis Copyright (C) 2003-2006 Paul Davis
Author: Taybin Rutkin
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -16,25 +15,14 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id$
*/ */
#include <cstdio> // Needed so that libraptor (included in lrdf) won't complain
#include <cerrno>
#include <iostream>
#include <sstream> #include <sstream>
#include <cctype>
#include <sys/types.h>
#include <sys/stat.h>
#include <fts.h>
#include <lrdf.h> #include <lrdf.h>
#include <pbd/compose.h> #include <pbd/compose.h>
#include <ardour/ardour.h>
#include <ardour/configuration.h>
#include <ardour/audio_library.h> #include <ardour/audio_library.h>
#include <ardour/utils.h> #include <ardour/utils.h>
@ -42,16 +30,11 @@
using namespace std; using namespace std;
using namespace ARDOUR; using namespace ARDOUR;
using namespace PBD;
static char* SOUNDFILE = "http://ardour.org/ontology/Soundfile"; static char* TAG = "http://ardour.org/ontology/Tag";
string AudioLibrary::state_node_name = "AudioLibrary";
AudioLibrary::AudioLibrary () AudioLibrary::AudioLibrary ()
{ {
// sfdb_paths.push_back("/Users/taybin/sounds");
src = "file:" + get_user_ardour_path() + "sfdb"; src = "file:" + get_user_ardour_path() + "sfdb";
// workaround for possible bug in raptor that crashes when saving to a // workaround for possible bug in raptor that crashes when saving to a
@ -59,80 +42,85 @@ AudioLibrary::AudioLibrary ()
touch_file(get_user_ardour_path() + "sfdb"); touch_file(get_user_ardour_path() + "sfdb");
lrdf_read_file(src.c_str()); lrdf_read_file(src.c_str());
lrdf_statement pattern;
pattern.subject = SOUNDFILE;
pattern.predicate = RDF_TYPE;
pattern.object = RDFS_CLASS;
pattern.object_type = lrdf_uri;
lrdf_statement* matches = lrdf_matches(&pattern);
// if empty DB, create basic schema
if (matches == 0) {
initialize_db ();
save_changes();
}
lrdf_free_statements(matches);
} }
AudioLibrary::~AudioLibrary () AudioLibrary::~AudioLibrary ()
{ {
} }
void
AudioLibrary::initialize_db ()
{
// define ardour:Soundfile
lrdf_add_triple(src.c_str(), SOUNDFILE, RDF_TYPE, RDFS_CLASS, lrdf_uri);
// add intergral fields
add_field(_("channels"));
add_field(_("samplerate"));
add_field(_("resolution"));
add_field(_("format"));
}
void void
AudioLibrary::save_changes () AudioLibrary::save_changes ()
{ {
if (lrdf_export_by_source(src.c_str(), src.substr(5).c_str())) { if (lrdf_export_by_source(src.c_str(), src.substr(5).c_str())) {
warning << string_compose(_("Could not open %1. Audio Library not saved"), src) << endmsg; PBD::warning << string_compose(_("Could not open %1. Audio Library not saved"), src) << endmsg;
} }
} }
void string
AudioLibrary::add_member (string member) AudioLibrary::path2uri (string path)
{ {
string file_uri(string_compose("file:%1", member)); stringstream uri;
uri << "file:" << path;
lrdf_add_triple(src.c_str(), file_uri.c_str(), RDF_TYPE, return uri.str();
SOUNDFILE, lrdf_uri);
} }
void void
AudioLibrary::remove_member (string uri) AudioLibrary::set_tags (string member, vector<string> tags)
{ {
lrdf_remove_uri_matches (uri.c_str()); sort (tags.begin(), tags.end());
tags.erase (unique(tags.begin(), tags.end()), tags.end());
string file_uri(path2uri(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);
}
}
vector<string>
AudioLibrary::get_tags (string member)
{
vector<string> tags;
lrdf_statement pattern;
pattern.subject = strdup(path2uri(member).c_str());
pattern.predicate = 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 void
AudioLibrary::search_members_and (vector<string>& members, AudioLibrary::search_members_and (vector<string>& members, const vector<string> tags)
const map<string,string>& fields)
{ {
lrdf_statement **head; lrdf_statement **head;
lrdf_statement* pattern = 0; lrdf_statement* pattern = 0;
lrdf_statement* old = 0; lrdf_statement* old = 0;
head = &pattern; head = &pattern;
map<string,string>::const_iterator i; vector<string>::const_iterator i;
for (i = fields.begin(); i != fields.end(); ++i){ for (i = tags.begin(); i != tags.end(); ++i){
pattern = new lrdf_statement; pattern = new lrdf_statement;
pattern->subject = "?"; pattern->subject = "?";
pattern->predicate = strdup(field_uri(i->first).c_str()); pattern->predicate = TAG;
pattern->object = strdup((i->second).c_str()); pattern->object = strdup((*i).c_str());
pattern->next = old; pattern->next = old;
old = pattern; old = pattern;
@ -146,7 +134,8 @@ AudioLibrary::search_members_and (vector<string>& members,
} }
lrdf_free_uris(ulist); lrdf_free_uris(ulist);
compact_vector(members); sort(members.begin(), members.end());
unique(members.begin(), members.end());
} }
// memory clean up // memory clean up
@ -160,262 +149,6 @@ AudioLibrary::search_members_and (vector<string>& members,
} }
} }
void
AudioLibrary::search_members_or (vector<string>& members,
const map<string,string>& fields)
{
map<string,string>::const_iterator i;
lrdf_statement pattern;
for (i = fields.begin(); i != fields.end(); ++i) {
pattern.subject = 0;
pattern.predicate = strdup(field_uri(i->first).c_str());
pattern.object = strdup((i->second).c_str());
pattern.object_type = lrdf_literal;
lrdf_statement* matched = lrdf_matches(&pattern);
lrdf_statement* old = matched;
while(matched) {
// printf ("OR: %s\n", matched->subject);
members.push_back(matched->subject);
matched = matched->next;
}
free(pattern.predicate);
free(pattern.object);
lrdf_free_statements (old);
}
compact_vector(members);
}
void
AudioLibrary::add_field (string name)
{
string local_field = field_uri(name);
lrdf_statement pattern;
pattern.subject = strdup(local_field.c_str());
pattern.predicate = RDF_TYPE;
pattern.object = RDF_BASE "Property";
pattern.object_type = lrdf_uri;
if(lrdf_exists_match(&pattern)) {
return;
}
// of type rdf:Property
lrdf_add_triple(src.c_str(), local_field.c_str(), RDF_TYPE,
RDF_BASE "Property", lrdf_uri);
// of range ardour:Soundfile
lrdf_add_triple(src.c_str(), local_field.c_str(), RDFS_BASE "range",
SOUNDFILE, lrdf_uri);
// of domain rdf:Literal
lrdf_add_triple(src.c_str(), local_field.c_str(), RDFS_BASE "domain",
RDF_BASE "Literal", lrdf_uri);
set_label (local_field, name);
fields_changed(); /* EMIT SIGNAL */
}
void
AudioLibrary::get_fields (vector<string>& fields)
{
lrdf_statement pattern;
pattern.subject = 0;
pattern.predicate = RDFS_BASE "range";
pattern.object = SOUNDFILE;
pattern.object_type = lrdf_uri;
lrdf_statement* matches = lrdf_matches(&pattern);
lrdf_statement* current = matches;
while (current != 0) {
fields.push_back(get_label(current->subject));
current = current->next;
}
lrdf_free_statements(matches);
compact_vector(fields);
}
void
AudioLibrary::remove_field (string name)
{
lrdf_remove_uri_matches(field_uri(name).c_str());
fields_changed (); /* EMIT SIGNAL */
}
string
AudioLibrary::get_field (string uri, string field)
{
lrdf_statement pattern;
pattern.subject = strdup(uri.c_str());
pattern.predicate = strdup(field_uri(field).c_str());
pattern.object = 0;
pattern.object_type = lrdf_literal;
lrdf_statement* matches = lrdf_matches(&pattern);
free(pattern.subject);
free(pattern.predicate);
stringstream object;
if (matches != 0){
object << matches->object;
}
lrdf_free_statements(matches);
return object.str();
}
void
AudioLibrary::set_field (string uri, string field, string literal)
{
lrdf_statement pattern;
pattern.subject = strdup(uri.c_str());
string local_field = field_uri(field);
pattern.predicate = strdup(local_field.c_str());
pattern.object = 0;
pattern.object_type = lrdf_literal;
lrdf_remove_matches(&pattern);
free(pattern.subject);
free(pattern.predicate);
lrdf_add_triple(src.c_str(), uri.c_str(), local_field.c_str(),
literal.c_str(), lrdf_literal);
fields_changed(); /* EMIT SIGNAL */
}
string
AudioLibrary::field_uri (string name)
{
stringstream local_field;
local_field << "file:sfdb/fields/" << name;
return local_field.str();
}
string
AudioLibrary::get_label (string uri)
{
lrdf_statement pattern;
pattern.subject = strdup(uri.c_str());
pattern.predicate = RDFS_BASE "label";
pattern.object = 0;
pattern.object_type = lrdf_literal;
lrdf_statement* matches = lrdf_matches (&pattern);
free(pattern.subject);
stringstream label;
if (matches != 0){
label << matches->object;
}
lrdf_free_statements(matches);
return label.str();
}
void
AudioLibrary::set_label (string uri, string label)
{
lrdf_statement pattern;
pattern.subject = strdup(uri.c_str());
pattern.predicate = RDFS_BASE "label";
pattern.object = 0;
pattern.object_type = lrdf_literal;
lrdf_remove_matches(&pattern);
free(pattern.subject);
lrdf_add_triple(src.c_str(), uri.c_str(), RDFS_BASE "label",
label.c_str(), lrdf_literal);
}
void
AudioLibrary::compact_vector(vector<string>& vec)
{
sort(vec.begin(), vec.end());
unique(vec.begin(), vec.end());
}
void
AudioLibrary::set_paths (vector<string> paths)
{
sfdb_paths = paths;
scan_paths ();
}
vector<string>
AudioLibrary::get_paths ()
{
return sfdb_paths;
}
void
AudioLibrary::scan_paths ()
{
if (sfdb_paths.size() < 1) {
return;
}
vector<char *> pathv(sfdb_paths.size());
unsigned int i;
for (i = 0; i < sfdb_paths.size(); ++i) {
pathv[i] = new char[sfdb_paths[i].length() +1];
sfdb_paths[i].copy(pathv[i], string::npos);
pathv[i][sfdb_paths[i].length()] = 0;
}
pathv[i] = 0;
FTS* ft = fts_open(&pathv[0], FTS_LOGICAL|FTS_NOSTAT|FTS_PHYSICAL|FTS_XDEV, 0);
if (errno) {
error << strerror(errno) << endmsg;
return;
}
lrdf_statement s;
s.predicate = RDF_TYPE;
s.object = SOUNDFILE;
s.object_type = lrdf_uri;
string filename;
while (FTSENT* file = fts_read(ft)) {
if ((file->fts_info & FTS_F) && (safe_file_extension(file->fts_name))) {
filename = "file:";
filename.append(file->fts_accpath);
s.subject = strdup(filename.c_str());
if (lrdf_exists_match(&s)) {
continue;
} else {
add_member(file->fts_accpath);
cout << file->fts_accpath << endl;
}
free(s.subject);
}
}
fts_close(ft);
for (i = 0; i < pathv.size(); ++i) {
delete[] pathv[i];
}
save_changes();
}
bool bool
AudioLibrary::safe_file_extension(string file) AudioLibrary::safe_file_extension(string file)
{ {
@ -438,43 +171,3 @@ AudioLibrary::safe_file_extension(string file)
#endif // HAVE_COREAUDIO #endif // HAVE_COREAUDIO
file.rfind(".voc") == string::npos); file.rfind(".voc") == string::npos);
} }
XMLNode&
AudioLibrary::get_state ()
{
XMLNode* root = new XMLNode(X_("AudioLibrary"));
for (vector<string>::iterator i = sfdb_paths.begin(); i != sfdb_paths.end(); ++i) {
XMLNode* node = new XMLNode(X_("Path"));
node->add_property("value", *i);
root->add_child_nocopy(*node);
}
return *root;
}
int
AudioLibrary::set_state (const XMLNode& node)
{
if (node.name() != X_("AudioLibrary")) {
fatal << "programming error: AudioLibrary: incorrect XML node sent to set_state()" << endmsg;
return -1;
}
XMLNodeList nodes = node.children(X_("Path"));
vector<string> paths;
XMLProperty* prop;
XMLNode* child;
for (XMLNodeConstIterator iter = nodes.begin(); iter != nodes.end(); ++iter) {
child = *iter;
if ((prop = child->property(X_("value"))) != 0) {
paths.push_back(prop->value());
}
}
set_paths (paths);
return 0;
}

View file

@ -25,7 +25,6 @@
#include <pbd/xml++.h> #include <pbd/xml++.h>
#include <ardour/ardour.h> #include <ardour/ardour.h>
#include <ardour/audio_library.h>
#include <ardour/configuration.h> #include <ardour/configuration.h>
#include <ardour/audio_diskstream.h> #include <ardour/audio_diskstream.h>
#include <ardour/destructive_filesource.h> #include <ardour/destructive_filesource.h>
@ -172,7 +171,6 @@ Configuration::get_state ()
} }
root->add_child_nocopy (ControlProtocolManager::instance().get_state()); root->add_child_nocopy (ControlProtocolManager::instance().get_state());
root->add_child_nocopy (Library->get_state());
return *root; return *root;
} }
@ -235,8 +233,6 @@ Configuration::set_state (const XMLNode& root)
} else if (node->name() == ControlProtocolManager::state_node_name) { } else if (node->name() == ControlProtocolManager::state_node_name) {
_control_protocol_state = new XMLNode (*node); _control_protocol_state = new XMLNode (*node);
} else if (node->name() == AudioLibrary::state_node_name) {
Library->set_state (*node);
} }
} }

View file

@ -86,7 +86,7 @@ Prompter::get_result (string &str, bool strip)
{ {
str = entry.get_text (); str = entry.get_text ();
if (strip) { if (strip) {
strip_whitespace_edges (str); PBD::strip_whitespace_edges (str);
} }
} }

View file

@ -3,6 +3,12 @@
#include <string> #include <string>
namespace PBD {
// returns the empty string if the entire string is whitespace
// so check length after calling.
extern void strip_whitespace_edges (std::string& str); extern void strip_whitespace_edges (std::string& str);
} // namespace PBD
#endif // __pbd_whitespace_h__ #endif // __pbd_whitespace_h__

View file

@ -2,6 +2,8 @@
using namespace std; using namespace std;
namespace PBD {
void void
strip_whitespace_edges (string& str) strip_whitespace_edges (string& str)
{ {
@ -24,7 +26,8 @@ strip_whitespace_edges (string& str)
} }
if (i == len) { if (i == len) {
/* its all whitespace, not much we can do */ /* it's all whitespace, not much we can do */
str = "";
return; return;
} }
@ -55,3 +58,4 @@ strip_whitespace_edges (string& str)
} }
} }
} // namespace PBD