Guitarix
ladspaback.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012, 2013 Andreas Degert, Hermann Meyer
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#include <ladspa.h>
20
21namespace ladspa {
22
23/****************************************************************
24 ** PortDesc
25 */
26
29};
30
32public:
33 enum { name_set = 0x01, dflt_set = 0x02, low_set = 0x04, up_set = 0x08, tp_set = 0x10, newrow_set = 0x20 };
34private:
35 Glib::ustring name;
36 float dflt;
37 float low;
38 float up;
40 std::map<int, Glib::ustring> enumdict;
41 bool newrow;
43 inline void sf(int f) { set_flags |= f; }
44 friend bool operator!=(const ChangeableValues& v1, const ChangeableValues& v2);
45public:
51 inline bool is_set(int f) const { return set_flags & f; }
52 inline void unset(int f) { set_flags &= ~f; }
53 inline void set_name(const Glib::ustring& nm) { name = nm; sf(name_set); }
54 inline void set_dflt(float v) { dflt = v; sf(dflt_set); }
55 inline void set_low(float v) { low = v; sf(low_set); }
56 inline void set_up(float v) { up = v; sf(up_set); }
57 inline void set_tp(DisplayType v) { tp = v; sf(tp_set); }
58 inline void set_newrow(bool v) { newrow = v; sf(newrow_set); }
59 inline const Glib::ustring& get_name() { return name; }
60 inline float get_dflt() { return dflt; }
61 inline float get_low() { return low; }
62 inline float get_up() { return up; }
63 inline DisplayType get_tp() { return tp; }
64 inline bool get_newrow() { return newrow; }
65 inline bool has_enumkey(int k) { return enumdict.find(k) != enumdict.end(); }
66 void set_enumvalue(int k, const Glib::ustring& v) { enumdict[k] = v; }
67 inline std::map<int, Glib::ustring>::iterator find_enum(int k) { return enumdict.find(k); }
68 inline void erase_enum(int k) { enumdict.erase(enumdict.find(k)); }
69 inline std::map<int, Glib::ustring>::iterator enum_end() { return enumdict.end(); }
70};
71
76};
77
78class PortDesc {
79private:
80public:
81 int idx;
82 int pos;
86 bool fake_up;
89 bool use_sr;
90 bool has_sr;
94 static const int SR = 44100;
95public:
99 float calc_step();
100 void set_default(float value, Glib::ustring label);
102 friend bool cmp_ctrl_ports(const PortDesc *a, const PortDesc *b);
103public:
104 PortDesc(int idx_, int pos_, bool is_output_, Glib::ustring name, const LADSPA_PortRangeHint& hint);
107 void reset();
108 void fixup(bool newrow);
109 bool check_changed(const PortDesc& vp) const;
110 Glib::ustring get_enum(int idx);
116 const Glib::ustring& get_name() { return user.is_set(ChangeableValues::name_set) ? user.get_name() : factory.get_name(); }
117 inline int get_pos() { return pos; }
118 void set_low(float v);
119 void set_up(float v);
120 void set_dflt(float v);
122 void set_newrow(bool v);
124 bool enumkey_changed(int k) { return user.has_enumkey(k); }
125 bool is_set(int f) { return user.is_set(f); }
126 void set_state(gx_system::JsonParser& jp, int version);
127};
128
129
130/****************************************************************
131 ** class PluginDesc
132 */
133
135public:
136 unsigned long UniqueID;
137 Glib::ustring Label;
138 Glib::ustring Name;
139 Glib::ustring shortname;
140 Glib::ustring Maker;
142 Glib::ustring MasterLabel;
143 int tp;
144 std::vector<PortDesc*> ctrl_ports;
145 std::string path;
146 int index;
147 Glib::ustring category;
148 Glib::ustring deduced_category;
151 bool is_lv2;
152 std::string ladspa_category;
153 bool active;
159public:
161 void reset();
165 int set_active(bool v);
166 void fixup();
168 void set_stereo_to_mono(bool v);
170 void set_category(const std::vector<Glib::ustring>& s);
171 void set_default(int idx, float value, const Glib::ustring& label);
172 void set_state(const Glib::ustring& fname);
173private:
174 PluginDesc(const LADSPA_Descriptor& desc, int tp_, std::vector<PortDesc*>& ctrl_ports_, const std::string path_, int index_);
175 PluginDesc(LilvWorld *world, const LilvPlugin* plugin, int tp_, std::vector<PortDesc*>& ctrl_ports_);
179 friend class LadspaPluginList;
180public:
181 void set_old();
182 void clear_old() { delete old; old = 0; }
185};
186
187/****************************************************************
188 ** class LadspaPluginList
189 */
190
191struct LV2Preset {
192 std::string sname;
193 std::vector<PortDesc*> ctrl_ports;
194 LilvPlugin* plugin;
195 unsigned int num_ports;
196 std::string cline;
198};
199
200
201class LadspaPluginList: private std::vector<PluginDesc*> {
202private:
203 typedef std::map<std::string, PluginDesc*> pluginmap;
204 LilvWorld* world;
205 const LilvPlugins* lv2_plugins;
206 LilvNode* lv2_AudioPort;
208 LilvNode* lv2_InputPort;
209 LilvNode* lv2_OutputPort;
211 LilvNode* lv2_AtomPort;
212private:
213 bool feature_is_supported(const char* uri);
214 static void get_preset_values(const char* port_symbol, void* user_data, const void* value, uint32_t size, uint32_t type);
215 static void set_preset_values(Glib::ustring port_symbol, LV2Preset* pdata, Glib::ustring value);
216 static inline std::string make_key(unsigned long unique_id) { return "ladspa://" + gx_system::to_string(unique_id); }
217 static void add_plugin(const LADSPA_Descriptor& desc, pluginmap& d, const std::string& path, int index);
218 static void load_defs(const std::string& path, pluginmap& d);
219 static void set_instances(const char *uri, pluginmap& d, std::vector<Glib::ustring>& label,
220 std::vector<unsigned long>& not_found, std::set<unsigned long>& seen);
221 static void descend(const char *uri, pluginmap& d,
222 std::vector<unsigned long>& not_found, std::set<unsigned long>& seen,
223 std::vector<Glib::ustring>& base);
224 void add_plugin(const LilvPlugin* plugin, pluginmap& d, gx_system::CmdlineOptions& options);
227public:
233 void load(gx_system::CmdlineOptions& options, std::vector<std::string>& old_not_found);
235 using std::vector<PluginDesc*>::begin;
236 using std::vector<PluginDesc*>::end;
237};
238
239} // namespace ladspa
bool has_settings(DisplayType tp) const
const Glib::ustring & get_name()
Definition: ladspaback.h:59
void serializeJSON(gx_system::JsonWriter &jw)
ChangeableValues(gx_system::JsonParser &jp)
bool is_set(int f) const
Definition: ladspaback.h:51
void set_enumvalue(int k, const Glib::ustring &v)
Definition: ladspaback.h:66
int get_excl_flags(DisplayType tp) const
std::map< int, Glib::ustring > enumdict
Definition: ladspaback.h:40
bool has_enumkey(int k)
Definition: ladspaback.h:65
void erase_enum(int k)
Definition: ladspaback.h:68
void set_low(float v)
Definition: ladspaback.h:55
std::map< int, Glib::ustring >::iterator find_enum(int k)
Definition: ladspaback.h:67
Glib::ustring name
Definition: ladspaback.h:35
std::map< int, Glib::ustring >::iterator enum_end()
Definition: ladspaback.h:69
void set_dflt(float v)
Definition: ladspaback.h:54
void set_newrow(bool v)
Definition: ladspaback.h:58
DisplayType get_tp()
Definition: ladspaback.h:63
friend bool operator!=(const ChangeableValues &v1, const ChangeableValues &v2)
void set_up(float v)
Definition: ladspaback.h:56
void set_tp(DisplayType v)
Definition: ladspaback.h:57
void set_name(const Glib::ustring &nm)
Definition: ladspaback.h:53
static void descend(const char *uri, pluginmap &d, std::vector< unsigned long > &not_found, std::set< unsigned long > &seen, std::vector< Glib::ustring > &base)
void readJSON(gx_system::JsonParser &jp)
void get_presets(LV2Preset *pdata)
static void add_plugin(const LADSPA_Descriptor &desc, pluginmap &d, const std::string &path, int index)
void lv2_load(pluginmap &d, gx_system::CmdlineOptions &options)
static void set_preset_values(Glib::ustring port_symbol, LV2Preset *pdata, Glib::ustring value)
LilvNode * lv2_connectionOptional
Definition: ladspaback.h:210
std::map< std::string, PluginDesc * > pluginmap
Definition: ladspaback.h:203
static void set_instances(const char *uri, pluginmap &d, std::vector< Glib::ustring > &label, std::vector< unsigned long > &not_found, std::set< unsigned long > &seen)
void load(gx_system::CmdlineOptions &options, std::vector< std::string > &old_not_found)
static std::string make_key(unsigned long unique_id)
Definition: ladspaback.h:216
void writeJSON(gx_system::JsonWriter &jw)
static void load_defs(const std::string &path, pluginmap &d)
static void get_preset_values(const char *port_symbol, void *user_data, const void *value, uint32_t size, uint32_t type)
const LilvPlugins * lv2_plugins
Definition: ladspaback.h:205
void add_plugin(const LilvPlugin *plugin, pluginmap &d, gx_system::CmdlineOptions &options)
bool feature_is_supported(const char *uri)
void save(gx_system::CmdlineOptions &options)
LilvNode * lv2_ControlPort
Definition: ladspaback.h:207
PluginDesc(gx_system::JsonParser &jp)
Glib::ustring shortname
Definition: ladspaback.h:139
void output_entry(gx_system::JsonWriter &jw)
void set_category(const std::vector< Glib::ustring > &s)
Glib::ustring Name
Definition: ladspaback.h:138
void set_add_wet_dry_controller(bool v)
void output(gx_system::JsonWriter &jw)
Glib::ustring Maker
Definition: ladspaback.h:140
PluginDesc(LilvWorld *world, const LilvPlugin *plugin, int tp_, std::vector< PortDesc * > &ctrl_ports_)
int set_active(bool v)
Glib::ustring category
Definition: ladspaback.h:147
std::string ladspa_category
Definition: ladspaback.h:152
PluginDesc(const LADSPA_Descriptor &desc, int tp_, std::vector< PortDesc * > &ctrl_ports_, const std::string path_, int index_)
Glib::ustring MasterLabel
Definition: ladspaback.h:142
Glib::ustring Label
Definition: ladspaback.h:137
std::string path
Definition: ladspaback.h:145
void set_state(const Glib::ustring &fname)
bool _i_check_has_settings()
void copy_ports(PluginDesc *p)
unsigned long UniqueID
Definition: ladspaback.h:136
PluginDesc * old
Definition: ladspaback.h:158
std::vector< PortDesc * > ctrl_ports
Definition: ladspaback.h:144
void serializeJSON(gx_system::JsonWriter &jw)
Glib::ustring deduced_category
Definition: ladspaback.h:148
void set_stereo_to_mono(bool v)
void set_default(int idx, float value, const Glib::ustring &label)
bool check_changed(const PortDesc &vp) const
void output(gx_system::JsonWriter &jw)
PortDesc(int idx_, int pos_, bool is_output_, Glib::ustring name, const LADSPA_PortRangeHint &hint)
PortDesc(gx_system::JsonParser &jp)
void set_state(gx_system::JsonParser &jp, int version)
void set_newrow(bool v)
void set_tp(DisplayType v)
void set_tp_default(const LADSPA_PortRangeHint &h, ChangeableValues &store)
void set_up(float v)
void set_default(float value, Glib::ustring label)
Glib::ustring get_enum(int idx)
friend bool cmp_ctrl_ports(const PortDesc *a, const PortDesc *b)
void fixup(bool newrow)
void set_low(float v)
static const int SR
Definition: ladspaback.h:94
DisplayType get_tp()
Definition: ladspaback.h:111
void set_dflt(float v)
bool enumkey_changed(int k)
Definition: ladspaback.h:124
void set_range_default(const LADSPA_PortRangeHint &h, ChangeableValues &store)
void set_default_value(const LADSPA_PortRangeHint &h, ChangeableValues &store)
ChangeableValues factory
Definition: ladspaback.h:92
void serializeJSON(gx_system::JsonWriter &jw)
ChangeableValues user
Definition: ladspaback.h:93
LADSPA_PortRangeHintDescriptor hint_desc
Definition: ladspaback.h:84
step_mode step
Definition: ladspaback.h:88
const Glib::ustring & get_name()
Definition: ladspaback.h:116
float get_dflt()
Definition: ladspaback.h:114
bool is_set(int f)
Definition: ladspaback.h:125
int LADSPA_PortRangeHintDescriptor
Definition: ladspa.h:200
std::string to_string(const T &t)
Definition: gx_system.h:561
@ stp_coarse
Definition: ladspaback.h:73
@ stp_normal
Definition: ladspaback.h:74
@ stp_fine
Definition: ladspaback.h:75
DisplayType
Definition: ladspaback.h:27
@ tp_atom
Definition: ladspaback.h:28
@ tp_enum
Definition: ladspaback.h:28
@ tp_display
Definition: ladspaback.h:28
@ tp_display_toggle
Definition: ladspaback.h:28
@ tp_enabled
Definition: ladspaback.h:28
@ tp_scale_log
Definition: ladspaback.h:28
@ tp_none
Definition: ladspaback.h:28
@ tp_int
Definition: ladspaback.h:28
@ tp_scale
Definition: ladspaback.h:28
@ tp_toggle
Definition: ladspaback.h:28
unsigned int num_ports
Definition: ladspaback.h:195
std::vector< PortDesc * > ctrl_ports
Definition: ladspaback.h:193
std::string sname
Definition: ladspaback.h:192
std::string cline
Definition: ladspaback.h:196
LilvPlugin * plugin
Definition: ladspaback.h:194