From 54e68d7fd35960b8ffae99ad9f48fe65cd213299 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 1 Oct 2016 05:46:29 -0400 Subject: Show audio and load information in status line --- src/gui/App.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++++++----- src/gui/App.hpp | 21 ++++++++++++-- src/gui/GraphBox.cpp | 14 +++++++++ src/gui/GraphBox.hpp | 3 ++ src/gui/Port.cpp | 37 ++---------------------- src/gui/rgba.hpp | 58 +++++++++++++++++++++++++++++++++++++ 6 files changed, 170 insertions(+), 44 deletions(-) create mode 100644 src/gui/rgba.hpp (limited to 'src/gui') diff --git a/src/gui/App.cpp b/src/gui/App.cpp index c023fe8c..a3055c91 100644 --- a/src/gui/App.cpp +++ b/src/gui/App.cpp @@ -51,6 +51,7 @@ #include "ThreadedLoader.hpp" #include "WidgetFactory.hpp" #include "WindowFactory.hpp" +#include "rgba.hpp" using namespace std; @@ -74,6 +75,11 @@ App::App(Ingen::World* world) , _window_factory(new WindowFactory(*this)) , _world(world) , _sample_rate(48000) + , _block_length(1024) + , _n_threads(1) + , _max_event_load(0.0f) + , _min_run_load(0.0f) + , _max_run_load(0.0f) , _enable_signal(true) , _requested_plugins(false) , _is_plugin(false) @@ -193,6 +199,8 @@ App::attach(SPtr client) sigc::mem_fun(this, &App::response)); _client->signal_error().connect( sigc::mem_fun(this, &App::error_message)); + _client->signal_put().connect( + sigc::mem_fun(this, &App::put)); _client->signal_property_change().connect( sigc::mem_fun(this, &App::property_change)); } @@ -270,19 +278,78 @@ App::set_tooltip(Gtk::Widget* widget, const LilvNode* node) } } +void +App::put(const Raul::URI& uri, + const Resource::Properties& properties, + Resource::Graph ctx) +{ + _enable_signal = false; + for (const auto& p : properties) { + property_change(uri, p.first, p.second); + } + _enable_signal = true; + _status_text = status_text(); + signal_status_text_changed.emit(_status_text); +} + void App::property_change(const Raul::URI& subject, const Raul::URI& key, const Atom& value) { - if (subject == Raul::URI("ingen:/engine") && key == uris().param_sampleRate) { - if (value.type() == forge().Int) { - log().info(fmt("Sample rate: %1%\n") % uris().forge.str(value)); - _sample_rate = value.get(); - } else { - log().error("Engine sample rate property is not an integer\n"); - } + if (subject != Raul::URI("ingen:/engine")) { + return; + } else if (key == uris().param_sampleRate && value.type() == forge().Int) { + _sample_rate = value.get(); + } else if (key == uris().bufsz_maxBlockLength && value.type() == forge().Int) { + _block_length = value.get(); + } else if (key == uris().ingen_numThreads && value.type() == forge().Int) { + _n_threads = value.get(); + } else if (key == uris().ingen_maxEventLoad && value.type() == forge().Float) { + _max_event_load = value.get(); + } else if (key == uris().ingen_minRunLoad && value.type() == forge().Float) { + _min_run_load = value.get(); + } else if (key == uris().ingen_meanRunLoad && value.type() == forge().Float) { + _mean_run_load = value.get(); + } else if (key == uris().ingen_maxRunLoad && value.type() == forge().Float) { + _max_run_load = value.get(); + } else { + _world->log().warn(fmt("Unknown engine property %1%\n") % key); + return; } + + if (_enable_signal) { + _status_text = status_text(); + signal_status_text_changed.emit(_status_text); + } +} + +static std::string +fraction_label(float f) +{ + static const uint32_t GREEN = 0x4A8A0EFF; + static const uint32_t RED = 0x960909FF; + + const uint32_t col = rgba_interpolate(GREEN, RED, std::min(f, 1.0f)); + char col_str[8]; + snprintf(col_str, sizeof(col_str), "%02X%02X%02X", + RGBA_R(col), RGBA_G(col), RGBA_B(col)); + return (fmt("%d%%") % col_str % (f * 100)).str(); +} + +std::string +App::status_text() const +{ + return (fmt("Audio: %2.1f kHz / %.1f ms Load: %s events + %s DSP: %s ≤ %s ≤ %s") + % (_sample_rate / 1e3f) + % (_block_length * 1e3f / (float)_sample_rate) + % fraction_label(_max_event_load) + % ((_n_threads == 1) + ? "1 thread" + : (fmt("%1% threads") % _n_threads).str()) + % fraction_label(_min_run_load) + % fraction_label(_mean_run_load) + % fraction_label(_max_run_load)).str(); } void diff --git a/src/gui/App.hpp b/src/gui/App.hpp index 6071c750..61336747 100644 --- a/src/gui/App.hpp +++ b/src/gui/App.hpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard + Copyright 2007-2016 David Robillard Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -25,6 +25,7 @@ #include #include "ingen/Atom.hpp" +#include "ingen/Resource.hpp" #include "ingen/Status.hpp" #include "ingen/World.hpp" #include "ingen/ingen.h" @@ -125,8 +126,13 @@ public: SPtr serialiser(); static SPtr create(Ingen::World* world); + void run(); + std::string status_text() const; + + sigc::signal signal_status_text_changed; + inline Ingen::World* world() const { return _world; } inline Ingen::URIs& uris() const { return _world->uris(); } inline Ingen::Log& log() const { return _world->log(); } @@ -137,6 +143,10 @@ protected: bool animate(); void response(int32_t id, Ingen::Status status, const std::string& subject); + void put(const Raul::URI& uri, + const Resource::Properties& properties, + Resource::Graph ctx); + void property_change(const Raul::URI& subject, const Raul::URI& key, const Atom& value); @@ -158,7 +168,14 @@ protected: Ingen::World* _world; - uint32_t _sample_rate; + int32_t _sample_rate; + int32_t _block_length; + int32_t _n_threads; + float _max_event_load; + float _mean_run_load; + float _min_run_load; + float _max_run_load; + std::string _status_text; typedef std::map ActivityPorts; ActivityPorts _activity_ports; diff --git a/src/gui/GraphBox.cpp b/src/gui/GraphBox.cpp index 10f063cc..692e378a 100644 --- a/src/gui/GraphBox.cpp +++ b/src/gui/GraphBox.cpp @@ -179,6 +179,10 @@ GraphBox::GraphBox(BaseObjectType* cobject, Glib::RefPtr clipboard = Gtk::Clipboard::get(); clipboard->signal_owner_change().connect( sigc::mem_fun(this, &GraphBox::event_clipboard_changed)); + + _status_label = Gtk::manage(new Gtk::Label("STATUS")); + _status_bar->pack_start(*_status_label, false, true, 0); + _status_label->show(); } GraphBox::~GraphBox() @@ -228,6 +232,16 @@ GraphBox::init_box(App& app) _breadcrumbs = new BreadCrumbs(*_app); _breadcrumbs->signal_graph_selected.connect( sigc::mem_fun(this, &GraphBox::set_graph_from_path)); + + _status_label->set_markup(app.status_text()); + app.signal_status_text_changed.connect( + sigc::mem_fun(*this, &GraphBox::set_status_text)); +} + +void +GraphBox::set_status_text(const std::string& text) +{ + _status_label->set_markup(text); } void diff --git a/src/gui/GraphBox.hpp b/src/gui/GraphBox.hpp index 0a55227e..af17a1ac 100644 --- a/src/gui/GraphBox.hpp +++ b/src/gui/GraphBox.hpp @@ -73,6 +73,8 @@ public: void init_box(App& app); + void set_status_text(const std::string& text); + void set_graph(SPtr graph, SPtr view); @@ -186,6 +188,7 @@ private: Gtk::Alignment* _alignment; BreadCrumbs* _breadcrumbs; Gtk::Statusbar* _status_bar; + Gtk::Label* _status_label; Gtk::HPaned* _doc_paned; Gtk::ScrolledWindow* _doc_scrolledwindow; diff --git a/src/gui/Port.cpp b/src/gui/Port.cpp index 1a9750a6..c643b379 100644 --- a/src/gui/Port.cpp +++ b/src/gui/Port.cpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard + Copyright 2007-2016 David Robillard Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -33,6 +33,7 @@ #include "WidgetFactory.hpp" #include "WindowFactory.hpp" #include "ingen_config.h" +#include "rgba.hpp" using namespace Ingen::Client; using namespace std; @@ -339,38 +340,6 @@ Port::on_event(GdkEvent* ev) return false; } -/* Peak colour stuff */ - -static inline uint32_t -rgba_to_uint(uint8_t r, uint8_t g, uint8_t b, uint8_t a) -{ - return ((((uint32_t)(r)) << 24) | - (((uint32_t)(g)) << 16) | - (((uint32_t)(b)) << 8) | - (((uint32_t)(a)))); -} - -static inline uint8_t -mono_interpolate(uint8_t v1, uint8_t v2, float f) -{ - return ((int)rint((v2) * (f) + (v1) * (1 - (f)))); -} - -#define RGBA_R(x) (((uint32_t)(x)) >> 24) -#define RGBA_G(x) ((((uint32_t)(x)) >> 16) & 0xFF) -#define RGBA_B(x) ((((uint32_t)(x)) >> 8) & 0xFF) -#define RGBA_A(x) (((uint32_t)(x)) & 0xFF) - -static inline uint32_t -rgba_interpolate(uint32_t c1, uint32_t c2, float f) -{ - return rgba_to_uint( - mono_interpolate(RGBA_R(c1), RGBA_R(c2), f), - mono_interpolate(RGBA_G(c1), RGBA_G(c2), f), - mono_interpolate(RGBA_B(c1), RGBA_B(c2), f), - mono_interpolate(RGBA_A(c1), RGBA_A(c2), f)); -} - inline static uint32_t peak_color(float peak) { @@ -386,8 +355,6 @@ peak_color(float peak) } } -/* End peak colour stuff */ - void Port::activity(const Atom& value) { diff --git a/src/gui/rgba.hpp b/src/gui/rgba.hpp new file mode 100644 index 00000000..8648aece --- /dev/null +++ b/src/gui/rgba.hpp @@ -0,0 +1,58 @@ +/* + This file is part of Ingen. + Copyright 2007-2016 David Robillard + + Ingen is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or any later version. + + Ingen 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 Affero General Public License for details. + + You should have received a copy of the GNU Affero General Public License + along with Ingen. If not, see . +*/ + +#ifndef INGEN_GUI_RGBA_HPP +#define INGEN_GUI_RGBA_HPP + +#include + +namespace Ingen { +namespace GUI { + +static inline uint32_t +rgba_to_uint(uint8_t r, uint8_t g, uint8_t b, uint8_t a) +{ + return ((((uint32_t)(r)) << 24) | + (((uint32_t)(g)) << 16) | + (((uint32_t)(b)) << 8) | + (((uint32_t)(a)))); +} + +static inline uint8_t +mono_interpolate(uint8_t v1, uint8_t v2, float f) +{ + return ((int)rint((v2) * (f) + (v1) * (1 - (f)))); +} + +#define RGBA_R(x) (((uint32_t)(x)) >> 24) +#define RGBA_G(x) ((((uint32_t)(x)) >> 16) & 0xFF) +#define RGBA_B(x) ((((uint32_t)(x)) >> 8) & 0xFF) +#define RGBA_A(x) (((uint32_t)(x)) & 0xFF) + +static inline uint32_t +rgba_interpolate(uint32_t c1, uint32_t c2, float f) +{ + return rgba_to_uint( + mono_interpolate(RGBA_R(c1), RGBA_R(c2), f), + mono_interpolate(RGBA_G(c1), RGBA_G(c2), f), + mono_interpolate(RGBA_B(c1), RGBA_B(c2), f), + mono_interpolate(RGBA_A(c1), RGBA_A(c2), f)); +} + +} // namespace GUI +} // namespace Ingen + +#endif // INGEN_GUI_RGBA_HPP -- cgit v1.2.1