+struct LIBCANVAS_API WaveViewThreadRequest
+{
+ public:
+ enum RequestType {
+ Quit,
+ Cancel,
+ Draw
+ };
+
+ WaveViewThreadRequest () : stop (0) {}
+
+ bool should_stop () const { return (bool) g_atomic_int_get (&stop); }
+ void cancel() { g_atomic_int_set (&stop, 1); }
+
+ RequestType type;
+ framepos_t start;
+ framepos_t end;
+ double width;
+ double height;
+ double samples_per_pixel;
+ uint16_t channel;
+ double region_amplitude;
+ Color fill_color;
+ boost::weak_ptr<const ARDOUR::Region> region;
+
+ /* resulting image, after request has been satisfied */
+
+ Cairo::RefPtr<Cairo::ImageSurface> image;
+
+ private:
+ gint stop; /* intended for atomic access */
+};
+
+class LIBCANVAS_API WaveView;
+
+class LIBCANVAS_API WaveViewCache
+{
+ public:
+ WaveViewCache();
+ ~WaveViewCache();
+
+ struct Entry {
+
+ /* these properties define the cache entry as unique.
+
+ If an image is in use by a WaveView and any of these
+ properties are modified on the WaveView, the image can no
+ longer be used (or may no longer be usable for start/end
+ parameters). It will remain in the cache until flushed for
+ some reason (typically the cache is full).
+ */
+
+ int channel;
+ Coord height;
+ float amplitude;
+ Color fill_color;
+ double samples_per_pixel;
+ framepos_t start;
+ framepos_t end;
+
+ /* the actual image referred to by the cache entry */
+
+ Cairo::RefPtr<Cairo::ImageSurface> image;
+
+ /* last time the cache entry was used */
+ uint64_t timestamp;
+
+ Entry (int chan, Coord hght, float amp, Color fcl, double spp, framepos_t strt, framepos_t ed,
+ Cairo::RefPtr<Cairo::ImageSurface> img)
+ : channel (chan)
+ , height (hght)
+ , amplitude (amp)
+ , fill_color (fcl)
+ , samples_per_pixel (spp)
+ , start (strt)
+ , end (ed)
+ , image (img) {}
+ };
+
+ uint64_t image_cache_threshold () const { return _image_cache_threshold; }
+ void set_image_cache_threshold (uint64_t);
+
+ void add (boost::shared_ptr<ARDOUR::AudioSource>, boost::shared_ptr<Entry>);
+ void use (boost::shared_ptr<ARDOUR::AudioSource>, boost::shared_ptr<Entry>);
+
+ void consolidate_image_cache (boost::shared_ptr<ARDOUR::AudioSource>,
+ int channel,
+ Coord height,
+ float amplitude,
+ Color fill_color,
+ double samples_per_pixel);
+
+ boost::shared_ptr<Entry> lookup_image (boost::shared_ptr<ARDOUR::AudioSource>,
+ framepos_t start, framepos_t end,
+ int _channel,
+ Coord height,
+ float amplitude,
+ Color fill_color,
+ double samples_per_pixel,
+ bool& full_image);
+
+ private:
+ /* an unsorted, unindexd collection of cache entries associated with
+ a particular AudioSource. All cache Entries in the collection
+ share the AudioSource in common, but represent different parameter
+ settings (e.g. height, color, samples per pixel etc.)
+ */
+ typedef std::vector<boost::shared_ptr<Entry> > CacheLine;
+ /* Indexed, non-sortable structure used to lookup images associated
+ * with a particular AudioSource
+ */
+ typedef std::map <boost::shared_ptr<ARDOUR::AudioSource>,CacheLine> ImageCache;
+ ImageCache cache_map;
+
+ /* Linear, sortable structure used when we need to do a timestamp-based
+ * flush of entries from the cache.
+ */
+ typedef std::pair<boost::shared_ptr<ARDOUR::AudioSource>,boost::shared_ptr<Entry> > ListEntry;
+ typedef std::vector<ListEntry> CacheList;
+ CacheList cache_list;
+
+ struct SortByTimestamp {
+ bool operator() (const WaveViewCache::ListEntry& a, const WaveViewCache::ListEntry& b) {
+ return a.second->timestamp < b.second->timestamp;
+ }
+ };
+ friend struct SortByTimestamp;
+
+ uint64_t image_cache_size;
+ uint64_t _image_cache_threshold;
+
+ uint64_t compute_image_cache_size ();
+ void cache_flush ();
+ bool cache_full ();
+};
+
+class LIBCANVAS_API WaveView : public Item, public sigc::trackable