make MIDI Patch Manager search in $user_config_dir/patchfiles for midnam files as...
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 20 Mar 2012 18:03:46 +0000 (18:03 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 20 Mar 2012 18:03:46 +0000 (18:03 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@11736 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/midi_patch_manager.h
libs/ardour/ardour/midi_patch_search_path.h [new file with mode: 0644]
libs/ardour/midi_patch_manager.cc
libs/ardour/midi_patch_search_path.cc [new file with mode: 0644]
libs/ardour/wscript

index f352009ba7ce731252fcdea814c9a000d69ae469..32b3ebc61de6edf885a85f6b4186f98347e4126a 100644 (file)
@@ -39,7 +39,7 @@ class MidiPatchManager : public PBD::ScopedConnectionList, public ARDOUR::Sessio
 {
        /// Singleton
 private:
-       MidiPatchManager() {};
+       MidiPatchManager();
        MidiPatchManager( const MidiPatchManager& );
        MidiPatchManager& operator= (const MidiPatchManager&);
 
@@ -136,6 +136,7 @@ public:
 private:
        void session_going_away();
        void refresh();
+       void add_session_patches();
 
        MidiNameDocuments                       _documents;
        MIDINameDocument::MasterDeviceNamesList _master_devices_by_model;
diff --git a/libs/ardour/ardour/midi_patch_search_path.h b/libs/ardour/ardour/midi_patch_search_path.h
new file mode 100644 (file)
index 0000000..5d27823
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+    Copyright (C) 2011 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
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef __ardour_midi_patch_search_path_h__
+#define __ardour_midi_patch_search_path_h__
+
+#include "pbd/search_path.h"
+
+namespace ARDOUR {
+
+       /**
+        * return a SearchPath containing directories in which to look for
+        * MIDI patch files ("*.midnam") aka MIDNAM files
+        *
+        * If ARDOUR_MIDI_PATCH_PATH is defined then the SearchPath returned
+        * will contain only those directories specified in it, otherwise it will
+        * contain the user and system directories which may contain control
+        * surface plugins.
+        */
+       PBD::SearchPath midi_patch_search_path ();
+
+} // namespace ARDOUR
+
+#endif /* __ardour_midi_patch_search_path_h__ */
index 2c2f36daa67e389e2278d243cf49924ce1dd4359..d3d080a179c3011243221788417f5088a70a658e 100644 (file)
@@ -27,6 +27,7 @@
 #include "ardour/session.h"
 #include "ardour/session_directory.h"
 #include "ardour/midi_patch_manager.h"
+#include "ardour/midi_patch_search_path.h"
 
 #include "i18n.h"
 
@@ -39,27 +40,28 @@ using namespace PBD::sys;
 
 MidiPatchManager* MidiPatchManager::_manager = 0;
 
+MidiPatchManager::MidiPatchManager ()
+{
+       refresh ();
+}
+
 void
 MidiPatchManager::set_session (Session* s)
 {
        SessionHandlePtr::set_session (s);
-       refresh();
+       add_session_patches ();
 }
 
 void
-MidiPatchManager::refresh()
+MidiPatchManager::add_session_patches ()
 {
-       _documents.clear();
-       _master_devices_by_model.clear();
-       _all_models.clear();
-
        if (!_session) {
                return;
        }
-
+       
        path path_to_patches = _session->session_directory().midi_patch_path();
 
-       if (!exists(path_to_patches)) {
+       if (!exists (path_to_patches)) {
                return;
        }
 
@@ -68,9 +70,45 @@ MidiPatchManager::refresh()
        Glib::PatternSpec pattern(string("*.midnam"));
        vector<path> result;
 
-       find_matching_files_in_directory(path_to_patches, pattern, result);
+       find_matching_files_in_directory (path_to_patches, pattern, result);
+
+       info << "Loading " << result.size() << " MIDI patches from " << path_to_patches.to_string() << endmsg;
+
+       for (vector<path>::iterator i = result.begin(); i != result.end(); ++i) {
+               boost::shared_ptr<MIDINameDocument> document(new MIDINameDocument(i->to_string()));
+               for (MIDINameDocument::MasterDeviceNamesList::const_iterator device =
+                                       document->master_device_names_by_model().begin();
+                               device != document->master_device_names_by_model().end();
+                               ++device) {
+                       //cerr << "got model " << device->first << endl;
+                       // have access to the documents by model name
+                       _documents[device->first] = document;
+                       // build a list of all master devices from all documents
+                       _master_devices_by_model[device->first] = device->second;
+                       _all_models.push_back(device->first);
+
+                       // make sure there are no double model names
+                       // TODO: handle this gracefully.
+                       assert(_documents.count(device->first) == 1);
+                       assert(_master_devices_by_model.count(device->first) == 1);
+               }
+       }
+}
+
+void
+MidiPatchManager::refresh()
+{
+       _documents.clear();
+       _master_devices_by_model.clear();
+       _all_models.clear();
+
+       SearchPath search_path = midi_patch_search_path ();
+       Glib::PatternSpec pattern (string("*.midnam"));
+       vector<path> result;
+
+       find_matching_files_in_search_path (search_path, pattern, result);
 
-       info << "Loading " << result.size() << " MIDI patches from " << path_to_patches.to_string() << endl;
+       info << "Loading " << result.size() << " MIDI patches from " << search_path.to_string() << endmsg;
 
        for (vector<path>::iterator i = result.begin(); i != result.end(); ++i) {
                boost::shared_ptr<MIDINameDocument> document(new MIDINameDocument(i->to_string()));
@@ -91,6 +129,10 @@ MidiPatchManager::refresh()
                        assert(_master_devices_by_model.count(device->first) == 1);
                }
        }
+
+       if (_session) {
+               add_session_patches ();
+       }
 }
 
 void
diff --git a/libs/ardour/midi_patch_search_path.cc b/libs/ardour/midi_patch_search_path.cc
new file mode 100644 (file)
index 0000000..014e41f
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+    Copyright (C) 2007 Tim Mayberry
+
+    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
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <glibmm/miscutils.h>
+
+#include "ardour/midi_name_search_path.h"
+#include "ardour/directory_names.h"
+#include "ardour/filesystem_paths.h"
+
+namespace {
+       const char * const midi_patch_env_variable_name = "ARDOUR_MIDI_PATCH_PATH";
+} // anonymous
+
+using namespace PBD;
+
+namespace ARDOUR {
+
+SearchPath
+midi_patch_search_path ()
+{
+       SearchPath spath (user_config_directory ());
+
+       spath += ardour_module_directory ();
+       spath.add_subdirectory_to_paths(midi_patch_dir_name);
+
+       bool midi_patch_path_defined = false;
+       SearchPath spath_env (Glib::getenv(midi_patch_env_variable_name, midi_patch_path_defined));
+
+       if (midi_patch_path_defined) {
+               spath += spath_env;
+       }
+
+       return spath;
+}
+
+} // namespace ARDOUR
index 91a7ea6e7d3d9e9fb71f09a48be86ccdf00e999e..ab04fde80b693f5bc51d36cf6b91a2b13b362cfc 100644 (file)
@@ -123,6 +123,7 @@ libardour_sources = [
         'midi_diskstream.cc',
         'midi_model.cc',
         'midi_patch_manager.cc',
+        'midi_patch_search_path.cc',
         'midi_playlist.cc',
         'midi_playlist_source.cc',
         'midi_port.cc',