From 8242478da50e02afe9fb4449ce092197250141d7 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 6 Feb 2020 14:43:41 -0700 Subject: [PATCH] try to fix awful confusion and misbehavior for plugin-provided MIDNAM situations We do not store the MIDNAM model as a GUIObject property if the using the plugin-provided MIDNAM. Selecting a different MIDNAM for the plugin should now result in that choice being saved/restored correctly. This all feels crazily complicated, but I don't want to change more of the architecture at this time --- gtk2_ardour/midi_time_axis.cc | 71 +++++++++++++++++++++++++---------- gtk2_ardour/midi_time_axis.h | 1 + 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc index 02ba43194e..19d2c892d5 100644 --- a/gtk2_ardour/midi_time_axis.cc +++ b/gtk2_ardour/midi_time_axis.cc @@ -254,7 +254,10 @@ MidiTimeAxisView::set_route (boost::shared_ptr rt) } if (gui_property (X_("midnam-model-name")).empty()) { - set_gui_property (X_("midnam-model-name"), "Generic"); + boost::shared_ptr pi = boost::dynamic_pointer_cast (_route->the_instrument ()); + if (!pi || !pi->plugin ()->has_midnam ()) { + set_gui_property (X_("midnam-model-name"), "Generic"); + } } if (gui_property (X_("midnam-custom-device-mode")).empty()) { @@ -276,7 +279,7 @@ MidiTimeAxisView::set_route (boost::shared_ptr rt) MIDI::Name::MidiPatchManager::instance().maybe_use (*this, invalidator (*this), boost::bind (&MidiTimeAxisView::use_midnam_info, this), gui_context()); - model_changed (gui_property(X_("midnam-model-name"))); + maybe_trigger_model_change (); custom_device_mode_changed (gui_property(X_("midnam-custom-device-mode"))); controls_vbox.pack_start(_midi_controls_box, false, false); @@ -358,7 +361,6 @@ MidiTimeAxisView::check_step_edit () void MidiTimeAxisView::use_midnam_info () { - std::cerr << "Using MIDNAM info from " << pthread_name() << endl; setup_midnam_patches (); update_patch_selector (); } @@ -412,6 +414,35 @@ MidiTimeAxisView::setup_midnam_patches () } } +void +MidiTimeAxisView::maybe_trigger_model_change () +{ + boost::shared_ptr pi = boost::dynamic_pointer_cast (_route->the_instrument ()); + + if (pi && pi->plugin ()->has_midnam ()) { + + const std::string model_name = pi->plugin ()->midnam_model (); + const std::string saved_model_name = gui_property (X_("midnam-model-name")); + + if (!saved_model_name.empty()) { + assert (saved_model_name != model_name); + /* user changed the MIDNAM model to something + other than the plugin provided one. We + should use that, and not the "plugin + provided" label. + */ + model_changed (saved_model_name); + + } else { + /* ensure that "Plugin Provided" is prefixed at the top of the list */ + model_changed (model_name); + if (_midnam_model_selector.items().empty () || _midnam_model_selector.items().begin()->get_label() != _("Plugin Provided")) { + setup_midnam_patches (); + } + } + } +} + void MidiTimeAxisView::update_patch_selector () { @@ -419,18 +450,7 @@ MidiTimeAxisView::update_patch_selector () PatchManager& patch_manager = PatchManager::instance(); if (_route) { - boost::shared_ptr pi = boost::dynamic_pointer_cast (_route->the_instrument ()); - if (pi && pi->plugin ()->has_midnam ()) { - std::string model_name = pi->plugin ()->midnam_model (); - if (gui_property (X_("midnam-model-name")) != model_name) { - /* user changed the MIDNAM model to something - other than the plugin provided one. We - should use that, and not the "plugin - provided" label. - */ - model_changed (gui_property (X_("midnam-model-name"))); - } - } + maybe_trigger_model_change (); } if (patch_manager.all_models().empty()) { @@ -448,17 +468,21 @@ MidiTimeAxisView::update_patch_selector () void MidiTimeAxisView::model_changed(const std::string& model) { - set_gui_property (X_("midnam-model-name"), model); - typedef MIDI::Name::MidiPatchManager PatchManager; PatchManager& patch_manager = PatchManager::instance(); - const std::list device_modes = patch_manager.custom_device_mode_names_by_model(model); + const std::list device_modes = patch_manager.custom_device_mode_names_by_model (model); if (patch_manager.is_custom_model (model)) { - _midnam_model_selector.set_text(_("Plugin Provided")); + _midnam_model_selector.set_text (_("Plugin Provided")); + /* Do not store the actual model name, because it will + * (potentially, at least) be unique to this instance of the + * host (this program). + */ + remove_gui_property (X_("midnam-model-name")); } else { _midnam_model_selector.set_text(model); + set_gui_property (X_("midnam-model-name"), model); } _midnam_custom_device_mode_selector.clear_items(); @@ -909,7 +933,14 @@ MidiTimeAxisView::get_device_names() { using namespace MIDI::Name; - const std::string model = gui_property (X_("midnam-model-name")); + std::string model = gui_property (X_("midnam-model-name")); + + if (model.empty()) { + boost::shared_ptr pi = boost::dynamic_pointer_cast (_route->the_instrument ()); + if (pi && pi->plugin ()->has_midnam ()) { + model = pi->plugin ()->midnam_model (); + } + } boost::shared_ptr midnam = MidiPatchManager::instance() .document_by_model(model); if (midnam) { diff --git a/gtk2_ardour/midi_time_axis.h b/gtk2_ardour/midi_time_axis.h index ee36d4c534..e364913bb0 100644 --- a/gtk2_ardour/midi_time_axis.h +++ b/gtk2_ardour/midi_time_axis.h @@ -127,6 +127,7 @@ private: sigc::connection _note_range_changed_connection; + void maybe_trigger_model_change (); void model_changed(const std::string& model); void custom_device_mode_changed(const std::string& mode);