PBD::strip_whitespace_edges() returns the empty string if the passed string is
authorTaybin Rutkin <taybin@taybin.com>
Fri, 1 Dec 2006 06:01:30 +0000 (06:01 +0000)
committerTaybin Rutkin <taybin@taybin.com>
Fri, 1 Dec 2006 06:01:30 +0000 (06:01 +0000)
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

14 files changed:
PACKAGER_README
gtk2_ardour/audio_time_axis.cc
gtk2_ardour/option_editor.cc
gtk2_ardour/option_editor.h
gtk2_ardour/route_time_axis.cc
gtk2_ardour/sfdb_ui.cc
gtk2_ardour/sfdb_ui.h
gtk2_ardour/visual_time_axis.cc
libs/ardour/ardour/audio_library.h
libs/ardour/audio_library.cc
libs/ardour/configuration.cc
libs/gtkmm2ext/prompter.cc
libs/pbd/pbd/whitespace.h
libs/pbd/whitespace.cc

index 36017496be7c4ec082ee3b53970a92fb4c860812..303df707f0eb141831a69fc1d7c364169053adaf 100644 (file)
@@ -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.
index 2be25f76aabed687c8f5ce1e83dce3a89ce6f956..4ab0428a5100ff6f5ce20d1d89b9ca4b59674e2d 100644 (file)
@@ -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>
index 3e461a85d7b475cad4ecaa169801d5c3cc8abff9..77af85584590dcac682817bdde6fe25b20e2416b 100644 (file)
@@ -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,23 +222,9 @@ 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 ()
 {
@@ -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);
                }
        }
 }
index 2076da3935b737db2e8d96b759876ddab1b84482..cc28a74e603620e5e0b292b2e91338ab8a8726f7 100644 (file)
@@ -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 */
 
index 348e4fb01f5665de920625b83c510def999b8e3d..4d0b50703736a8c95d50001051fc67391e50f362 100644 (file)
@@ -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());
        }
 }
index 150b07166176117f04832ea778c5de4a502bf835..3084844f7898c8d8fd5654fcba6d64727c65de70 100644 (file)
@@ -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
     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,56 +223,35 @@ 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)
 {
@@ -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);
index d7c2c14014af4816ab58c58cefef54034b513d97..c8a0d316a5c5fa4509da2764d6a9c2b80c5a2e51 100644 (file)
@@ -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>
 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__
index 24cafdbe67a0985b74bc3e660ab6d53c7ed11361..20fe13603e742a8bb188edd6f0a057d7a2f9f045 100644 (file)
@@ -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);
        }
 }
index f5ac6da65497683fdb979b38677736d25e57ccc5..4edf6d94e48165f4eec2845578483fe59aa90391 100644 (file)
@@ -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__
 #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);
 };
 
index 3aa6d05be1fea88bc087318d349829c1583e8ab8..7a8414946ce79db2712821299a9dd27426b0ab5a 100644 (file)
@@ -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
     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>
 
 
 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,80 +42,85 @@ 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 ()
 {
 }
 
-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);
 }
index e84e92fa26beabc64d5fe3a976ccef2aa0265379..eb3d8794472932bb0f195ddefb89027c4d4d3838 100644 (file)
@@ -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);
                }
        }
 
index c3a04f19a884dea9a92e04f0b9a6006ad74fe210..d06204d35617f1e27a291678db29ffa3348efed1 100644 (file)
@@ -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);
        }
 }
 
index 6620a8fb50f9fe27b564e4cab6359774815ed9ab..6adb41641c70c879ee416fba73c5524191ddf739 100644 (file)
@@ -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__
index 53616133ade362f96c87e2778d1b38b7892fdb93..a719fb169f2af983150620c8f56da841a036a2b3 100644 (file)
@@ -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