X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fcanvas%2Fcanvas%2Fwave_view.h;h=f26c3a5c104dfeb8c1ee6d31d973406b303943ad;hb=c4c7598adbc9e5eca5fe04a23bb7e88fc0989f34;hp=b75b8c5312a691ee11f6b3746a270783d962ace6;hpb=e2f0c5f91e2579c41d8efc9495b6ebac31a61ba3;p=ardour.git diff --git a/libs/canvas/canvas/wave_view.h b/libs/canvas/canvas/wave_view.h index b75b8c5312..f26c3a5c10 100644 --- a/libs/canvas/canvas/wave_view.h +++ b/libs/canvas/canvas/wave_view.h @@ -20,6 +20,7 @@ #include #include +#include #include "pbd/properties.h" @@ -27,6 +28,7 @@ #include +#include "canvas/visibility.h" #include "canvas/item.h" #include "canvas/fill.h" #include "canvas/outline.h" @@ -43,15 +45,55 @@ class WaveViewTest; namespace ArdourCanvas { -class WaveView : virtual public Item, public Outline, public Fill +class LIBCANVAS_API WaveView : public Item { public: + enum Shape { Normal, - Rectified, + Rectified }; - WaveView (Group *, boost::shared_ptr); + struct CacheEntry { + int channel; + Coord height; + float amplitude; + Color fill_color; + framepos_t start; + framepos_t end; + Cairo::RefPtr image; + + CacheEntry(int chan, Coord hght, float amp, Color fcl, framepos_t strt, framepos_t ed, Cairo::RefPtr img) : + + channel (chan), height (hght), amplitude (amp), fill_color (fcl), + start (strt), end (ed), image (img) {} + }; + + /* final ImageSurface rendered with colours */ + Cairo::RefPtr _image; + + /* Displays a single channel of waveform data for the given Region. + + x = 0 in the waveview corresponds to the first waveform datum taken + from region->start() samples into the source data. + + x = N in the waveview corresponds to the (N * spp)'th sample + measured from region->start() into the source data. + + when drawing, we will map the zeroth-pixel of the waveview + into a window. + + The waveview itself contains a set of pre-rendered Cairo::ImageSurfaces + that cache sections of the display. This is filled on-demand and + never cleared until something explicitly marks the cache invalid + (such as a change in samples_per_pixel, the log scaling, rectified or + other view parameters). + */ + + + WaveView (Canvas *, boost::shared_ptr); + WaveView (Item*, boost::shared_ptr); + ~WaveView (); void render (Rect const & area, Cairo::RefPtr) const; void compute_bounding_box () const; @@ -76,7 +118,6 @@ public: double gradient_depth() const { return _gradient_depth; } void set_shape (Shape); - /* currently missing because we don't need them (yet): set_shape_independent(); set_logscaled_independent() @@ -85,6 +126,7 @@ public: static void set_global_gradient_depth (double); static void set_global_logscaled (bool); static void set_global_shape (Shape); + static void set_global_show_waveform_clipping (bool); static double global_gradient_depth() { return _global_gradient_depth; } static bool global_logscaled() { return _global_logscaled; } @@ -93,6 +135,9 @@ public: void set_amplitude_above_axis (double v); double amplitude_above_axis () const { return _amplitude_above_axis; } + static void set_clip_level (double dB); + static PBD::Signal0 ClipLevelChanged; + #ifdef CANVAS_COMPATIBILITY void*& property_gain_src () { return _foo_void; @@ -105,65 +150,16 @@ private: #endif - /** A cached, pre-rendered image of some section of a waveform. - - It spans a range given relative to the start of the source - of the waveform data, so a range from N..M corresponds - to the sample range N..M within the source. - - Invalidated by a changes to: - - samples_per_pixel - colors - height - - */ - - class CacheEntry - { - public: - CacheEntry (WaveView const *, double, double, int); - ~CacheEntry (); - - double start () const { - return _start; - } - - double end () const { - return _end; - } - - boost::shared_array peaks () const { - return _peaks; - } + friend class ::WaveViewTest; - Cairo::RefPtr image(); - void clear_image (); - - private: - Coord position (Coord) const; - - WaveView const * _wave_view; - - double _start; - double _end; - int _n_peaks; - - boost::shared_array _peaks; - Cairo::RefPtr _image; - }; - - friend class CacheEntry; - friend class ::WaveViewTest; - - void invalidate_whole_cache (); + static std::map , std::vector > _image_cache; + void consolidate_image_cache () const; void invalidate_image_cache (); boost::shared_ptr _region; int _channel; double _samples_per_pixel; Coord _height; - Color _wave_color; bool _show_zero; Color _zero_color; Color _clip_color; @@ -174,23 +170,30 @@ private: bool _logscaled_independent; bool _gradient_depth_independent; double _amplitude_above_axis; + float _region_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. */ ARDOUR::frameoffset_t _region_start; - mutable std::list _cache; - - PBD::ScopedConnection invalidation_connection; + PBD::ScopedConnectionList invalidation_connection; static double _global_gradient_depth; static bool _global_logscaled; static Shape _global_shape; + static bool _global_show_waveform_clipping; + static double _clip_level; static PBD::Signal0 VisualPropertiesChanged; void handle_visual_property_change (); + void handle_clip_level_change (); + + void get_image (Cairo::RefPtr& image, framepos_t start, framepos_t end, double& image_offset) const; + + ArdourCanvas::Coord y_extent (double, bool) const; + void draw_image (Cairo::RefPtr&, ARDOUR::PeakData*, int) const; }; }