Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old session loading #104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions libs/ardour/location.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "pbd/stl_delete.h"
#include "pbd/xml++.h"
#include "pbd/enumwriter.h"
#include "pbd/statefulidpredicates.h"

#include "ardour/location.h"
#include "ardour/midi_scene_change.h"
Expand Down Expand Up @@ -610,6 +611,8 @@ Location::set_state (const XMLNode& node, int version)
}

if (!set_id (node)) {
// Old versions did not write ids for locations: make a new one.
reset_id();
warning << _("XML node for Location has no ID information") << endmsg;
}

Expand Down Expand Up @@ -1056,21 +1059,20 @@ Locations::set_state (const XMLNode& node, int version)

try {

Location* loc = 0;
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;
if (prop_id) {
LocationList::const_iterator i = std::find_if(
locations.begin(), locations.end(),
PBD::StatefulIdEquals(prop_id->value()));

if (i != locations.end()) {
/* we can re-use an old Location object */
loc = *i;
loc->set_state (**niter, version);
}
}

Location* loc;
if (i != locations.end()) {
/* we can re-use an old Location object */
loc = *i;
loc->set_state (**niter, version);
} else {
if (!loc) {
loc = new Location (_session, **niter);
}

Expand Down
2 changes: 1 addition & 1 deletion libs/ardour/session_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ Session::load_state (string snapshot_name)
} else {
if (prop->value().find ('.') != string::npos) {
/* old school version format */
if (prop->value()[0] == '2') {
if (prop->value()[0] < '3') {
Stateful::loading_state_version = 2000;
} else {
Stateful::loading_state_version = 3000;
Expand Down
59 changes: 59 additions & 0 deletions libs/pbd/pbd/statefulidpredicates.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright (C) 2015 Paul Davis
Author: Sakari Bergen

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 __pbd_statefulidpredicate_h__
#define __pbd_statefulidpredicate_h__

#include "pbd/libpbd_visibility.h"
#include "pbd/id.h"
#include "pbd/stateful.h"

namespace PBD {

struct LIBPBD_TEMPLATE_MEMBER_API StatefulIdEquals
{
StatefulIdEquals(ID const & id)
: id(id)
{}

template<typename StatefulPtr>
bool operator() (StatefulPtr p)
{
return p && compare(*p);
}

bool operator() (Stateful const & s)
{
return compare(s);
}

private:

bool compare(Stateful const & s)
{
return s.id() == id;
}

ID const & id;
};

} // namespace PBD

#endif // __pbd_statefulidpredicate_h__