diff options
author | Taybin Rutkin <taybin@taybin.com> | 2006-12-01 06:01:30 +0000 |
---|---|---|
committer | Taybin Rutkin <taybin@taybin.com> | 2006-12-01 06:01:30 +0000 |
commit | 927553f6b83add18d03f4bae55421743342d5704 (patch) | |
tree | d5379ff2b00477f274f28a608732375449b02672 | |
parent | c103132ae60973dc4ee0831a70b5c6aa1b3d9747 (diff) |
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
-rw-r--r-- | PACKAGER_README | 2 | ||||
-rw-r--r-- | gtk2_ardour/audio_time_axis.cc | 1 | ||||
-rw-r--r-- | gtk2_ardour/option_editor.cc | 42 | ||||
-rw-r--r-- | gtk2_ardour/option_editor.h | 5 | ||||
-rw-r--r-- | gtk2_ardour/route_time_axis.cc | 6 | ||||
-rw-r--r-- | gtk2_ardour/sfdb_ui.cc | 159 | ||||
-rw-r--r-- | gtk2_ardour/sfdb_ui.h | 163 | ||||
-rw-r--r-- | gtk2_ardour/visual_time_axis.cc | 6 | ||||
-rw-r--r-- | libs/ardour/ardour/audio_library.h | 49 | ||||
-rw-r--r-- | libs/ardour/audio_library.cc | 445 | ||||
-rw-r--r-- | libs/ardour/configuration.cc | 4 | ||||
-rw-r--r-- | libs/gtkmm2ext/prompter.cc | 2 | ||||
-rw-r--r-- | libs/pbd/pbd/whitespace.h | 6 | ||||
-rw-r--r-- | libs/pbd/whitespace.cc | 6 |
14 files changed, 221 insertions, 675 deletions
diff --git a/PACKAGER_README b/PACKAGER_README index 36017496be..303df707f0 100644 --- a/PACKAGER_README +++ b/PACKAGER_README @@ -12,4 +12,4 @@ file) will be removed. (2) STANDARD TEMPLATES The templates in ./templates are intended for installation in -$prefix/share/ardour/templates. +$prefix/share/ardour2/templates. diff --git a/gtk2_ardour/audio_time_axis.cc b/gtk2_ardour/audio_time_axis.cc index 2be25f76aa..4ab0428a51 100644 --- a/gtk2_ardour/audio_time_axis.cc +++ b/gtk2_ardour/audio_time_axis.cc @@ -30,7 +30,6 @@ #include <pbd/error.h> #include <pbd/stl_delete.h> -#include <pbd/whitespace.h> #include <pbd/memento_command.h> #include <gtkmm2ext/gtk_ui.h> diff --git a/gtk2_ardour/option_editor.cc b/gtk2_ardour/option_editor.cc index 3e461a85d7..77af855845 100644 --- a/gtk2_ardour/option_editor.cc +++ b/gtk2_ardour/option_editor.cc @@ -20,7 +20,6 @@ #include <pbd/whitespace.h> -#include <ardour/audio_library.h> #include <ardour/session.h> #include <ardour/audioengine.h> #include <ardour/configuration.h> @@ -60,7 +59,6 @@ OptionEditor::OptionEditor (ARDOUR_UI& uip, PublicEditor& ed, Mixer_UI& mixui) /* Paths */ path_table (11, 2), - sfdb_path_view(), /* Fades */ @@ -224,24 +222,10 @@ OptionEditor::setup_path_options() 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); - 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(); } void -OptionEditor::sfdb_paths_changed () -{ - Library->set_paths (sfdb_path_view.get_paths()); -} - -void OptionEditor::add_session_paths () { click_path_entry.set_sensitive (true); @@ -659,19 +643,12 @@ OptionEditor::click_sound_changed () return; } - if (path.empty()) { + strip_whitespace_edges (path); + if (path == _("internal")) { Config->set_click_sound (""); - } else { - - strip_whitespace_edges (path); - - if (path == _("internal")) { - Config->set_click_sound (""); - } else { - Config->set_click_sound (path); - } + Config->set_click_sound (path); } } } @@ -686,19 +663,12 @@ OptionEditor::click_emphasis_sound_changed () return; } - if (path.empty()) { + strip_whitespace_edges (path); + if (path == _("internal")) { Config->set_click_emphasis_sound (""); - } else { - - strip_whitespace_edges (path); - - if (path == _("internal")) { - Config->set_click_emphasis_sound (""); - } else { - Config->set_click_emphasis_sound (path); - } + Config->set_click_emphasis_sound (path); } } } diff --git a/gtk2_ardour/option_editor.h b/gtk2_ardour/option_editor.h index 2076da3935..cc28a74e60 100644 --- a/gtk2_ardour/option_editor.h +++ b/gtk2_ardour/option_editor.h @@ -33,8 +33,6 @@ #include <gtkmm/radiobutton.h> #include <gtkmm/comboboxtext.h> -#include <gtkmm2ext/pathlist.h> - #include <ardour/session.h> #include "ardour_dialog.h" @@ -75,13 +73,10 @@ class OptionEditor : public Gtk::Dialog Gtk::Table path_table; Gtk::Entry session_raid_entry; - Gtkmm2ext::PathList sfdb_path_view; - void setup_path_options(); void add_session_paths (); void remove_session_paths (); void raid_path_changed (); - void sfdb_paths_changed (); /* fades */ diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index 348e4fb01f..4d0b507037 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -1105,17 +1105,17 @@ RouteTimeAxisView::name_entry_changed () return; } + strip_whitespace_edges(x); + if (x.length() == 0) { name_entry.set_text (_route->name()); return; } - strip_whitespace_edges(x); - if (_session.route_name_unique (x)) { _route->set_name (x, this); } 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()); } } diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc index 150b071661..3084844f78 100644 --- a/gtk2_ardour/sfdb_ui.cc +++ b/gtk2_ardour/sfdb_ui.cc @@ -1,6 +1,5 @@ /* - Copyright (C) 2005 Paul Davis - Written by Taybin Rutkin + Copyright (C) 2005-2006 Paul Davis 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 @@ -16,16 +15,17 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #include <map> #include <cerrno> +#include <sstream> #include <gtkmm/box.h> #include <gtkmm/stock.h> #include <pbd/convert.h> +#include <pbd/whitespace.h> #include <gtkmm2ext/utils.h> @@ -52,14 +52,12 @@ SoundFileBox::SoundFileBox () : _session(0), current_pid(0), - fields(Gtk::ListStore::create(label_columns)), main_box (false, 3), top_box (true, 4), bottom_box (true, 4), play_btn(_("Play")), stop_btn(_("Stop")), - add_field_btn(_("Add Field...")), - remove_field_btn(_("Remove Field")) + apply_btn(_("Apply")) { set_name (X_("SoundFileBox")); border_frame.set_label (_("Soundfile Info")); @@ -75,38 +73,21 @@ SoundFileBox::SoundFileBox () main_box.pack_start(channels, false, false); main_box.pack_start(samplerate, 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(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.pack_start(add_field_btn); - top_box.pack_start(remove_field_btn); - - remove_field_btn.set_sensitive(false); + top_box.pack_start(apply_btn); bottom_box.set_homogeneous(true); bottom_box.pack_start(play_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)); stop_btn.signal_clicked().connect (mem_fun (*this, &SoundFileBox::stop_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)); + apply_btn.signal_clicked().connect (mem_fun (*this, &SoundFileBox::apply_btn_clicked)); show_all(); stop_btn.hide(); @@ -136,7 +117,7 @@ SoundFileBox::setup_labels (string filename) } 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_text (sf_info.format_name); @@ -148,37 +129,28 @@ SoundFileBox::setup_labels (string filename) samplerate.set_text (string_compose(_("Samplerate: %1"), sf_info.samplerate)); timecode.set_alignment (0.0f, 0.0f); - timecode.set_text (string_compose (_("Timecode: %1"), PBD::length2string(sf_info.timecode, sf_info.samplerate))); - - setup_fields (); + timecode.set_text (string_compose (_("Timecode: %1"), length2string(sf_info.timecode, sf_info.samplerate))); + 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; } -void -SoundFileBox::setup_fields () -{ - ENSURE_GUI_THREAD(mem_fun (*this, &SoundFileBox::setup_fields)); - - fields->clear (); - - 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; - } - } +bool +SoundFileBox::tags_entry_left (GdkEventFocus* event) +{ + apply_btn_clicked (); + + return true; } void @@ -228,7 +200,6 @@ SoundFileBox::play_btn_clicked () newpair.first = path; newpair.second = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (srclist, 0, srclist[0]->length(), rname, 0, Region::DefaultFlags, false)); - res = region_cache.insert (newpair); the_region = res.first; } @@ -252,57 +223,36 @@ SoundFileBox::stop_btn_clicked () } void -SoundFileBox::add_field_clicked () -{ - ArdourPrompter prompter (true); - string name; - - prompter.set_prompt (_("Name for Field")); - prompter.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT); - prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false); - - switch (prompter.run ()) { - case Gtk::RESPONSE_ACCEPT: - prompter.get_result (name); - if (name.length()) { - Library->add_field (name); - Library->save_changes (); - } - break; - - default: - break; - } -} - -void -SoundFileBox::remove_field_clicked () +SoundFileBox::apply_btn_clicked () { - field_view.get_selection()->selected_foreach_iter(mem_fun(*this, &SoundFileBox::delete_row)); + string tag_string = tags_entry.get_text (); - Library->save_changes (); -} + vector<string> tags; -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); + static const string DELIMITERS = ","; + // Skip delimiters at beginning. + string::size_type last_pos = tag_string.find_first_not_of(DELIMITERS, 0); + // Find first "non-delimiter". + 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); + } + // Skip delimiters. Note the "not_of" + last_pos = tag_string.find_first_not_of(DELIMITERS, pos); + // Find next "non-delimiter" + pos = tag_string.find_first_of(DELIMITERS, last_pos); + } + + Library->set_tags (path, tags); 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 SoundFileBox::audition_status_changed (bool active) { ENSURE_GUI_THREAD(bind (mem_fun (*this, &SoundFileBox::audition_status_changed), 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. static const char *import_mode_strings[] = { N_("Add to Region list"), @@ -335,6 +275,7 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s) : ArdourDialog (title, false), chooser (Gtk::FILE_CHOOSER_ACTION_OPEN) { + set_default_size (700, 500); get_vbox()->pack_start(chooser); chooser.set_preview_widget(preview); chooser.set_select_multiple (true); diff --git a/gtk2_ardour/sfdb_ui.h b/gtk2_ardour/sfdb_ui.h index d7c2c14014..c8a0d316a5 100644 --- a/gtk2_ardour/sfdb_ui.h +++ b/gtk2_ardour/sfdb_ui.h @@ -1,6 +1,5 @@ /* - Copyright (C) 2005 Paul Davis - Written by Taybin Rutkin + Copyright (C) 2005-2006 Paul Davis 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 @@ -16,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef __ardour_sfdb_ui_h__ @@ -36,8 +34,6 @@ #include <gtkmm/comboboxtext.h> #include <gtkmm/frame.h> #include <gtkmm/label.h> -#include <gtkmm/liststore.h> -#include <gtkmm/treeview.h> #include <ardour/session.h> #include <ardour/audiofilesource.h> @@ -48,117 +44,98 @@ class SoundFileBox : public Gtk::VBox { public: - SoundFileBox (); - virtual ~SoundFileBox () {}; - - void set_session (ARDOUR::Session* s); - bool setup_labels (std::string filename); + SoundFileBox (); + virtual ~SoundFileBox () {}; + + void set_session (ARDOUR::Session* s); + bool setup_labels (std::string filename); protected: ARDOUR::Session* _session; 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; - - pid_t current_pid; - - Gtk::Label length; - Gtk::Label format; - Gtk::Label channels; - Gtk::Label samplerate; - Gtk::Label timecode; - - Gtk::TreeView field_view; - Glib::RefPtr<Gtk::ListStore> fields; - std::string selected_field; - - Gtk::Frame border_frame; - - Gtk::VBox main_box; - Gtk::VBox path_box; - Gtk::HBox top_box; - Gtk::HBox bottom_box; - - Gtk::Button play_btn; - Gtk::Button stop_btn; - Gtk::Button add_field_btn; - Gtk::Button remove_field_btn; - - void setup_fields (); - - void play_btn_clicked (); - void stop_btn_clicked (); - void add_field_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); + + ARDOUR::SoundFileInfo sf_info; + + pid_t current_pid; + + Gtk::Label length; + Gtk::Label format; + Gtk::Label channels; + Gtk::Label samplerate; + Gtk::Label timecode; + + Gtk::Frame border_frame; + + Gtk::Entry tags_entry; + + Gtk::VBox main_box; + Gtk::VBox path_box; + Gtk::HBox top_box; + Gtk::HBox bottom_box; + + Gtk::Button play_btn; + Gtk::Button stop_btn; + Gtk::Button apply_btn; + + bool tags_entry_left (GdkEventFocus* event); + void play_btn_clicked (); + void stop_btn_clicked (); + void apply_btn_clicked (); + + void audition_status_changed (bool state); }; class SoundFileBrowser : public ArdourDialog { public: - SoundFileBrowser (std::string title, ARDOUR::Session* _s = 0); - virtual ~SoundFileBrowser () {}; - - virtual void set_session (ARDOUR::Session*); + SoundFileBrowser (std::string title, ARDOUR::Session* _s = 0); + virtual ~SoundFileBrowser () {}; + + virtual void set_session (ARDOUR::Session*); protected: - Gtk::FileChooserWidget chooser; - SoundFileBox preview; - - void update_preview (); + Gtk::FileChooserWidget chooser; + SoundFileBox preview; + + void update_preview (); }; class SoundFileChooser : public SoundFileBrowser { public: - SoundFileChooser (std::string title, ARDOUR::Session* _s = 0); - virtual ~SoundFileChooser () {}; - - std::string get_filename () {return chooser.get_filename();}; + SoundFileChooser (std::string title, ARDOUR::Session* _s = 0); + virtual ~SoundFileChooser () {}; + + std::string get_filename () {return chooser.get_filename();}; }; class SoundFileOmega : public SoundFileBrowser { public: - SoundFileOmega (std::string title, ARDOUR::Session* _s); - virtual ~SoundFileOmega () {}; - - /* these are returned by the Dialog::run() method. note - that builtin GTK responses are all negative, leaving - positive values for application-defined responses. - */ - - const static int ResponseImport = 1; - const static int ResponseEmbed = 2; - - std::vector<Glib::ustring> get_paths (); - bool get_split (); - - void set_mode (Editing::ImportMode); - Editing::ImportMode get_mode (); + SoundFileOmega (std::string title, ARDOUR::Session* _s); + virtual ~SoundFileOmega () {}; + + /* these are returned by the Dialog::run() method. note + that builtin GTK responses are all negative, leaving + positive values for application-defined responses. + */ + + const static int ResponseImport = 1; + const static int ResponseEmbed = 2; + + std::vector<Glib::ustring> get_paths (); + bool get_split (); + + void set_mode (Editing::ImportMode); + Editing::ImportMode get_mode (); protected: - Gtk::CheckButton split_check; - Gtk::ComboBoxText mode_combo; - - void mode_changed (); - - static std::vector<std::string> mode_strings; + Gtk::CheckButton split_check; + Gtk::ComboBoxText mode_combo; + + void mode_changed (); + + static std::vector<std::string> mode_strings; }; #endif // __ardour_sfdb_ui_h__ diff --git a/gtk2_ardour/visual_time_axis.cc b/gtk2_ardour/visual_time_axis.cc index 24cafdbe67..20fe13603e 100644 --- a/gtk2_ardour/visual_time_axis.cc +++ b/gtk2_ardour/visual_time_axis.cc @@ -375,17 +375,17 @@ VisualTimeAxis::name_entry_changed() return; } + strip_whitespace_edges(x); + if (x.length() == 0) { name_entry.set_text (time_axis_name); return; } - strip_whitespace_edges(x); - if (!editor.get_named_time_axis(x)) { set_time_axis_name(x, this); } 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); } } diff --git a/libs/ardour/ardour/audio_library.h b/libs/ardour/ardour/audio_library.h index f5ac6da654..4edf6d94e4 100644 --- a/libs/ardour/ardour/audio_library.h +++ b/libs/ardour/ardour/audio_library.h @@ -1,6 +1,5 @@ /* - Copyright (C) 2003 Paul Davis - Author: Taybin Rutkin + Copyright (C) 2003-2006 Paul Davis 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 @@ -16,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __ardour_audio_library_h__ @@ -26,63 +24,30 @@ #include <map> #include <vector> -#include <sigc++/signal.h> - -#include <pbd/stateful.h> - using std::vector; using std::string; using std::map; namespace ARDOUR { -class AudioLibrary : public Stateful +class AudioLibrary { public: AudioLibrary (); ~AudioLibrary (); - static string state_node_name; - - XMLNode& get_state (void); - 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 set_tags (string member, vector<string> tags); + vector<string> get_tags (string member); - 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 search_members_and (vector<string>& results, const vector<string> tags); void save_changes(); - - sigc::signal<void> fields_changed; 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; - void initialize_db(); - void compact_vector (vector<string>& vec); + string path2uri (string); + bool safe_file_extension (string); }; diff --git a/libs/ardour/audio_library.cc b/libs/ardour/audio_library.cc index 3aa6d05be1..7a8414946c 100644 --- a/libs/ardour/audio_library.cc +++ b/libs/ardour/audio_library.cc @@ -1,6 +1,5 @@ /* - Copyright (C) 2003 Paul Davis - Author: Taybin Rutkin + Copyright (C) 2003-2006 Paul Davis 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 @@ -16,25 +15,14 @@ along with this program; if not, write to the Free Software 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 <cctype> - -#include <sys/types.h> -#include <sys/stat.h> -#include <fts.h> #include <lrdf.h> #include <pbd/compose.h> -#include <ardour/ardour.h> -#include <ardour/configuration.h> #include <ardour/audio_library.h> #include <ardour/utils.h> @@ -42,16 +30,11 @@ using namespace std; using namespace ARDOUR; -using namespace PBD; - -static char* SOUNDFILE = "http://ardour.org/ontology/Soundfile"; -string AudioLibrary::state_node_name = "AudioLibrary"; +static char* TAG = "http://ardour.org/ontology/Tag"; AudioLibrary::AudioLibrary () { -// sfdb_paths.push_back("/Users/taybin/sounds"); - src = "file:" + get_user_ardour_path() + "sfdb"; // workaround for possible bug in raptor that crashes when saving to a @@ -59,23 +42,6 @@ AudioLibrary::AudioLibrary () touch_file(get_user_ardour_path() + "sfdb"); 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 () @@ -83,56 +49,78 @@ 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 AudioLibrary::save_changes () { 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 -AudioLibrary::add_member (string member) +string +AudioLibrary::path2uri (string path) { - string file_uri(string_compose("file:%1", member)); - - lrdf_add_triple(src.c_str(), file_uri.c_str(), RDF_TYPE, - SOUNDFILE, lrdf_uri); + stringstream uri; + uri << "file:" << path; + return uri.str(); } void -AudioLibrary::remove_member (string uri) +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)); + + 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) { - lrdf_remove_uri_matches (uri.c_str()); + 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 -AudioLibrary::search_members_and (vector<string>& members, - const map<string,string>& fields) +AudioLibrary::search_members_and (vector<string>& members, const vector<string> tags) { lrdf_statement **head; lrdf_statement* pattern = 0; lrdf_statement* old = 0; head = &pattern; - map<string,string>::const_iterator i; - for (i = fields.begin(); i != fields.end(); ++i){ + vector<string>::const_iterator i; + for (i = tags.begin(); i != tags.end(); ++i){ pattern = new lrdf_statement; pattern->subject = "?"; - pattern->predicate = strdup(field_uri(i->first).c_str()); - pattern->object = strdup((i->second).c_str()); + pattern->predicate = TAG; + pattern->object = strdup((*i).c_str()); pattern->next = old; old = pattern; @@ -146,7 +134,8 @@ AudioLibrary::search_members_and (vector<string>& members, } lrdf_free_uris(ulist); - compact_vector(members); + sort(members.begin(), members.end()); + unique(members.begin(), members.end()); } // memory clean up @@ -160,321 +149,25 @@ 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 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 && + 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 && + file.rfind(".mp3") == string::npos && + file.rfind(".aac") == string::npos && + file.rfind(".mp4") == string::npos && #endif // HAVE_COREAUDIO - 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; + file.rfind(".voc") == string::npos); } diff --git a/libs/ardour/configuration.cc b/libs/ardour/configuration.cc index e84e92fa26..eb3d879447 100644 --- a/libs/ardour/configuration.cc +++ b/libs/ardour/configuration.cc @@ -25,7 +25,6 @@ #include <pbd/xml++.h> #include <ardour/ardour.h> -#include <ardour/audio_library.h> #include <ardour/configuration.h> #include <ardour/audio_diskstream.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 (Library->get_state()); return *root; } @@ -235,8 +233,6 @@ Configuration::set_state (const XMLNode& root) } else if (node->name() == ControlProtocolManager::state_node_name) { _control_protocol_state = new XMLNode (*node); - } else if (node->name() == AudioLibrary::state_node_name) { - Library->set_state (*node); } } diff --git a/libs/gtkmm2ext/prompter.cc b/libs/gtkmm2ext/prompter.cc index c3a04f19a8..d06204d356 100644 --- a/libs/gtkmm2ext/prompter.cc +++ b/libs/gtkmm2ext/prompter.cc @@ -86,7 +86,7 @@ Prompter::get_result (string &str, bool strip) { str = entry.get_text (); if (strip) { - strip_whitespace_edges (str); + PBD::strip_whitespace_edges (str); } } diff --git a/libs/pbd/pbd/whitespace.h b/libs/pbd/pbd/whitespace.h index 6620a8fb50..6adb41641c 100644 --- a/libs/pbd/pbd/whitespace.h +++ b/libs/pbd/pbd/whitespace.h @@ -3,6 +3,12 @@ #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); +} // namespace PBD + #endif // __pbd_whitespace_h__ diff --git a/libs/pbd/whitespace.cc b/libs/pbd/whitespace.cc index 53616133ad..a719fb169f 100644 --- a/libs/pbd/whitespace.cc +++ b/libs/pbd/whitespace.cc @@ -2,6 +2,8 @@ using namespace std; +namespace PBD { + void strip_whitespace_edges (string& str) { @@ -24,7 +26,8 @@ strip_whitespace_edges (string& str) } if (i == len) { - /* its all whitespace, not much we can do */ + /* it's all whitespace, not much we can do */ + str = ""; return; } @@ -55,3 +58,4 @@ strip_whitespace_edges (string& str) } } +} // namespace PBD |