2 Copyright (C) 2000-2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "ardour/automation_list.h"
23 #include "ardour/location.h"
24 #include "ardour/midi_automation_list_binder.h"
25 #include "ardour/playlist.h"
26 #include "ardour/region.h"
27 #include "ardour/region_factory.h"
28 #include "ardour/route.h"
29 #include "ardour/session.h"
30 #include "ardour/session_playlists.h"
31 #include "ardour/source.h"
32 #include "ardour/tempo.h"
33 #include "evoral/Curve.hpp"
34 #include "pbd/error.h"
35 #include "pbd/failed_constructor.h"
37 #include "pbd/memento_command.h"
38 #include "pbd/stateful_diff_command.h"
39 #include "pbd/statefuldestructible.h"
40 #include "pbd/types_convert.h"
45 using namespace ARDOUR;
49 void Session::register_with_memento_command_factory(PBD::ID id, PBD::StatefulDestructible *ptr)
55 Session::memento_command_factory(XMLNode *n)
58 XMLNode *before = 0, *after = 0;
62 bool have_id = n->get_property ("obj-id", id);
64 /* get before/after */
66 if (n->name() == "MementoCommand") {
67 before = new XMLNode(*n->children().front());
68 after = new XMLNode(*n->children().back());
70 } else if (n->name() == "MementoUndoCommand") {
71 before = new XMLNode(*n->children().front());
73 } else if (n->name() == "MementoRedoCommand") {
74 after = new XMLNode(*n->children().front());
76 } else if (n->name() == "PlaylistCommand") {
77 before = new XMLNode(*n->children().front());
78 after = new XMLNode(*n->children().back());
83 info << string_compose (_("Tried to reconstitute a MementoCommand with no contents, failing. id=%1"), id.to_s()) << endmsg;
88 std::string type_name;
89 n->get_property ("type-name", type_name);
91 if (type_name == "ARDOUR::AudioRegion" || type_name == "ARDOUR::MidiRegion" || type_name == "ARDOUR::Region") {
92 boost::shared_ptr<Region> r = RegionFactory::region_by_id (id);
94 return new MementoCommand<Region>(*r, before, after);
97 } else if (type_name == "ARDOUR::AudioSource" || type_name == "ARDOUR::MidiSource") {
98 if (sources.count(id))
99 return new MementoCommand<Source>(*sources[id], before, after);
101 } else if (type_name == "ARDOUR::Location") {
102 Location* loc = _locations->get_location_by_id(id);
104 return new MementoCommand<Location>(*loc, before, after);
107 } else if (type_name == "ARDOUR::Locations") {
108 return new MementoCommand<Locations>(*_locations, before, after);
110 } else if (type_name == "ARDOUR::TempoMap") {
111 return new MementoCommand<TempoMap>(*_tempo_map, before, after);
113 } else if (type_name == "ARDOUR::Playlist" || type_name == "ARDOUR::AudioPlaylist" || type_name == "ARDOUR::MidiPlaylist") {
114 if (boost::shared_ptr<Playlist> pl = playlists->by_name(child->property("name")->value())) {
115 return new MementoCommand<Playlist>(*(pl.get()), before, after);
118 } else if (type_name == "ARDOUR::Route" || type_name == "ARDOUR::AudioTrack" || type_name == "ARDOUR::MidiTrack") {
119 if (boost::shared_ptr<Route> r = route_by_id(id)) {
120 return new MementoCommand<Route>(*r, before, after);
122 error << string_compose (X_("Route %1 not found in session"), id) << endmsg;
125 } else if (type_name == "Evoral::Curve" || type_name == "ARDOUR::AutomationList") {
127 std::map<PBD::ID, AutomationList*>::iterator i = automation_lists.find(id);
128 if (i != automation_lists.end()) {
129 return new MementoCommand<AutomationList>(*i->second, before, after);
132 return new MementoCommand<AutomationList> (
133 new MidiAutomationListBinder (n, sources),
138 std::cerr << "Alist " << id << " not found\n";
140 } else if (registry.count(id)) { // For Editor and AutomationLine which are off-limits herea
141 return new MementoCommand<PBD::StatefulDestructible>(*registry[id], before, after);
145 info << string_compose (_("Could not reconstitute MementoCommand from XMLNode. object type = %1 id = %2"), type_name, id.to_s()) << endmsg;
151 Session::stateful_diff_command_factory (XMLNode* n)
154 std::string type_name;
155 if (!n->get_property ("obj-id", id) || !n->get_property ("type-name", type_name)) {
156 error << _("Could get object ID and type name for StatefulDiffCommand from XMLNode.")
161 if ((type_name == "ARDOUR::AudioRegion" || type_name == "ARDOUR::MidiRegion")) {
162 boost::shared_ptr<Region> r = RegionFactory::region_by_id (id);
164 return new StatefulDiffCommand (r, *n);
167 } else if (type_name == "ARDOUR::AudioPlaylist" || type_name == "ARDOUR::MidiPlaylist") {
168 boost::shared_ptr<Playlist> p = playlists->by_id (id);
170 return new StatefulDiffCommand (p, *n);
172 std::cerr << "Playlist with ID = " << id << " not found\n";
178 info << string_compose (
179 _("Could not reconstitute StatefulDiffCommand from XMLNode. object type = %1 id = %2"), type_name, id.to_s())