2 * Copyright (C) 2018 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 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"))
36 , _sort_avg_button (_("Sort by Average Load"))
37 , _sort_max_button (_("Sort by Worst-Case Load"))
39 _scroller.set_border_width (0);
40 _scroller.set_shadow_type (Gtk::SHADOW_NONE);
41 _scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
44 _reset_button.set_name ("generic button");
45 _sort_avg_button.set_name ("generic button");
46 _sort_max_button.set_name ("generic button");
48 _reset_button.signal_clicked.connect (sigc::mem_fun (*this, &PluginDSPLoadWindow::clear_all_stats));
49 _sort_avg_button.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginDSPLoadWindow::sort_by_stats), true));
50 _sort_max_button.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginDSPLoadWindow::sort_by_stats), false));
56 Gtk::Viewport* viewport = (Gtk::Viewport*) _scroller.get_child();
57 viewport->set_shadow_type(Gtk::SHADOW_NONE);
58 viewport->set_border_width(0);
60 _ctrlbox.pack_end (_reset_button, Gtk::PACK_SHRINK, 2);
61 _ctrlbox.pack_end (_sort_avg_button, Gtk::PACK_SHRINK, 2);
62 _ctrlbox.pack_end (_sort_max_button, Gtk::PACK_SHRINK, 2);
66 PluginDSPLoadWindow::~PluginDSPLoadWindow ()
72 PluginDSPLoadWindow::set_session (Session* s)
74 ArdourWindow::set_session (s);
77 } else if (is_visible ()) {
83 PluginDSPLoadWindow::session_going_away ()
85 ENSURE_GUI_THREAD (*this, &PluginDSPLoadWindow::session_going_away);
86 ArdourWindow::session_going_away ();
91 PluginDSPLoadWindow::on_show ()
93 ArdourWindow::on_show ();
98 PluginDSPLoadWindow::on_hide ()
100 ArdourWindow::on_hide ();
105 PluginDSPLoadWindow::clear_all_stats ()
107 RouteList routes = _session->get_routelist ();
108 for (RouteList::const_iterator i = routes.begin(); i != routes.end(); ++i) {
109 (*i)->foreach_processor (sigc::mem_fun (*this, &PluginDSPLoadWindow::clear_processor_stats));
116 DSPLoadSorter (bool avg) : _avg (avg) {}
117 bool operator() (PluginLoadStatsGui* a, PluginLoadStatsGui* b) {
118 return _avg ? (a->dsp_avg () < b->dsp_avg ()) : (a->dsp_max () < b->dsp_max ());
123 PluginDSPLoadWindow::sort_by_stats (bool avg)
125 std::list<PluginLoadStatsGui*> pl;
126 std::list<Gtk::Widget*> children = _box.get_children ();
127 for (std::list<Gtk::Widget*>::iterator child = children.begin(); child != children.end(); ++child) {
128 Gtk::Frame* frame = dynamic_cast<Gtk::Frame*>(*child);
129 if (!frame) continue;
130 PluginLoadStatsGui* plsg = dynamic_cast<PluginLoadStatsGui*>(frame->get_child());
135 pl.sort (DSPLoadSorter (avg));
137 for (std::list<PluginLoadStatsGui*>::iterator i = pl.begin(); i != pl.end(); ++i, ++pos) {
138 Gtk::Container* p = (*i)->get_parent();
140 _box.reorder_child (*p, pos);
145 PluginDSPLoadWindow::drop_references ()
147 std::list<Gtk::Widget*> children = _box.get_children ();
148 for (std::list<Gtk::Widget*>::iterator child = children.begin(); child != children.end(); ++child) {
150 _box.remove (**child);
151 if (*child != &_ctrlbox) {
155 _route_connections.drop_connections ();
156 _processor_connections.drop_connections ();
160 PluginDSPLoadWindow::refill_processors ()
163 if (!_session || _session->deletion_in_progress()) {
164 /* may be called from session d'tor, removing monitor-section w/plugin */
168 _session->RouteAdded.connect (
169 _route_connections, invalidator (*this), boost::bind (&PluginDSPLoadWindow::refill_processors, this), gui_context()
172 RouteList routes = _session->get_routelist ();
173 for (RouteList::const_iterator i = routes.begin(); i != routes.end(); ++i) {
175 (*i)->foreach_processor (sigc::bind (sigc::mem_fun (*this, &PluginDSPLoadWindow::add_processor_to_display), (*i)->name()));
177 (*i)->processors_changed.connect (
178 _route_connections, invalidator (*this), boost::bind (&PluginDSPLoadWindow::refill_processors, this), gui_context()
181 (*i)->DropReferences.connect (
182 _route_connections, invalidator (*this), boost::bind (&PluginDSPLoadWindow::refill_processors, this), gui_context()
186 if (_box.get_children().size() == 0) {
187 _box.add (*Gtk::manage (new Gtk::Label (_("No Plugins"))));
189 } else if (_box.get_children().size() > 1) {
190 _box.pack_start (_ctrlbox, Gtk::PACK_SHRINK, 2);
196 PluginDSPLoadWindow::add_processor_to_display (boost::weak_ptr<Processor> w, std::string const& route_name)
198 boost::shared_ptr<Processor> p = w.lock ();
199 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (p);
200 if (!pi || !pi->provides_stats ()) {
203 p->DropReferences.connect (_processor_connections, MISSING_INVALIDATOR, boost::bind (&PluginDSPLoadWindow::refill_processors, this), gui_context());
204 PluginLoadStatsGui* plsg = new PluginLoadStatsGui (pi);
206 std::string name = route_name + " - " + pi->name();
207 Gtk::Frame* frame = new Gtk::Frame (name.c_str());
208 frame->add (*Gtk::manage (plsg));
209 _box.pack_start (*frame, Gtk::PACK_SHRINK, 2);
211 plsg->start_updating ();
216 PluginDSPLoadWindow::clear_processor_stats (boost::weak_ptr<Processor> w)
218 boost::shared_ptr<Processor> p = w.lock ();
219 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (p);