Delete temporary Window Proxy for dialogs
[ardour.git] / gtk2_ardour / plugin_dspload_window.cc
index 104ec9d7b6f7079f4f4f322a49ad684aabaebeb4..2e20f9dcc8949436f760e7cea31e464ff2f5d156 100644 (file)
@@ -32,12 +32,16 @@ using namespace ARDOUR;
 
 PluginDSPLoadWindow::PluginDSPLoadWindow ()
        : ArdourWindow (_("Plugin DSP Load"))
+       , _reset_button (_("Reset All Stats"))
 {
        _scroller.set_border_width (0);
        _scroller.set_shadow_type (Gtk::SHADOW_NONE);
        _scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
        _scroller.add (_box);
 
+       _reset_button.set_name ("generic button");
+       _reset_button.signal_clicked.connect (sigc::mem_fun (*this, &PluginDSPLoadWindow::clear_all_stats));
+
        add (_scroller);
        _box.show ();
        _scroller.show ();
@@ -58,6 +62,8 @@ PluginDSPLoadWindow::set_session (Session* s)
        ArdourWindow::set_session (s);
        if (!s) {
                drop_references ();
+       } else if (is_visible ()) {
+               refill_processors ();
        }
 }
 
@@ -83,6 +89,15 @@ PluginDSPLoadWindow::on_hide ()
        drop_references ();
 }
 
+void
+PluginDSPLoadWindow::clear_all_stats ()
+{
+       RouteList routes = _session->get_routelist ();
+       for (RouteList::const_iterator i = routes.begin(); i != routes.end(); ++i) {
+               (*i)->foreach_processor (sigc::mem_fun (*this, &PluginDSPLoadWindow::clear_processor_stats));
+       }
+}
+
 void
 PluginDSPLoadWindow::drop_references ()
 {
@@ -90,14 +105,27 @@ PluginDSPLoadWindow::drop_references ()
        for (std::list<Gtk::Widget*>::iterator child = children.begin(); child != children.end(); ++child) {
                (*child)->hide ();
                _box.remove (**child);
-               delete *child;
+               if (*child != &_reset_button) {
+                       delete *child;
+               }
        }
+       _route_connections.drop_connections ();
+       _processor_connections.drop_connections ();
 }
 
 void
 PluginDSPLoadWindow::refill_processors ()
 {
        drop_references ();
+       if (!_session || _session->deletion_in_progress()) {
+               /* may be called from session d'tor, removing monitor-section w/plugin */
+               return;
+       }
+
+       _session->RouteAdded.connect (
+                       _route_connections, invalidator (*this), boost::bind (&PluginDSPLoadWindow::refill_processors, this), gui_context()
+                       );
+
        RouteList routes = _session->get_routelist ();
        for (RouteList::const_iterator i = routes.begin(); i != routes.end(); ++i) {
 
@@ -108,13 +136,16 @@ PluginDSPLoadWindow::refill_processors ()
                                );
 
                (*i)->DropReferences.connect (
-                               _route_connections, invalidator (*this), boost::bind (&PluginDSPLoadWindow::drop_references, this), gui_context()
+                               _route_connections, invalidator (*this), boost::bind (&PluginDSPLoadWindow::refill_processors, this), gui_context()
                                );
        }
 
        if (_box.get_children().size() == 0) {
                _box.add (*Gtk::manage (new Gtk::Label (_("No Plugins"))));
                _box.show_all ();
+       } else if (_box.get_children().size() > 1) {
+               _box.pack_start (_reset_button, Gtk::PACK_SHRINK, 2);
+               _reset_button.show ();
        }
 }
 
@@ -126,7 +157,7 @@ PluginDSPLoadWindow::add_processor_to_display (boost::weak_ptr<Processor> w, std
        if (!pi) {
                return;
        }
-       p->DropReferences.connect (_processor_connections, MISSING_INVALIDATOR, boost::bind (&PluginDSPLoadWindow::drop_references, this), gui_context());
+       p->DropReferences.connect (_processor_connections, MISSING_INVALIDATOR, boost::bind (&PluginDSPLoadWindow::refill_processors, this), gui_context());
        PluginLoadStatsGui* plsg = new PluginLoadStatsGui (pi);
        
        std::string name = route_name + " - " + pi->name();
@@ -137,3 +168,13 @@ PluginDSPLoadWindow::add_processor_to_display (boost::weak_ptr<Processor> w, std
        plsg->start_updating ();
        frame->show_all ();
 }
+
+void
+PluginDSPLoadWindow::clear_processor_stats (boost::weak_ptr<Processor> w)
+{
+       boost::shared_ptr<Processor> p = w.lock ();
+       boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (p);
+       if (pi) {
+               pi->clear_stats ();
+       }
+}