diff --git a/libs/ardour/ardour/midi_patch_manager.h b/libs/ardour/ardour/midi_patch_manager.h index 3c10a3a149..aa4fda108e 100644 --- a/libs/ardour/ardour/midi_patch_manager.h +++ b/libs/ardour/ardour/midi_patch_manager.h @@ -57,12 +57,16 @@ public: return *_manager; } + PBD::Signal0 PatchesChanged; + + bool add_custom_midnam (const std::string& id, const std::string& midnam); + bool remove_custom_midnam (const std::string& id); + void add_search_path (const PBD::Searchpath& search_path); void remove_search_path (const PBD::Searchpath& search_path); - boost::shared_ptr document_by_model(std::string model_name) - { return _documents[model_name]; } + boost::shared_ptr document_by_model(std::string model_name) const; boost::shared_ptr master_device_by_model(std::string model_name) { return _master_devices_by_model[model_name]; } @@ -139,7 +143,8 @@ public: const DeviceNamesByMaker& devices_by_manufacturer() const { return _devices_by_manufacturer; } private: - bool add_midi_name_document(const std::string& file_path); + bool load_midi_name_document(const std::string& file_path); + bool add_midi_name_document(boost::shared_ptr); bool remove_midi_name_document(const std::string& file_path); void add_midnam_files_from_directory(const std::string& directory_path); diff --git a/libs/ardour/midi_patch_manager.cc b/libs/ardour/midi_patch_manager.cc index 8a6d8dfd10..e3bf899bf5 100644 --- a/libs/ardour/midi_patch_manager.cc +++ b/libs/ardour/midi_patch_manager.cc @@ -68,6 +68,28 @@ MidiPatchManager::add_search_path (const Searchpath& search_path) } } +bool +MidiPatchManager::add_custom_midnam (const std::string& id, const std::string& midnam) +{ + boost::shared_ptr document; + document = boost::shared_ptr(new MIDINameDocument()); + XMLTree mxml; + if (mxml.read_buffer (midnam, true)) { + if (0 == document->set_state (mxml, *mxml.root())) { + document->set_file_path ("custom:" + id); + add_midi_name_document (document); + return true; + } + } + return false; +} + +bool +MidiPatchManager::remove_custom_midnam (const std::string& id) +{ + return remove_midi_name_document ("custom:" + id); +} + void MidiPatchManager::add_midnam_files_from_directory(const std::string& directory_path) { @@ -80,7 +102,7 @@ MidiPatchManager::add_midnam_files_from_directory(const std::string& directory_p << endmsg; for (vector::const_iterator i = result.begin(); i != result.end(); ++i) { - add_midi_name_document (*i); + load_midi_name_document (*i); } } @@ -116,7 +138,7 @@ MidiPatchManager::remove_midnam_files_from_directory(const std::string& director } bool -MidiPatchManager::add_midi_name_document (const std::string& file_path) +MidiPatchManager::load_midi_name_document (const std::string& file_path) { boost::shared_ptr document; try { @@ -127,6 +149,22 @@ MidiPatchManager::add_midi_name_document (const std::string& file_path) << endmsg; return false; } + return add_midi_name_document (document); +} + +boost::shared_ptr +MidiPatchManager::document_by_model(std::string model_name) const +{ + MidiNameDocuments::const_iterator i = _documents.find (model_name); + if (i != _documents.end ()) { + return i->second; + } + return boost::shared_ptr (); +} + +bool +MidiPatchManager::add_midi_name_document (boost::shared_ptr document) +{ for (MIDINameDocument::MasterDeviceNamesList::const_iterator device = document->master_device_names_by_model().begin(); device != document->master_device_names_by_model().end(); @@ -134,7 +172,7 @@ MidiPatchManager::add_midi_name_document (const std::string& file_path) if (_documents.find(device->first) != _documents.end()) { warning << string_compose(_("Duplicate MIDI device `%1' in `%2' ignored"), device->first, - file_path) << endmsg; + document->file_path()) << endmsg; continue; } @@ -155,6 +193,8 @@ MidiPatchManager::add_midi_name_document (const std::string& file_path) assert(_documents.count(device->first) == 1); assert(_master_devices_by_model.count(device->first) == 1); } + + PatchesChanged(); /* EMIT SIGNAL */ return true; } @@ -167,9 +207,10 @@ MidiPatchManager::remove_midi_name_document (const std::string& file_path) boost::shared_ptr document = i->second; + cout << string_compose(_("Removing MIDI patch file %1"), file_path) << "\n"; info << string_compose(_("Removing MIDI patch file %1"), file_path) << endmsg; - _documents.erase(i++); + i = _documents.erase(i); for (MIDINameDocument::MasterDeviceNamesList::const_iterator device = document->master_device_names_by_model().begin(); @@ -189,5 +230,8 @@ MidiPatchManager::remove_midi_name_document (const std::string& file_path) ++i; } } + if (removed) { + PatchesChanged(); /* EMIT SIGNAL */ + } return removed; } diff --git a/libs/midi++2/midi++/midnam_patch.h b/libs/midi++2/midi++/midnam_patch.h index 683f52f84d..f6f5f12edf 100644 --- a/libs/midi++2/midi++/midnam_patch.h +++ b/libs/midi++2/midi++/midnam_patch.h @@ -469,9 +469,10 @@ public: virtual ~MIDINameDocument() {}; const std::string& file_path () const { return _file_path; } - const std::string& author() const { return _author; } + void set_author(const std::string& author) { _author = author; } + void set_file_path(const std::string& file_path) { _file_path = file_path; } boost::shared_ptr master_device_names(const std::string& model); @@ -483,7 +484,7 @@ public: int set_state (const XMLTree&, const XMLNode&); private: - const std::string _file_path; + std::string _file_path; std::string _author; MasterDeviceNamesList _master_device_names_list; MasterDeviceNames::Models _all_models;