PatchChange Dialog: update title & refresh midnam on change
[ardour.git] / gtk2_ardour / patch_change_widget.cc
index 521ad60313b6c08f55a34c25e9b341626f4e9906..0d167eb576f3440c8946a6df0798df925b356ae8 100644 (file)
@@ -19,7 +19,6 @@
 
 #include <bitset>
 #include <gtkmm/frame.h>
-#include <boost/algorithm/string.hpp>
 
 #include "pbd/unwind.h"
 
@@ -141,6 +140,14 @@ PatchChangeWidget::~PatchChangeWidget ()
        delete _pianomm;
 }
 
+void
+PatchChangeWidget::refresh ()
+{
+       if (is_visible ()) {
+               on_show ();
+       }
+}
+
 void
 PatchChangeWidget::on_show ()
 {
@@ -237,7 +244,7 @@ PatchChangeWidget::refill_program_list ()
        if (_current_patch_bank) {
                const MIDI::Name::PatchNameList& patches = _current_patch_bank->patch_name_list ();
                for (MIDI::Name::PatchNameList::const_iterator i = patches.begin(); i != patches.end(); ++i) {
-                       std::string n = (*i)->name ();
+                       const std::string n = (*i)->name ();
                        MIDI::Name::PatchPrimaryKey const& key = (*i)->patch_primary_key ();
 
                        const uint8_t pgm = key.program();
@@ -477,10 +484,20 @@ PatchChangeWidget::program (uint8_t chn) const
 
 /* ***************************************************************************/
 
-PatchChangeGridDialog::PatchChangeGridDialog (std::string const& title, boost::shared_ptr<ARDOUR::Route> r)
-       : ArdourDialog (title, false, false)
+PatchChangeGridDialog::PatchChangeGridDialog (boost::shared_ptr<ARDOUR::Route> r)
+       : ArdourDialog (string_compose (_("Select Patch for '%1"), r->name()), false, false)
        , w (r)
 {
+       r->PropertyChanged.connect (_route_connection, invalidator (*this), boost::bind (&PatchChangeGridDialog::route_property_changed, this, _1, boost::weak_ptr<Route>(r)), gui_context());
        get_vbox()->add (w);
        w.show ();
 }
+
+void
+PatchChangeGridDialog::route_property_changed (const PBD::PropertyChange& what_changed, boost::weak_ptr<Route> wr)
+{
+       boost::shared_ptr<ARDOUR::Route> r = wr.lock ();
+       if (r && what_changed.contains (ARDOUR::Properties::name)) {
+               set_title (string_compose (_("Select Patch for '%1"), r->name()));
+       }
+}