From a0044e5f715563d3abfdbf6c431c97ed41eb9b0d Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 16 Apr 2013 10:07:52 -0400 Subject: add back various functionality to waveviews such as zero line, amplitude scaling --- gtk2_ardour/audio_region_view.cc | 39 +++++++++++++----- gtk2_ardour/ghostregion.cc | 4 +- gtk2_ardour/tape_region_view.cc | 5 ++- libs/canvas/canvas.cc | 13 ++++++ libs/canvas/canvas/canvas.h | 3 +- libs/canvas/canvas/wave_view.h | 40 ++++++++++-------- libs/canvas/text.cc | 4 +- libs/canvas/wave_view.cc | 87 ++++++++++++++++++++++++++++++++++++---- 8 files changed, 155 insertions(+), 40 deletions(-) diff --git a/gtk2_ardour/audio_region_view.cc b/gtk2_ardour/audio_region_view.cc index eaa1f2fabb..6f15aacf55 100644 --- a/gtk2_ardour/audio_region_view.cc +++ b/gtk2_ardour/audio_region_view.cc @@ -330,10 +330,10 @@ AudioRegionView::fade_out_active_changed () void AudioRegionView::region_scale_amplitude_changed () { - ENSURE_GUI_THREAD (*this, &AudioRegionView::region_scale_amplitude_changed) + double g = audio_region()->scale_amplitude (); for (uint32_t n = 0; n < waves.size(); ++n) { - waves[n]->rebuild (); + waves[n]->set_amplitude (g); } } @@ -766,8 +766,8 @@ AudioRegionView::set_colors () waves[n]->set_outline_color (ARDOUR_UI::config()->canvasvar_WaveForm.get()); } - waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get(); - waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get(); + waves[n]->set_clip_color (ARDOUR_UI::config()->canvasvar_WaveFormClip.get()); + waves[n]->set_zero_color (ARDOUR_UI::config()->canvasvar_ZeroLine.get()); } } @@ -780,7 +780,7 @@ AudioRegionView::setup_waveform_visibility () this when waveforms are hidden. */ // CAIROCANVAS - //waves[n]->set_samples_per_pixel (_samples_per_pixel); + // waves[n]->set_samples_per_pixel (_samples_per_pixel); waves[n]->show(); } } else { @@ -909,14 +909,22 @@ AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/) wave->set_fill_color (ARDOUR_UI::config()->canvasvar_WaveFormFill.get()); } - wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get(); - wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get(); + wave->set_clip_color (ARDOUR_UI::config()->canvasvar_WaveFormClip.get()); + wave->set_zero_color (ARDOUR_UI::config()->canvasvar_ZeroLine.get()); // CAIROCANVAS // wave->property_zero_line() = true; wave->set_region_start (_region->start()); - wave->property_rectified() = Config->get_waveform_shape() == Rectified; - wave->property_logscaled() = Config->get_waveform_scale() == Logarithmic; + + switch (Config->get_waveform_shape()) { + case Rectified: + wave->set_shape (WaveView::Rectified); + break; + default: + wave->set_shape (WaveView::Normal); + } + + wave->set_logscaled (Config->get_waveform_scale() == Logarithmic); if (!Config->get_show_waveforms ()) { wave->hide(); @@ -1025,8 +1033,17 @@ AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent */* void AudioRegionView::setup_waveform_shape () { + WaveView::Shape shape; + + switch (Config->get_waveform_shape()) { + case Rectified: + shape = WaveView::Rectified; + break; + default: + shape = WaveView::Normal; + } for (vector::iterator wave = waves.begin(); wave != waves.end() ; ++wave) { - (*wave)->property_rectified() = Config->get_waveform_shape() == Rectified; + (*wave)->set_shape (shape); } } @@ -1034,7 +1051,7 @@ void AudioRegionView::setup_waveform_scale () { for (vector::iterator wave = waves.begin(); wave != waves.end() ; ++wave) { - (*wave)->property_logscaled() = Config->get_waveform_scale() == Logarithmic; + (*wave)->set_logscaled (Config->get_waveform_scale() == Logarithmic); } } diff --git a/gtk2_ardour/ghostregion.cc b/gtk2_ardour/ghostregion.cc index f881efa8d2..7a01df65f0 100644 --- a/gtk2_ardour/ghostregion.cc +++ b/gtk2_ardour/ghostregion.cc @@ -147,8 +147,8 @@ AudioGhostRegion::set_colors () for (uint32_t n=0; n < waves.size(); ++n) { waves[n]->set_outline_color (ARDOUR_UI::config()->canvasvar_GhostTrackWave.get()); waves[n]->set_fill_color (fill_color); - waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWaveClip.get(); - waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_GhostTrackZeroLine.get(); + waves[n]->set_clip_color (ARDOUR_UI::config()->canvasvar_GhostTrackWaveClip.get()); + waves[n]->set_zero_color (ARDOUR_UI::config()->canvasvar_GhostTrackZeroLine.get()); } } diff --git a/gtk2_ardour/tape_region_view.cc b/gtk2_ardour/tape_region_view.cc index eb4d8271c9..d626f3df49 100644 --- a/gtk2_ardour/tape_region_view.cc +++ b/gtk2_ardour/tape_region_view.cc @@ -79,7 +79,7 @@ TapeAudioRegionView::~TapeAudioRegionView() } void -TapeAudioRegionView::update (uint32_t n) +TapeAudioRegionView::update (uint32_t /*n*/) { /* check that all waves are build and ready */ @@ -88,7 +88,8 @@ TapeAudioRegionView::update (uint32_t n) } ENSURE_GUI_THREAD (*this, &TapeAudioRegionView::update, n); - waves[n]->rebuild (); + // CAIROCANVAS + // waves[n]->rebuild (); } void 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 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) {} void item_shown_or_hidden (Item *); + void item_visual_property_changed (Item*); void item_changed (Item *, boost::optional); void item_moved (Item *, boost::optional); - virtual Cairo::RefPtr context () = 0; + virtual Cairo::RefPtr context () = 0; std::list 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); void render (Rect const & area, Cairo::RefPtr) 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 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 @@ -46,6 +47,12 @@ WaveView::WaveView (Group* parent, boost::shared_ptr 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) { @@ -215,6 +222,65 @@ WaveView::region_resized () _bounding_box_dirty = true; } +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) { @@ -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 () } - + -- cgit v1.2.3