Allow to dynamically un/load Midnam Patches
This commit is contained in:
parent
06700cb2f4
commit
0332c127cd
@ -57,12 +57,16 @@ public:
|
||||
return *_manager;
|
||||
}
|
||||
|
||||
PBD::Signal0<void> 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<MIDINameDocument> document_by_model(std::string model_name)
|
||||
{ return _documents[model_name]; }
|
||||
boost::shared_ptr<MIDINameDocument> document_by_model(std::string model_name) const;
|
||||
|
||||
boost::shared_ptr<MasterDeviceNames> 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<MIDINameDocument>);
|
||||
bool remove_midi_name_document(const std::string& file_path);
|
||||
|
||||
void add_midnam_files_from_directory(const std::string& directory_path);
|
||||
|
@ -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<MIDINameDocument> document;
|
||||
document = boost::shared_ptr<MIDINameDocument>(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<std::string>::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<MIDINameDocument> 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<MIDINameDocument>
|
||||
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<MIDINameDocument> ();
|
||||
}
|
||||
|
||||
bool
|
||||
MidiPatchManager::add_midi_name_document (boost::shared_ptr<MIDINameDocument> 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<MIDINameDocument> 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;
|
||||
}
|
||||
|
@ -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<MasterDeviceNames> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user