[SCM] calf/master: + Framework: API documentation updates for preset system, minor refactoring (common function for retrieving filenames for built-in and user presets)
js at users.alioth.debian.org
js at users.alioth.debian.org
Tue May 7 15:37:27 UTC 2013
The following commit has been merged in the master branch:
commit a9f8ae1855ad56e39b02193e44d2b7d80a0e5bf3
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date: Sat Aug 2 21:57:15 2008 +0000
+ Framework: API documentation updates for preset system, minor refactoring (common function for retrieving filenames for built-in and user presets)
git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@251 78b06b96-2940-0410-b7fc-879d825d01d8
diff --git a/src/calf/preset.h b/src/calf/preset.h
index 5a5ae3e..bae2a40 100644
--- a/src/calf/preset.h
+++ b/src/calf/preset.h
@@ -33,21 +33,34 @@ namespace synth {
class plugin_ctl_iface;
+/// Contents of single preset
struct plugin_preset
{
- int bank, program;
+ /// Bank the preset belongs to (not used yet)
+ int bank;
+ /// Program number of the preset (not used yet)
+ int program;
+ /// Name of the preset
std::string name;
+ /// Name of the plugin the preset is for
std::string plugin;
+ /// Names of parameters in values array (for each item in param_names there should be a counterpart in values)
std::vector<std::string> param_names;
+ /// Values of parameters
std::vector<float> values;
+ /// DSSI configure-style variables
std::map<std::string, std::string> variables;
plugin_preset() : bank(0), program(0) {}
- std::string to_xml();
+ /// Export preset as XML
+ std::string to_xml();
+ /// "Upload" preset content to the plugin
void activate(plugin_ctl_iface *plugin);
+ /// "Download" preset content from the plugin
void get_from(plugin_ctl_iface *plugin);
};
+/// Exception thrown by preset system
struct preset_exception
{
std::string message, param, fulltext;
@@ -68,39 +81,58 @@ struct preset_exception
}
};
+/// A vector of presets
typedef std::vector<plugin_preset> preset_vector;
+/// A single list of presets (usually there are two - @see get_builtin_presets(), get_user_presets() )
struct preset_list
{
+ /// Parser states
enum parser_state
{
- START,
- LIST,
- PRESET,
- VALUE,
- VAR,
+ START, ///< Beginning of parsing process (before root element)
+ LIST, ///< Inside root element
+ PRESET, ///< Inside preset definition
+ VALUE, ///< Inside (empty) param tag
+ VAR, ///< Inside (non-empty) var tag
} state;
+ /// Contained presets (usually for all plugins)
preset_vector presets;
+ /// Temporary preset used during parsing process
plugin_preset parser_preset;
+ /// Preset number counters for DSSI (currently broken)
std::map<std::string, int> last_preset_ids;
+ /// The key used in current <var name="key"> tag (for state == VAR)
std::string current_key;
- static std::string get_preset_filename();
+ /// Return the name of the built-in or user-defined preset file
+ static std::string get_preset_filename(bool builtin);
+ /// Load default preset list (built-in or user-defined)
bool load_defaults(bool builtin);
void parse(const std::string &data);
+ /// Load preset list from XML file
void load(const char *filename);
+ /// Save preset list as XML file
void save(const char *filename);
+ /// Append or replace a preset (replaces a preset with the same plugin and preset name)
void add(const plugin_preset &sp);
+ /// Get a sublist of presets for a given plugin (those with plugin_preset::plugin == plugin)
void get_for_plugin(preset_vector &vec, const char *plugin);
protected:
+ /// Internal function: start element handler for expat
static void xml_start_element_handler(void *user_data, const char *name, const char *attrs[]);
+ /// Internal function: end element handler for expat
static void xml_end_element_handler(void *user_data, const char *name);
+ /// Internal function: character data (tag text content) handler for expat
static void xml_character_data_handler(void *user_data, const char *data, int len);
};
+/// Return the current list of built-in (factory) presets (these are loaded from system-wide file)
extern preset_list &get_builtin_presets();
+
+/// Return the current list of user-defined presets (these are loaded from ~/.calfpresets)
extern preset_list &get_user_presets();
};
diff --git a/src/preset.cpp b/src/preset.cpp
index 7acdb09..6eb70c7 100644
--- a/src/preset.cpp
+++ b/src/preset.cpp
@@ -110,10 +110,17 @@ void plugin_preset::get_from(plugin_ctl_iface *plugin)
plugin->send_configures(&tmp);
}
-string synth::preset_list::get_preset_filename()
+string synth::preset_list::get_preset_filename(bool builtin)
{
- const char *home = getenv("HOME");
- return string(home)+"/.calfpresets";
+ if (builtin)
+ {
+ return PKGLIBDIR "/presets.xml";
+ }
+ else
+ {
+ const char *home = getenv("HOME");
+ return string(home)+"/.calfpresets";
+ }
}
void preset_list::xml_start_element_handler(void *user_data, const char *name, const char *attrs[])
@@ -246,20 +253,11 @@ bool preset_list::load_defaults(bool builtin)
{
try {
struct stat st;
- if (!builtin)
- {
- if (!stat(preset_list::get_preset_filename().c_str(), &st)) {
- load(preset_list::get_preset_filename().c_str());
- if (!presets.empty())
- return true;
- }
- }
- else
- {
- if (presets.empty() && !stat(PKGLIBDIR "/presets.xml", &st)) {
- load(PKGLIBDIR "/presets.xml");
+ string name = preset_list::get_preset_filename(builtin);
+ if (!stat(name.c_str(), &st)) {
+ load(name.c_str());
+ if (!presets.empty())
return true;
- }
}
}
catch(preset_exception &ex)
diff --git a/src/preset_gui.cpp b/src/preset_gui.cpp
index 6880767..c3d799a 100644
--- a/src/preset_gui.cpp
+++ b/src/preset_gui.cpp
@@ -73,7 +73,7 @@ void synth::store_preset(GtkWindow *toplevel, plugin_gui *gui)
sp.get_from(gui->plugin);
preset_list tmp;
try {
- tmp.load(tmp.get_preset_filename().c_str());
+ tmp.load(tmp.get_preset_filename(false).c_str());
}
catch(...)
{
@@ -99,7 +99,7 @@ void synth::store_preset(GtkWindow *toplevel, plugin_gui *gui)
}
tmp.add(sp);
get_user_presets() = tmp;
- get_user_presets().save(tmp.get_preset_filename().c_str());
+ get_user_presets().save(tmp.get_preset_filename(false).c_str());
gui->window->main->refresh_all_presets(false);
}
//gtk_window_set_transient_for(GTK_WINDOW(store_preset_dlg), toplevel);
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list