Skip to content

Commit

Permalink
Better fix for 6183.
Browse files Browse the repository at this point in the history
Invalidate all source entries from the image cache when we get our
region's DropReferences signal, while ignoring any subsequent regions with
no source.
  • Loading branch information
nmains committed Mar 28, 2015
1 parent 57e227f commit 8962bfb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
2 changes: 2 additions & 0 deletions libs/canvas/canvas/wave_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class LIBCANVAS_API WaveView : public Item

static std::map <boost::shared_ptr<ARDOUR::AudioSource>, std::vector <CacheEntry> > _image_cache;
void consolidate_image_cache () const;
void invalidate_source (boost::weak_ptr<ARDOUR::AudioSource>);
void invalidate_image_cache ();

boost::shared_ptr<ARDOUR::AudioRegion> _region;
Expand All @@ -188,6 +189,7 @@ class LIBCANVAS_API WaveView : public Item
ARDOUR::frameoffset_t _region_start;

PBD::ScopedConnectionList invalidation_connection;
PBD::ScopedConnection _source_invalidated_connection;

static double _global_gradient_depth;
static bool _global_logscaled;
Expand Down
42 changes: 31 additions & 11 deletions libs/canvas/wave_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

#include <gdkmm/general.h>

#include "gtk2_ardour/gui_thread.h"

using namespace std;
using namespace ARDOUR;
using namespace ArdourCanvas;
Expand Down Expand Up @@ -74,6 +76,10 @@ WaveView::WaveView (Canvas* c, boost::shared_ptr<ARDOUR::AudioRegion> region)
, _start_shift (0.0)
, _region_start (region->start())
{
_region->DropReferences.connect (_source_invalidated_connection, MISSING_INVALIDATOR,
boost::bind (&ArdourCanvas::WaveView::invalidate_source,
this, boost::weak_ptr<AudioSource>(_region->audio_source())), gui_context());

VisualPropertiesChanged.connect_same_thread (invalidation_connection, boost::bind (&WaveView::handle_visual_property_change, this));
ClipLevelChanged.connect_same_thread (invalidation_connection, boost::bind (&WaveView::handle_clip_level_change, this));
}
Expand All @@ -97,12 +103,17 @@ WaveView::WaveView (Item* parent, boost::shared_ptr<ARDOUR::AudioRegion> region)
, _region_amplitude (_region->scale_amplitude ())
, _region_start (region->start())
{
_region->DropReferences.connect (_source_invalidated_connection, MISSING_INVALIDATOR,
boost::bind (&ArdourCanvas::WaveView::invalidate_source,
this, boost::weak_ptr<AudioSource>(_region->audio_source())), gui_context());

VisualPropertiesChanged.connect_same_thread (invalidation_connection, boost::bind (&WaveView::handle_visual_property_change, this));
ClipLevelChanged.connect_same_thread (invalidation_connection, boost::bind (&WaveView::handle_clip_level_change, this));
}

WaveView::~WaveView ()
{
_source_invalidated_connection.disconnect();
invalidate_image_cache ();
}

Expand Down Expand Up @@ -206,23 +217,32 @@ WaveView::set_clip_level (double dB)
}

void
WaveView::invalidate_image_cache ()
WaveView::invalidate_source (boost::weak_ptr<AudioSource> src)
{
vector <uint32_t> deletion_list;
vector <CacheEntry> caches;
if (boost::shared_ptr<AudioSource> source = src.lock()) {

/* The source may have disappeared in the case of rec regions.*/
if (_region->n_channels() == 0) {
std::map <boost::shared_ptr<ARDOUR::AudioSource>, std::vector <CacheEntry> >::iterator i;
for (i = _image_cache.begin(); i != _image_cache.end(); ++i) {
if (i->first.unique()) {
for (uint32_t n = 0; n < (*i).second.size (); ++n) {
(*i).second[n].image.clear ();
for (i = _image_cache.begin (); i != _image_cache.end (); ++i) {
if (i->first == source) {
for (uint32_t n = 0; n < i->second.size (); ++n) {
i->second[n].image.clear ();
}
(*i).second.clear ();
_image_cache.erase(i->first);
i->second.clear ();
_image_cache.erase (i->first);
}
}
}
}

void
WaveView::invalidate_image_cache ()
{
vector <uint32_t> deletion_list;
vector <CacheEntry> caches;

/* The source may have disappeared.*/

if (_region->n_channels() == 0) {
return;
}

Expand Down

0 comments on commit 8962bfb

Please sign in to comment.