4 * Copyright (C) 2007 Krzysztof Foltman
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 * Boston, MA 02111-1307, USA.
21 #ifndef __CALF_PRESET_H
22 #define __CALF_PRESET_H
32 namespace calf_plugins
{
34 class plugin_ctl_iface
;
36 /// Contents of single preset
39 /// Bank the preset belongs to (not used yet)
41 /// Program number of the preset (not used yet)
43 /// Name of the preset
45 /// Name of the plugin the preset is for
47 /// Names of parameters in values array (for each item in param_names there should be a counterpart in values)
48 std::vector
<std::string
> param_names
;
49 /// Values of parameters
50 std::vector
<float> values
;
51 /// DSSI configure-style variables
52 std::map
<std::string
, std::string
> variables
;
54 plugin_preset() : bank(0), program(0) {}
55 /// Export preset as XML
57 /// "Upload" preset content to the plugin
58 void activate(plugin_ctl_iface
*plugin
);
59 /// "Download" preset content from the plugin
60 void get_from(plugin_ctl_iface
*plugin
);
63 /// Exception thrown by preset system
64 struct preset_exception
66 std::string message
, param
, fulltext
;
68 preset_exception(const std::string
&_message
, const std::string
&_param
, int _error
)
69 : message(_message
), param(_param
), error(_error
)
74 fulltext
= message
+ " " + param
+ " (" + strerror(error
) + ")";
76 fulltext
= message
+ " " + param
;
77 return fulltext
.c_str();
84 /// A vector of presets
85 typedef std::vector
<plugin_preset
> preset_vector
;
87 /// A single list of presets (usually there are two - @see get_builtin_presets(), get_user_presets() )
93 START
, ///< Beginning of parsing process (before root element)
94 LIST
, ///< Inside root element
95 PRESET
, ///< Inside preset definition
96 VALUE
, ///< Inside (empty) param tag
97 VAR
, ///< Inside (non-empty) var tag
100 /// Contained presets (usually for all plugins)
101 preset_vector presets
;
102 /// Temporary preset used during parsing process
103 plugin_preset parser_preset
;
104 /// Preset number counters for DSSI (currently broken)
105 std::map
<std::string
, int> last_preset_ids
;
106 /// The key used in current <var name="key"> tag (for state == VAR)
107 std::string current_key
;
109 /// Return the name of the built-in or user-defined preset file
110 static std::string
get_preset_filename(bool builtin
);
111 /// Load default preset list (built-in or user-defined)
112 bool load_defaults(bool builtin
);
113 void parse(const std::string
&data
);
114 /// Load preset list from XML file
115 void load(const char *filename
);
116 /// Save preset list as XML file
117 void save(const char *filename
);
118 /// Append or replace a preset (replaces a preset with the same plugin and preset name)
119 void add(const plugin_preset
&sp
);
120 /// Get a sublist of presets for a given plugin (those with plugin_preset::plugin == plugin)
121 void get_for_plugin(preset_vector
&vec
, const char *plugin
);
124 /// Internal function: start element handler for expat
125 static void xml_start_element_handler(void *user_data
, const char *name
, const char *attrs
[]);
126 /// Internal function: end element handler for expat
127 static void xml_end_element_handler(void *user_data
, const char *name
);
128 /// Internal function: character data (tag text content) handler for expat
129 static void xml_character_data_handler(void *user_data
, const char *data
, int len
);
132 /// Return the current list of built-in (factory) presets (these are loaded from system-wide file)
133 extern preset_list
&get_builtin_presets();
135 /// Return the current list of user-defined presets (these are loaded from ~/.calfpresets)
136 extern preset_list
&get_user_presets();