4 #include "pbd/stateful.h"
5 #include "ardour/send.h"
6 #include "ardour/track.h"
13 using namespace ARDOUR;
14 using namespace SessionUtils;
16 /* this is copied from Session::new_route_from_template */
17 void trim_state_for_mixer_copy (Session*s, XMLNode& node)
19 /* trim bitslots from listen sends so that new ones are used */
20 XMLNodeList children = node.children ();
21 for (XMLNodeList::iterator i = children.begin(); i != children.end(); ++i) {
22 if ((*i)->name() == X_("Processor")) {
23 /* ForceIDRegeneration does not catch the following */
24 XMLProperty const * role = (*i)->property (X_("role"));
25 XMLProperty const * type = (*i)->property (X_("type"));
26 if (role && role->value() == X_("Aux")) {
27 /* check if the target bus exists.
28 * we should not save aux-sends in templates.
30 XMLProperty const * target = (*i)->property (X_("target"));
32 (*i)->add_property ("type", "dangling-aux-send");
35 boost::shared_ptr<Route> r = s->route_by_id (target->value());
36 if (!r || boost::dynamic_pointer_cast<Track>(r)) {
37 (*i)->add_property ("type", "dangling-aux-send");
41 if (role && role->value() == X_("Listen")) {
42 (*i)->remove_property (X_("bitslot"));
44 else if (role && (role->value() == X_("Send") || role->value() == X_("Aux"))) {
48 xrole = Delivery::Role (string_2_enum (role->value(), xrole));
49 std::string name = Send::name_and_id_new_send(*s, xrole, bitslot, false);
50 snprintf (buf, sizeof (buf), "%" PRIu32, bitslot);
51 (*i)->remove_property (X_("bitslot"));
52 (*i)->remove_property (X_("name"));
53 (*i)->add_property ("bitslot", buf);
54 (*i)->add_property ("name", name);
56 else if (type && type->value() == X_("return")) {
57 // Return::set_state() generates a new one
58 (*i)->remove_property (X_("bitslot"));
60 else if (type && type->value() == X_("port")) {
61 // PortInsert::set_state() handles the bitslot
62 (*i)->remove_property (X_("bitslot"));
63 (*i)->add_property ("ignore-name", "1");
70 static void copy_mixer_settings (Session*s, boost::shared_ptr<Route> dst, XMLNode& state)
72 PBD::Stateful::ForceIDRegeneration force_ids;
74 trim_state_for_mixer_copy (s, state);
75 state.remove_nodes_and_delete ("Diskstream");
76 state.remove_nodes_and_delete ("Automation");
79 dst->set_state (state, PBD::Stateful::loading_state_version);
82 int main (int argc, char* argv[])
85 printf ("Usage: copy-mix <session1-dir> <session1-name> <session2-dir> <session2-name>\n");
89 std::string session1_dir (argv[1]);
90 std::string session1_name (argv[2]);
92 std::string session2_dir = (argv[3]);
93 std::string session2_name = (argv[4]);
98 std::map<std::string,XMLNode*> routestate;
100 s = SessionUtils::load_session ( session1_dir, session1_name);
103 printf("Cannot load source session.\n");
104 SessionUtils::cleanup();
108 // get route state from first session
109 boost::shared_ptr<RouteList> rl = s->get_routes ();
110 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
111 XMLNode& state ((*i)->get_state());
112 routestate[(*i)->name()] = &state;
115 SessionUtils::unload_session(s);
118 // open target session
119 s = SessionUtils::load_session (session2_dir, session2_name);
121 printf("Cannot load target session.\n");
122 SessionUtils::cleanup();
126 // iterate over all routes in the target session..
127 rl = s->get_routes ();
128 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
129 boost::shared_ptr<Route> r = *i;
130 // skip special busses
131 if (r->is_master() || r->is_monitor() || r->is_auditioner()) {
134 // find matching route by name
135 std::map<std::string,XMLNode*>::iterator it = routestate.find (r->name ());
136 if (it == routestate.end()) {
137 printf (" -- no match for '%s'\n", (*i)->name().c_str());
140 printf ("-- found match '%s'\n", (*i)->name().c_str());
141 XMLNode *state = it->second;
143 copy_mixer_settings (s, r, *state);
149 SessionUtils::unload_session(s);
152 for (std::map<std::string,XMLNode*>::iterator i = routestate.begin(); i != routestate.end(); ++i) {
153 XMLNode *state = i->second;
157 SessionUtils::cleanup();