part-way through getting the audioengine changes to compile
[ardour.git] / libs / ardour / session_configuration.cc
1 /*
2     Copyright (C) 2009 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "pbd/pathexpand.h"
21
22 #include "ardour/types.h"
23 #include "ardour/session_configuration.h"
24 #include "i18n.h"
25
26 using namespace ARDOUR;
27 using namespace PBD;
28
29 SessionConfiguration::SessionConfiguration ()
30         :
31 /* construct variables */
32 #undef  CONFIG_VARIABLE
33 #undef  CONFIG_VARIABLE_SPECIAL
34 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
35 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
36 #include "ardour/session_configuration_vars.h"
37 #undef  CONFIG_VARIABLE
38 #undef  CONFIG_VARIABLE_SPECIAL
39         foo (0)
40 {
41
42 }
43
44 XMLNode&
45 SessionConfiguration::get_state ()
46 {
47         XMLNode* root;
48         LocaleGuard lg (X_("POSIX"));
49
50         root = new XMLNode ("Ardour");
51         root->add_child_nocopy (get_variables ());
52
53         return *root;
54 }
55
56
57 XMLNode&
58 SessionConfiguration::get_variables ()
59 {
60         XMLNode* node;
61         LocaleGuard lg (X_("POSIX"));
62
63         node = new XMLNode ("Config");
64
65 #undef  CONFIG_VARIABLE
66 #undef  CONFIG_VARIABLE_SPECIAL
67 #define CONFIG_VARIABLE(type,var,Name,value) \
68         var.add_to_node (*node);
69 #define CONFIG_VARIABLE_SPECIAL(type,var,Name,value,mutator) \
70         var.add_to_node (*node);
71 #include "ardour/session_configuration_vars.h"
72 #undef  CONFIG_VARIABLE
73 #undef  CONFIG_VARIABLE_SPECIAL
74
75         return *node;
76 }
77
78
79 int
80 SessionConfiguration::set_state (XMLNode const& root, int /*version*/)
81 {
82         if (root.name() != "Ardour") {
83                 return -1;
84         }
85
86         for (XMLNodeConstIterator i = root.children().begin(); i != root.children().end(); ++i) {
87                 if ((*i)->name() == "Config") {
88                         set_variables (**i);
89                 }
90         }
91
92         return 0;
93 }
94
95 void
96 SessionConfiguration::set_variables (const XMLNode& node)
97 {
98 #undef  CONFIG_VARIABLE
99 #undef  CONFIG_VARIABLE_SPECIAL
100 #define CONFIG_VARIABLE(type,var,name,value) \
101         if (var.set_from_node (node)) { \
102                 ParameterChanged (name);                  \
103         }
104 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
105         if (var.set_from_node (node)) {    \
106                 ParameterChanged (name);                     \
107         }
108
109 #include "ardour/session_configuration_vars.h"
110 #undef  CONFIG_VARIABLE
111 #undef  CONFIG_VARIABLE_SPECIAL
112
113 }
114 void
115 SessionConfiguration::map_parameters (boost::function<void (std::string)>& functor)
116 {
117 #undef  CONFIG_VARIABLE
118 #undef  CONFIG_VARIABLE_SPECIAL
119 #define CONFIG_VARIABLE(type,var,name,value)                 functor (name);
120 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) functor (name);
121 #include "ardour/session_configuration_vars.h"
122 #undef  CONFIG_VARIABLE
123 #undef  CONFIG_VARIABLE_SPECIAL
124 }