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)
26 Session::memento_command_factory(XMLNode *n)
29 XMLNode *before = 0, *after = 0;
33 id = PBD::ID(n->property("obj_id")->value());
35 /* get before/after */
37 if (n->name() == "MementoCommand") {
38 before = new XMLNode(*n->children().front());
39 after = new XMLNode(*n->children().back());
41 } else if (n->name() == "MementoUndoCommand") {
42 before = new XMLNode(*n->children().front());
44 } else if (n->name() == "MementoRedoCommand") {
45 after = new XMLNode(*n->children().front());
47 } else if (n->name() == "PlaylistCommand") {
48 before = new XMLNode(*n->children().front());
49 after = new XMLNode(*n->children().back());
55 error << _("Tried to reconstitute a MementoCommand with no contents, failing. id=") << id.to_s() << endmsg;
60 string obj_T = n->property ("type_name")->value();
61 if (obj_T == typeid (AudioRegion).name() || obj_T == typeid (Region).name()) {
62 if (audio_regions.count(id))
63 return new MementoCommand<AudioRegion>(*audio_regions[id], before, after);
64 } else if (obj_T == typeid (AudioSource).name()) {
65 if (audio_sources.count(id))
66 return new MementoCommand<AudioSource>(*audio_sources[id], before, after);
67 } else if (obj_T == typeid (Location).name()) {
68 return new MementoCommand<Location>(*_locations.get_location_by_id(id), before, after);
69 } else if (obj_T == typeid (Locations).name()) {
70 return new MementoCommand<Locations>(_locations, before, after);
71 } else if (obj_T == typeid (TempoMap).name()) {
72 return new MementoCommand<TempoMap>(*_tempo_map, before, after);
73 } else if (obj_T == typeid (Playlist).name() || obj_T == typeid (AudioPlaylist).name()) {
74 if (boost::shared_ptr<Playlist> pl = playlist_by_name(child->property("name")->value())) {
75 return new MementoCommand<Playlist>(*(pl.get()), before, after);
77 } else if (obj_T == typeid (Route).name() || obj_T == typeid (AudioTrack).name()) {
78 return new MementoCommand<Route>(*route_by_id(id), before, after);
79 } else if (obj_T == typeid (Curve).name() || obj_T == typeid (AutomationList).name()) {
80 if (automation_lists.count(id))
81 return new MementoCommand<AutomationList>(*automation_lists[id], before, after);
82 } else if (registry.count(id)) { // For Editor and AutomationLine which are off-limits here
83 return new MementoCommand<PBD::StatefulThingWithGoingAway>(*registry[id], before, after);
87 error << string_compose (_("could not reconstitute MementoCommand from XMLNode. object type = %1 id = %2"), obj_T, id.to_s()) << endmsg;
92 Session::global_state_command_factory(XMLNode *n)
94 error << string_compose (_("cannot reconstitute %1 from XML yet, ignored"), n->name()) << endmsg;
99 Session::GlobalSoloStateCommand::GlobalSoloStateCommand(Session &sess, void *src)
100 : sess(sess), src(src)
102 after = before = sess.get_global_route_boolean(&Route::soloed);
104 void Session::GlobalSoloStateCommand::mark()
106 after = sess.get_global_route_boolean(&Route::soloed);
108 void Session::GlobalSoloStateCommand::operator()()
110 sess.set_global_solo(after, src);
112 void Session::GlobalSoloStateCommand::undo()
114 sess.set_global_solo(before, src);
116 XMLNode &Session::GlobalSoloStateCommand::get_state()
118 XMLNode *node = new XMLNode("GlobalSoloStateCommand");
123 Session::GlobalMuteStateCommand::GlobalMuteStateCommand(Session &sess, void *src)
124 : sess(sess), src(src)
126 after = before = sess.get_global_route_boolean(&Route::muted);
128 void Session::GlobalMuteStateCommand::mark()
130 after = sess.get_global_route_boolean(&Route::muted);
132 void Session::GlobalMuteStateCommand::operator()()
134 sess.set_global_mute(after, src);
136 void Session::GlobalMuteStateCommand::undo()
138 sess.set_global_mute(before, src);
140 XMLNode &Session::GlobalMuteStateCommand::get_state()
142 XMLNode *node = new XMLNode("GlobalMuteStateCommand");
147 Session::GlobalRecordEnableStateCommand::GlobalRecordEnableStateCommand(Session &sess, void *src)
148 : sess(sess), src(src)
150 after = before = sess.get_global_route_boolean(&Route::record_enabled);
152 void Session::GlobalRecordEnableStateCommand::mark()
154 after = sess.get_global_route_boolean(&Route::record_enabled);
156 void Session::GlobalRecordEnableStateCommand::operator()()
158 sess.set_global_record_enable(after, src);
160 void Session::GlobalRecordEnableStateCommand::undo()
162 sess.set_global_record_enable(before, src);
164 XMLNode &Session::GlobalRecordEnableStateCommand::get_state()
166 XMLNode *node = new XMLNode("GlobalRecordEnableStateCommand");
171 Session::GlobalMeteringStateCommand::GlobalMeteringStateCommand(Session &sess, void *src)
172 : sess(sess), src(src)
174 after = before = sess.get_global_route_metering();
176 void Session::GlobalMeteringStateCommand::mark()
178 after = sess.get_global_route_metering();
180 void Session::GlobalMeteringStateCommand::operator()()
182 sess.set_global_route_metering(after, src);
184 void Session::GlobalMeteringStateCommand::undo()
186 sess.set_global_route_metering(before, src);
188 XMLNode &Session::GlobalMeteringStateCommand::get_state()
190 XMLNode *node = new XMLNode("GlobalMeteringStateCommand");
194 } // namespace ARDOUR