Guitarix
gx_pluginloader.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Hermann Meyer, James Warden, Andreas Degert, Pete Shorthose
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 // utility class
20 // FIXME should be moved somewhere else
21 struct stringcomp {
22  inline bool operator() (const char* lhs, const char* rhs) const {
23  return strcmp(lhs, rhs) < 0;
24  }
25 };
26 
27 namespace gx_engine {
28 
29 class EngineControl;
30 
31 /****************************************************************
32  ** class Plugin
33  ** Defines audio processing module and variables for
34  ** user interface
35 */
36 
37 enum { // additional flags for PluginDef (used internally)
38  PGNI_DYN_POSITION = 0x10000, // plugin is part of dynamically ordered rack
39  PGNI_NOT_OWN = 0x20000, // not owned by PluginList
40  PGNI_UI_REG = 0x40000, // Plugin registered in user interface
41  PGNI_IS_LV2 = 0x80000, // Plugin is in LV2 format
42  PGNI_IS_LADSPA = 0x100000, // Plugin is in LADSPA format
43 };
44 
45 class Plugin {
46 private:
47  PluginDef *pdef;
48  BoolParameter *p_box_visible; // In Rack: UI Interface Box visible
49  BoolParameter *p_plug_visible; // In Box: UI Interface Box visible
50  BoolParameter *p_on_off; // Audio Processing
51  IntParameter *p_position; // Position in Rack / Audio Processing Chain
52  IntParameter *p_effect_post_pre; // pre/post amp position (post = 0)
53  int pos_tmp;
54 public:
55  PluginDef *get_pdef() { return pdef; }
56  void set_pdef(PluginDef *p) { pdef = p; }
57  enum { POST_WEIGHT = 2000 };
58  Plugin(PluginDef *pl=0);
60  void writeJSON(gx_system::JsonWriter& jw);
61  bool get_box_visible() const { return p_box_visible && p_box_visible->get_value(); }
62  bool get_plug_visible() const { return p_plug_visible && p_plug_visible->get_value(); }
63  bool get_on_off() const { return p_on_off->get_value(); }
64  int get_position() const { return p_position->get_value(); }
65  int get_effect_post_pre() const { return p_effect_post_pre->get_value(); }
66  void set_box_visible(bool v) const { if (p_box_visible) p_box_visible->set(v); }
67  void set_plug_visible(bool v) const { if (p_plug_visible) p_plug_visible->set(v); }
68  void set_on_off(bool v) const { p_on_off->set(v); }
69  void set_position(int v) const { p_position->set(v); }
70  void set_effect_post_pre(int v) const { p_effect_post_pre->set(v); }
71  const std::string& id_box_visible() const { return p_box_visible->id(); }
72  const std::string& id_plug_visible() const { return p_plug_visible->id(); }
73  const std::string& id_on_off() const { return p_on_off->id(); }
74  const std::string& id_position() const { return p_position->id(); }
75  const std::string& id_effect_post_pre() const { return p_effect_post_pre->id(); }
76  inline int position_weight() { return get_effect_post_pre() ? get_position() : get_position() + POST_WEIGHT; }
77  void register_vars(ParamMap& param, EngineControl& seq);
78  void copy_position(const Plugin& plugin);
79  friend class PluginListBase;
80  friend class PluginList;
81  friend void printlist(const char *title, const list<Plugin*>& modules, bool header);
82 };
83 
84 /****************************************************************
85  ** class UiBuilderBase
86  */
87 
88 class UiBuilderBase: public UiBuilder {
89 public:
90  virtual bool load(Plugin *p) = 0;
91 };
92 
93 /****************************************************************
94  ** class ParamRegImpl
95  */
96 
97 class ParamRegImpl: public ParamReg {
98 private:
99  static ParamMap *pmap;
100  static float *registerVar_(const char* id, const char* name, const char* tp,
101  const char* tooltip, float* var, float val,
102  float low, float up, float step);
103  static void registerBoolVar_(const char* id, const char* name, const char* tp,
104  const char* tooltip, bool* var, bool val);
105  static void registerNonMidiVar_(const char * id, bool*var, bool preset, bool nosave);
106  static void registerNonMidiFloatVar_(const char * id, float *var, bool preset, bool nosave,
107  float val, float low, float up, float step);
108  static float *registerNonMidiSharedVar_(const char * id, float *var, bool preset, bool nosave,
109  float val, float low, float up, float step);
110  static void registerEnumVar_(const char *id, const char* name, const char* tp,
111  const char* tooltip, const value_pair* values, float *var, float val,
112  float low, float up, float step);
113  static float *registerSharedEnumVar_(const char *id, const char* name, const char* tp,
114  const char* tooltip, const value_pair* values, float *var, float val,
115  float low, float up, float step);
116  static void registerIEnumVar_(const char *id, const char* name, const char* tp,
117  const char* tooltip, const value_pair* values, int *var, int val);
118 public:
119  ParamRegImpl(ParamMap* pm);
120 };
121 
122 /****************************************************************
123  ** class PluginList
124  ** container of plugins for all processing chains
125  */
126 
127 enum PluginPos { // where to add a plugin (per processing chain)
130  PLUGIN_POS_END // keep last one
131 };
132 
133 typedef PluginDef *(*plugindef_creator)();
134 
136 public:
137  typedef pair<const std::string, Plugin*> map_pair;
138  typedef map<const std::string, Plugin*> pluginmap;
139 protected:
141  PLUGIN_POS_RACK_STEREO = PLUGIN_POS_END+1,
142  PLUGIN_POS_COUNT // keep last one
143  };
144  pluginmap pmap;
145  sigc::signal<void,const char*,bool> insert_remove;
146 public:
147  PluginListBase();
148  ~PluginListBase();
149  void cleanup();
150  Plugin *find_plugin(const std::string& id) const;
151  Plugin *lookup_plugin(const std::string& id) const;
152  void append_rack(UiBuilderBase& ui);
153  void writeJSON(gx_system::JsonWriter& jw);
154  void readJSON(gx_system::JsonParser& jp, ParamMap& pmap);
155  pluginmap::iterator begin() { return pmap.begin(); }
156  pluginmap::iterator end() { return pmap.end(); }
157  int insert_plugin(Plugin *pvars);
158  void update_plugin(Plugin *pvars);
159  void delete_module(Plugin *pl);
160 };
161 
162 class PluginList: public PluginListBase {
163  EngineControl& seq;
164  int plugin_pos[PLUGIN_POS_COUNT];
165  int add_module(Plugin *pl, PluginPos pos, int flags);
166 public:
168  ~PluginList();
169  void set_samplerate(int samplerate); // call set_samplerate of all plugins
170  int load_from_path(const string& path, PluginPos pos = PLUGIN_POS_RACK);
171  int load_library(const string& path, PluginPos pos = PLUGIN_POS_RACK);
172  int add(Plugin *pl, PluginPos pos, int flags);
173  Plugin *add(PluginDef *p, PluginPos pos = PLUGIN_POS_RACK, int flags=0);
174  int add(PluginDef **p, PluginPos pos = PLUGIN_POS_RACK, int flags=0);
175  int add(plugindef_creator *p, PluginPos pos = PLUGIN_POS_RACK, int flags=0);
176  int check_version(PluginDef *p);
177  void registerGroup(PluginDef *pd, ParameterGroups& groups);
178  void registerParameter(Plugin *pl, ParamMap& param, ParamRegImpl& preg);
179  void registerPlugin(Plugin *pl, ParamMap& param, ParameterGroups& groups);
180  void unregisterGroup(PluginDef *pd, ParameterGroups& groups);
181  void unregisterParameter(Plugin *pl, ParamMap& param);
182  void rescueParameter(Plugin *pl, ParamMap& param);
183  void unregisterPlugin(Plugin *pl, ParamMap& param, ParameterGroups& groups);
184  void registerAllPlugins(ParamMap& param, ParameterGroups& groups);
185  void ordered_mono_list(list<Plugin*>& mono, int mode);
186  void ordered_stereo_list(list<Plugin*>& stereo, int mode);
187  void ordered_list(list<Plugin*>& l, bool stereo, int flagmask, int flagvalue);
188  sigc::signal<void,const char*,bool>& signal_insert_remove() { return insert_remove; }
189 #ifndef NDEBUG
190  void printlist(bool ordered = true);
191 #endif
192 };
193 
194 #ifndef NDEBUG
195 void printlist(const char *title, const list<Plugin*>& modules, bool header=true);
196 #else
197 inline void printlist(const char *, const list<Plugin*>&, bool=true) {}
198 #endif
199 
200 } // !namespace gx_engine
PluginDef * get_pdef()
const std::string & id_on_off() const
sigc::signal< void, const char *, bool > insert_remove
bool get_plug_visible() const
void set_pdef(PluginDef *p)
void printlist(const char *title, const list< Plugin *> &modules, bool header=true)
bool get_on_off() const
const std::string & id_plug_visible() const
bool get_box_visible() const
bool operator()(const char *lhs, const char *rhs) const
const std::string & id_box_visible() const
const std::string & id_position() const
int get_effect_post_pre() const
PluginDef *(* plugindef_creator)()
const std::string & id_effect_post_pre() const
void set_effect_post_pre(int v) const
void set_position(int v) const
map< const std::string, Plugin * > pluginmap
void set_plug_visible(bool v) const
pluginmap::iterator begin()
void set_box_visible(bool v) const
void set_on_off(bool v) const
int get_position() const
const string & id() const
Definition: gx_parameter.h:173
pair< const std::string, Plugin * > map_pair
sigc::signal< void, const char *, bool > & signal_insert_remove()
pluginmap::iterator end()