1 #include <ardour/session.h>
2 #include <ardour/route.h>
3 #include <pbd/memento_command.h>
4 #include <ardour/diskstream.h>
5 #include <ardour/playlist.h>
6 #include <ardour/audioplaylist.h>
7 #include <ardour/audio_track.h>
8 #include <ardour/tempo.h>
9 #include <ardour/audiosource.h>
10 #include <ardour/audioregion.h>
11 #include <pbd/error.h>
12 #include <pbd/statefuldestructible.h>
20 void Session::register_with_memento_command_factory(PBD::ID id, PBD::StatefulThingWithGoingAway *ptr)
25 Command *Session::memento_command_factory(XMLNode *n)
28 XMLNode *before = 0, *after = 0;
32 id = PBD::ID(n->property("obj_id")->value());
34 /* get before/after */
36 if (n->name() == "MementoCommand") {
37 before = new XMLNode(*n->children().front());
38 after = new XMLNode(*n->children().back());
40 } else if (n->name() == "MementoUndoCommand") {
41 before = new XMLNode(*n->children().front());
43 } else if (n->name() == "MementoRedoCommand") {
44 after = new XMLNode(*n->children().front());
46 } else if (n->name() == "PlaylistCommand") {
47 before = new XMLNode(*n->children().front());
48 after = new XMLNode(*n->children().back());
54 error << _("Tried to reconstitute a MementoCommand with no contents, failing. id=") << id.to_s() << endmsg;
59 string obj_T = n->property ("type_name")->value();
60 if (obj_T == typeid (AudioRegion).name() || obj_T == typeid (Region).name()) {
61 if (audio_regions.count(id))
62 return new MementoCommand<AudioRegion>(*audio_regions[id], before, after);
63 } else if (obj_T == typeid (AudioSource).name()) {
64 if (audio_sources.count(id))
65 return new MementoCommand<AudioSource>(*audio_sources[id], before, after);
66 } else if (obj_T == typeid (Location).name()) {
67 return new MementoCommand<Location>(*_locations.get_location_by_id(id), before, after);
68 } else if (obj_T == typeid (Locations).name()) {
69 return new MementoCommand<Locations>(_locations, before, after);
70 } else if (obj_T == typeid (TempoMap).name()) {
71 return new MementoCommand<TempoMap>(*_tempo_map, before, after);
72 } else if (obj_T == typeid (Playlist).name() || obj_T == typeid (AudioPlaylist).name()) {
73 if (boost::shared_ptr<Playlist> pl = playlist_by_name(child->property("name")->value())) {
74 return new MementoCommand<Playlist>(*(pl.get()), before, after);
76 } else if (obj_T == typeid (Route).name() || obj_T == typeid (AudioTrack).name()) {
77 return new MementoCommand<Route>(*route_by_id(id), before, after);
78 } else if (obj_T == typeid (Curve).name() || obj_T == typeid (AutomationList).name()) {
79 if (automation_lists.count(id))
80 return new MementoCommand<AutomationList>(*automation_lists[id], before, after);
81 } else if (registry.count(id)) { // For Editor and AutomationLine which are off-limits here
82 return new MementoCommand<PBD::StatefulThingWithGoingAway>(*registry[id], before, after);
86 error << string_compose (_("could not reconstitute MementoCommand from XMLNode. object type = %1 id = %2"), obj_T, id.to_s()) << endmsg;
91 Session::GlobalSoloStateCommand::GlobalSoloStateCommand(Session &sess, void *src)
92 : sess(sess), src(src)
94 after = before = sess.get_global_route_boolean(&Route::soloed);
96 void Session::GlobalSoloStateCommand::mark()
98 after = sess.get_global_route_boolean(&Route::soloed);
100 void Session::GlobalSoloStateCommand::operator()()
102 sess.set_global_solo(after, src);
104 void Session::GlobalSoloStateCommand::undo()
106 sess.set_global_solo(before, src);
108 XMLNode &Session::GlobalSoloStateCommand::get_state()
110 XMLNode *node = new XMLNode("GlobalSoloStateCommand");
115 Session::GlobalMuteStateCommand::GlobalMuteStateCommand(Session &sess, void *src)
116 : sess(sess), src(src)
118 after = before = sess.get_global_route_boolean(&Route::muted);
120 void Session::GlobalMuteStateCommand::mark()
122 after = sess.get_global_route_boolean(&Route::muted);
124 void Session::GlobalMuteStateCommand::operator()()
126 sess.set_global_mute(after, src);
128 void Session::GlobalMuteStateCommand::undo()
130 sess.set_global_mute(before, src);
132 XMLNode &Session::GlobalMuteStateCommand::get_state()
134 XMLNode *node = new XMLNode("GlobalMuteStateCommand");
139 Session::GlobalRecordEnableStateCommand::GlobalRecordEnableStateCommand(Session &sess, void *src)
140 : sess(sess), src(src)
142 after = before = sess.get_global_route_boolean(&Route::record_enabled);
144 void Session::GlobalRecordEnableStateCommand::mark()
146 after = sess.get_global_route_boolean(&Route::record_enabled);
148 void Session::GlobalRecordEnableStateCommand::operator()()
150 sess.set_global_record_enable(after, src);
152 void Session::GlobalRecordEnableStateCommand::undo()
154 sess.set_global_record_enable(before, src);
156 XMLNode &Session::GlobalRecordEnableStateCommand::get_state()
158 XMLNode *node = new XMLNode("GlobalRecordEnableStateCommand");
163 Session::GlobalMeteringStateCommand::GlobalMeteringStateCommand(Session &sess, void *src)
164 : sess(sess), src(src)
166 after = before = sess.get_global_route_metering();
168 void Session::GlobalMeteringStateCommand::mark()
170 after = sess.get_global_route_metering();
172 void Session::GlobalMeteringStateCommand::operator()()
174 sess.set_global_route_metering(after, src);
176 void Session::GlobalMeteringStateCommand::undo()
178 sess.set_global_route_metering(before, src);
180 XMLNode &Session::GlobalMeteringStateCommand::get_state()
182 XMLNode *node = new XMLNode("GlobalMeteringStateCommand");
186 } // namespace ARDOUR