summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-03-06 15:40:42 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-03-06 15:40:42 +0000
commitb6b68881b2c59c216d2195b1cea5e667187d83ed (patch)
tree6f6cae22e8d2175bbc54d428472402cd2d73eb2c /libs
parent4ffcec7b7974f9fb65b2da295cbadb219f2a1970 (diff)
remove the session region list; GUI now represents (a relatively unfiltered view of) the raw region list that always contains every single region ever created
git-svn-id: svn://localhost/ardour2/branches/3.0@6739 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/ardour/region_factory.h9
-rw-r--r--libs/ardour/ardour/session.h10
-rw-r--r--libs/ardour/ardour/session_region.h39
-rw-r--r--libs/ardour/playlist.cc7
-rw-r--r--libs/ardour/plugin_manager.cc2
-rw-r--r--libs/ardour/region_factory.cc55
-rw-r--r--libs/ardour/session.cc163
-rw-r--r--libs/ardour/session_state.cc12
-rw-r--r--libs/ardour/strip_silence.cc94
9 files changed, 131 insertions, 260 deletions
diff --git a/libs/ardour/ardour/region_factory.h b/libs/ardour/ardour/region_factory.h
index a01103603a..2bff4dd104 100644
--- a/libs/ardour/ardour/region_factory.h
+++ b/libs/ardour/ardour/region_factory.h
@@ -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;
};
}
diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h
index cf88f2e6bd..7d94515efa 100644
--- a/libs/ardour/ardour/session.h
+++ b/libs/ardour/ardour/session.h
@@ -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
index 136aaa0022..0000000000
--- a/libs/ardour/ardour/session_region.h
+++ /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__ */
diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc
index 0549982217..5cf0627448 100644
--- a/libs/ardour/playlist.cc
+++ b/libs/ardour/playlist.cc
@@ -113,12 +113,9 @@ 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));
diff --git a/libs/ardour/plugin_manager.cc b/libs/ardour/plugin_manager.cc
index f4d638e3bc..ebf0ecab3c 100644
--- a/libs/ardour/plugin_manager.cc
+++ b/libs/ardour/plugin_manager.cc
@@ -145,7 +145,9 @@ PluginManager::PluginManager ()
PluginManager::~PluginManager()
{
+#ifdef HAVE_SLV2
delete _lv2_world;
+#endif
}
diff --git a/libs/ardour/region_factory.cc b/libs/ardour/region_factory.cc
index 3f4af2462c..8a24bc954c 100644
--- a/libs/ardour/region_factory.cc
+++ b/libs/ardour/region_factory.cc
@@ -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 ();
}
diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc
index 53c8ea2350..31fd036890 100644
--- a/libs/ardour/session.cc
+++ b/libs/ardour/session.cc
@@ -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
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index 014200da1c..f960660555 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -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");
diff --git a/libs/ardour/strip_silence.cc b/libs/ardour/strip_silence.cc
index ae35eebd8f..21e1ad5450 100644
--- a/libs/ardour/strip_silence.cc
+++ b/libs/ardour/strip_silence.cc
@@ -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;
}