diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2013-04-16 10:07:52 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2013-04-16 10:07:52 -0400 |
commit | a0044e5f715563d3abfdbf6c431c97ed41eb9b0d (patch) | |
tree | 0b241404a09cd3914783c7ce38efae3ee8fb3f83 /libs | |
parent | e3db2d3ca52620970c4c493d629b546da29aee47 (diff) |
add back various functionality to waveviews such as zero line, amplitude scaling
Diffstat (limited to 'libs')
-rw-r--r-- | libs/canvas/canvas.cc | 13 | ||||
-rw-r--r-- | libs/canvas/canvas/canvas.h | 3 | ||||
-rw-r--r-- | libs/canvas/canvas/wave_view.h | 40 | ||||
-rw-r--r-- | libs/canvas/text.cc | 4 | ||||
-rw-r--r-- | libs/canvas/wave_view.cc | 87 |
5 files changed, 122 insertions, 25 deletions
diff --git a/libs/canvas/canvas.cc b/libs/canvas/canvas.cc index 7bd55feebc..726e4fb2fc 100644 --- a/libs/canvas/canvas.cc +++ b/libs/canvas/canvas.cc @@ -165,6 +165,19 @@ Canvas::item_shown_or_hidden (Item* item) } } +/** Called when an item has a change to its visual properties + * that do NOT affect its bounding box. + * @param item Item that has been modified. + */ +void +Canvas::item_visual_property_changed (Item* item) +{ + boost::optional<Rect> bbox = item->bounding_box (); + if (bbox) { + queue_draw_item_area (item, bbox.get ()); + } +} + /** Called when an item has changed, but not moved. * @param item Item that has changed. * @param pre_change_bounding_box The bounding box of item before the change, diff --git a/libs/canvas/canvas/canvas.h b/libs/canvas/canvas/canvas.h index 9c0f690f93..9b31844e7e 100644 --- a/libs/canvas/canvas/canvas.h +++ b/libs/canvas/canvas/canvas.h @@ -73,10 +73,11 @@ public: /** Called when an item is being destroyed */ virtual void item_going_away (Item *, boost::optional<Rect>) {} void item_shown_or_hidden (Item *); + void item_visual_property_changed (Item*); void item_changed (Item *, boost::optional<Rect>); void item_moved (Item *, boost::optional<Rect>); - virtual Cairo::RefPtr<Cairo::Context> context () = 0; + virtual Cairo::RefPtr<Cairo::Context> context () = 0; std::list<Rect> const & renders () const { return _renders; diff --git a/libs/canvas/canvas/wave_view.h b/libs/canvas/canvas/wave_view.h index 8362380921..33fec55e72 100644 --- a/libs/canvas/canvas/wave_view.h +++ b/libs/canvas/canvas/wave_view.h @@ -46,6 +46,11 @@ namespace ArdourCanvas { class WaveView : virtual public Item, public Outline, public Fill { public: + enum Shape { + Normal, + Rectified, + }; + WaveView (Group *, boost::shared_ptr<ARDOUR::AudioRegion>); void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const; @@ -58,8 +63,17 @@ public: void region_resized (); - /* XXX */ - void rebuild () {} + void set_show_zero_line (bool); + bool show_zero_line() const { return _show_zero; } + void set_zero_color (Color); + void set_clip_color (Color); + void set_amplitude (double); + double amplitude() const { return _amplitude; } + void set_logscaled (bool); + bool logscaled() const { return _logscaled; } + + void set_shape (Shape); + Shape shape() const; #ifdef CANVAS_COMPATIBILITY void*& property_gain_src () { @@ -68,22 +82,9 @@ public: void*& property_gain_function () { return _foo_void; } - bool& property_rectified () { - return _foo_bool; - } - bool& property_logscaled () { - return _foo_bool; - } double& property_amplitude_above_axis () { return _foo_double; } - Color& property_clip_color () { - return _foo_uint; - } - Color& property_zero_color () { - return _foo_uint; - } - private: void* _foo_void; bool _foo_bool; @@ -114,7 +115,7 @@ private: void clear_image (); private: - Coord position (float) const; + Coord position (Coord) const; WaveView const * _wave_view; int _start; @@ -135,6 +136,13 @@ private: double _samples_per_pixel; Coord _height; Color _wave_color; + bool _show_zero; + Color _zero_color; + Shape _shape; + Color _clip_color; + bool _logscaled; + double _amplitude; + /** The `start' value to use for the region; we can't use the region's * value as the crossfade editor needs to alter it. */ diff --git a/libs/canvas/text.cc b/libs/canvas/text.cc index 66d523fce6..c0bac2f7ee 100644 --- a/libs/canvas/text.cc +++ b/libs/canvas/text.cc @@ -119,7 +119,9 @@ Text::compute_bounding_box () const Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context); layout->set_text (_text); - layout->set_font_description (*_font_description); + if (_font_description) { + layout->set_font_description (*_font_description); + } layout->set_alignment (_alignment); Pango::Rectangle const r = layout->get_ink_extents (); diff --git a/libs/canvas/wave_view.cc b/libs/canvas/wave_view.cc index 9ab06c4649..4a4a78d47e 100644 --- a/libs/canvas/wave_view.cc +++ b/libs/canvas/wave_view.cc @@ -30,6 +30,7 @@ #include "canvas/wave_view.h" #include "canvas/utils.h" +#include "canvas/canvas.h" #include <gdkmm/general.h> @@ -46,6 +47,12 @@ WaveView::WaveView (Group* parent, boost::shared_ptr<ARDOUR::AudioRegion> region , _samples_per_pixel (0) , _height (64) , _wave_color (0xffffffff) + , _show_zero (true) + , _zero_color (0xff0000ff) + , _shape (Normal) + , _clip_color (0xff0000ff) + , _logscaled (false) + , _amplitude (1.0) , _region_start (0) { @@ -216,6 +223,65 @@ WaveView::region_resized () } void +WaveView::set_logscaled (bool yn) +{ + if (_logscaled != yn) { + _logscaled = yn; + invalidate_whole_cache (); + _canvas->item_visual_property_changed (this); + } +} + +void +WaveView::set_amplitude (double a) +{ + if (_amplitude != a) { + _amplitude = a; + invalidate_whole_cache (); + _canvas->item_visual_property_changed (this); + } +} + +void +WaveView::set_zero_color (Color c) +{ + if (_zero_color != c) { + _zero_color = c; + invalidate_whole_cache (); + _canvas->item_visual_property_changed (this); + } +} + +void +WaveView::set_clip_color (Color c) +{ + if (_clip_color != c) { + _clip_color = c; + invalidate_whole_cache (); + _canvas->item_visual_property_changed (this); + } +} + +void +WaveView::set_show_zero_line (bool yn) +{ + if (_show_zero != yn) { + _show_zero = yn; + invalidate_whole_cache (); + _canvas->item_visual_property_changed (this); + } +} + +void +WaveView::set_shape (Shape s) +{ + if (_shape != s) { + _shape = s; + _canvas->item_visual_property_changed (this); + } +} + +void WaveView::set_region_start (frameoffset_t start) { _region_start = start; @@ -262,20 +328,27 @@ WaveView::CacheEntry::image () _wave_view->setup_outline_context (context); context->move_to (0.5, position (_peaks[0].min)); for (int i = 1; i < _n_peaks; ++i) { - context->line_to (i + 0.5, position (_peaks[i].max)); + context->line_to (i + 0.5, position (_wave_view->amplitude() * _peaks[i].max)); } context->stroke (); context->move_to (0.5, position (_peaks[0].min)); for (int i = 1; i < _n_peaks; ++i) { - context->line_to (i + 0.5, position (_peaks[i].min)); + context->line_to (i + 0.5, position (_wave_view->amplitude() * _peaks[i].min)); } context->stroke (); set_source_rgba (context, _wave_view->_fill_color); for (int i = 0; i < _n_peaks; ++i) { - context->move_to (i + 0.5, position (_peaks[i].max) - 1); - context->line_to (i + 0.5, position (_peaks[i].min) + 1); + context->move_to (i + 0.5, position (_wave_view->amplitude() * (_peaks[i].max)) - 1); + context->line_to (i + 0.5, position (_wave_view->amplitude() * (_peaks[i].min)) + 1); + context->stroke (); + } + + if (_wave_view->show_zero_line()) { + set_source_rgba (context, _wave_view->_zero_color); + context->move_to (0, position (0.0)); + context->line_to (_n_peaks, position (0.0)); context->stroke (); } } @@ -285,9 +358,9 @@ WaveView::CacheEntry::image () Coord -WaveView::CacheEntry::position (float s) const +WaveView::CacheEntry::position (Coord s) const { - return (s + 1) * _wave_view->_height / 2; + return (s+1.0) * (_wave_view->_height / 2.0); } void @@ -297,4 +370,4 @@ WaveView::CacheEntry::clear_image () } - + |