From 381d4debf4c84816d08ff4de27bc9ae8d5d15f28 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 16 Apr 2013 21:23:50 -0400 Subject: [PATCH] make waveform gradient depth continuously variable. color probably needs adjusting as do color stops to get a pleasing effect at most settings --- gtk2_ardour/theme_manager.cc | 26 +++++++++++++++++++------- gtk2_ardour/theme_manager.h | 6 ++++-- gtk2_ardour/ui_config_vars.h | 2 +- libs/canvas/canvas/wave_view.h | 18 +++++++++++------- libs/canvas/wave_view.cc | 21 ++++++++++++++------- 5 files changed, 49 insertions(+), 24 deletions(-) diff --git a/gtk2_ardour/theme_manager.cc b/gtk2_ardour/theme_manager.cc index f1538c98e9..8a350fca49 100644 --- a/gtk2_ardour/theme_manager.cc +++ b/gtk2_ardour/theme_manager.cc @@ -58,7 +58,9 @@ ThemeManager::ThemeManager() , light_button (_("Light Theme")) , reset_button (_("Restore Defaults")) , flat_buttons (_("Draw \"flat\" buttons")) - , gradient_waveforms (_("Draw waveforms with color gradient")) + , waveform_gradient_depth (0, 1.0, 0.1) + , waveform_gradient_depth_label (_("Waveforms color gradient depth")) + { set_title (_("Theme Manager")); @@ -94,10 +96,18 @@ ThemeManager::ThemeManager() vbox->pack_start (theme_selection_hbox, PACK_SHRINK); vbox->pack_start (reset_button, PACK_SHRINK); vbox->pack_start (flat_buttons, PACK_SHRINK); - vbox->pack_start (gradient_waveforms, PACK_SHRINK); + + Gtk::HBox* hbox = Gtk::manage (new Gtk::HBox()); + hbox->set_spacing (6); + hbox->pack_start (waveform_gradient_depth, true, true); + hbox->pack_start (waveform_gradient_depth_label, false, false); + + vbox->pack_start (*hbox, PACK_SHRINK); vbox->pack_start (scroller); add (*vbox); + waveform_gradient_depth.set_update_policy (Gtk::UPDATE_DELAYED); + color_display.signal_button_press_event().connect (sigc::mem_fun (*this, &ThemeManager::button_press_event), false); color_dialog.get_colorsel()->set_has_opacity_control (true); @@ -109,7 +119,7 @@ ThemeManager::ThemeManager() light_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_light_theme_button_toggled)); reset_button.signal_clicked().connect (sigc::mem_fun (*this, &ThemeManager::reset_canvas_colors)); flat_buttons.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_flat_buttons_toggled)); - gradient_waveforms.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_gradient_waveforms_toggled)); + waveform_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_waveform_gradient_depth_change)); set_size_request (-1, 400); setup_theme (); @@ -247,11 +257,13 @@ ThemeManager::on_flat_buttons_toggled () } void -ThemeManager::on_gradient_waveforms_toggled () +ThemeManager::on_waveform_gradient_depth_change () { - ARDOUR_UI::config()->gradient_waveforms.set (gradient_waveforms.get_active()); + double v = waveform_gradient_depth.get_value(); + + ARDOUR_UI::config()->waveform_gradient_depth.set (v); ARDOUR_UI::config()->set_dirty (); - ArdourCanvas::WaveView::set_gradient_waveforms (gradient_waveforms.get_active()); + ArdourCanvas::WaveView::set_global_gradient_depth (v); } void @@ -363,7 +375,7 @@ ThemeManager::setup_theme () } flat_buttons.set_active (ARDOUR_UI::config()->flat_buttons.get()); - gradient_waveforms.set_active (ARDOUR_UI::config()->gradient_waveforms.get()); + waveform_gradient_depth.set_value (ARDOUR_UI::config()->waveform_gradient_depth.get()); load_rc_file(rcfile, false); } diff --git a/gtk2_ardour/theme_manager.h b/gtk2_ardour/theme_manager.h index d08713dc3e..225f26ee79 100644 --- a/gtk2_ardour/theme_manager.h +++ b/gtk2_ardour/theme_manager.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "ardour_window.h" #include "ui_config.h" @@ -43,7 +44,7 @@ class ThemeManager : public ArdourWindow void on_dark_theme_button_toggled (); void on_light_theme_button_toggled (); void on_flat_buttons_toggled (); - void on_gradient_waveforms_toggled (); + void on_waveform_gradient_depth_change (); private: struct ColorDisplayModelColumns : public Gtk::TreeModel::ColumnRecord { @@ -70,7 +71,8 @@ class ThemeManager : public ArdourWindow Gtk::RadioButton light_button; Gtk::Button reset_button; Gtk::CheckButton flat_buttons; - Gtk::CheckButton gradient_waveforms; + Gtk::HScale waveform_gradient_depth; + Gtk::Label waveform_gradient_depth_label; bool button_press_event (GdkEventButton*); }; diff --git a/gtk2_ardour/ui_config_vars.h b/gtk2_ardour/ui_config_vars.h index f64e1ca141..40a10d79a0 100644 --- a/gtk2_ardour/ui_config_vars.h +++ b/gtk2_ardour/ui_config_vars.h @@ -19,5 +19,5 @@ UI_CONFIG_VARIABLE(std::string, ui_rc_file, "ui-rc-file", "ardour3_ui_dark.rc") UI_CONFIG_VARIABLE(bool, flat_buttons, "flat-buttons", false) -UI_CONFIG_VARIABLE(bool, gradient_waveforms, "gradient-waveforms", false) +UI_CONFIG_VARIABLE(float, waveform_gradient_depth, "waveform-gradient-depth", 0.6) diff --git a/libs/canvas/canvas/wave_view.h b/libs/canvas/canvas/wave_view.h index 44cc6f6f70..4fd45cff5d 100644 --- a/libs/canvas/canvas/wave_view.h +++ b/libs/canvas/canvas/wave_view.h @@ -72,6 +72,8 @@ public: void set_clip_color (Color); void set_amplitude (double); void set_logscaled (bool); + void set_gradient_depth (double); + double gradient_depth() const { return _gradient_depth; } void set_shape (Shape); double amplitude() const { return _amplitude; } @@ -80,13 +82,13 @@ public: set_logscaled_independent() */ - static void set_gradient_waveforms (bool); + static void set_global_gradient_depth (double); static void set_global_logscaled (bool); static void set_global_shape (Shape); - static bool gradient_waveforms() { return _gradient_waveforms; } - static bool global_logscaled() { return _global_logscaled; } - static Shape global_shape() { return _global_shape; } + static double global_gradient_depth() { return _global_gradient_depth; } + static bool global_logscaled() { return _global_logscaled; } + static Shape global_shape() { return _global_shape; } #ifdef CANVAS_COMPATIBILITY void*& property_gain_src () { @@ -154,9 +156,11 @@ private: Color _clip_color; bool _logscaled; Shape _shape; + double _gradient_depth; double _amplitude; bool _shape_independent; bool _logscaled_independent; + bool _gradient_depth_independent; /** The `start' value to use for the region; we can't use the region's * value as the crossfade editor needs to alter it. @@ -167,9 +171,9 @@ private: PBD::ScopedConnection invalidation_connection; - static bool _gradient_waveforms; - static bool _global_logscaled; - static Shape _global_shape; + static double _global_gradient_depth; + static bool _global_logscaled; + static Shape _global_shape; static PBD::Signal0 VisualPropertiesChanged; diff --git a/libs/canvas/wave_view.cc b/libs/canvas/wave_view.cc index f420c73980..6a2661262a 100644 --- a/libs/canvas/wave_view.cc +++ b/libs/canvas/wave_view.cc @@ -40,7 +40,7 @@ using namespace std; using namespace ARDOUR; using namespace ArdourCanvas; -bool WaveView::_gradient_waveforms = true; +double WaveView::_global_gradient_depth = 0.6; bool WaveView::_global_logscaled = false; WaveView::Shape WaveView::_global_shape = WaveView::Normal; @@ -60,9 +60,11 @@ WaveView::WaveView (Group* parent, boost::shared_ptr region , _clip_color (0xff0000ff) , _logscaled (_global_logscaled) , _shape (_global_shape) + , _gradient_depth (_global_gradient_depth) , _amplitude (1.0) , _shape_independent (false) , _logscaled_independent (false) + , _gradient_depth_independent (false) , _region_start (0) { VisualPropertiesChanged.connect_same_thread (invalidation_connection, boost::bind (&WaveView::handle_visual_property_change, this)); @@ -83,6 +85,11 @@ WaveView::handle_visual_property_change () changed = true; } + if (!_gradient_depth_independent && (_gradient_depth != global_gradient_depth())) { + _gradient_depth = global_gradient_depth(); + changed = true; + } + if (changed) { invalidate_image_cache (); } @@ -482,8 +489,8 @@ WaveView::CacheEntry::image () context->close_path (); - if (WaveView::gradient_waveforms()) { - + if (_wave_view->gradient_depth() != 0.0) { + Cairo::RefPtr gradient (Cairo::LinearGradient::create (0, 0, 0, _wave_view->_height)); double stops[3]; @@ -508,7 +515,7 @@ WaveView::CacheEntry::image () double h, s, v; color_to_hsv (_wave_view->_fill_color, h, s, v); /* tone down the saturation */ - s *= 0.60; + s *= 1.0 - _wave_view->gradient_depth(); Color center = hsv_to_color (h, s, v, a); color_to_rgba (center, r, g, b, a); gradient->add_color_stop_rgba (stops[1], r, g, b, a); @@ -553,10 +560,10 @@ WaveView::CacheEntry::clear_image () } void -WaveView::set_gradient_waveforms (bool yn) +WaveView::set_global_gradient_depth (double depth) { - if (_gradient_waveforms != yn) { - _gradient_waveforms = yn; + if (_global_gradient_depth != depth) { + _global_gradient_depth = depth; VisualPropertiesChanged (); /* EMIT SIGNAL */ } } -- 2.30.2