LMMS
Loading...
Searching...
No Matches
preset.h
Go to the documentation of this file.
1/* Calf DSP Library
2 * Preset management
3 *
4 * Copyright (C) 2007 Krzysztof Foltman
5 *
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.
10 *
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.
15 *
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., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02111-1307, USA.
20 */
21#ifndef __CALF_PRESET_H
22#define __CALF_PRESET_H
23
24#include <vector>
25#include <string.h>
26#include "utils.h"
27
28namespace calf_plugins {
29
30struct plugin_ctl_iface;
31
34{
36 int bank;
40 std::string name;
42 std::string plugin;
44 std::vector<std::string> param_names;
46 std::vector<float> values;
48 std::map<std::string, std::string> variables;
49
52 std::string to_xml();
57
58 std::string get_safe_name();
59};
60
63{
64 std::string message, param, fulltext;
65 int error;
66 preset_exception(const std::string &_message, const std::string &_param, int _error)
67 : message(_message), param(_param), error(_error)
68 {
69 }
70 const char *what() {
71 if (error)
72 fulltext = message + " " + param + " (" + strerror(error) + ")";
73 else
74 fulltext = message + " " + param;
75 return fulltext.c_str();
76 }
78 {
79 }
80};
81
83typedef std::vector<plugin_preset> preset_vector;
84
87{
90 {
94 std::string type;
96 std::string instance_name;
104 std::vector<std::pair<std::string, std::string> > automation_entries;
105
107 void reset();
108 };
109
122
130 std::map<std::string, int> last_preset_ids;
132 std::string current_key;
136 std::vector<plugin_snapshot> plugins;
137
139 static std::string get_preset_filename(bool builtin, const std::string *pkglibdir_path = NULL);
141 bool load_defaults(bool builtin, const std::string *pkglibdir_path = NULL);
143 void parse(const std::string &data, bool in_rack_mode);
145 void load(const char *filename, bool in_rack_mode);
147 void save(const char *filename);
149 void add(const plugin_preset &sp);
151 void get_for_plugin(preset_vector &vec, const char *plugin);
152
153protected:
155 static void xml_start_element_handler(void *user_data, const char *name, const char *attrs[]);
157 static void xml_end_element_handler(void *user_data, const char *name);
159 static void xml_character_data_handler(void *user_data, const char *data, int len);
160};
161
164
167
168};
169
170#endif
#define NULL
Definition CarlaBridgeFormat.cpp:30
uint8_t sp
Definition Spc_Cpu.h:145
static char filename[]
Definition features.c:5
static const char * name
Definition pugl.h:1582
JSAMPIMAGE data
Definition jpeglib.h:945
Definition benchmark.cpp:53
preset_list & get_user_presets()
Return the current list of user-defined presets (these are loaded from ~/.calfpresets).
Definition preset.cpp:44
std::vector< plugin_preset > preset_vector
A vector of presets.
Definition preset.h:83
preset_list & get_builtin_presets()
Return the current list of built-in (factory) presets (these are loaded from system-wide file).
Definition preset.cpp:38
Interface for host-GUI-plugin interaction (should be really split in two, but ... meh).
Definition giface.h:389
Contents of single preset.
Definition preset.h:34
std::string to_xml()
Export preset as XML.
Definition preset.cpp:50
std::vector< float > values
Values of parameters.
Definition preset.h:46
plugin_preset()
Definition preset.h:50
void get_from(plugin_ctl_iface *plugin)
"Download" preset content from the plugin
Definition preset.cpp:116
std::string plugin
Name of the plugin the preset is for.
Definition preset.h:42
std::map< std::string, std::string > variables
DSSI configure-style variables.
Definition preset.h:48
int program
Program number of the preset (not used yet).
Definition preset.h:38
std::string name
Name of the preset.
Definition preset.h:40
std::vector< std::string > param_names
Names of parameters in values array (for each item in param_names there should be a counterpart in va...
Definition preset.h:44
void activate(plugin_ctl_iface *plugin)
"Upload" preset content to the plugin
Definition preset.cpp:79
int bank
Bank the preset belongs to (not used yet).
Definition preset.h:36
std::string get_safe_name()
Definition preset.cpp:68
std::string message
Definition preset.h:64
~preset_exception()
Definition preset.h:77
const char * what()
Definition preset.h:70
int error
Definition preset.h:65
preset_exception(const std::string &_message, const std::string &_param, int _error)
Definition preset.h:66
std::string param
Definition preset.h:64
std::string fulltext
Definition preset.h:64
Plugin list item.
Definition preset.h:90
int output_index
Index of the first output port.
Definition preset.h:100
int input_index
Index of the first input port.
Definition preset.h:98
int midi_index
Index of the first MIDI port.
Definition preset.h:102
std::string instance_name
Instance name.
Definition preset.h:96
std::string type
Plugin type.
Definition preset.h:94
int preset_offset
Preset offset.
Definition preset.h:92
std::vector< std::pair< std::string, std::string > > automation_entries
Automation assignments for this plugin.
Definition preset.h:104
void reset()
Reset to initial values.
Definition preset.cpp:152
A single list of presets (usually there are two -.
Definition preset.h:87
void load(const char *filename, bool in_rack_mode)
Load preset list from XML file.
Definition preset.cpp:384
std::map< std::string, int > last_preset_ids
Preset number counters for DSSI (currently broken).
Definition preset.h:130
plugin_preset parser_preset
Temporary preset used during parsing process.
Definition preset.h:126
std::string current_key
The key used in current tag (for state == VAR).
Definition preset.h:132
void parse(const std::string &data, bool in_rack_mode)
Load preset list from an in-memory XML string.
Definition preset.cpp:367
void add(const plugin_preset &sp)
Append or replace a preset (replaces a preset with the same plugin and preset name).
Definition preset.cpp:440
static void xml_start_element_handler(void *user_data, const char *name, const char *attrs[])
Internal function: start element handler for expat.
Definition preset.cpp:160
bool load_defaults(bool builtin, const std::string *pkglibdir_path=NULL)
Load default preset list (built-in or user-defined).
Definition preset.cpp:349
static void xml_end_element_handler(void *user_data, const char *name)
Internal function: end element handler for expat.
Definition preset.cpp:279
preset_vector presets
Contained presets (usually for all plugins).
Definition preset.h:124
plugin_snapshot parser_plugin
Temporary plugin desc used during parsing process.
Definition preset.h:128
enum calf_plugins::preset_list::parser_state state
void save(const char *filename)
Save preset list as XML file.
Definition preset.cpp:417
static void xml_character_data_handler(void *user_data, const char *data, int len)
Internal function: character data (tag text content) handler for expat.
Definition preset.cpp:338
std::vector< plugin_snapshot > plugins
List of plugin states for rack mode.
Definition preset.h:136
parser_state
Parser states.
Definition preset.h:112
@ PRESET
Inside preset definition.
Definition preset.h:115
@ PLUGIN
Inside plugin element (calfjackhost snapshots only).
Definition preset.h:118
@ START
Beginning of parsing process (before root element).
Definition preset.h:113
@ VALUE
Inside (empty) param tag.
Definition preset.h:116
@ RACK
Inside rack element (calfjackhost snapshots only).
Definition preset.h:119
@ LIST
Inside root element.
Definition preset.h:114
@ AUTOMATION_ENTRY
inside automation element (calfjackhost snapshots only, always an empty element)
Definition preset.h:120
@ VAR
Inside (non-empty) var tag.
Definition preset.h:117
void get_for_plugin(preset_vector &vec, const char *plugin)
Get a sublist of presets for a given plugin (those with plugin_preset::plugin == plugin).
Definition preset.cpp:431
static std::string get_preset_filename(bool builtin, const std::string *pkglibdir_path=NULL)
Return the name of the built-in or user-defined preset file.
Definition preset.cpp:137
bool rack_mode
The file is loaded in rack mode (and rack/plugin elements are expected).
Definition preset.h:134