NO-OP: whitespace
[ardour.git] / libs / ardour / export_preset.cc
1 /*
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>
6  *
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.
11  *
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.
16  *
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.
20  */
21
22 #include "ardour/export_preset.h"
23
24 #include "ardour/session.h"
25
26 using namespace std;
27 using namespace ARDOUR;
28
29 ExportPreset::ExportPreset (string filename, Session & s) :
30   session (s), global (filename), local (0)
31 {
32         XMLNode * root;
33         std::string str;
34         if ((root = global.root())) {
35                 if (root->get_property ("id", str)) {
36                         set_id (str);
37                 }
38                 if (root->get_property ("name", str)) {
39                         set_name (str);
40                 }
41
42                 XMLNode * instant_xml = get_instant_xml ();
43                 if (instant_xml) {
44                         XMLNode * instant_copy = new XMLNode (*instant_xml);
45                         set_local_state (*instant_copy);
46                 }
47         }
48 }
49
50 ExportPreset::~ExportPreset ()
51 {
52         delete local;
53 }
54
55 void
56 ExportPreset::set_name (string const & name)
57 {
58         _name = name;
59
60         XMLNode * node;
61         if ((node = global.root())) {
62                 node->set_property ("name", name);
63         }
64         if (local) {
65                 local->set_property ("name", name);
66         }
67 }
68
69 void
70 ExportPreset::set_id (string const & id)
71 {
72         _id = id;
73
74         XMLNode * node;
75         if ((node = global.root())) {
76                 node->set_property ("id", id);
77         }
78         if (local) {
79                 local->set_property ("id", id);
80         }
81 }
82
83 void
84 ExportPreset::set_global_state (XMLNode & state)
85 {
86         delete global.root ();
87         global.set_root (&state);
88
89         set_id (_id.to_s());
90         set_name (_name);
91 }
92
93 void
94 ExportPreset::set_local_state (XMLNode & state)
95 {
96         delete local;
97         local = &state;
98
99         set_id (_id.to_s());
100         set_name (_name);
101 }
102
103 void
104 ExportPreset::save (std::string const & filename)
105 {
106         save_instant_xml ();
107
108         if (global.root()) {
109                 global.set_filename (filename);
110                 global.write ();
111         }
112 }
113
114 void
115 ExportPreset::remove_local () const
116 {
117         remove_instant_xml ();
118 }
119
120 XMLNode *
121 ExportPreset::get_instant_xml () const
122 {
123         XMLNode * instant_xml;
124
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())) {
130                                 return *it;
131                         }
132                 }
133         }
134
135         return 0;
136 }
137
138 void
139 ExportPreset::save_instant_xml () const
140 {
141         if (!local) { return; }
142
143         /* First remove old, then add new */
144
145         remove_instant_xml ();
146
147         XMLNode * instant_xml;
148         if ((instant_xml = session.instant_xml ("ExportPresets"))) {
149                 instant_xml->add_child_copy (*local);
150         } else {
151                 instant_xml = new XMLNode ("ExportPresets");
152                 instant_xml->add_child_copy (*local);
153                 session.add_instant_xml (*instant_xml, false);
154         }
155 }
156
157 void
158 ExportPreset::remove_instant_xml () const
159 {
160         XMLNode * instant_xml;
161         if ((instant_xml = session.instant_xml ("ExportPresets"))) {
162                 instant_xml->remove_nodes_and_delete ("id", _id.to_s());
163         }
164 }