2 Copyright (C) 2008 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "ardour/export_preset.h"
23 #include "ardour/session.h"
25 using namespace ARDOUR;
27 ExportPreset::ExportPreset (string filename, Session & s) :
28 session (s), global (filename), local (0)
31 if ((root = global.root())) {
33 if ((prop = root->property ("id"))) {
34 set_id (prop->value());
36 if ((prop = root->property ("name"))) {
37 set_name (prop->value());
40 XMLNode * instant_xml = get_instant_xml ();
42 XMLNode * instant_copy = new XMLNode (*instant_xml);
43 set_local_state (*instant_copy);
48 ExportPreset::~ExportPreset ()
54 ExportPreset::set_name (string const & name)
59 if ((node = global.root())) {
60 node->add_property ("name", name);
63 local->add_property ("name", name);
68 ExportPreset::set_id (string const & id)
73 if ((node = global.root())) {
74 node->add_property ("id", id);
77 local->add_property ("id", id);
82 ExportPreset::set_global_state (XMLNode & state)
84 delete global.root ();
85 global.set_root (&state);
92 ExportPreset::set_local_state (XMLNode & state)
102 ExportPreset::save (std::string const & filename)
106 global.set_filename (filename);
112 ExportPreset::remove_local () const
114 remove_instant_xml ();
118 ExportPreset::get_instant_xml () const
120 XMLNode * instant_xml;
122 if ((instant_xml = session.instant_xml ("ExportPresets"))) {
123 XMLNodeList children = instant_xml->children ("ExportPreset");
124 for (XMLNodeList::iterator it = children.begin(); it != children.end(); ++it) {
126 if ((prop = (*it)->property ("id")) && _id == PBD::UUID(prop->value())) {
136 ExportPreset::save_instant_xml () const
138 if (!local) { return; }
140 /* First remove old, then add new */
142 remove_instant_xml ();
144 XMLNode * instant_xml;
145 if ((instant_xml = session.instant_xml ("ExportPresets"))) {
146 instant_xml->add_child_copy (*local);
148 instant_xml = new XMLNode ("ExportPresets");
149 instant_xml->add_child_copy (*local);
150 session.add_instant_xml (*instant_xml, false);
155 ExportPreset::remove_instant_xml () const
157 XMLNode * instant_xml;
158 if ((instant_xml = session.instant_xml ("ExportPresets"))) {
159 instant_xml->remove_nodes_and_delete ("id", _id.to_s());