First pass of sfdb tag searching. Not functional, but very very close.
authorTaybin Rutkin <taybin@taybin.com>
Fri, 5 Jan 2007 04:24:23 +0000 (04:24 +0000)
committerTaybin Rutkin <taybin@taybin.com>
Fri, 5 Jan 2007 04:24:23 +0000 (04:24 +0000)
git-svn-id: svn://localhost/ardour2/trunk@1272 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/ardour.bindings
gtk2_ardour/sfdb_ui.cc
gtk2_ardour/sfdb_ui.h
libs/ardour/ardour/audio_library.h
libs/ardour/ardour/audiofilesource.h
libs/ardour/audio_library.cc
libs/ardour/audiofilesource.cc
libs/pbd/pbd/tokenizer.h

index dcb75c754835d5942ecb0718ad7c6e09cc4cfa6f..8d280b536d44980cf30b5b3bbc2f5f5e15deb5f5 100644 (file)
@@ -1,4 +1,4 @@
-; ardour.bin GtkAccelMap rc-file         -*- scheme -*-
+; ardour-2.0beta10 GtkAccelMap rc-file         -*- scheme -*-
 ; this file is an automated accelerator map dump
 ;
 ; (gtk_accel_path "<Actions>/RegionList/RegionListSort" "")
index 3084844f7898c8d8fd5654fcba6d64727c65de70..d3c61859919e31cc8b5a71dd4fb399fc4b1d084b 100644 (file)
@@ -25,6 +25,7 @@
 #include <gtkmm/stock.h>
 
 #include <pbd/convert.h>
+#include <pbd/tokenizer.h>
 #include <pbd/whitespace.h>
 
 #include <gtkmm2ext/utils.h>
@@ -53,13 +54,15 @@ SoundFileBox::SoundFileBox ()
        _session(0),
        current_pid(0),
        main_box (false, 3),
-       top_box (true, 4),
        bottom_box (true, 4),
        play_btn(_("Play")),
        stop_btn(_("Stop")),
        apply_btn(_("Apply"))
 {
        set_name (X_("SoundFileBox"));
+       
+       set_size_request (250, 500);
+       
        border_frame.set_label (_("Soundfile Info"));
        border_frame.add (main_box);
 
@@ -74,12 +77,9 @@ SoundFileBox::SoundFileBox ()
        main_box.pack_start(samplerate, false, false);
        main_box.pack_start(timecode, false, false);
        main_box.pack_start(tags_entry, true, true);
-       main_box.pack_start(top_box, false, false);
+       main_box.pack_start(apply_btn, false, false);
        main_box.pack_start(bottom_box, false, false);
 
-       top_box.set_homogeneous(true);
-       top_box.pack_start(apply_btn);
-
        bottom_box.set_homogeneous(true);
        bottom_box.pack_start(play_btn);
        bottom_box.pack_start(stop_btn);
@@ -89,8 +89,16 @@ SoundFileBox::SoundFileBox ()
        stop_btn.signal_clicked().connect (mem_fun (*this, &SoundFileBox::stop_btn_clicked));
        apply_btn.signal_clicked().connect (mem_fun (*this, &SoundFileBox::apply_btn_clicked));
 
-       show_all();
+       length.set_alignment (0.0f, 0.0f);
+       format.set_alignment (0.0f, 0.0f);
+       channels.set_alignment (0.0f, 0.0f);
+       samplerate.set_alignment (0.0f, 0.0f);
+       timecode.set_alignment (0.0f, 0.0f);
+
+       stop_btn.set_no_show_all (true);
        stop_btn.hide();
+       
+       show_all();
 }
 
 void
@@ -113,22 +121,24 @@ SoundFileBox::setup_labels (string filename)
        string error_msg;
 
        if(!AudioFileSource::get_soundfile_info (filename, sf_info, error_msg)) {
+               length.set_text (_("Length: n/a"));
+               format.set_text (_("Format: n/a"));
+               channels.set_text (_("Channels: n/a"));
+               samplerate.set_text (_("Samplerate: n/a"));
+               timecode.set_text (_("Timecode: n/a"));
+               tags_entry.set_text ("");
+               
+               tags_entry.set_sensitive (false);
+               play_btn.set_sensitive (false);
+               apply_btn.set_sensitive (false);
+               
                return false;
        }
 
-       length.set_alignment (0.0f, 0.0f);
        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);
-
-       channels.set_alignment (0.0f, 0.0f);
        channels.set_text (string_compose(_("Channels: %1"), sf_info.channels));
-
-       samplerate.set_alignment (0.0f, 0.0f);
        samplerate.set_text (string_compose(_("Samplerate: %1"), sf_info.samplerate));
-
-       timecode.set_alignment (0.0f, 0.0f);
        timecode.set_text (string_compose (_("Timecode: %1"), length2string(sf_info.timecode, sf_info.samplerate)));
 
        vector<string> tags = Library->get_tags (filename);
@@ -142,6 +152,12 @@ SoundFileBox::setup_labels (string filename)
        }
        tags_entry.set_text (tag_string.str());
        
+       tags_entry.set_sensitive (true);
+       if (_session) {
+               play_btn.set_sensitive (true);
+       }
+       apply_btn.set_sensitive (true);
+       
        return true;
 }
 
@@ -229,25 +245,11 @@ SoundFileBox::apply_btn_clicked ()
 
        vector<string> tags;
 
-       static const string DELIMITERS = ",";
+    if (!PBD::tokenize (tag_string, string(","), std::back_inserter (tags), true)) {
+               warning << _("SoundFileBox: Could not tokenize string: ") << tag_string << endmsg;
+               return;
+       }
        
-       // 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 ();
 }
@@ -273,15 +275,39 @@ static const char *import_mode_strings[] = {
 
 SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s)
        : ArdourDialog (title, false),
-         chooser (Gtk::FILE_CHOOSER_ACTION_OPEN)
+         chooser (Gtk::FILE_CHOOSER_ACTION_OPEN),
+         found_list (Gtk::ListStore::create(found_list_columns)),
+         found_list_view (found_list),
+         found_search_btn (_("Search"))
 {
        set_default_size (700, 500);
-       get_vbox()->pack_start(chooser);
-       chooser.set_preview_widget(preview);
-       chooser.set_select_multiple (true);
+       Gtk::HBox* hbox = manage(new Gtk::HBox);
+       hbox->pack_start(notebook);
+       hbox->pack_start(preview, Gtk::PACK_SHRINK);
+       get_vbox()->pack_start(*hbox);
+
+       hbox = manage(new Gtk::HBox);
+       hbox->pack_start (found_entry);
+       hbox->pack_start (found_search_btn);
+       
+       Gtk::VBox* vbox = manage(new Gtk::VBox);
+       vbox->pack_start (*hbox, Gtk::PACK_SHRINK);
+       vbox->pack_start (found_list_view);
+       found_list_view.append_column(_("Paths"), found_list_columns.pathname);
+       
+       notebook.append_page (chooser, _("Files"));
+       notebook.append_page (*vbox, _("Tags"));
 
+       filter.add_custom (Gtk::FILE_FILTER_FILENAME, mem_fun(*this, &SoundFileBrowser::on_custom));
+       chooser.set_filter (filter);
+       chooser.set_select_multiple (true);
        chooser.signal_update_preview().connect(mem_fun(*this, &SoundFileBrowser::update_preview));
+       found_list_view.get_selection()->signal_changed().connect(mem_fun(*this, &SoundFileBrowser::found_list_view_selected));
+       
+       found_search_btn.signal_clicked().connect(mem_fun(*this, &SoundFileBrowser::found_search_clicked));
 
+       show_all ();
+       
        set_session (s);
 }
 
@@ -291,10 +317,46 @@ SoundFileBrowser::set_session (Session* s)
        preview.set_session(s);
 }
 
+bool
+SoundFileBrowser::on_custom (const Gtk::FileFilter::Info& filter_info)
+{
+       return AudioFileSource::safe_file_extension(filter_info.filename);
+}
+
 void
 SoundFileBrowser::update_preview ()
 {
-       chooser.set_preview_widget_active(preview.setup_labels(chooser.get_filename()));
+       preview.setup_labels(chooser.get_filename());
+}
+
+void
+SoundFileBrowser::found_list_view_selected ()
+{
+       
+}
+
+void
+SoundFileBrowser::found_search_clicked ()
+{
+       string tag_string = found_entry.get_text ();
+
+       vector<string> tags;
+
+    if (!PBD::tokenize (tag_string, string(","), std::back_inserter (tags), true)) {
+               warning << _("SoundFileBox: Could not tokenize string: ") << tag_string << endmsg;
+               return;
+       }
+
+       vector<string> results;
+       Library->search_members_and (results, tags);
+       
+       found_list->clear();
+       for (vector<string>::iterator i = results.begin(); i != results.end(); ++i) {
+               Gtk::TreeModel::iterator new_row = found_list->append();
+               Gtk::TreeModel::Row row = *new_row;
+               cout << *i << endl;
+               row[found_list_columns.pathname] = *i;
+       }
 }
 
 SoundFileChooser::SoundFileChooser (string title, ARDOUR::Session* s)
@@ -303,6 +365,7 @@ SoundFileChooser::SoundFileChooser (string title, ARDOUR::Session* s)
 {
        add_button (Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
        add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+       
        show_all ();
 }
 
@@ -312,9 +375,7 @@ SoundFileOmega::SoundFileOmega (string title, ARDOUR::Session* s)
        : SoundFileBrowser (title, s),
          split_check (_("Split Channels"))
 {
-       if (mode_strings.empty()) {
-               mode_strings = I18N (import_mode_strings);
-       }
+//     add_button (Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
 
        ARDOUR_UI::instance()->tooltips().set_tip(split_check, 
                        _("Create a region for each channel"));
@@ -323,24 +384,21 @@ SoundFileOmega::SoundFileOmega (string title, ARDOUR::Session* s)
        ARDOUR_UI::instance()->tooltips().set_tip(*btn, 
                        _("Link to an external file"));
 
-       add_button (Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
-
        btn = add_button (_("Import"), ResponseImport);
        ARDOUR_UI::instance()->tooltips().set_tip(*btn, 
                        _("Copy a file to the session folder"));
-
-       Gtk::HBox *box = manage (new Gtk::HBox());
-
+       
+       if (mode_strings.empty()) {
+               mode_strings = I18N (import_mode_strings);
+       }
        Gtkmm2ext::set_popdown_strings (mode_combo, mode_strings);
 
        set_mode (Editing::ImportAsRegion);
 
-       box->pack_start (split_check);
-       box->pack_start (mode_combo);
+       get_action_area()->pack_start (split_check);
+       get_action_area()->pack_start (mode_combo);
 
        mode_combo.signal_changed().connect (mem_fun (*this, &SoundFileOmega::mode_changed));
-
-       chooser.set_extra_widget (*box);
        
        show_all ();
 }
index c8a0d316a5c5fa4509da2764d6a9c2b80c5a2e51..ae51bcfe270399efcc80df0e575c77e2a4902b27 100644 (file)
@@ -70,7 +70,6 @@ class SoundFileBox : public Gtk::VBox
        
        Gtk::VBox main_box;
        Gtk::VBox path_box;
-       Gtk::HBox top_box;
        Gtk::HBox bottom_box;
        
        Gtk::Button play_btn;
@@ -95,9 +94,30 @@ class SoundFileBrowser : public ArdourDialog
 
   protected:
        Gtk::FileChooserWidget chooser;
+       Gtk::FileFilter filter;
        SoundFileBox preview;
        
+       class FoundTagColumns : public Gtk::TreeModel::ColumnRecord
+       {
+         public:
+               Gtk::TreeModelColumn<string> pathname;
+               
+               FoundTagColumns() { add(pathname); }
+       };
+       
+       FoundTagColumns found_list_columns;
+       Glib::RefPtr<Gtk::ListStore> found_list;
+       Gtk::TreeView found_list_view;
+       Gtk::Entry found_entry;
+       Gtk::Button found_search_btn;
+       
+       Gtk::Notebook notebook;
+       
        void update_preview ();
+       void found_list_view_selected ();
+       void found_search_clicked ();
+       
+       bool on_custom (const Gtk::FileFilter::Info& filter_info);
 };
 
 class SoundFileChooser : public SoundFileBrowser
index 4edf6d94e48165f4eec2845578483fe59aa90391..8c01f0e3dc1562176fd78b213081e563391d5993 100644 (file)
@@ -46,9 +46,8 @@ class AudioLibrary
   private:
        string src;
        
-       string path2uri (string);
-       
-       bool safe_file_extension (string);
+       string path2uri (string path);
+       string uri2path (string uri);   
 };
 
 extern AudioLibrary* Library;
index 66cc240770134484d3eb0ba618e0a1044eeaddd7..2133136e689be13c8945382933d7d1314cd1ddc4 100644 (file)
@@ -59,6 +59,8 @@ class AudioFileSource : public AudioSource {
 
        static bool get_soundfile_info (string path, SoundFileInfo& _info, string& error);
 
+       static bool safe_file_extension (string path);
+
        void set_allow_remove_if_empty (bool yn);
        void mark_for_remove();
 
index 92069d929ff7c25ea3af2916256d8bc4234b76ec..2ed4739a961fe357e58caf49821ebf657d8cccfd 100644 (file)
@@ -77,6 +77,13 @@ AudioLibrary::path2uri (string path)
        return uri.str();
 }
 
+string
+AudioLibrary::uri2path (string uri)
+{
+       string path = xmlURIUnescapeString(uri.c_str(), 0, 0);
+       return path.substr(5);
+}
+
 void
 AudioLibrary::set_tags (string member, vector<string> tags)
 {
@@ -142,8 +149,8 @@ AudioLibrary::search_members_and (vector<string>& members, const vector<string>
        if (*head != 0) {
                lrdf_uris* ulist = lrdf_match_multi(*head);
                for (uint32_t j = 0; ulist && j < ulist->count; ++j) {
-//                     printf("AND: %s\n", ulist->items[j]);
-                       members.push_back(ulist->items[j]);
+//                     cerr << "AND: " << uri2path(ulist->items[j]) << endl;
+                       members.push_back(uri2path(ulist->items[j]));
                }
                lrdf_free_uris(ulist);
 
@@ -154,33 +161,9 @@ AudioLibrary::search_members_and (vector<string>& members, const vector<string>
        // memory clean up
        pattern = *head;
        while(pattern){
-               free(pattern->predicate);
                free(pattern->object);
                old = pattern;
                pattern = pattern->next;
                delete old;
        }
 }
-
-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 &&
-#ifdef HAVE_COREAUDIO
-               file.rfind(".mp3") == string::npos &&
-               file.rfind(".aac") == string::npos &&
-               file.rfind(".mp4") == string::npos &&
-#endif // HAVE_COREAUDIO
-               file.rfind(".voc") == string::npos);
-}
index 53809c3c2f61297bdbb7ed00793076a0cb3010fd..1915957f3dea18fec89390213e630bedc5bfe3d1 100644 (file)
@@ -543,3 +543,26 @@ AudioFileSource::setup_peakfile ()
                return 0;
        }
 }
+
+bool
+AudioFileSource::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 &&
+#ifdef HAVE_COREAUDIO
+               file.rfind(".mp3") == string::npos &&
+               file.rfind(".aac") == string::npos &&
+               file.rfind(".mp4") == string::npos &&
+#endif // HAVE_COREAUDIO
+               file.rfind(".voc") == string::npos);
+}
index a976b7934118868b1f66f3349467f93cac2ac701..b80e3eac4a4dcd7043c2cdb1320fcb5f021be3df 100644 (file)
@@ -4,18 +4,24 @@
 #include <iterator>
 #include <string>
 
+#include <pbd/whitespace.h>
+
 namespace PBD {
 
 /**
     Tokenize string, this should work for standard
-    strings aswell as Glib::ustring. This is a bit of a hack,
+    strings as well as Glib::ustring. This is a bit of a hack,
     there are much better string tokenizing patterns out there.
+       If strip_whitespace is set to true, tokens will be checked to see
+       that they still have a length after stripping.  If no length, they
+       are discarded.
 */
 template<typename StringType, typename Iter>
 unsigned int
 tokenize(const StringType& str,        
         const StringType& delims,
-        Iter it)
+        Iter it,
+               bool strip_whitespace=false)
 {
     typename StringType::size_type start_pos = 0;
     typename StringType::size_type end_pos = 0;
@@ -28,14 +34,30 @@ tokenize(const StringType& str,
             if (end_pos == str.npos) {
                 end_pos = str.length();
             }
-            *it++ = str.substr(start_pos, end_pos - start_pos);
+               if (strip_whitespace) {
+                               StringType stripped = str.substr(start_pos, end_pos - start_pos);
+                               strip_whitespace_edges (stripped);
+                               if (stripped.length()) {
+                                       *it++ = stripped;
+                               }
+                       } else {
+               *it++ = str.substr(start_pos, end_pos - start_pos);
+                       }
             ++token_count;
             start_pos = str.find_first_not_of(delims, end_pos + 1);
         }
     } while (start_pos != str.npos);
 
     if (start_pos != str.npos) {
-        *it++ = str.substr(start_pos, str.length() - start_pos);
+       if (strip_whitespace) {
+                       StringType stripped = str.substr(start_pos, str.length() - start_pos);
+                       strip_whitespace_edges (stripped);
+                       if (stripped.length()) {
+                               *it++ = stripped;
+                       }
+               } else {
+               *it++ = str.substr(start_pos, str.length() - start_pos);
+               }
         ++token_count;
     }