From ae91577f2c34119d07be11cc03d99483eeb5d4e6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 5 May 2011 12:09:37 +0000 Subject: Re-use locations when setting location list state, so that selected locations are preserved through an undo (#3929). git-svn-id: svn://localhost/ardour2/branches/3.0@9480 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/location.cc | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'libs') diff --git a/libs/ardour/location.cc b/libs/ardour/location.cc index 4f90b32282..086b6ed0c8 100644 --- a/libs/ardour/location.cc +++ b/libs/ardour/location.cc @@ -801,13 +801,15 @@ Locations::set_state (const XMLNode& node, int version) XMLNodeList nlist = node.children(); - locations.clear (); + /* build up a new locations list in here */ + LocationList new_locations; + current_location = 0; Location* session_range_location = 0; if (version < 3000) { session_range_location = new Location (_session, 0, 0, _("session"), Location::IsSessionRange); - locations.push_back (session_range_location); + new_locations.push_back (session_range_location); } { @@ -818,7 +820,23 @@ Locations::set_state (const XMLNode& node, int version) try { - Location *loc = new Location (_session, **niter); + XMLProperty const * prop_id = (*niter)->property ("id"); + assert (prop_id); + PBD::ID id (prop_id->value ()); + + LocationList::const_iterator i = locations.begin(); + while (i != locations.end () && (*i)->id() != id) { + ++i; + } + + Location* loc; + if (i != locations.end()) { + /* we can re-use an old Location object */ + loc = *i; + loc->set_state (**niter, version); + } else { + loc = new Location (_session, **niter); + } bool add = true; @@ -850,7 +868,7 @@ Locations::set_state (const XMLNode& node, int version) } if (add) { - locations.push_back (loc); + new_locations.push_back (loc); } } @@ -859,6 +877,8 @@ Locations::set_state (const XMLNode& node, int version) } } + locations = new_locations; + if (locations.size()) { current_location = locations.front(); } else { -- cgit v1.2.3