fix CPI window handling:
authorRobin Gareus <robin@gareus.org>
Sat, 13 Sep 2014 14:59:02 +0000 (16:59 +0200)
committerRobin Gareus <robin@gareus.org>
Sat, 13 Sep 2014 14:59:02 +0000 (16:59 +0200)
Move control-surface editor-window management to the control surface.
The Preferences-Dialog is not aware of session specific or surface
specific actions and cannot properly manage the window.

gtk2_ardour/ardour_ui_dialogs.cc
gtk2_ardour/rc_option_editor.cc
libs/surfaces/generic_midi/gmcp_gui.cc
libs/surfaces/mackie/gui.cc

index 0dc7104f8c8c28b5755ec19380a7a8daa5a6dbdf..8cd65ef378979017444160735b59df48f909b45f 100644 (file)
 
 #include "ardour/audioengine.h"
 #include "ardour/automation_watch.h"
+#include "ardour/control_protocol_manager.h"
 #include "ardour/profile.h"
 #include "ardour/session.h"
+#include "control_protocol/control_protocol.h"
 
 #include "actions.h"
 #include "add_route_dialog.h"
@@ -262,6 +264,16 @@ ARDOUR_UI::unload_session (bool hide_stuff)
                }
        }
 
+       {
+               // tear down session specific CPI (owned by rc_config_editor which can remain)
+               ControlProtocolManager& m = ControlProtocolManager::instance ();
+               for (std::list<ControlProtocolInfo*>::iterator i = m.control_protocol_info.begin(); i != m.control_protocol_info.end(); ++i) {
+                       if (*i && (*i)->protocol && (*i)->protocol->has_editor ()) {
+                               (*i)->protocol->tear_down_gui ();
+                       }
+               }
+       }
+
        if (hide_stuff) {
                editor->hide ();
                mixer->hide ();
index ced64a9d6e99ec31e86218315bde83304ee29a65..a4d2b5dee2325c9052eb3ec604eb816c0c5569fd 100644 (file)
@@ -795,17 +795,7 @@ private:
                        if (!was_enabled) {
                                ControlProtocolManager::instance().activate (*cpi);
                        } else {
-                               Gtk::Window* win = r[_model.editor];
-                               if (win) {
-                                       win->hide ();
-                               }
-
                                ControlProtocolManager::instance().deactivate (*cpi);
-                                       
-                               if (win) {
-                                       delete win;
-                                       r[_model.editor] = 0;
-                               }
                        }
                }
 
@@ -817,8 +807,8 @@ private:
                }
        }
 
-        void edit_clicked (GdkEventButton* ev)
-        {
+       void edit_clicked (GdkEventButton* ev)
+       {
                if (ev->type != GDK_2BUTTON_PRESS) {
                        return;
                }
@@ -828,26 +818,32 @@ private:
                TreeModel::Row row;
 
                row = *(_view.get_selection()->get_selected());
-
-               Window* win = row[_model.editor];
-               if (win && !win->is_visible()) {
-                       win->present ();
-               } else {
-                       cpi = row[_model.protocol_info];
-
-                       if (cpi && cpi->protocol && cpi->protocol->has_editor ()) {
-                               Box* box = (Box*) cpi->protocol->get_gui ();
-                               if (box) {
-                                       string title = row[_model.name];
-                                       ArdourWindow* win = new ArdourWindow (_parent, title);
-                                       win->set_title ("Control Protocol Options");
-                                       win->add (*box);
-                                       box->show ();
-                                       win->present ();
-                                       row[_model.editor] = win;
-                               }
-                       }
+               if (!row[_model.enabled]) {
+                       return;
+               }
+               cpi = row[_model.protocol_info];
+               if (!cpi || !cpi->protocol || !cpi->protocol->has_editor ()) {
+                       return;
+               }
+               Box* box = (Box*) cpi->protocol->get_gui ();
+               if (!box) {
+                       return;
+               }
+               if (box->get_parent()) {
+                       static_cast<ArdourWindow*>(box->get_parent())->present();
+                       return;
                }
+               string title = row[_model.name];
+               /* once created, the window is managed by the surface itself (as ->get_parent())
+                * Surface's tear_down_gui() is called on session close, when de-activating
+                * or re-initializing a surface.
+                * tear_down_gui() hides an deletes the Window if it exists.
+                */
+               ArdourWindow* win = new ArdourWindow (_parent, title);
+               win->set_title ("Control Protocol Options");
+               win->add (*box);
+               box->show ();
+               win->present ();
        }
 
         class ControlSurfacesModelColumns : public TreeModelColumnRecord
@@ -860,14 +856,12 @@ private:
                        add (enabled);
                        add (feedback);
                        add (protocol_info);
-                       add (editor);
                }
 
                TreeModelColumn<string> name;
                TreeModelColumn<bool> enabled;
                TreeModelColumn<bool> feedback;
                TreeModelColumn<ControlProtocolInfo*> protocol_info;
-               TreeModelColumn<Gtk::Window*> editor;
        };
 
        Glib::RefPtr<ListStore> _store;
index 6c1ee1ba3d3e340c281fd42c857ee659ccc111c4..379f7c822c70bb1d0e34bb18c80c587a0a30b532 100644 (file)
@@ -68,13 +68,22 @@ GenericMidiControlProtocol::get_gui () const
        if (!gui) {
                const_cast<GenericMidiControlProtocol*>(this)->build_gui ();
        }
+       static_cast<Gtk::VBox*>(gui)->show_all();
        return gui;
 }
 
 void
 GenericMidiControlProtocol::tear_down_gui ()
 {
+       if (gui) {
+               Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
+               if (w) {
+                       w->hide();
+                       delete w;
+               }
+       }
        delete (GMCPGUI*) gui;
+       gui = 0;
 }
 
 void
index 7425b388266c5369de132e370bbc8228c801bafa..6753f0a97c965b7dff6d8e25ce8172f81afb7f28 100644 (file)
@@ -51,14 +51,22 @@ MackieControlProtocol::get_gui () const
        if (!_gui) {
                const_cast<MackieControlProtocol*>(this)->build_gui ();
        }
-
+       static_cast<Gtk::Notebook*>(_gui)->show_all();
        return _gui;
 }
 
 void
 MackieControlProtocol::tear_down_gui ()
 {
+       if (_gui) {
+               Gtk::Widget *w = static_cast<Gtk::Widget*>(_gui)->get_parent();
+               if (w) {
+                       w->hide();
+                       delete w;
+               }
+       }
        delete (MackieControlProtocolGUI*) _gui;
+       _gui = 0;
 }
 
 void