From: Paul Davis Date: Tue, 20 Mar 2012 18:03:46 +0000 (+0000) Subject: make MIDI Patch Manager search in $user_config_dir/patchfiles for midnam files as... X-Git-Tag: 3.0~1921 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;ds=sidebyside;h=494635b99b9cdac42fd7a14e80c78ce437d6f606;p=ardour.git make MIDI Patch Manager search in $user_config_dir/patchfiles for midnam files as well as the per-session equivalent. need to stop it from doing at session shutdown time too. git-svn-id: svn://localhost/ardour2/branches/3.0@11736 d708f5d6-7413-0410-9779-e7cbd77b26cf --- diff --git a/libs/ardour/ardour/midi_patch_manager.h b/libs/ardour/ardour/midi_patch_manager.h index f352009ba7..32b3ebc61d 100644 --- a/libs/ardour/ardour/midi_patch_manager.h +++ b/libs/ardour/ardour/midi_patch_manager.h @@ -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 index 0000000000..5d27823461 --- /dev/null +++ b/libs/ardour/ardour/midi_patch_search_path.h @@ -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__ */ diff --git a/libs/ardour/midi_patch_manager.cc b/libs/ardour/midi_patch_manager.cc index 2c2f36daa6..d3d080a179 100644 --- a/libs/ardour/midi_patch_manager.cc +++ b/libs/ardour/midi_patch_manager.cc @@ -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 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::iterator i = result.begin(); i != result.end(); ++i) { + boost::shared_ptr 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 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::iterator i = result.begin(); i != result.end(); ++i) { boost::shared_ptr 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 index 0000000000..014e41f190 --- /dev/null +++ b/libs/ardour/midi_patch_search_path.cc @@ -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 + +#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 diff --git a/libs/ardour/wscript b/libs/ardour/wscript index 91a7ea6e7d..ab04fde80b 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -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',