Remove empty MIDI regions which result from recordings made when no MIDI data is...
authorCarl Hetherington <carl@carlh.net>
Wed, 26 May 2010 16:03:47 +0000 (16:03 +0000)
committerCarl Hetherington <carl@carlh.net>
Wed, 26 May 2010 16:03:47 +0000 (16:03 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7167 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/playlist.h
libs/ardour/midi_diskstream.cc
libs/ardour/playlist.cc

index d13789fa380daf4998bca37e577ccc2c11925cef..1021b8dba0bff763f3bb6284975dd7315d95cdde 100644 (file)
@@ -136,6 +136,7 @@ class Playlist : public SessionObject
 
        void add_region (boost::shared_ptr<Region>, framepos_t position, float times = 1, bool auto_partition = false);
        void remove_region (boost::shared_ptr<Region>);
+       void remove_region_by_source (boost::shared_ptr<Source>);
        void get_equivalent_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >&);
        void get_region_list_equivalent_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >&);
        void replace_region (boost::shared_ptr<Region> old, boost::shared_ptr<Region> newr, framepos_t pos);
index e58c8896bd33711d083a8544c13a68b0c7df183e..fa2cdce0140e8664149e8a0fea55cf94785d0414 100644 (file)
@@ -1321,6 +1321,10 @@ MidiDiskstream::use_new_write_source (uint32_t n)
        if (_write_source) {
 
                if (_write_source->is_empty ()) {
+                       /* remove any region that is using this empty source; they can result when MIDI recordings
+                          are made, but no MIDI data is received.
+                       */
+                       _playlist->remove_region_by_source (_write_source);
                        _write_source->mark_for_remove ();
                        _write_source->drop_references ();
                        _write_source.reset();
index 7c9ac93c3ca0dd70e52aec7a7f1e3202f91f63ee..1d506dcee7d78c018a1258b5f0bbb264c59d0f1b 100644 (file)
@@ -2939,3 +2939,22 @@ Playlist::has_region_at (framepos_t const p) const
 
        return (i != regions.end());
 }
+
+/** Remove any region that uses a given source */
+void
+Playlist::remove_region_by_source (boost::shared_ptr<Source> s)
+{
+       RegionLock rl (this);
+       
+       RegionList::iterator i = regions.begin();
+       while (i != regions.end()) {
+               RegionList::iterator j = i;
+               ++j;
+               
+               if ((*i)->uses_source (s)) {
+                       remove_region_internal (*i);
+               }
+
+               i = j;
+       }
+}