{
/// Singleton
private:
- MidiPatchManager() {};
+ MidiPatchManager();
MidiPatchManager( const MidiPatchManager& );
MidiPatchManager& operator= (const MidiPatchManager&);
private:
void session_going_away();
void refresh();
+ void add_session_patches();
MidiNameDocuments _documents;
MIDINameDocument::MasterDeviceNamesList _master_devices_by_model;
--- /dev/null
+/*
+ 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__ */
#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"
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;
}
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()));
assert(_master_devices_by_model.count(device->first) == 1);
}
}
+
+ if (_session) {
+ add_session_patches ();
+ }
}
void
--- /dev/null
+/*
+ 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
'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',