allow diskstream deletion after a track is removed by using weak_ptr<Diskstream>...
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 18 May 2007 16:52:50 +0000 (16:52 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Fri, 18 May 2007 16:52:50 +0000 (16:52 +0000)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@1883 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/audio_streamview.cc
gtk2_ardour/audio_streamview.h
gtk2_ardour/editor_route_list.cc
gtk2_ardour/route_time_axis.cc
gtk2_ardour/streamview.cc
gtk2_ardour/streamview.h
libs/ardour/ardour/session.h
libs/ardour/session.cc
libs/ardour/track.cc

index 279130ad381ee919573249401c945e751f199293..35078804a28c1c9aa5a1152733d5c0270efab69d 100644 (file)
@@ -279,9 +279,15 @@ AudioStreamView::playlist_modified ()
 }
 
 void
-AudioStreamView::playlist_changed (boost::shared_ptr<Diskstream> ds)
+AudioStreamView::playlist_changed (boost::weak_ptr<Diskstream> wptr)
 {
-       ENSURE_GUI_THREAD (bind (mem_fun (*this, &AudioStreamView::playlist_changed), ds));
+       ENSURE_GUI_THREAD (bind (mem_fun (*this, &AudioStreamView::playlist_changed), wptr));
+
+       boost::shared_ptr<Diskstream> ds  = wptr.lock();
+
+       if (!ds) {
+               return;
+       }
 
        StreamView::playlist_changed(ds);
 
index 12d400bebdbce42abbe6abf80ffbfc044dd8c696..b2d538471f74baeae574b94190f8f37f02c8efe0 100644 (file)
@@ -91,7 +91,7 @@ class AudioStreamView : public StreamView
        void undisplay_diskstream ();
        void redisplay_diskstream ();
        void playlist_modified ();
-       void playlist_changed (boost::shared_ptr<ARDOUR::Diskstream>);
+       void playlist_changed (boost::weak_ptr<ARDOUR::Diskstream>);
 
        void add_crossfade (boost::shared_ptr<ARDOUR::Crossfade>);
        void add_crossfade_weak (boost::weak_ptr<ARDOUR::Crossfade>);
index 1876b17f10e900caf760a56ba01b4469ccd3e002..e2ed6f719172a5181b251ad4333ad21a7ed86845 100644 (file)
@@ -133,24 +133,25 @@ Editor::remove_route (TimeAxisView *tv)
 {
        ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
 
-       
        TrackViewList::iterator i;
        TreeModel::Children rows = route_display_model->children();
        TreeModel::Children::iterator ri;
 
-       if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
-               track_views.erase (i);
-       }
-
        for (ri = rows.begin(); ri != rows.end(); ++ri) {
                if ((*ri)[route_display_columns.tv] == tv) {
                        route_display_model->erase (ri);
                        break;
                }
        }
+
+       if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
+               track_views.erase (i);
+       }
+
        /* since the editor mixer goes away when you remove a route, set the
         * button to inactive and untick the menu option
         */
+
        editor_mixer_button.set_active(false);
        ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
 
index f14aa53e71d9b4c2ce0b14ad7d4938dca342b119..dd75113f680e0385e6c6b98242356a4803a36d09 100644 (file)
@@ -296,7 +296,6 @@ RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
 
 void
 RouteTimeAxisView::playlist_changed ()
-
 {
        label_view ();
 
index 2a5c13a2240164043e7fec5cf39e102b814d6a89..62d8e99254964867142eb5e0fecfcbb20ab6cd2a 100644 (file)
@@ -194,11 +194,17 @@ StreamView::undisplay_diskstream ()
 }
 
 void
-StreamView::display_diskstream (boost::shared_ptr<Diskstream> ds)
+StreamView::display_diskstream (boost::weak_ptr<Diskstream> wds)
 {
+       boost::shared_ptr<Diskstream> ds = wds.lock();
+
+       if (!ds) {
+               return;
+       }
+               
        playlist_change_connection.disconnect();
-       playlist_changed (ds);
-       playlist_change_connection = ds->PlaylistChanged.connect (bind (mem_fun (*this, &StreamView::playlist_changed), ds));
+       playlist_changed (wds);
+       playlist_change_connection = ds->PlaylistChanged.connect (bind (mem_fun (*this, &StreamView::playlist_changed), wds));
 }
 
 void
@@ -210,9 +216,15 @@ StreamView::playlist_modified ()
 }
 
 void
-StreamView::playlist_changed (boost::shared_ptr<Diskstream> ds)
+StreamView::playlist_changed (boost::weak_ptr<Diskstream> wptr)
 {
-       ENSURE_GUI_THREAD (bind (mem_fun (*this, &StreamView::playlist_changed), ds));
+       ENSURE_GUI_THREAD (bind (mem_fun (*this, &StreamView::playlist_changed), wptr));
+
+       boost::shared_ptr<Diskstream> ds = wptr.lock();
+       
+       if (!ds) {
+               return;
+       }
 
        /* disconnect from old playlist */
 
@@ -238,7 +250,7 @@ StreamView::diskstream_changed ()
        Track *t;
 
        if ((t = _trackview.track()) != 0) {
-               Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun (*this, &StreamView::display_diskstream), t->diskstream()));
+               Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun (*this, &StreamView::display_diskstream), boost::weak_ptr<Diskstream> (t->diskstream())));
        } else {
                Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &StreamView::undisplay_diskstream));
        }
index 657bfa90448ff23324526a54831b11e87d485fec..ef55ebc4af305a99bc94c6c868dacf05de752824 100644 (file)
@@ -111,12 +111,12 @@ protected:
        virtual void remove_region_view (boost::weak_ptr<ARDOUR::Region> );
        //void         remove_rec_region (boost::shared_ptr<ARDOUR::Region>); (unused)
 
-       void         display_diskstream (boost::shared_ptr<ARDOUR::Diskstream>);
+       void         display_diskstream (boost::weak_ptr<ARDOUR::Diskstream>);
        virtual void undisplay_diskstream ();
        virtual void redisplay_diskstream () = 0;
        void         diskstream_changed ();
        
-       virtual void playlist_changed (boost::shared_ptr<ARDOUR::Diskstream>);
+       virtual void playlist_changed (boost::weak_ptr<ARDOUR::Diskstream>);
        virtual void playlist_modified ();
        
        virtual void color_handler (ColorID, uint32_t) = 0;
index 70a9d7c96f91cd08fd9801a8676e86c06e6eef01..fb7d24568f411a2751d70e2b722fab130d007c89 100644 (file)
@@ -1497,7 +1497,7 @@ class Session : public PBD::StatefulDestructible
        boost::shared_ptr<Playlist> XMLPlaylistFactory (const XMLNode&);
 
        void playlist_length_changed ();
-       void diskstream_playlist_changed (boost::shared_ptr<Diskstream>);
+       void diskstream_playlist_changed (boost::weak_ptr<Diskstream>);
 
        /* NAMED SELECTIONS */
 
index d3b65210a405c65e196de60180e8b22412c8d899..c2c21a631d2bcfc393555d8eb5ee190d46fc71b5 100644 (file)
@@ -986,8 +986,15 @@ Session::playlist_length_changed ()
 }
 
 void
-Session::diskstream_playlist_changed (boost::shared_ptr<Diskstream> dstream)
+Session::diskstream_playlist_changed (boost::weak_ptr<Diskstream> wptr)
 {
+       boost::shared_ptr<Diskstream> dstream = wptr.lock();
+       
+       if (!dstream) {
+               return;
+
+       }
+
        boost::shared_ptr<Playlist> playlist;
 
        if ((playlist = dstream->playlist()) != 0) {
@@ -2019,12 +2026,12 @@ Session::add_diskstream (boost::shared_ptr<Diskstream> dstream)
                /* writer goes out of scope, copies ds back to main */
        } 
 
-       dstream->PlaylistChanged.connect (sigc::bind (mem_fun (*this, &Session::diskstream_playlist_changed), dstream));
+       dstream->PlaylistChanged.connect (sigc::bind (mem_fun (*this, &Session::diskstream_playlist_changed), 
+                                                     boost::weak_ptr<Diskstream> (dstream)));
        /* this will connect to future changes, and check the current length */
        diskstream_playlist_changed (dstream);
 
        dstream->prepare ();
-
 }
 
 void
@@ -2077,6 +2084,8 @@ Session::remove_route (shared_ptr<Route> route)
                        boost::shared_ptr<DiskstreamList> d = dsl.get_copy();
                        d->remove (ds);
                }
+
+               diskstreams.flush ();
        }
 
        find_current_end ();
@@ -2085,8 +2094,9 @@ Session::remove_route (shared_ptr<Route> route)
        set_dirty();
 
        // We need to disconnect the routes inputs and outputs 
-       route->disconnect_inputs(NULL);
-       route->disconnect_outputs(NULL);
+
+       route->disconnect_inputs (0);
+       route->disconnect_outputs (0);
        
        /* get rid of it from the dead wood collection in the route list manager */
 
index 95e21e67359c8e928fee56dc106fba29b3480fa3..e9b16b137c55cda01718dd1e96738c08f09769b9 100644 (file)
@@ -60,6 +60,9 @@ Track::Track (Session& sess, const XMLNode& node, DataType default_type)
 
 Track::~Track ()
 {
+       if (_diskstream) {
+               _diskstream->drop_references ();
+       }
 }
 
 void