Fix midnam replacement:
authorRobin Gareus <robin@gareus.org>
Sun, 30 Oct 2016 20:24:26 +0000 (21:24 +0100)
committerRobin Gareus <robin@gareus.org>
Sun, 30 Oct 2016 20:24:26 +0000 (21:24 +0100)
Unloading before update may otherwise reset the patch to
generic midi (when the current patch is no longer available)

libs/ardour/ardour/midi_patch_manager.h
libs/ardour/lv2_plugin.cc
libs/ardour/midi_patch_manager.cc

index aa4fda108e071b5fe94a0fc0810c3cb730381d4b..5eb34dbbf4047c91754ce1028310809c5e00dab9 100644 (file)
@@ -60,6 +60,7 @@ public:
        PBD::Signal0<void> PatchesChanged;
 
        bool add_custom_midnam (const std::string& id, const std::string& midnam);
+       bool update_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);
@@ -145,7 +146,7 @@ public:
 private:
        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);
+       bool remove_midi_name_document(const std::string& file_path, bool emit_signal = true);
 
        void add_midnam_files_from_directory(const std::string& directory_path);
        void remove_midnam_files_from_directory(const std::string& directory_path);
index 94760dc336b356ac05243c8a16c95a0a3683f26c..eca7f0c0ef77f2512309e05178e1e6fee139c40d 100644 (file)
@@ -982,9 +982,15 @@ LV2Plugin::read_midnam () {
                std::stringstream ss;
                ss << (void*)this;
                ss << unique_id();
-               MIDI::Name::MidiPatchManager::instance().remove_custom_midnam (ss.str());
-               rv = MIDI::Name::MidiPatchManager::instance().add_custom_midnam (ss.str(), midnam);
+               rv = MIDI::Name::MidiPatchManager::instance().update_custom_midnam (ss.str(), midnam);
+       }
+#ifndef NDEBUG
+       if (rv) {
+               info << string_compose(_("LV2: update midnam for plugin '%1'"), name ()) << endmsg;
+       } else {
+               warning << string_compose(_("LV2: Failed to parse midnam of plugin '%1'"), name ()) << endmsg;
        }
+#endif
        _midname_interface->free (midnam);
        return rv;
 }
index a400eb3b772126b323cf5e981bccf468aa3c1a48..ab93b173066d46a71cb70c6921a3c5ddf7d1b077 100644 (file)
@@ -90,6 +90,13 @@ MidiPatchManager::remove_custom_midnam (const std::string& id)
        return remove_midi_name_document ("custom:" + id);
 }
 
+bool
+MidiPatchManager::update_custom_midnam (const std::string& id, const std::string& midnam)
+{
+       remove_midi_name_document ("custom:" + id, false);
+       return add_custom_midnam (id, midnam);
+}
+
 void
 MidiPatchManager::add_midnam_files_from_directory(const std::string& directory_path)
 {
@@ -165,6 +172,7 @@ MidiPatchManager::document_by_model(std::string model_name) const
 bool
 MidiPatchManager::add_midi_name_document (boost::shared_ptr<MIDINameDocument> document)
 {
+       bool added = false;
        for (MIDINameDocument::MasterDeviceNamesList::const_iterator device =
                 document->master_device_names_by_model().begin();
             device != document->master_device_names_by_model().end();
@@ -189,17 +197,20 @@ MidiPatchManager::add_midi_name_document (boost::shared_ptr<MIDINameDocument> do
                _devices_by_manufacturer[manufacturer].insert(
                    std::make_pair(device->first, device->second));
 
+               added = true;
                // TODO: handle this gracefully.
                assert(_documents.count(device->first) == 1);
                assert(_master_devices_by_model.count(device->first) == 1);
        }
 
-       PatchesChanged(); /* EMIT SIGNAL */
-       return true;
+       if (added) {
+               PatchesChanged(); /* EMIT SIGNAL */
+       }
+       return added;
 }
 
 bool
-MidiPatchManager::remove_midi_name_document (const std::string& file_path)
+MidiPatchManager::remove_midi_name_document (const std::string& file_path, bool emit_signal)
 {
        bool removed = false;
        for (MidiNameDocuments::iterator i = _documents.begin(); i != _documents.end();) {
@@ -229,7 +240,7 @@ MidiPatchManager::remove_midi_name_document (const std::string& file_path)
                        ++i;
                }
        }
-       if (removed) {
+       if (removed && emit_signal) {
                PatchesChanged(); /* EMIT SIGNAL */
        }
        return removed;