switch MIDI Clock slave code to use DEBUG_TRACE; don't make it require start/stop...
[ardour2.git] / libs / ardour / export_preset.cc
blob92fcb9e5a7acc6e6cf6ed827dca22ecfc1d60219
1 /*
2 Copyright (C) 2008 Paul Davis
3 Author: Sakari Bergen
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 std;
26 using namespace ARDOUR;
28 ExportPreset::ExportPreset (string filename, Session & s) :
29 session (s), global (filename), local (0)
31 XMLNode * root;
32 if ((root = global.root())) {
33 XMLProperty * prop;
34 if ((prop = root->property ("id"))) {
35 set_id (prop->value());
37 if ((prop = root->property ("name"))) {
38 set_name (prop->value());
41 XMLNode * instant_xml = get_instant_xml ();
42 if (instant_xml) {
43 XMLNode * instant_copy = new XMLNode (*instant_xml);
44 set_local_state (*instant_copy);
49 ExportPreset::~ExportPreset ()
51 delete local;
54 void
55 ExportPreset::set_name (string const & name)
57 _name = name;
59 XMLNode * node;
60 if ((node = global.root())) {
61 node->add_property ("name", name);
63 if (local) {
64 local->add_property ("name", name);
68 void
69 ExportPreset::set_id (string const & id)
71 _id = id;
73 XMLNode * node;
74 if ((node = global.root())) {
75 node->add_property ("id", id);
77 if (local) {
78 local->add_property ("id", id);
82 void
83 ExportPreset::set_global_state (XMLNode & state)
85 delete global.root ();
86 global.set_root (&state);
88 set_id (_id.to_s());
89 set_name (_name);
92 void
93 ExportPreset::set_local_state (XMLNode & state)
95 delete local;
96 local = &state;
98 set_id (_id.to_s());
99 set_name (_name);
102 void
103 ExportPreset::save (std::string const & filename)
105 save_instant_xml ();
106 if (global.root()) {
107 global.set_filename (filename);
108 global.write ();
112 void
113 ExportPreset::remove_local () const
115 remove_instant_xml ();
118 XMLNode *
119 ExportPreset::get_instant_xml () const
121 XMLNode * instant_xml;
123 if ((instant_xml = session.instant_xml ("ExportPresets"))) {
124 XMLNodeList children = instant_xml->children ("ExportPreset");
125 for (XMLNodeList::iterator it = children.begin(); it != children.end(); ++it) {
126 XMLProperty * prop;
127 if ((prop = (*it)->property ("id")) && _id == PBD::UUID(prop->value())) {
128 return *it;
133 return 0;
136 void
137 ExportPreset::save_instant_xml () const
139 if (!local) { return; }
141 /* First remove old, then add new */
143 remove_instant_xml ();
145 XMLNode * instant_xml;
146 if ((instant_xml = session.instant_xml ("ExportPresets"))) {
147 instant_xml->add_child_copy (*local);
148 } else {
149 instant_xml = new XMLNode ("ExportPresets");
150 instant_xml->add_child_copy (*local);
151 session.add_instant_xml (*instant_xml, false);
155 void
156 ExportPreset::remove_instant_xml () const
158 XMLNode * instant_xml;
159 if ((instant_xml = session.instant_xml ("ExportPresets"))) {
160 instant_xml->remove_nodes_and_delete ("id", _id.to_s());