diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2015-10-19 14:52:48 +1000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2015-10-22 11:51:03 -0400 |
commit | 689862cafb0333978268e21b08670d07255ccb99 (patch) | |
tree | 368e980e3cc1cccd360da468919ed24865e602a0 /libs/ardour/midi_patch_manager.cc | |
parent | 3bd928591b62443631b373a2c8a2481aa3cff764 (diff) |
Decouple Session from MidiPatchManager and reduce parsing of midnam xml files
The MidiPatchManager only requires a reference to the session to get the path
to the Session midnam directory so change it so that the path is passed to
MidiPatchManager::add_search_path on Session construction and removed on
Session Destruction. This will also make it easier to test and reduce compile
times etc.
For the common case where the Session doesn't have a Session specific midnam
patch files directory(for instance a new session) it won't cause a refresh and
reparsing of all the midnam files. This saves about 2 seconds to load a Session
on my machine(fast machine with SSD), or about half the time spent in the
Session constructor for a new session.
There is still going to be that initial cost of parsing the midnam files when
the first session is created after starting Ardour. Options to remove that
would be to parse the files asynchronously and or use a faster xml
parser(eventually), neither of which seem worth doing at this stage.
This change will cause a performance regression for the uncommon case where a
Session with Session specific midnam files is unloaded and then another Session
with Session specific midnam files is loaded as it will cause the common midnam
files in midi_patch_path to be parsed twice(unload and load).
Diffstat (limited to 'libs/ardour/midi_patch_manager.cc')
-rw-r--r-- | libs/ardour/midi_patch_manager.cc | 97 |
1 files changed, 49 insertions, 48 deletions
diff --git a/libs/ardour/midi_patch_manager.cc b/libs/ardour/midi_patch_manager.cc index c6e70b2a6c..83a7a20c7f 100644 --- a/libs/ardour/midi_patch_manager.cc +++ b/libs/ardour/midi_patch_manager.cc @@ -25,8 +25,6 @@ #include "pbd/file_utils.h" #include "pbd/error.h" -#include "ardour/session.h" -#include "ardour/session_directory.h" #include "ardour/midi_patch_manager.h" #include "ardour/search_paths.h" @@ -43,13 +41,56 @@ MidiPatchManager* MidiPatchManager::_manager = 0; MidiPatchManager::MidiPatchManager () { + add_search_path(midi_patch_search_path ()); } void -MidiPatchManager::set_session (Session* s) +MidiPatchManager::add_search_path (const Searchpath& search_path) { - SessionHandlePtr::set_session (s); - refresh (); + bool do_refresh = false; + + for (Searchpath::const_iterator i = search_path.begin(); i != search_path.end(); ++i) { + + if (_search_path.contains(*i)) { + // already processed files from this path + continue; + } + + if (!Glib::file_test (*i, Glib::FILE_TEST_EXISTS)) { + continue; + } + + if (!Glib::file_test (*i, Glib::FILE_TEST_IS_DIR)) { + continue; + } + + _search_path.add_directory (*i); + do_refresh = true; + } + + if (do_refresh) { + refresh(); + } +} + +void +MidiPatchManager::remove_search_path (const Searchpath& search_path) +{ + bool do_refresh = false; + + for (Searchpath::const_iterator i = search_path.begin(); i != search_path.end(); ++i) { + + if (!_search_path.contains(*i)) { + continue; + } + + _search_path.remove_directory (*i); + do_refresh = true; + } + + if (do_refresh) { + refresh(); + } } bool @@ -95,32 +136,6 @@ MidiPatchManager::add_midi_name_document (const std::string& file_path) } void -MidiPatchManager::add_session_patches () -{ - if (!_session) { - return; - } - - std::string path_to_patches = _session->session_directory().midi_patch_path(); - - if (!Glib::file_test (path_to_patches, Glib::FILE_TEST_EXISTS)) { - return; - } - - assert (Glib::file_test (path_to_patches, Glib::FILE_TEST_IS_DIR)); - - vector<std::string> result; - - find_files_matching_pattern (result, path_to_patches, "*.midnam"); - - info << "Loading " << result.size() << " MIDI patches from " << path_to_patches << endmsg; - - for (vector<std::string>::iterator i = result.begin(); i != result.end(); ++i) { - add_midi_name_document(*i); - } -} - -void MidiPatchManager::refresh() { _documents.clear(); @@ -128,28 +143,14 @@ MidiPatchManager::refresh() _all_models.clear(); _devices_by_manufacturer.clear(); - Searchpath search_path = midi_patch_search_path (); vector<std::string> result; - find_files_matching_pattern (result, search_path, "*.midnam"); + find_files_matching_pattern (result, _search_path, "*.midnam"); - info << "Loading " << result.size() << " MIDI patches from " << search_path.to_string() << endmsg; + info << "Loading " << result.size() << " MIDI patches from " + << _search_path.to_string() << endmsg; for (vector<std::string>::iterator i = result.begin(); i != result.end(); ++i) { add_midi_name_document (*i); } - - if (_session) { - add_session_patches (); - } -} - -void -MidiPatchManager::session_going_away () -{ - SessionHandlePtr::session_going_away (); - _documents.clear(); - _master_devices_by_model.clear(); - _all_models.clear(); - _devices_by_manufacturer.clear(); } |