probably fix cleanup issues, but testing required
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 21 Mar 2007 02:39:12 +0000 (02:39 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 21 Mar 2007 02:39:12 +0000 (02:39 +0000)
git-svn-id: svn://localhost/ardour2/trunk@1632 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/canvas-simplerect.c
gtk2_ardour/editor_ops.cc
gtk2_ardour/selection.cc
libs/ardour/ardour/playlist.h
libs/ardour/ardour/source.h
libs/ardour/audioregion.cc
libs/ardour/playlist.cc
libs/ardour/source.cc

index e7a74880616b0642fcdd912091118f1ccfe266b6..d50943f0c3dfc55ba9b3868898eabb0f8d483d3b 100644 (file)
@@ -354,8 +354,8 @@ gnome_canvas_simplerect_reset_bounds (GnomeCanvasItem *item)
        gnome_canvas_request_redraw (item->canvas, 
                                     unionrect.x0 - 0.5,
                                     unionrect.y0 - 0.5,
-                                    unionrect.x1 + 0.5,
-                                    unionrect.y1 + 0.5);
+                                    unionrect.x1 + 1.5,
+                                    unionrect.y1 + 1.5);
 }
 
 /* 
index ba874fc7cf0fb74879681d8ab9c275919163f5c6..e6c57901333c468a82046a837fa2cd68d9c9a41d 100644 (file)
@@ -2811,19 +2811,21 @@ Editor::cut_copy_regions (CutCopyOp op)
                }
                
                boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion>((*x)->region());
+               boost::shared_ptr<Region> _xx;
                
                switch (op) {
                case Cut:
                        if (!ar) break;
                        
-                       npl->add_region (RegionFactory::create (ar), (*x)->region()->position() - first_position);
+                       _xx = RegionFactory::create ((*x)->region());
+                       npl->add_region (_xx, (*x)->region()->position() - first_position);
                        pl->remove_region (((*x)->region()));
                        break;
                        
                case Copy:
                        if (!ar) break;
                        
-                       npl->add_region (RegionFactory::create (ar), (*x)->region()->position() - first_position);
+                       npl->add_region ((*x)->region(), (*x)->region()->position() - first_position);
                        break;
                        
                case Clear:
@@ -2843,10 +2845,11 @@ Editor::cut_copy_regions (CutCopyOp op)
                foo.push_back ((*i).pl);
        }
        
+
        if (!foo.empty()) {
                cut_buffer->set (foo);
        }
-       
+
        for (set<PlaylistState, lt_playlist>::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) {
                (*pl).playlist->thaw ();
                session->add_command (new MementoCommand<Playlist>(*(*pl).playlist, (*pl).before, &(*pl).playlist->get_state()));
index 8a9d27a4ed2c30762f62ad07e3017dcd8e4d5051..2b1b522d12fce2819f2aea42b69d9cdaf6bc0b51 100644 (file)
@@ -131,6 +131,8 @@ Selection::clear_playlists ()
        /* Selections own their playlists */
 
        for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
+               /* selections own their own regions, which are copies of the "originals". make them go away */
+               (*i)->drop_regions ();
                (*i)->release ();
        }
 
index 6e36d3120bee3aa273730468164a6dafebd5ad29..103e95929e2a7d347aece186d3440dd2f4884a63 100644 (file)
@@ -138,6 +138,12 @@ class Playlist : public PBD::StatefulDestructible, public boost::enable_shared_f
        
        virtual bool destroy_region (boost::shared_ptr<Region>) = 0;
 
+       /* special case function used by UI selection objects, which have playlists that actually own the regions
+          within them.
+       */
+
+       void drop_regions ();
+
   protected:
        friend class Session;
 
index ae63b8c5fb5fefa93b32ab9a95bd120d9e5b44a5..7ffa616a404ef797e091ea8dbbbc61fed7e4da2a 100644 (file)
@@ -63,7 +63,9 @@ class Source : public PBD::StatefulDestructible
        string            _name;
        time_t            _timestamp;
 
-       std::set<boost::shared_ptr<ARDOUR::Playlist> > _playlists;
+       Glib::Mutex playlist_lock;
+       typedef std::map<boost::shared_ptr<ARDOUR::Playlist>, uint32_t > PlaylistMap;
+       PlaylistMap _playlists;
 
   private:
        uint32_t          _in_use;
index 24249a63649440b07e5680dc28015e2f4dc012d4..db6e5fc08932b321f30649286ec35d88b2dee683 100644 (file)
@@ -1057,7 +1057,6 @@ AudioRegion::separate_by_channel (Session& session, vector<boost::shared_ptr<Aud
 
                boost::shared_ptr<Region> r = RegionFactory::create (srcs, _start, _length, new_name, _layer, f);
                boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion> (r);
-               cerr << "new region name is " << ar->name() << endl;
 
                v.push_back (ar);
                
@@ -1281,7 +1280,6 @@ AudioRegion::normalize_to (float target_dB)
        boost::shared_ptr<Playlist> pl (playlist());
 
        if (pl) {
-               cerr << "Send modified\n";
                pl->Modified();
        }
 
@@ -1368,6 +1366,7 @@ void
 AudioRegion::set_playlist (boost::weak_ptr<Playlist> wpl)
 {
        boost::shared_ptr<Playlist> old_playlist = (_playlist.lock());
+
        boost::shared_ptr<Playlist> pl (wpl.lock());
 
        if (old_playlist == pl) {
@@ -1390,7 +1389,7 @@ AudioRegion::set_playlist (boost::weak_ptr<Playlist> wpl)
        } else {
                if (old_playlist) {
                        for (SourceList::const_iterator i = sources.begin(); i != sources.end(); ++i) {
-                               (*i)->remove_playlist (_playlist);
+                               (*i)->remove_playlist (old_playlist);
                        }
                }
        }
index 496be33950d84ca2e475fc456dd712bcdbd931e7..ae9e23fcc94adc2ab7a9ba5195a6e7ce2d916b74 100644 (file)
@@ -574,6 +574,11 @@ Playlist::remove_region_internal (boost::shared_ptr<Region>region)
                old_length = _get_maximum_extent();
        }
 
+       if (!in_set_state) {
+               /* unset playlist */
+               region->set_playlist (boost::weak_ptr<Playlist>());
+       }
+
        for (i = regions.begin(); i != regions.end(); ++i) {
                if (*i == region) {
 
@@ -1174,6 +1179,14 @@ Playlist::region_changed (Change what_changed, boost::shared_ptr<Region> region)
        return save;
 }
 
+void
+Playlist::drop_regions ()
+{
+       RegionLock rl (this);
+       regions.clear ();
+       all_regions.clear ();
+}
+
 void
 Playlist::clear (bool with_signals)
 {
index fe14fc72af8b2d1ffbf600978621aed3a40211de..7f680e7100f6e934725d7737e07f5a49cd0145b8 100644 (file)
@@ -111,7 +111,17 @@ Source::set_state (const XMLNode& node)
 void
 Source::add_playlist (boost::shared_ptr<Playlist> pl)
 {
-       _playlists.insert (pl);
+       std::pair<PlaylistMap::iterator,bool> res;
+       std::pair<boost::shared_ptr<Playlist>, uint32_t> newpair (pl, 1);
+       Glib::Mutex::Lock lm (playlist_lock);
+
+       res = _playlists.insert (newpair);
+
+       if (!res.second) {
+               /* it already existed, bump count */
+               res.first->second++;
+       }
+               
        pl->GoingAway.connect (bind (mem_fun (*this, &Source::remove_playlist), boost::weak_ptr<Playlist> (pl)));
 }
 
@@ -124,10 +134,15 @@ Source::remove_playlist (boost::weak_ptr<Playlist> wpl)
                return;
        }
 
-       std::set<boost::shared_ptr<Playlist> >::iterator x;
+       PlaylistMap::iterator x;
+       Glib::Mutex::Lock lm (playlist_lock);
 
        if ((x = _playlists.find (pl)) != _playlists.end()) {
-               _playlists.erase (x);
+               if (x->second > 1) {
+                       x->second--;
+               } else {
+                       _playlists.erase (x);
+               }
        }
 }