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]; }
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);
}
}
+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)
{
<< endmsg;
for (vector<std::string>::const_iterator i = result.begin(); i != result.end(); ++i) {
- add_midi_name_document (*i);
+ load_midi_name_document (*i);
}
}
}
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 {
<< 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();
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;
}
assert(_documents.count(device->first) == 1);
assert(_master_devices_by_model.count(device->first) == 1);
}
+
+ PatchesChanged(); /* EMIT SIGNAL */
return true;
}
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();
++i;
}
}
+ if (removed) {
+ PatchesChanged(); /* EMIT SIGNAL */
+ }
return removed;
}
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);
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;