ardour
export_preset.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 Paul Davis
3  Author: Sakari Bergen
4 
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.
9 
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.
14 
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.
18 
19 */
20 
21 #include "ardour/export_preset.h"
22 
23 #include "ardour/session.h"
24 
25 using namespace std;
26 using namespace ARDOUR;
27 
28 ExportPreset::ExportPreset (string filename, Session & s) :
29  session (s), global (filename), local (0)
30 {
31  XMLNode * root;
32  if ((root = global.root())) {
33  XMLProperty * prop;
34  if ((prop = root->property ("id"))) {
35  set_id (prop->value());
36  }
37  if ((prop = root->property ("name"))) {
38  set_name (prop->value());
39  }
40 
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);
45  }
46  }
47 }
48 
50 {
51  delete local;
52 }
53 
54 void
55 ExportPreset::set_name (string const & name)
56 {
57  _name = name;
58 
59  XMLNode * node;
60  if ((node = global.root())) {
61  node->add_property ("name", name);
62  }
63  if (local) {
64  local->add_property ("name", name);
65  }
66 }
67 
68 void
69 ExportPreset::set_id (string const & id)
70 {
71  _id = id;
72 
73  XMLNode * node;
74  if ((node = global.root())) {
75  node->add_property ("id", id);
76  }
77  if (local) {
78  local->add_property ("id", id);
79  }
80 }
81 
82 void
84 {
85  delete global.root ();
86  global.set_root (&state);
87 
88  set_id (_id.to_s());
89  set_name (_name);
90 }
91 
92 void
94 {
95  delete local;
96  local = &state;
97 
98  set_id (_id.to_s());
99  set_name (_name);
100 }
101 
102 void
103 ExportPreset::save (std::string const & filename)
104 {
105  save_instant_xml ();
106 
107  if (global.root()) {
108  global.set_filename (filename);
109  global.write ();
110  }
111 }
112 
113 void
115 {
117 }
118 
119 XMLNode *
121 {
122  XMLNode * instant_xml;
123 
124  if ((instant_xml = session.instant_xml ("ExportPresets"))) {
125  XMLNodeList children = instant_xml->children ("ExportPreset");
126  for (XMLNodeList::iterator it = children.begin(); it != children.end(); ++it) {
127  XMLProperty * prop;
128  if ((prop = (*it)->property ("id")) && _id == PBD::UUID(prop->value())) {
129  return *it;
130  }
131  }
132  }
133 
134  return 0;
135 }
136 
137 void
139 {
140  if (!local) { return; }
141 
142  /* First remove old, then add new */
143 
145 
146  XMLNode * instant_xml;
147  if ((instant_xml = session.instant_xml ("ExportPresets"))) {
148  instant_xml->add_child_copy (*local);
149  } else {
150  instant_xml = new XMLNode ("ExportPresets");
151  instant_xml->add_child_copy (*local);
152  session.add_instant_xml (*instant_xml, false);
153  }
154 }
155 
156 void
158 {
159  XMLNode * instant_xml;
160  if ((instant_xml = session.instant_xml ("ExportPresets"))) {
161  instant_xml->remove_nodes_and_delete ("id", _id.to_s());
162  }
163 }
const std::string & value() const
Definition: xml++.h:159
bool write() const
Definition: xml++.cc:147
void set_id(std::string const &id)
XMLNode * add_child_copy(const XMLNode &)
Definition: xml++.cc:363
Definition: Beats.hpp:239
const XMLNodeList & children(const std::string &str=std::string()) const
Definition: xml++.cc:329
void remove_instant_xml() const
std::list< XMLNode * > XMLNodeList
Definition: xml++.h:44
XMLProperty * property(const char *)
Definition: xml++.cc:413
XMLNode * set_root(XMLNode *n)
Definition: xml++.h:63
std::string to_s() const
Definition: uuid.cc:33
XMLNode * root() const
Definition: xml++.h:62
Definition: amp.h:29
void set_global_state(XMLNode &state)
void remove_local() const
const std::string & set_filename(const std::string &fn)
Definition: xml++.h:66
XMLProperty * add_property(const char *name, const std::string &value)
void save(std::string const &filename)
const char * name
void set_name(std::string const &name)
XMLNode * instant_xml(const std::string &str)
Definition: xml++.h:95
void add_instant_xml(XMLNode &, bool write_to_config=true)
The instant xml file is written to the session directory.
std::string name() const
Definition: export_preset.h:42
PBD::UUID const & id() const
Definition: export_preset.h:41
void save_instant_xml() const
void set_local_state(XMLNode &state)
Definition: uuid.h:32
void remove_nodes_and_delete(const std::string &)
XMLNode * get_instant_xml() const