diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 698b1ebef6..979ab3504a 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -1687,6 +1687,7 @@ ARDOUR_UI::update_xrun_count () if (_session) { const unsigned int x = _session->get_xrun_count (); + dsp_load_indicator.set_xrun_count (x); if (x > 9999) { snprintf (buf, sizeof (buf), _("X: >10K"), X_("red")); } else { @@ -1694,6 +1695,7 @@ ARDOUR_UI::update_xrun_count () } } else { snprintf (buf, sizeof (buf), _("X: ?"), X_("yellow")); + dsp_load_indicator.set_xrun_count (UINT_MAX); } xrun_label.set_markup (buf); set_tip (xrun_label, _("Audio dropouts. Shift+click to reset")); @@ -1709,6 +1711,7 @@ ARDOUR_UI::update_cpu_load () */ double const c = AudioEngine::instance()->get_dsp_load (); + dsp_load_indicator.set_dsp_load (c); snprintf (buf, sizeof (buf), _("DSP: %5.1f%%"), c >= 90 ? X_("red") : X_("green"), c); cpu_load_label.set_markup (buf); } diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index a6bac4ca9e..a703ac7c33 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -74,6 +74,7 @@ #include "add_route_dialog.h" #include "ardour_dialog.h" #include "ardour_window.h" +#include "dsp_load_indicator.h" #include "editing.h" #include "enums.h" #include "mini_timeline.h" @@ -483,9 +484,10 @@ private: void toggle_time_master (); void toggle_video_sync (); - ShuttleControl shuttle_box; - MiniTimeline mini_timeline; - TimeInfoBox *time_info_box; + ShuttleControl shuttle_box; + MiniTimeline mini_timeline; + TimeInfoBox* time_info_box; + DspLoadIndicator dsp_load_indicator; ArdourWidgets::ArdourButton auto_return_button; ArdourWidgets::ArdourButton follow_edits_button; diff --git a/gtk2_ardour/ardour_ui2.cc b/gtk2_ardour/ardour_ui2.cc index 748cd2abd0..ebd6261fec 100644 --- a/gtk2_ardour/ardour_ui2.cc +++ b/gtk2_ardour/ardour_ui2.cc @@ -190,6 +190,14 @@ ARDOUR_UI::repack_transport_hbox () mini_timeline.show(); } + if (dsp_load_indicator.get_parent()) { + transport_hbox.remove (dsp_load_indicator); + } + if (UIConfiguration::instance().get_show_dsp_load_info ()) { + transport_hbox.pack_start (dsp_load_indicator, false, false); + dsp_load_indicator.show(); + } + if (editor_meter) { if (meter_box.get_parent()) { transport_hbox.remove (meter_box); diff --git a/gtk2_ardour/ardour_ui_options.cc b/gtk2_ardour/ardour_ui_options.cc index ca18c5f555..b9e9d8d3f3 100644 --- a/gtk2_ardour/ardour_ui_options.cc +++ b/gtk2_ardour/ardour_ui_options.cc @@ -470,6 +470,8 @@ ARDOUR_UI::parameter_changed (std::string p) ArdourWaveView::WaveView::set_global_gradient_depth (UIConfiguration::instance().get_waveform_gradient_depth()); } else if (p == "show-mini-timeline") { repack_transport_hbox (); + } else if (p == "show-dsp-load-info") { + repack_transport_hbox (); } else if (p == "show-toolbar-recpunch") { repack_transport_hbox (); } else if (p == "show-toolbar-monitoring") { diff --git a/gtk2_ardour/dsp_load_indicator.cc b/gtk2_ardour/dsp_load_indicator.cc new file mode 100644 index 0000000000..bf033b7b32 --- /dev/null +++ b/gtk2_ardour/dsp_load_indicator.cc @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2017 Robin Gareus + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "gtkmm2ext/utils.h" +#include "widgets/tooltips.h" + +#include "ardour_ui.h" +#include "dsp_load_indicator.h" +#include "ui_config.h" + +#include "pbd/i18n.h" + +#define PADDING 3 + +DspLoadIndicator::DspLoadIndicator () + : _dsp_load (0) + , _xrun_count (0) +{ + _layout = Pango::Layout::create (get_pango_context ()); + _layout->set_text ("99.9%"); +} + +DspLoadIndicator::~DspLoadIndicator () +{ +} + +void +DspLoadIndicator::on_size_request (Gtk::Requisition* req) +{ + req->width = req->height = 0; + CairoWidget::on_size_request (req); + + int w, h; + _layout->get_pixel_size (w, h); + + req->width = std::max (req->width, std::max (12, h + PADDING)); + req->height = std::max (req->height, 20 /*std::max (20, w + PADDING) */); +} + +void +DspLoadIndicator::set_xrun_count (const unsigned int xruns) +{ + if (xruns == _xrun_count) { + return; + } + _xrun_count = xruns; + queue_draw (); + update_tooltip (); +} + +void +DspLoadIndicator::set_dsp_load (const double load) +{ + if (load == _dsp_load) { + return; + } + _dsp_load = load; + + char buf[64]; + snprintf (buf, sizeof (buf), "%.1f%%", _dsp_load); + _layout->set_text (buf); + + queue_draw (); + update_tooltip (); +} + +void +DspLoadIndicator::update_tooltip () +{ + char buf[64]; + if (_xrun_count == UINT_MAX) { + snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: ?"), _dsp_load); + } else if (_xrun_count > 9999) { + snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: >10k"), _dsp_load); + } else { + snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: %u"), _dsp_load, _xrun_count); + } + ArdourWidgets::set_tooltip (*this, buf); +} + +void +DspLoadIndicator::render (Cairo::RefPtr const& ctx, cairo_rectangle_t*) +{ + cairo_t* cr = ctx->cobj (); + Gtkmm2ext::Color base = UIConfiguration::instance ().color ("ruler base"); + Gtkmm2ext::Color text = UIConfiguration::instance ().color ("ruler text"); + + const int width = get_width (); + const int height = get_height (); + + Gtkmm2ext::rounded_rectangle (cr, 0, 0, width, height, PADDING + 1); + Gtkmm2ext::set_source_rgba (cr, base); + cairo_fill (cr); + + if (_xrun_count > 0) { + Gtkmm2ext::rounded_rectangle (cr, 1, 1, width - 2, height - 2, PADDING + 1); + cairo_set_source_rgba (cr, 0.5, 0, 0, 1.0); + cairo_fill (cr); + } + + Gtkmm2ext::rounded_rectangle (cr, PADDING, PADDING, width - PADDING - PADDING, height - PADDING - PADDING, PADDING + 1); + cairo_clip (cr); + + int bh = (height - PADDING - PADDING) * _dsp_load / 100.f; + cairo_rectangle (cr, PADDING, height - PADDING - bh, width - PADDING, bh); + + if (_dsp_load > 90) { + cairo_set_source_rgba (cr, .9, 0, 0, 1.0); + } else if (_dsp_load > 80) { + cairo_set_source_rgba (cr, .7, .6, 0, 1.0); + } else { + cairo_set_source_rgba (cr, 0, .5, 0, 1.0); + } + cairo_fill (cr); + + int w, h; + _layout->get_pixel_size (w, h); + + cairo_save (cr); + cairo_new_path (cr); + cairo_translate (cr, width * .5, height * .5); + cairo_rotate (cr, M_PI * -.5); + + cairo_move_to (cr, w * -.5, h * -.5); + pango_cairo_update_layout (cr, _layout->gobj()); + Gtkmm2ext::set_source_rgb_a (cr, base, 0.5); + pango_cairo_layout_path (cr, _layout->gobj()); + cairo_set_line_width (cr, 1.5); + cairo_stroke (cr); + + cairo_move_to (cr, w * -.5, h * -.5); + pango_cairo_update_layout (cr, _layout->gobj()); + Gtkmm2ext::set_source_rgba (cr, text); + pango_cairo_show_layout (cr, _layout->gobj()); + + cairo_restore (cr); +} + +bool +DspLoadIndicator::on_button_release_event (GdkEventButton *ev) +{ + ARDOUR::Session* s = ARDOUR_UI::instance ()->the_session (); + if (s) { + s->reset_xrun_count (); + } + return true; +} diff --git a/gtk2_ardour/dsp_load_indicator.h b/gtk2_ardour/dsp_load_indicator.h new file mode 100644 index 0000000000..012347e1a9 --- /dev/null +++ b/gtk2_ardour/dsp_load_indicator.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2017 Robin Gareus + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __gtkardour_dsp_load_indicator_h__ +#define __gtkardour_dsp_load_indicator_h__ + +#include + +#include "gtkmm2ext/cairo_widget.h" + +class DspLoadIndicator : public CairoWidget +{ + public: + DspLoadIndicator (); + ~DspLoadIndicator (); + + void set_xrun_count (const unsigned int xruns); + void set_dsp_load (const double load); + +private: + void on_size_request (Gtk::Requisition*); + void render (Cairo::RefPtr const&, cairo_rectangle_t*); + bool on_button_release_event (GdkEventButton*); + + void update_tooltip (); + + Glib::RefPtr _layout; + float _dsp_load; + unsigned int _xrun_count; +}; + +#endif diff --git a/gtk2_ardour/rc_option_editor.cc b/gtk2_ardour/rc_option_editor.cc index f5dfcab0a1..84d0628183 100644 --- a/gtk2_ardour/rc_option_editor.cc +++ b/gtk2_ardour/rc_option_editor.cc @@ -3796,6 +3796,14 @@ RCOptionEditor::RCOptionEditor () )); } + add_option (_("Appearance/Toolbar"), + new BoolOption ( + "show-dsp-load-info", + _("Display DSP Load Information"), + sigc::mem_fun (UIConfiguration::instance(), &UIConfiguration::get_show_dsp_load_info), + sigc::mem_fun (UIConfiguration::instance(), &UIConfiguration::set_show_dsp_load_info) + )); + add_option (_("Appearance/Toolbar"), new BoolOption ( "show-mini-timeline", diff --git a/gtk2_ardour/ui_config_vars.h b/gtk2_ardour/ui_config_vars.h index 9b27e1e8c1..315cb02b26 100644 --- a/gtk2_ardour/ui_config_vars.h +++ b/gtk2_ardour/ui_config_vars.h @@ -82,6 +82,7 @@ UI_CONFIG_VARIABLE (bool, show_toolbar_recpunch, "show-toolbar-recpunch", true) UI_CONFIG_VARIABLE (bool, show_toolbar_monitoring, "show-toolbar-monitoring", false) UI_CONFIG_VARIABLE (bool, show_toolbar_selclock, "show-toolbar-selclock", false) UI_CONFIG_VARIABLE (bool, show_mini_timeline, "show-mini-timeline", true) +UI_CONFIG_VARIABLE (bool, show_dsp_load_info, "show-dsp-load-info", true) UI_CONFIG_VARIABLE (bool, show_secondary_clock, "show-secondary-clock", true) UI_CONFIG_VARIABLE (double, waveform_clip_level, "waveform-clip-level", -0.0933967) /* units of dB */ UI_CONFIG_VARIABLE (bool, hiding_groups_deactivates_groups, "hiding-groups-deactivates-groups", true) diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index 171e17498f..c8af5ce97f 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -65,6 +65,7 @@ gtk2_ardour_sources = [ 'curvetest.cc', 'debug.cc', 'duplicate_routes_dialog.cc', + 'dsp_load_indicator.cc', 'edit_note_dialog.cc', 'editing.cc', 'editor.cc',