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 
21 namespace ladspa {
22 
23 /****************************************************************
24  ** PortDesc
25  */
26 
29 };
30 
32 public:
33  enum { name_set = 0x01, dflt_set = 0x02, low_set = 0x04, up_set = 0x08, tp_set = 0x10, newrow_set = 0x20 };
34 private:
35  Glib::ustring name;
36  float dflt;
37  float low;
38  float up;
39  DisplayType tp;
40  std::map<int, Glib::ustring> enumdict;
41  bool newrow;
42  int set_flags;
43  inline void sf(int f) { set_flags |= f; }
44  friend bool operator!=(const ChangeableValues& v1, const ChangeableValues& v2);
45 public:
46  ChangeableValues(): name(), dflt(), low(), up(), tp(tp_scale), enumdict(), newrow(), set_flags(0) {}
49  int get_excl_flags(DisplayType tp) const;
50  bool has_settings(DisplayType tp) const;
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 
72 enum step_mode {
76 };
77 
78 class PortDesc {
79 private:
80 public:
81  int idx;
82  int pos;
83  bool is_output;
84  LADSPA_PortRangeHintDescriptor hint_desc;
85  bool fake_low;
86  bool fake_up;
87  bool fake_dflt;
89  bool use_sr;
90  bool has_sr;
94  static const int SR = 44100;
95 public:
96  void set_range_default(const LADSPA_PortRangeHint& h, ChangeableValues& store);
97  void set_default_value(const LADSPA_PortRangeHint& h, ChangeableValues& store);
98  void set_tp_default(const LADSPA_PortRangeHint& h, ChangeableValues& store);
99  float calc_step();
100  void set_default(float value, Glib::ustring label);
101  void output(gx_system::JsonWriter& jw);
102  friend bool cmp_ctrl_ports(const PortDesc *a, const PortDesc *b);
103 public:
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);
111  inline DisplayType get_tp() { return user.is_set(ChangeableValues::tp_set) ? user.get_tp() : factory.get_tp(); }
112  inline float get_low() { return user.is_set(ChangeableValues::low_set) ? user.get_low() : factory.get_low(); }
113  inline float get_up() { return user.is_set(ChangeableValues::up_set) ? user.get_up() : factory.get_up(); }
114  inline float get_dflt() { return user.is_set(ChangeableValues::dflt_set) ? user.get_dflt() : factory.get_dflt(); }
115  inline bool get_newrow() { return user.is_set(ChangeableValues::newrow_set) ? user.get_newrow() : factory.get_newrow(); }
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);
121  void set_tp(DisplayType v);
122  void set_newrow(bool v);
123  bool has_settings();
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 
134 class PluginDesc {
135 public:
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;
149  int quirks;
151  bool is_lv2;
152  std::string ladspa_category;
153  bool active;
158 public:
159  int quirks_get();
160  void reset();
161  bool check_changed();
162  bool _i_check_has_settings();
163  void check_has_settings();
164  int set_active(bool v);
165  void fixup();
166  void set_add_wet_dry_controller(bool v);
167  void copy_ports(PluginDesc *p);
168  void set_category(const std::vector<Glib::ustring>& s);
169  void set_default(int idx, float value, const Glib::ustring& label);
170  void set_state(const Glib::ustring& fname);
171 private:
172  PluginDesc(const LADSPA_Descriptor& desc, int tp_, std::vector<PortDesc*>& ctrl_ports_, const std::string path_, int index_);
173  PluginDesc(LilvWorld *world, const LilvPlugin* plugin, int tp_, std::vector<PortDesc*>& ctrl_ports_);
175  ~PluginDesc();
177  friend class LadspaPluginList;
178 public:
179  void set_old();
180  void clear_old() { delete old; old = 0; }
181  void output_entry(gx_system::JsonWriter& jw);
182  void output(gx_system::JsonWriter& jw);
183 };
184 
185 
186 /****************************************************************
187  ** class LadspaPluginList
188  */
189 
190 struct LV2Preset {
191  std::string sname;
192  std::vector<PortDesc*> ctrl_ports;
193  LilvPlugin* plugin;
194  unsigned int num_ports;
195  std::string cline;
197 };
198 
199 
200 class LadspaPluginList: private std::vector<PluginDesc*> {
201 private:
202  typedef std::map<std::string, PluginDesc*> pluginmap;
203  LilvWorld* world;
204  const LilvPlugins* lv2_plugins;
205  LilvNode* lv2_AudioPort;
206  LilvNode* lv2_ControlPort;
207  LilvNode* lv2_InputPort;
208  LilvNode* lv2_OutputPort;
209  LilvNode* lv2_connectionOptional;
210 private:
211  static char** uris;
212  static size_t n_uris;
213  static LV2_URID map_uri(LV2_URID_Map_Handle handle, const char* uri);
214  static const char* unmap_uri(LV2_URID_Map_Handle handle, LV2_URID urid);
215  static void get_preset_values(const char* port_symbol, void* user_data, const void* value, uint32_t size, uint32_t type);
216  static void set_preset_values(Glib::ustring port_symbol, LV2Preset* pdata, Glib::ustring value);
217  static inline std::string make_key(unsigned long unique_id) { return "ladspa://" + gx_system::to_string(unique_id); }
218  static void add_plugin(const LADSPA_Descriptor& desc, pluginmap& d, const std::string& path, int index);
219  static void load_defs(const std::string& path, pluginmap& d);
220  static void set_instances(const char *uri, pluginmap& d, std::vector<Glib::ustring>& label,
221  std::vector<unsigned long>& not_found, std::set<unsigned long>& seen);
222  static void descend(const char *uri, pluginmap& d,
223  std::vector<unsigned long>& not_found, std::set<unsigned long>& seen,
224  std::vector<Glib::ustring>& base);
225  void add_plugin(const LilvPlugin* plugin, pluginmap& d, gx_system::CmdlineOptions& options);
226  void lv2_load(pluginmap& d, gx_system::CmdlineOptions& options);
227  void get_presets(LV2Preset *pdata);
228 public:
230  ~LadspaPluginList();
232  void readJSON(gx_system::JsonParser& jp);
233  void writeJSON(gx_system::JsonWriter& jw);
234  void load(gx_system::CmdlineOptions& options, std::vector<std::string>& old_not_found);
235  void save(gx_system::CmdlineOptions& options);
236  using std::vector<PluginDesc*>::begin;
238 };
239 
240 } // namespace ladspa
CmdConnection::msg_type end
Definition: jsonrpc.cpp:256
void set_enumvalue(int k, const Glib::ustring &v)
Definition: ladspaback.h:66
Glib::ustring Maker
Definition: ladspaback.h:140
DisplayType
Definition: ladspaback.h:27
void erase_enum(int k)
Definition: ladspaback.h:68
DisplayType get_tp()
Definition: ladspaback.h:111
unsigned int num_ports
Definition: ladspaback.h:194
std::string cline
Definition: ladspaback.h:195
const Glib::ustring & get_name()
Definition: ladspaback.h:59
Glib::ustring category
Definition: ladspaback.h:147
std::string sname
Definition: ladspaback.h:191
friend bool operator!=(const ChangeableValues &v1, const ChangeableValues &v2)
Definition: ladspaback.cpp:97
Glib::ustring Label
Definition: ladspaback.h:137
std::map< int, Glib::ustring >::iterator enum_end()
Definition: ladspaback.h:69
void serializeJSON(gx_system::JsonWriter &jw)
Definition: ladspaback.cpp:162
ChangeableValues factory
Definition: ladspaback.h:92
int get_excl_flags(DisplayType tp) const
Definition: ladspaback.cpp:180
bool has_enumkey(int k)
Definition: ladspaback.h:65
std::vector< PortDesc * > ctrl_ports
Definition: ladspaback.h:144
void set_up(float v)
Definition: ladspaback.h:56
std::string ladspa_category
Definition: ladspaback.h:152
DisplayType get_tp()
Definition: ladspaback.h:63
float get_dflt()
Definition: ladspaback.h:114
PluginDesc * old
Definition: ladspaback.h:157
const Glib::ustring & get_name()
Definition: ladspaback.h:116
std::vector< PortDesc * > ctrl_ports
Definition: ladspaback.h:192
Glib::ustring deduced_category
Definition: ladspaback.h:148
Glib::ustring Name
Definition: ladspaback.h:138
bool has_settings(DisplayType tp) const
Definition: ladspaback.cpp:190
void set_newrow(bool v)
Definition: ladspaback.h:58
bool cmp_ctrl_ports(const PortDesc *a, const PortDesc *b)
Definition: ladspaback.cpp:861
step_mode step
Definition: ladspaback.h:88
bool is_set(int f)
Definition: ladspaback.h:125
LilvPlugin * plugin
Definition: ladspaback.h:193
LADSPA_PortRangeHintDescriptor hint_desc
Definition: ladspaback.h:84
void set_tp(DisplayType v)
Definition: ladspaback.h:57
bool is_set(int f) const
Definition: ladspaback.h:51
std::string to_string(const T &t)
Definition: gx_system.h:525
Glib::ustring MasterLabel
Definition: ladspaback.h:142
ChangeableValues user
Definition: ladspaback.h:93
Glib::ustring shortname
Definition: ladspaback.h:139
void set_low(float v)
Definition: ladspaback.h:55
void set_name(const Glib::ustring &nm)
Definition: ladspaback.h:53
bool enumkey_changed(int k)
Definition: ladspaback.h:124
unsigned long UniqueID
Definition: ladspaback.h:136
void set_dflt(float v)
Definition: ladspaback.h:54
std::map< int, Glib::ustring >::iterator find_enum(int k)
Definition: ladspaback.h:67
std::string path
Definition: ladspaback.h:145