2 * Copyright (C) 2008-2009 Carl Hetherington <carl@carlh.net>
3 * Copyright (C) 2008 Sakari Bergen <sakari.bergen@beatwaves.net>
4 * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
5 * Copyright (C) 2011-2016 Paul Davis <paul@linuxaudiosystems.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "ardour/export_preset.h"
24 #include "ardour/session.h"
27 using namespace ARDOUR;
29 ExportPreset::ExportPreset (string filename, Session & s) :
30 session (s), global (filename), local (0)
34 if ((root = global.root())) {
35 if (root->get_property ("id", str)) {
38 if (root->get_property ("name", str)) {
42 XMLNode * instant_xml = get_instant_xml ();
44 XMLNode * instant_copy = new XMLNode (*instant_xml);
45 set_local_state (*instant_copy);
50 ExportPreset::~ExportPreset ()
56 ExportPreset::set_name (string const & name)
61 if ((node = global.root())) {
62 node->set_property ("name", name);
65 local->set_property ("name", name);
70 ExportPreset::set_id (string const & id)
75 if ((node = global.root())) {
76 node->set_property ("id", id);
79 local->set_property ("id", id);
84 ExportPreset::set_global_state (XMLNode & state)
86 delete global.root ();
87 global.set_root (&state);
94 ExportPreset::set_local_state (XMLNode & state)
104 ExportPreset::save (std::string const & filename)
109 global.set_filename (filename);
115 ExportPreset::remove_local () const
117 remove_instant_xml ();
121 ExportPreset::get_instant_xml () const
123 XMLNode * instant_xml;
125 if ((instant_xml = session.instant_xml ("ExportPresets"))) {
126 XMLNodeList children = instant_xml->children ("ExportPreset");
127 for (XMLNodeList::iterator it = children.begin(); it != children.end(); ++it) {
128 XMLProperty const * prop;
129 if ((prop = (*it)->property ("id")) && _id == PBD::UUID(prop->value())) {
139 ExportPreset::save_instant_xml () const
141 if (!local) { return; }
143 /* First remove old, then add new */
145 remove_instant_xml ();
147 XMLNode * instant_xml;
148 if ((instant_xml = session.instant_xml ("ExportPresets"))) {
149 instant_xml->add_child_copy (*local);
151 instant_xml = new XMLNode ("ExportPresets");
152 instant_xml->add_child_copy (*local);
153 session.add_instant_xml (*instant_xml, false);
158 ExportPreset::remove_instant_xml () const
160 XMLNode * instant_xml;
161 if ((instant_xml = session.instant_xml ("ExportPresets"))) {
162 instant_xml->remove_nodes_and_delete ("id", _id.to_s());