2 * Copyright (C) 2017 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 "gtkmm2ext/utils.h"
20 #include "widgets/tooltips.h"
22 #include "ardour_ui.h"
23 #include "dsp_load_indicator.h"
24 #include "ui_config.h"
30 DspLoadIndicator::DspLoadIndicator ()
34 _layout = Pango::Layout::create (get_pango_context ());
35 _layout->set_text ("99.9%");
38 DspLoadIndicator::~DspLoadIndicator ()
43 DspLoadIndicator::on_size_request (Gtk::Requisition* req)
45 req->width = req->height = 0;
46 CairoWidget::on_size_request (req);
49 _layout->get_pixel_size (w, h);
51 req->width = std::max (req->width, std::max (12, h + PADDING));
52 req->height = std::max (req->height, 20 /*std::max (20, w + PADDING) */);
56 DspLoadIndicator::set_xrun_count (const unsigned int xruns)
58 if (xruns == _xrun_count) {
67 DspLoadIndicator::set_dsp_load (const double load)
69 if (load == _dsp_load) {
75 snprintf (buf, sizeof (buf), "%.1f%%", _dsp_load);
76 _layout->set_text (buf);
83 DspLoadIndicator::update_tooltip ()
86 if (_xrun_count == UINT_MAX) {
87 snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: ?"), _dsp_load);
88 } else if (_xrun_count > 9999) {
89 snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: >10k"), _dsp_load);
91 snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: %u"), _dsp_load, _xrun_count);
93 ArdourWidgets::set_tooltip (*this, buf);
97 DspLoadIndicator::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
99 cairo_t* cr = ctx->cobj ();
100 Gtkmm2ext::Color base = UIConfiguration::instance ().color ("ruler base");
101 Gtkmm2ext::Color text = UIConfiguration::instance ().color ("ruler text");
103 const int width = get_width ();
104 const int height = get_height ();
106 Gtkmm2ext::rounded_rectangle (cr, 0, 0, width, height, PADDING + 1);
107 Gtkmm2ext::set_source_rgba (cr, base);
110 if (_xrun_count > 0) {
111 Gtkmm2ext::rounded_rectangle (cr, 1, 1, width - 2, height - 2, PADDING + 1);
112 cairo_set_source_rgba (cr, 0.5, 0, 0, 1.0);
116 Gtkmm2ext::rounded_rectangle (cr, PADDING, PADDING, width - PADDING - PADDING, height - PADDING - PADDING, PADDING + 1);
119 int bh = (height - PADDING - PADDING) * _dsp_load / 100.f;
120 cairo_rectangle (cr, PADDING, height - PADDING - bh, width - PADDING, bh);
122 if (_dsp_load > 90) {
123 cairo_set_source_rgba (cr, .9, 0, 0, 1.0);
124 } else if (_dsp_load > 80) {
125 cairo_set_source_rgba (cr, .7, .6, 0, 1.0);
127 cairo_set_source_rgba (cr, 0, .5, 0, 1.0);
132 _layout->get_pixel_size (w, h);
136 cairo_translate (cr, width * .5, height * .5);
137 cairo_rotate (cr, M_PI * -.5);
139 cairo_move_to (cr, w * -.5, h * -.5);
140 pango_cairo_update_layout (cr, _layout->gobj());
141 Gtkmm2ext::set_source_rgb_a (cr, base, 0.5);
142 pango_cairo_layout_path (cr, _layout->gobj());
143 cairo_set_line_width (cr, 1.5);
146 cairo_move_to (cr, w * -.5, h * -.5);
147 pango_cairo_update_layout (cr, _layout->gobj());
148 Gtkmm2ext::set_source_rgba (cr, text);
149 pango_cairo_show_layout (cr, _layout->gobj());
155 DspLoadIndicator::on_button_release_event (GdkEventButton *ev)
157 ARDOUR::Session* s = ARDOUR_UI::instance ()->the_session ();
159 s->reset_xrun_count ();