remove the session region list; GUI now represents (a relatively unfiltered view...
authorPaul Davis <paul@linuxaudiosystems.com>
Sat, 6 Mar 2010 15:40:42 +0000 (15:40 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Sat, 6 Mar 2010 15:40:42 +0000 (15:40 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@6739 d708f5d6-7413-0410-9779-e7cbd77b26cf

12 files changed:
gtk2_ardour/editor.cc
gtk2_ardour/editor_regions.cc
gtk2_ardour/editor_regions.h
libs/ardour/ardour/region_factory.h
libs/ardour/ardour/session.h
libs/ardour/ardour/session_region.h [deleted file]
libs/ardour/playlist.cc
libs/ardour/plugin_manager.cc
libs/ardour/region_factory.cc
libs/ardour/session.cc
libs/ardour/session_state.cc
libs/ardour/strip_silence.cc

index 1b03576ace9bdde0fc8ad0716c9790414fa583a0..4b97ceea2df2ab6c855276d7eddbfa70bb26d6a0 100644 (file)
@@ -4971,7 +4971,7 @@ Editor::hide_a_region (boost::shared_ptr<Region> r)
 void
 Editor::remove_a_region (boost::shared_ptr<Region> r)
 {
-       _session->remove_region_from_region_list (r);
+       // _session->remove_region_from_region_list (r);
 }
 
 void
index 39e8b84c1bf4c1493de0a46e3b67508bb139150e..18b6971fe833d7eb5e4007e4fe0fd0b332debae2 100644 (file)
@@ -28,8 +28,9 @@
 
 #include "ardour/audioregion.h"
 #include "ardour/audiofilesource.h"
+#include "ardour/region_factory.h"
+#include "ardour/session.h"
 #include "ardour/silentfilesource.h"
-#include "ardour/session_region.h"
 #include "ardour/profile.h"
 
 #include <gtkmm2ext/stop_signal.h>
@@ -139,7 +140,6 @@ EditorRegions::set_session (ARDOUR::Session* s)
 
        if (_session) {
                _session->RegionsAdded.connect (_session_connections, ui_bind (&EditorRegions::handle_new_regions, this, _1), gui_context());
-               _session->RegionRemoved.connect (_session_connections, ui_bind (&EditorRegions::handle_region_removed, this, _1), gui_context());
                _session->RegionHiddenChange.connect (_session_connections, ui_bind (&EditorRegions::region_hidden, this, _1), gui_context());
        }
 
@@ -147,15 +147,7 @@ EditorRegions::set_session (ARDOUR::Session* s)
 }
 
 void
-EditorRegions::handle_region_removed (boost::weak_ptr<Region> wregion)
-{
-       ENSURE_GUI_THREAD (*this, &EditorRegions::handle_region_removed, wregion)
-
-       redisplay ();
-}
-
-void
-EditorRegions::handle_new_regions (vector<boost::weak_ptr<Region> >& v)
+EditorRegions::handle_new_regions (vector<boost::shared_ptr<Region> >& v)
 {
        ENSURE_GUI_THREAD (*this, &EditorRegions::handle_new_regions, v)
        add_regions (v);
@@ -180,13 +172,10 @@ EditorRegions::region_hidden (boost::shared_ptr<Region> r)
 
 
 void
-EditorRegions::add_regions (vector<boost::weak_ptr<Region> >& regions)
+EditorRegions::add_regions (vector<boost::shared_ptr<Region> >& regions)
 {
-       for (vector<boost::weak_ptr<Region> >::iterator x = regions.begin(); x != regions.end(); ++x) {
-               boost::shared_ptr<Region> region ((*x).lock());
-               if (region) {
-                       add_region (region);
-               }
+       for (vector<boost::shared_ptr<Region> >::iterator x = regions.begin(); x != regions.end(); ++x) {
+                add_region (*x);
        }
 }
 
@@ -511,7 +500,11 @@ EditorRegions::redisplay ()
        */
 
        tmp_region_list.clear();
-       _session->foreach_region (this, &EditorRegions::insert_into_tmp_regionlist);
+
+        const RegionFactory::RegionMap& regions (RegionFactory::regions());
+        for (RegionFactory::RegionMap::const_iterator i = regions.begin(); i != regions.end(); ++i) {
+                insert_into_tmp_regionlist (i->second);
+        }
 
        for (list<boost::shared_ptr<Region> >::iterator r = tmp_region_list.begin(); r != tmp_region_list.end(); ++r) {
                add_region (*r);
@@ -1000,7 +993,7 @@ EditorRegions::button_release (GdkEventButton *ev)
        }
 
        if (region && Keyboard::is_delete_event (ev)) {
-               _session->remove_region_from_region_list (region);
+               // _session->remove_region_from_region_list (region);
                return true;
        }
 
index 33e077261cdecefadec190129b10e2d79b7936d0..c4ec4a1ba2f4bc1a7ff666605879e84398666f4f 100644 (file)
@@ -121,10 +121,9 @@ private:
        int sorter (Gtk::TreeModel::iterator, Gtk::TreeModel::iterator);
 
        void handle_new_region (boost::weak_ptr<ARDOUR::Region>);
-       void handle_new_regions (std::vector<boost::weak_ptr<ARDOUR::Region> >& );
-       void handle_region_removed (boost::weak_ptr<ARDOUR::Region>);
+       void handle_new_regions (std::vector<boost::shared_ptr<ARDOUR::Region> >& );
        void add_region (boost::shared_ptr<ARDOUR::Region>);
-       void add_regions (std::vector<boost::weak_ptr<ARDOUR::Region> > & );
+       void add_regions (std::vector<boost::shared_ptr<ARDOUR::Region> > & );
        void region_hidden (boost::shared_ptr<ARDOUR::Region>);
        void region_hidden_weak (boost::weak_ptr<ARDOUR::Region>);
        void populate_row (boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::Row const &);
index a01103603a2d5b306953c2a67aab424e117d9f7d..2bff4dd104d134da81363d5186b2977ce794cdcd 100644 (file)
@@ -24,6 +24,7 @@
 #include <glibmm/thread.h>
 
 #include "pbd/id.h"
+#include "pbd/signals.h"
 
 #include "ardour/types.h"
 #include "ardour/region.h"
@@ -77,11 +78,17 @@ class RegionFactory {
        /** create a region with specified sources @param srcs and XML state */
        static boost::shared_ptr<Region> create (SourceList& srcs, const XMLNode&);
 
+       static void map_remove (boost::shared_ptr<Region>);
+        static void delete_all_regions ();
+        static const RegionMap& regions() { return region_map; }
+        static uint32_t nregions ();
+
   private:
         static Glib::StaticMutex region_map_lock;
        static RegionMap region_map;
        static void map_add (boost::shared_ptr<Region>);
-       static void map_remove (boost::shared_ptr<Region>);
+        
+        static PBD::ScopedConnectionList region_list_connections;
 };
 
 }
index cf88f2e6bde11e07c4ac6678c1b11d9976b49057..7d94515efa968531c808e5d4a7da1dc42ed46296 100644 (file)
@@ -501,14 +501,12 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        /* region info  */
 
-        boost::shared_ptr<Region> region_by_id (const PBD::ID&) const;
        boost::shared_ptr<Region> find_whole_file_parent (boost::shared_ptr<Region const>) const;
 
        void add_regions (std::vector<boost::shared_ptr<Region> >&);
 
-       PBD::Signal1<void,boost::weak_ptr<Region> >              RegionAdded;
-       PBD::Signal1<void,std::vector<boost::weak_ptr<Region> >&> RegionsAdded;
-       PBD::Signal1<void,boost::weak_ptr<Region> >              RegionRemoved;
+       PBD::Signal1<void,std::vector<boost::shared_ptr<Region> >&> RegionsAdded;
+       PBD::Signal1<void,boost::shared_ptr<Region> >               RegionRemoved;
 
        int region_name (std::string& result, std::string base = std::string(""), bool newlevel = false);
        std::string new_region_name (std::string);
@@ -518,8 +516,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        boost::shared_ptr<AudioRegion> XMLAudioRegionFactory (const XMLNode&, bool full);
        boost::shared_ptr<MidiRegion>  XMLMidiRegionFactory (const XMLNode&, bool full);
 
-       template<class T> void foreach_region (T *obj, void (T::*func)(boost::shared_ptr<Region>));
-
        /* source management */
 
        void import_audiofiles (ImportStatus&);
@@ -1259,8 +1255,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void update_region_name_map (boost::shared_ptr<Region>);
 
        mutable Glib::Mutex region_lock;
-       typedef std::map<PBD::ID,boost::shared_ptr<Region> > RegionList;
-       RegionList regions;
 
        void add_region (boost::shared_ptr<Region>);
        void region_changed (const PBD::PropertyChange&, boost::weak_ptr<Region>);
diff --git a/libs/ardour/ardour/session_region.h b/libs/ardour/ardour/session_region.h
deleted file mode 100644 (file)
index 136aaa0..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
-    Copyright (C) 2000-2007 Paul Davis
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#ifndef __ardour_session_region_h__
-#define __ardour_session_region_h__
-
-#include "ardour/session.h"
-#include "ardour/audioregion.h"
-
-namespace ARDOUR {
-
-template<class T> void
-Session::foreach_region (T *obj, void (T::*func)(boost::shared_ptr<Region>))
-{
-       Glib::Mutex::Lock lm (region_lock);
-       for (RegionList::iterator i = regions.begin(); i != regions.end(); i++) {
-               (obj->*func) (i->second);
-       }
-}
-
-} // namespace ARDOUR
-
-#endif /* __ardour_session_region_h__ */
index 054998221716701b932a9c1601c657248c7f4609..5cf062744805add24434e98ea1421ec7f7acc223 100644 (file)
@@ -112,13 +112,10 @@ RegionListProperty::lookup_id (const ID& id)
 {
         boost::shared_ptr<Region> ret =  _playlist.region_by_id (id);
         
-        if (!ret) {
-                ret = _playlist.session().region_by_id (id);
-        }
-
         if (!ret) {
                 ret = RegionFactory::region_by_id (id);
         }
+
         return ret;
 }
 
@@ -2077,8 +2074,6 @@ Playlist::property_factory (const XMLNode& history_node) const
 
         for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
 
-                /* XXX property name needs capitalizing */
-
                 if ((*i)->name() == capitalize (regions.property_name())) {
                         
                         RegionListProperty* rlp = new RegionListProperty (*const_cast<Playlist*> (this));
index f4d638e3bc87ed77e4b8c0aea5a855e2307eda50..ebf0ecab3cd83636259e406a10ef5865b6d62690 100644 (file)
@@ -145,7 +145,9 @@ PluginManager::PluginManager ()
 
 PluginManager::~PluginManager()
 {
+#ifdef HAVE_SLV2
        delete _lv2_world;
+#endif
 }
 
 
index 3f4af2462c28e31aacf6a29e9b1bdc0caee83889..8a24bc954c466f985b07d7bb4fdfbc298ce24aee 100644 (file)
@@ -38,6 +38,7 @@ using namespace PBD;
 PBD::Signal1<void,boost::shared_ptr<Region> > RegionFactory::CheckNewRegion;
 Glib::StaticMutex RegionFactory::region_map_lock;
 RegionFactory::RegionMap RegionFactory::region_map;
+PBD::ScopedConnectionList RegionFactory::region_list_connections;
 
 boost::shared_ptr<Region>
 RegionFactory::create (boost::shared_ptr<const Region> region)
@@ -287,7 +288,6 @@ RegionFactory::create (SourceList& srcs, const XMLNode& node)
        return ret;
 }
 
-
 void
 RegionFactory::map_add (boost::shared_ptr<Region> r)
 {
@@ -298,19 +298,19 @@ RegionFactory::map_add (boost::shared_ptr<Region> r)
         { 
                 Glib::Mutex::Lock lm (region_map_lock);
                 region_map.insert (p);
-                /* we pay no attention to attempts to delete regions */
         }
+
+        r->DropReferences.connect_same_thread (region_list_connections, boost::bind (&RegionFactory::map_remove, r));
 }
 
 void
 RegionFactory::map_remove (boost::shared_ptr<Region> r)
 {
-        { 
-                Glib::Mutex::Lock lm (region_map_lock);
-                RegionMap::iterator i = region_map.find (r->id());
-                if (i != region_map.end()) {
-                        region_map.erase (i);
-                }
+        Glib::Mutex::Lock lm (region_map_lock);
+        RegionMap::iterator i = region_map.find (r->id());
+
+        if (i != region_map.end()) {
+                region_map.erase (i);
         }
 }
 
@@ -330,5 +330,42 @@ RegionFactory::region_by_id (const PBD::ID& id)
 void
 RegionFactory::clear_map ()
 {
-       region_map.clear ();
+        region_list_connections.drop_connections ();
+
+        {
+                Glib::Mutex::Lock lm (region_map_lock);
+                region_map.clear ();
+        }
+
+}
+
+void
+RegionFactory::delete_all_regions ()
+{
+        RegionMap copy;
+
+        /* copy region list */
+        {
+                Glib::Mutex::Lock lm (region_map_lock);
+                copy = region_map;
+        }
+
+        /* clear existing map */
+        clear_map ();
+
+        /* tell everyone to drop references */
+        for (RegionMap::iterator i = copy.begin(); i != copy.end(); ++i) {
+                i->second->drop_references ();
+        }
+
+        /* the copy should now hold the only references, which will
+           vanish as we leave this scope, thus calling all destructors.
+        */
+}
+        
+uint32_t
+RegionFactory::nregions ()
+{
+        Glib::Mutex::Lock lm (region_map_lock);
+        return region_map.size ();
 }
index 53c8ea2350e75093bceb8241659ffecf7bb94e64..31fd036890e8e64974dec8fb7489c9651e27fce5 100644 (file)
@@ -353,10 +353,6 @@ Session::destroy ()
 
        _engine.remove_session ();
 
-       /* clear region map. it doesn't hold references, but lets just be sensible here */
-
-       RegionFactory::clear_map ();
-
        /* clear history so that no references to objects are held any more */
 
        _history.clear ();
@@ -403,11 +399,7 @@ Session::destroy ()
        named_selections.clear ();
 
        DEBUG_TRACE (DEBUG::Destruction, "delete regions\n");
-       for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
-               DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for region %1 ; pre-ref = %2\n", i->second->name(), i->second.use_count()));
-               i->second->drop_references ();
-       }
-       regions.clear ();
+       RegionFactory::delete_all_regions ();
 
        DEBUG_TRACE (DEBUG::Destruction, "delete routes\n");
        
@@ -2559,7 +2551,8 @@ Session::new_region_name (string old)
 
        while (number < (UINT_MAX-1)) {
 
-               RegionList::const_iterator i;
+                const RegionFactory::RegionMap& regions (RegionFactory::regions());
+               RegionFactory::RegionMap::const_iterator i;
                string sbuf;
 
                number++;
@@ -2598,9 +2591,7 @@ Session::region_name (string& result, string base, bool newlevel)
 
        if (base == "") {
 
-               Glib::Mutex::Lock lm (region_lock);
-
-               snprintf (buf, sizeof (buf), "%d", (int)regions.size() + 1);
+               snprintf (buf, sizeof (buf), "%d", RegionFactory::nregions() + 1);
                result = "region.";
                result += buf;
 
@@ -2652,84 +2643,23 @@ Session::add_region (boost::shared_ptr<Region> region)
 void
 Session::add_regions (vector<boost::shared_ptr<Region> >& new_regions)
 {
-       bool added = false;
-
-       {
-               Glib::Mutex::Lock lm (region_lock);
-
-               for (vector<boost::shared_ptr<Region> >::iterator ii = new_regions.begin(); ii != new_regions.end(); ++ii) {
-
-                       boost::shared_ptr<Region> region = *ii;
-
-                       if (region == 0) {
-
-                               error << _("Session::add_region() ignored a null region. Warning: you might have lost a region.") << endmsg;
-
-                       } else {
-
-                               RegionList::iterator x;
-
-                               for (x = regions.begin(); x != regions.end(); ++x) {
-
-                                       if (region->region_list_equivalent (x->second)) {
-                                               break;
-                                       }
-                               }
-
-                               if (x == regions.end()) {
-
-                                       pair<RegionList::key_type,RegionList::mapped_type> entry;
-
-                                       entry.first = region->id();
-                                       entry.second = region;
-
-                                       pair<RegionList::iterator,bool> x = regions.insert (entry);
-
-                                       if (!x.second) {
-                                               return;
-                                       }
-
-                                       added = true;
-                               }
-                       }
-               }
-       }
-
-       /* mark dirty because something has changed even if we didn't
-          add the region to the region list.
+       /* mark dirty because something has changed
        */
 
        set_dirty ();
-
-       if (added) {
-
-               vector<boost::weak_ptr<Region> > v;
-               boost::shared_ptr<Region> first_r;
-
-               for (vector<boost::shared_ptr<Region> >::iterator ii = new_regions.begin(); ii != new_regions.end(); ++ii) {
-
-                       boost::shared_ptr<Region> region = *ii;
-
-                       if (region == 0) {
-
-                               error << _("Session::add_region() ignored a null region. Warning: you might have lost a region.") << endmsg;
-
-                       } else {
-                               v.push_back (region);
-
-                               if (!first_r) {
-                                       first_r = region;
-                               }
-                       }
-
-                       region->PropertyChanged.connect_same_thread (*this, boost::bind (&Session::region_changed, this, _1, boost::weak_ptr<Region>(region)));
-                       update_region_name_map (region);
-               }
-
-               if (!v.empty()) {
-                       RegionsAdded (v); /* EMIT SIGNAL */
-               }
-       }
+        
+        for (vector<boost::shared_ptr<Region> >::iterator ii = new_regions.begin(); ii != new_regions.end(); ++ii) {
+                
+                boost::shared_ptr<Region> region = *ii;
+                assert (region);
+                
+                region->PropertyChanged.connect_same_thread (*this, boost::bind (&Session::region_changed, this, _1, boost::weak_ptr<Region>(region)));
+                update_region_name_map (region);
+        }
+        
+        if (!new_regions.empty()) {
+                RegionsAdded (new_regions); /* EMIT SIGNAL */
+        }
 }
 
 void
@@ -2773,39 +2703,23 @@ Session::region_changed (const PropertyChange& what_changed, boost::weak_ptr<Reg
 void
 Session::remove_region (boost::weak_ptr<Region> weak_region)
 {
-       RegionList::iterator i;
        boost::shared_ptr<Region> region (weak_region.lock ());
 
        if (!region) {
                return;
        }
 
-       bool removed = false;
-
-       {
-               Glib::Mutex::Lock lm (region_lock);
-
-               if ((i = regions.find (region->id())) != regions.end()) {
-                       regions.erase (i);
-                       removed = true;
-               }
-       }
-
-       /* mark dirty because something has changed even if we didn't
-          remove the region from the region list.
-       */
-
+        RegionFactory::map_remove (region);
        set_dirty();
 
-       if (removed) {
-                RegionRemoved(region); /* EMIT SIGNAL */
-       }
+        RegionRemoved(region); /* EMIT SIGNAL */
 }
 
 boost::shared_ptr<Region>
 Session::find_whole_file_parent (boost::shared_ptr<Region const> child) const
 {
-       RegionList::const_iterator i;
+        const RegionFactory::RegionMap& regions (RegionFactory::regions());
+       RegionFactory::RegionMap::const_iterator i;
        boost::shared_ptr<Region> region;
 
        Glib::Mutex::Lock lm (region_lock);
@@ -2825,20 +2739,6 @@ Session::find_whole_file_parent (boost::shared_ptr<Region const> child) const
        return boost::shared_ptr<Region> ();
 }
 
-boost::shared_ptr<Region>
-Session::region_by_id (const PBD::ID& id) const
-{
-       Glib::Mutex::Lock lm (region_lock);
-
-        RegionList::const_iterator i = regions.find (id);
-
-        if (i != regions.end()) {
-                return i->second;
-       }
-
-       return boost::shared_ptr<Region> ();
-}
-
 int
 Session::destroy_region (boost::shared_ptr<Region> region)
 {
@@ -2858,10 +2758,10 @@ Session::destroy_region (boost::shared_ptr<Region> region)
 
        for (vector<boost::shared_ptr<Source> >::iterator i = srcs.begin(); i != srcs.end(); ++i) {
 
-                       (*i)->mark_for_remove ();
-                       (*i)->drop_references ();
-
-                       cerr << "source was not used by any playlist\n";
+                (*i)->mark_for_remove ();
+                (*i)->drop_references ();
+                
+                cerr << "source was not used by any playlist\n";
        }
 
        return 0;
@@ -2892,10 +2792,6 @@ Session::remove_last_capture ()
                }
        }
 
-       for (list<boost::shared_ptr<Region> >::iterator i = r.begin(); i != r.end(); ++i) {
-               remove_region (*i);
-       }
-       
        destroy_regions (r);
 
        save_state (_current_snapshot_name);
@@ -2903,13 +2799,6 @@ Session::remove_last_capture ()
        return 0;
 }
 
-int
-Session::remove_region_from_region_list (boost::shared_ptr<Region> r)
-{
-       remove_region (r);
-       return 0;
-}
-
 /* Source Management */
 
 void
index 014200da1c8f9a107c527e2d2430f4ee0c3de41d..f960660555f2397368fc4014b1b790de7187bf10 100644 (file)
@@ -991,16 +991,6 @@ Session::state(bool full_state)
 
        if (full_state) {
                Glib::Mutex::Lock rl (region_lock);
-#if 0
-               for (RegionList::const_iterator i = regions.begin(); i != regions.end(); ++i) {
-
-                       /* only store regions not attached to playlists */
-
-                       if (i->second->playlist() == 0) {
-                               child->add_child_nocopy (i->second->state (true));
-                       }
-               }
-#else
                 const RegionFactory::RegionMap& region_map (RegionFactory::all_regions());
                 for (RegionFactory::RegionMap::const_iterator i = region_map.begin(); i != region_map.end(); ++i) {
                         boost::shared_ptr<Region> r = i->second;
@@ -1009,8 +999,6 @@ Session::state(bool full_state)
                                 child->add_child_nocopy (r->state (true));
                         }
                 }
-#endif
-
        }
 
        child = node->add_child ("DiskStreams");
index ae35eebd8f537f431494313953a0f32b133f7d36..21e1ad5450ade46f730d378c4cf291a8e1fc22ee 100644 (file)
@@ -17,6 +17,8 @@
 
 */
 
+#include "pbd/property_list.h"
+
 #include "ardour/strip_silence.h"
 #include "ardour/audioregion.h"
 #include "ardour/region_factory.h"
@@ -44,7 +46,8 @@ StripSilence::run (boost::shared_ptr<Region> r)
        results.clear ();
 
        /* we only operate on AudioRegions, for now, though this could be adapted to MIDI
-          as well I guess */
+          as well I guess 
+        */
        boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (r);
         InterThreadInfo itt;
         
@@ -78,59 +81,54 @@ StripSilence::run (boost::shared_ptr<Region> r)
        }
 
        std::list<std::pair<framepos_t, framecnt_t > >::const_iterator s = silence.begin ();
-       framepos_t const pos = region->position ();
-       framepos_t const end = region->start () + region->length() - 1;
-       framepos_t const start = region->start ();
-
-       region = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (region));
-       region->set_name (session.new_region_name (region->name ()));
-       boost::shared_ptr<AudioRegion> last_region = region;
-       results.push_back (region);
-
-       if (s->first == 0) {
-               /* the region starts with some silence */
-
-               /* we must set length to an intermediate value here, otherwise the call
-               ** to set_start will fail */
-               region->set_length (region->length() - s->second + _fade_length, 0);
-               region->set_start (start + s->second - _fade_length, 0);
-               region->set_position (pos + s->second - _fade_length, 0);
-               region->set_fade_in_active (true);
-               region->set_fade_in (AudioRegion::Linear, _fade_length);
-               s++;
-       }
+        PBD::PropertyList plist;
+        framepos_t start = 0;
+        framepos_t end;
+        bool in_silence;
+        boost::shared_ptr<AudioRegion> copy;
 
-       while (s != silence.end()) {
+        if (s->first == 0) {
+                /* initial segment, starting at zero, is silent */
+                end = s->second;
+                in_silence = true;
+        } else {
+                /* initial segment, starting at zero, is audible */
+                end = s->first;
+                in_silence = false;
+        }
 
-               /* trim the end of this region */
-               region->trim_end (pos + s->first + _fade_length, 0);
-               region->set_fade_out_active (true);
-               region->set_fade_out (AudioRegion::Linear, _fade_length);
+        while (s != silence.end()) {
 
-               /* make a new region and trim its start */
-               region = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (region));
-               region->set_name (session.new_region_name (region->name ()));
-               last_region = region;
-               assert (region);
-               results.push_back (region);
+                framecnt_t interval_duration;
 
-               /* set length here for the same reasons as above */
-               region->set_length (region->length() - s->second + _fade_length, 0);
-               region->set_start (start + s->second - _fade_length, 0);
-               region->set_position (pos + s->second - _fade_length, 0);
-               region->set_fade_in_active (true);
-               region->set_fade_in (AudioRegion::Linear, _fade_length);
+                interval_duration = end - start;
 
-               s++;
-       }
 
-       if (silence.back().second == end) {
-               /* the last region we created is zero-sized, so just remove it */
-               results.pop_back ();
-       } else {
-               /* finish off the last region */
-               last_region->trim_end (end, 0);
-       }
+                if (!in_silence && interval_duration > 0) {
+
+                        plist.clear ();
+                        plist.add (Properties::length, interval_duration);
+                        plist.add (Properties::position, region->position() + start);
+
+                        copy = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create 
+                                                                         (region, start, plist));
+
+                        copy->set_name (session.new_region_name (region->name ()));
+
+                        std::cerr << "New silent delineated region called " << copy->name()
+                                  << " @ " << copy->start() << " length = " << copy->length() << " pos = " << 
+                                copy->position() << std::endl;
+
+                        copy->set_fade_in_active (true);
+                        copy->set_fade_in (AudioRegion::Linear, _fade_length);
+                        results.push_back (copy);
+                }
+
+                start = end;
+                ++s;
+                end = s->first;
+                in_silence = !in_silence;
+        }
 
        return 0;
 }