From 3ef2b738b728b9758b527028b88d9d44b929c1d7 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 6 Apr 2014 17:35:19 +0000 Subject: Resurrect toolbar with Jack info and dropout indicator. Move legend to right hand side of toolbar. Store toolbar visible state in configuration. git-svn-id: http://svn.drobilla.net/lad/trunk/patchage@5359 a436a847-0d15-0410-975c-d299462d15a1 --- src/Configuration.cpp | 6 +- src/Configuration.hpp | 4 ++ src/JackDriver.cpp | 39 ++++++++---- src/JackDriver.hpp | 2 + src/Patchage.cpp | 87 ++++++++++++++++++++++++--- src/Patchage.hpp | 14 ++++- src/patchage.ui | 161 +++++++++++++++++++++++++++++++++++++++++++++----- 7 files changed, 275 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 3c4b5f0..8653591 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -38,6 +38,7 @@ Configuration::Configuration() , _window_size(640, 480) , _zoom(1.0) , _font_size(12.0) + , _show_toolbar(true) { _port_colors[JACK_AUDIO] = _default_port_colors[JACK_AUDIO] = 0x244678FF; _port_colors[JACK_MIDI] = _default_port_colors[JACK_MIDI] = 0x960909FF; @@ -164,7 +165,7 @@ Configuration::load() while (file.good()) { std::string key; if (file.peek() == '\"') { - /* Old versions ommitted the module_position key and listed + /* Old versions omitted the module_position key and listed positions starting with module name in quotes. */ key = "module_position"; } else { @@ -179,6 +180,8 @@ Configuration::load() file >> _zoom; } else if (key == "font_size") { file >> _font_size; + } else if (key == "show_toolbar") { + file >> _show_toolbar; } else if (key == "port_color") { std::string type_name; uint32_t rgba; @@ -275,6 +278,7 @@ Configuration::save() file << "window_size " << _window_size.x << " " << _window_size.y << std::endl; file << "zoom_level " << _zoom << std::endl; file << "font_size " << _font_size << std::endl; + file << "show_toolbar " << _show_toolbar << std::endl; file << std::hex << std::uppercase; for (int i = 0; i < N_PORT_TYPES; ++i) { diff --git a/src/Configuration.hpp b/src/Configuration.hpp index 1fc786b..06c5978 100644 --- a/src/Configuration.hpp +++ b/src/Configuration.hpp @@ -56,6 +56,9 @@ public: float get_font_size() const { return _font_size; } void set_font_size(float font_size) { _font_size = font_size; } + float get_show_toolbar() const { return _show_toolbar; } + void set_show_toolbar(float show_toolbar) { _show_toolbar = show_toolbar; } + uint32_t get_port_color(PortType type) const { return _port_colors[type]; } void set_port_color(PortType type, uint32_t rgba) { _port_colors[type] = rgba; @@ -84,6 +87,7 @@ private: Coord _window_size; float _zoom; float _font_size; + bool _show_toolbar; }; #endif // PATCHAGE_CONFIGURATION_HPP diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index db06480..bb40647 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -86,14 +86,6 @@ JackDriver::attach(bool launch_daemon) signal_attached.emit(); std::stringstream ss; _app->info_msg("Jack: Attached."); - const jack_nframes_t buffer_size = this->buffer_size(); - const jack_nframes_t sample_rate = this->sample_rate(); - if (sample_rate != 0) { - const int latency_ms = lrintf((buffer_size * 1000 / (float)sample_rate)); - ss << "Jack: Latency: " << buffer_size << " frames @ " - << (sample_rate / 1000) << "kHz (" << latency_ms << "ms)."; - _app->info_msg(ss.str()); - } } else { _app->error_msg("Jack: Client activation failed."); _is_activated = false; @@ -463,9 +455,6 @@ JackDriver::jack_xrun_cb(void* jack_driver) ++me->_xruns; me->_xrun_delay = jack_get_xrun_delayed_usecs(me->_client); - me->_app->warning_msg((format("Jack: xrun of %1%ms.") - % me->_xrun_delay).str()); - jack_reset_max_delayed_usecs(me->_client); return 0; @@ -499,6 +488,34 @@ JackDriver::reset_xruns() _xrun_delay = 0; } +float +JackDriver::get_max_dsp_load() +{ + float max_load = 0.0f; + if (_client) { + const float max_delay = jack_get_max_delayed_usecs(_client); + const float rate = sample_rate(); + const float size = buffer_size(); + const float period = size / rate * 1000000; // usec + + if (max_delay > period) { + max_load = 1.0; + jack_reset_max_delayed_usecs(_client); + } else { + max_load = max_delay / period; + } + } + return max_load; +} + +void +JackDriver::reset_max_dsp_load() +{ + if (_client) { + jack_reset_max_delayed_usecs(_client); + } +} + bool JackDriver::set_buffer_size(jack_nframes_t size) { diff --git a/src/JackDriver.hpp b/src/JackDriver.hpp index 9722f0f..1789704 100644 --- a/src/JackDriver.hpp +++ b/src/JackDriver.hpp @@ -67,6 +67,8 @@ public: uint32_t get_xruns() { return _xruns; } void reset_xruns(); + float get_max_dsp_load(); + void reset_max_dsp_load(); jack_client_t* client() { return _client; } diff --git a/src/Patchage.cpp b/src/Patchage.cpp index 6c47eb8..85d950f 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -101,7 +101,7 @@ Patchage::Patchage(int argc, char** argv) , INIT_WIDGET(_menu_save_close_session) , INIT_WIDGET(_menu_view_arrange) , INIT_WIDGET(_menu_view_messages) - , INIT_WIDGET(_menu_view_legend) + , INIT_WIDGET(_menu_view_toolbar) , INIT_WIDGET(_menu_view_refresh) , INIT_WIDGET(_menu_view_human_names) , INIT_WIDGET(_menu_zoom_in) @@ -114,6 +114,11 @@ Patchage::Patchage(int argc, char** argv) , INIT_WIDGET(_messages_clear_but) , INIT_WIDGET(_messages_close_but) , INIT_WIDGET(_messages_win) + , INIT_WIDGET(_toolbar) + , INIT_WIDGET(_clear_load_but) + , INIT_WIDGET(_xrun_progress) + , INIT_WIDGET(_latency_label) + , INIT_WIDGET(_legend_alignment) , INIT_WIDGET(_status_text) , _legend(NULL) , _attach(true) @@ -164,6 +169,9 @@ Patchage::Patchage(int argc, char** argv) _main_scrolledwin->signal_scroll_event().connect( sigc::mem_fun(this, &Patchage::on_scroll)); + _clear_load_but->signal_clicked().connect( + sigc::mem_fun(this, &Patchage::clear_load)); + #ifdef PATCHAGE_JACK_SESSION _menu_open_session->signal_activate().connect( sigc::mem_fun(this, &Patchage::show_open_session_dialog)); @@ -197,8 +205,8 @@ Patchage::Patchage(int argc, char** argv) sigc::mem_fun(this, &Patchage::on_arrange)); _menu_view_messages->signal_activate().connect( sigc::mem_fun(this, &Patchage::on_show_messages)); - _menu_view_legend->signal_activate().connect( - sigc::mem_fun(this, &Patchage::on_view_legend)); + _menu_view_toolbar->signal_activate().connect( + sigc::mem_fun(this, &Patchage::on_view_toolbar)); _menu_help_about->signal_activate().connect( sigc::mem_fun(this, &Patchage::on_help_about)); _menu_zoom_in->signal_activate().connect( @@ -248,8 +256,9 @@ Patchage::Patchage(int argc, char** argv) _legend = new Legend(*_conf); _legend->signal_color_changed.connect( sigc::mem_fun(this, &Patchage::on_legend_color_change)); - _main_vbox->pack_end(*Gtk::manage(_legend), false, false); - + _legend_alignment->add(*Gtk::manage(_legend)); + _legend->show_all(); + _about_win->set_transient_for(*_main_win); #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) @@ -268,6 +277,7 @@ Patchage::Patchage(int argc, char** argv) connect_widgets(); update_state(); + _menu_view_toolbar->set_active(_conf->get_show_toolbar()); _canvas->widget().grab_focus(); @@ -328,6 +338,7 @@ Patchage::attach() _enable_refresh = true; refresh(); + update_toolbar(); } bool @@ -370,6 +381,53 @@ Patchage::idle_callback() _refresh = false; _driver_detached = false; + // Update load every 5 idle callbacks + static int count = 0; + if (++count == 5) { + update_load(); + count = 0; + } + + return true; +} + +void +Patchage::update_toolbar() +{ +#if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) + if (_jack_driver->is_attached()) { + const jack_nframes_t buffer_size = _jack_driver->buffer_size(); + const jack_nframes_t sample_rate = _jack_driver->sample_rate(); + if (sample_rate != 0) { + const int latency_ms = lrintf(buffer_size * 1000 / (float)sample_rate); + std::stringstream ss; + ss << buffer_size << " frames @ " + << (sample_rate / 1000) << "kHz (" << latency_ms << "ms)"; + _latency_label->set_label(ss.str()); + _latency_label->set_visible(true); + return; + } + } +#endif + _latency_label->set_visible(false); +} + +bool +Patchage::update_load() +{ +#if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) + if (_jack_driver->is_attached()) { + char buf[8]; + snprintf(tmp_buf, sizeof(tmp_buf), "%u", _jack_driver->get_xruns()); + _xrun_progress->set_text(std::string(tmp_buf) + " Dropouts"); + + const float max_dsp_load = _jack_driver->get_max_dsp_load(); + if (max_dsp_load != last_max_dsp_load) { + _xrun_progress->set_fraction(max_dsp_load); + } + } +#endif + return true; } @@ -414,6 +472,16 @@ Patchage::store_window_location() _conf->set_window_size(window_size); } +void +Patchage::clear_load() +{ +#if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) + _xrun_progress->set_fraction(0.0); + _jack_driver->reset_xruns(); + _jack_driver->reset_max_dsp_load(); +#endif +} + void Patchage::error_msg(const std::string& msg) { @@ -833,13 +901,14 @@ Patchage::on_show_messages() } void -Patchage::on_view_legend() +Patchage::on_view_toolbar() { - if (_menu_view_legend->get_active()) { - _legend->show(); + if (_menu_view_toolbar->get_active()) { + _toolbar->show(); } else { - _legend->hide(); + _toolbar->hide(); } + _conf->set_show_toolbar(_menu_view_toolbar->get_active()); } bool diff --git a/src/Patchage.hpp b/src/Patchage.hpp index f620fa4..06cbace 100644 --- a/src/Patchage.hpp +++ b/src/Patchage.hpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -35,6 +36,8 @@ #include #include #include +#include +#include #include #include @@ -97,7 +100,7 @@ protected: void on_quit(); void on_export_dot(); void on_show_messages(); - void on_view_legend(); + void on_view_toolbar(); void on_store_positions(); void on_view_human_names(); void on_zoom_in(); @@ -113,7 +116,9 @@ protected: void zoom(double z); bool idle_callback(); + void clear_load(); bool update_load(); + void update_toolbar(); void buffer_size_changed(); @@ -153,7 +158,7 @@ protected: Widget _menu_save_close_session; Widget _menu_view_arrange; Widget _menu_view_messages; - Widget _menu_view_legend; + Widget _menu_view_toolbar; Widget _menu_view_refresh; Widget _menu_view_human_names; Widget _menu_zoom_in; @@ -166,6 +171,11 @@ protected: Widget _messages_clear_but; Widget _messages_close_but; Widget _messages_win; + Widget _toolbar; + Widget _clear_load_but; + Widget _xrun_progress; + Widget _latency_label; + Widget _legend_alignment; Widget _status_text; Legend* _legend; diff --git a/src/patchage.ui b/src/patchage.ui index b23e915..c8f7a25 100644 --- a/src/patchage.ui +++ b/src/patchage.ui @@ -1,6 +1,7 @@ + False True @@ -693,10 +694,10 @@ Nedko Arnaudov <nedko@arnaudov.name> Lapo Calamandrei patchage - + False - + False @@ -889,14 +890,14 @@ Nedko Arnaudov <nedko@arnaudov.name> - + False True False - _Legend... + _Toolbar... True - False - + True + @@ -930,8 +931,8 @@ Nedko Arnaudov <nedko@arnaudov.name> False True True - + @@ -975,30 +976,30 @@ Nedko Arnaudov <nedko@arnaudov.name> - _Increase Font Size False True False + _Increase Font Size True - _Decrease Font Size False True False + _Decrease Font Size True - _Normal Font Size False True False + _Normal Font Size True @@ -1069,6 +1070,138 @@ Nedko Arnaudov <nedko@arnaudov.name> 0 + + + True + False + icons + False + 1 + True + + + False + True + False + True + Clear the dropout indicator + Clear dropout indicator. + gtk-clear + + + False + True + + + + + False + True + False + + + True + False + 0 + + + True + False + True + Drouput (XRun) Indicator + +The bar represents the percentage of available time used for audio processing (i.e. the DSP load). If the bar reaches 100%, a dropout will occur. + Load and dropout gauge. The bar shows the percentage of available time used for audio processing. If it reaches 100%, a dropout will occur, and the bar is reset. Click to reset. + True + 0.10000000149 + 0 Dropouts + 100 + + + + + + + False + + + + + False + True + False + False + + + True + False + Jack buffer size and sample rate. + 0 + + + True + False + + + True + False + / + + + False + False + 0 + + + + + False + ? frames @ ? kHz (? ms) + + + False + False + 1 + 1 + + + + + + + + + False + + + + + False + True + False + + + True + False + 1 + 0 + + + + + + + + True + + + + + False + True + 1 + + True @@ -1084,7 +1217,7 @@ Nedko Arnaudov <nedko@arnaudov.name> True True - 1 + 2 @@ -1103,13 +1236,13 @@ Nedko Arnaudov <nedko@arnaudov.name> dialog main_win - + True False GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 2 - + True False GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -1122,7 +1255,6 @@ Nedko Arnaudov <nedko@arnaudov.name> True False GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - False True @@ -1142,7 +1274,6 @@ Nedko Arnaudov <nedko@arnaudov.name> True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - False True -- cgit v1.2.1