2 * Copyright (C) 2018 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <gtkmm/frame.h>
20 #include <gtkmm/label.h>
21 #include <gtkmm/viewport.h>
23 #include "ardour/session.h"
24 #include "gtkmm2ext/gui_thread.h"
26 #include "plugin_dspload_ui.h"
27 #include "plugin_dspload_window.h"
31 using namespace ARDOUR;
33 PluginDSPLoadWindow::PluginDSPLoadWindow ()
34 : ArdourWindow (_("Plugin DSP Load"))
35 , _reset_button (_("Reset All Stats"))
37 _scroller.set_border_width (0);
38 _scroller.set_shadow_type (Gtk::SHADOW_NONE);
39 _scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
42 _reset_button.set_name ("generic button");
43 _reset_button.signal_clicked.connect (sigc::mem_fun (*this, &PluginDSPLoadWindow::clear_all_stats));
49 Gtk::Viewport* viewport = (Gtk::Viewport*) _scroller.get_child();
50 viewport->set_shadow_type(Gtk::SHADOW_NONE);
51 viewport->set_border_width(0);
54 PluginDSPLoadWindow::~PluginDSPLoadWindow ()
60 PluginDSPLoadWindow::set_session (Session* s)
62 ArdourWindow::set_session (s);
65 } else if (is_visible ()) {
71 PluginDSPLoadWindow::session_going_away ()
73 ENSURE_GUI_THREAD (*this, &PluginDSPLoadWindow::session_going_away);
74 ArdourWindow::session_going_away ();
79 PluginDSPLoadWindow::on_show ()
81 ArdourWindow::on_show ();
86 PluginDSPLoadWindow::on_hide ()
88 ArdourWindow::on_hide ();
93 PluginDSPLoadWindow::clear_all_stats ()
95 RouteList routes = _session->get_routelist ();
96 for (RouteList::const_iterator i = routes.begin(); i != routes.end(); ++i) {
97 (*i)->foreach_processor (sigc::mem_fun (*this, &PluginDSPLoadWindow::clear_processor_stats));
102 PluginDSPLoadWindow::drop_references ()
104 std::list<Gtk::Widget*> children = _box.get_children ();
105 for (std::list<Gtk::Widget*>::iterator child = children.begin(); child != children.end(); ++child) {
107 _box.remove (**child);
108 if (*child != &_reset_button) {
112 _route_connections.drop_connections ();
113 _processor_connections.drop_connections ();
117 PluginDSPLoadWindow::refill_processors ()
120 if (!_session || _session->deletion_in_progress()) {
121 /* may be called from session d'tor, removing monitor-section w/plugin */
125 _session->RouteAdded.connect (
126 _route_connections, invalidator (*this), boost::bind (&PluginDSPLoadWindow::refill_processors, this), gui_context()
129 RouteList routes = _session->get_routelist ();
130 for (RouteList::const_iterator i = routes.begin(); i != routes.end(); ++i) {
132 (*i)->foreach_processor (sigc::bind (sigc::mem_fun (*this, &PluginDSPLoadWindow::add_processor_to_display), (*i)->name()));
134 (*i)->processors_changed.connect (
135 _route_connections, invalidator (*this), boost::bind (&PluginDSPLoadWindow::refill_processors, this), gui_context()
138 (*i)->DropReferences.connect (
139 _route_connections, invalidator (*this), boost::bind (&PluginDSPLoadWindow::refill_processors, this), gui_context()
143 if (_box.get_children().size() == 0) {
144 _box.add (*Gtk::manage (new Gtk::Label (_("No Plugins"))));
146 } else if (_box.get_children().size() > 1) {
147 _box.pack_start (_reset_button, Gtk::PACK_SHRINK, 2);
148 _reset_button.show ();
153 PluginDSPLoadWindow::add_processor_to_display (boost::weak_ptr<Processor> w, std::string const& route_name)
155 boost::shared_ptr<Processor> p = w.lock ();
156 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (p);
157 if (!pi || !pi->provides_stats ()) {
160 p->DropReferences.connect (_processor_connections, MISSING_INVALIDATOR, boost::bind (&PluginDSPLoadWindow::refill_processors, this), gui_context());
161 PluginLoadStatsGui* plsg = new PluginLoadStatsGui (pi);
163 std::string name = route_name + " - " + pi->name();
164 Gtk::Frame* frame = new Gtk::Frame (name.c_str());
165 frame->add (*Gtk::manage (plsg));
166 _box.pack_start (*frame, Gtk::PACK_SHRINK, 2);
168 plsg->start_updating ();
173 PluginDSPLoadWindow::clear_processor_stats (boost::weak_ptr<Processor> w)
175 boost::shared_ptr<Processor> p = w.lock ();
176 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (p);