Fix broken logic and possible NULL pointer dereference for Bundle XML.
[ardour.git] / libs / canvas / canvas / wave_view.h
index 307528c685507e03d8cb2e3d2fff2e1f109c7497..f26c3a5c104dfeb8c1ee6d31d973406b303943ad 100644 (file)
@@ -45,14 +45,33 @@ class WaveViewTest;
        
 namespace ArdourCanvas {
 
-class LIBCANVAS_API WaveView : virtual public Item, public Outline, public Fill
+class LIBCANVAS_API WaveView : public Item
 {
 public:
+
         enum Shape { 
                Normal,
-               Rectified,
+               Rectified
         };
 
+       struct CacheEntry {
+               int channel;
+               Coord height;
+               float amplitude;
+               Color fill_color;
+               framepos_t start;
+               framepos_t end;
+               Cairo::RefPtr<Cairo::ImageSurface> image;
+
+       CacheEntry(int chan, Coord hght, float amp, Color fcl, framepos_t strt, framepos_t ed, Cairo::RefPtr<Cairo::ImageSurface> img)  :
+               
+               channel (chan), height (hght), amplitude (amp), fill_color (fcl), 
+                       start (strt), end (ed), image (img) {} 
+       };
+
+       /* final ImageSurface rendered with colours */
+       Cairo::RefPtr<Cairo::ImageSurface> _image;
+       
     /* Displays a single channel of waveform data for the given Region.
 
        x = 0 in the waveview corresponds to the first waveform datum taken
@@ -72,7 +91,8 @@ public:
     */
 
 
-       WaveView (Group *, boost::shared_ptr<ARDOUR::AudioRegion>);
+       WaveView (Canvas *, boost::shared_ptr<ARDOUR::AudioRegion>);
+       WaveView (Item*, boost::shared_ptr<ARDOUR::AudioRegion>);
        ~WaveView ();
 
        void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const;
@@ -132,7 +152,9 @@ private:
 
         friend class ::WaveViewTest;
 
-       void invalidate_image ();
+       static std::map <boost::shared_ptr<ARDOUR::AudioSource>, std::vector <CacheEntry> > _image_cache;
+       void consolidate_image_cache () const;
+       void invalidate_image_cache ();
 
        boost::shared_ptr<ARDOUR::AudioRegion> _region;
        int    _channel;
@@ -148,16 +170,12 @@ 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 ARDOUR::framepos_t _sample_start; 
-        mutable ARDOUR::framepos_t _sample_end; 
-        mutable Cairo::RefPtr<Cairo::ImageSurface> _image;
 
         PBD::ScopedConnectionList invalidation_connection;
 
@@ -172,9 +190,10 @@ private:
         void handle_visual_property_change ();
         void handle_clip_level_change ();
 
-        void ensure_cache (ARDOUR::framepos_t sample_start, ARDOUR::framepos_t sample_end) const;
-        ArdourCanvas::Coord position (double) const;
-        void draw_image (ARDOUR::PeakData*, int npeaks) const;
+       void get_image (Cairo::RefPtr<Cairo::ImageSurface>& image, framepos_t start, framepos_t end, double& image_offset) const;
+
+        ArdourCanvas::Coord y_extent (double, bool) const;
+       void draw_image (Cairo::RefPtr<Cairo::ImageSurface>&, ARDOUR::PeakData*, int) const;
 };
 
 }