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_NEED_UPDATE = 0x80000, // Plugin needs update
42 };
43 
44 class Plugin {
45 private:
46  PluginDef *pdef;
47  BoolParameter *p_box_visible; // In Rack: UI Interface Box visible
48  BoolParameter *p_plug_visible; // In Box: UI Interface Box visible
49  BoolParameter *p_on_off; // Audio Processing
50  IntParameter *p_position; // Position in Rack / Audio Processing Chain
51  IntParameter *p_effect_post_pre; // pre/post amp position (post = 0)
52  int pos_tmp;
53 public:
54  PluginDef *get_pdef() { return pdef; }
55  void set_pdef(PluginDef *p) { pdef = p; }
56  enum { POST_WEIGHT = 2000 };
57  Plugin(PluginDef *pl=0);
59  void writeJSON(gx_system::JsonWriter& jw);
60  bool get_box_visible() const { return p_box_visible && p_box_visible->get_value(); }
61  bool get_plug_visible() const { return p_plug_visible && p_plug_visible->get_value(); }
62  bool get_on_off() const { return p_on_off->get_value(); }
63  int get_position() const { return p_position->get_value(); }
64  int get_effect_post_pre() const { return p_effect_post_pre->get_value(); }
65  void set_box_visible(bool v) const { if (p_box_visible) p_box_visible->set(v); }
66  void set_plug_visible(bool v) const { if (p_plug_visible) p_plug_visible->set(v); }
67  void set_on_off(bool v) const { p_on_off->set(v); }
68  void set_position(int v) const { p_position->set(v); }
69  void set_effect_post_pre(int v) const { p_effect_post_pre->set(v); }
70  const std::string& id_box_visible() const { return p_box_visible->id(); }
71  const std::string& id_plug_visible() const { return p_plug_visible->id(); }
72  const std::string& id_on_off() const { return p_on_off->id(); }
73  const std::string& id_position() const { return p_position->id(); }
74  const std::string& id_effect_post_pre() const { return p_effect_post_pre->id(); }
75  inline int position_weight() { return get_effect_post_pre() ? get_position() : get_position() + POST_WEIGHT; }
76  void register_vars(ParamMap& param, EngineControl& seq);
77  void copy_position(const Plugin& plugin);
78  friend class PluginListBase;
79  friend class PluginList;
80  friend void printlist(const char *title, const list<Plugin*>& modules, bool header);
81 };
82 
83 /****************************************************************
84  ** class UiBuilderBase
85  */
86 
87 class UiBuilderBase: public UiBuilder {
88 public:
89  virtual bool load(Plugin *p) = 0;
90 };
91 
92 /****************************************************************
93  ** class ParamRegImpl
94  */
95 
96 class ParamRegImpl: public ParamReg {
97 private:
98  static ParamMap *pmap;
99  static float *registerVar_(const char* id, const char* name, const char* tp,
100  const char* tooltip, float* var, float val,
101  float low, float up, float step);
102  static void registerBoolVar_(const char* id, const char* name, const char* tp,
103  const char* tooltip, bool* var, bool val);
104  static void registerNonMidiVar_(const char * id, bool*var, bool preset, bool nosave);
105  static void registerNonMidiFloatVar_(const char * id, float *var, bool preset, bool nosave,
106  float val, float low, float up, float step);
107  static void registerEnumVar_(const char *id, const char* name, const char* tp,
108  const char* tooltip, const value_pair* values, float *var, float val,
109  float low, float up, float step);
110  static float *registerSharedEnumVar_(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 void registerIEnumVar_(const char *id, const char* name, const char* tp,
114  const char* tooltip, const value_pair* values, int *var, int val);
115 public:
116  ParamRegImpl(ParamMap* pm);
117 };
118 
119 /****************************************************************
120  ** class PluginList
121  ** container of plugins for all processing chains
122  */
123 
124 enum PluginPos { // where to add a plugin (per processing chain)
127  PLUGIN_POS_END // keep last one
128 };
129 
130 typedef PluginDef *(*plugindef_creator)();
131 
133 public:
134  typedef pair<const std::string, Plugin*> map_pair;
135  typedef map<const std::string, Plugin*> pluginmap;
136 protected:
138  PLUGIN_POS_RACK_STEREO = PLUGIN_POS_END+1,
139  PLUGIN_POS_COUNT // keep last one
140  };
141  pluginmap pmap;
142  sigc::signal<void,const char*,bool> insert_remove;
143 public:
144  PluginListBase();
145  ~PluginListBase();
146  void cleanup();
147  Plugin *find_plugin(const std::string& id) const;
148  Plugin *lookup_plugin(const std::string& id) const;
149  void append_rack(UiBuilderBase& ui);
150  void writeJSON(gx_system::JsonWriter& jw);
151  void readJSON(gx_system::JsonParser& jp, ParamMap& pmap);
152  pluginmap::iterator begin() { return pmap.begin(); }
153  pluginmap::iterator end() { return pmap.end(); }
154  int insert_plugin(Plugin *pvars);
155  void update_plugin(Plugin *pvars);
156  void delete_module(Plugin *pl);
157 };
158 
159 class PluginList: public PluginListBase {
160  EngineControl& seq;
161  int plugin_pos[PLUGIN_POS_COUNT];
162  int add_module(Plugin *pl, PluginPos pos, int flags);
163 public:
165  ~PluginList();
166  void set_samplerate(int samplerate); // call set_samplerate of all plugins
167  int load_from_path(const string& path, PluginPos pos = PLUGIN_POS_RACK);
168  int load_library(const string& path, PluginPos pos = PLUGIN_POS_RACK);
169  int add(Plugin *pl, PluginPos pos, int flags);
170  Plugin *add(PluginDef *p, PluginPos pos = PLUGIN_POS_RACK, int flags=0);
171  int add(PluginDef **p, PluginPos pos = PLUGIN_POS_RACK, int flags=0);
172  int add(plugindef_creator *p, PluginPos pos = PLUGIN_POS_RACK, int flags=0);
173  int check_version(PluginDef *p);
174  void registerGroup(PluginDef *pd, ParameterGroups& groups);
175  void registerParameter(Plugin *pl, ParamMap& param, ParamRegImpl& preg);
176  void registerPlugin(Plugin *pl, ParamMap& param, ParameterGroups& groups);
177  void unregisterGroup(PluginDef *pd, ParameterGroups& groups);
178  void unregisterParameter(Plugin *pl, ParamMap& param);
179  void rescueParameter(Plugin *pl, ParamMap& param);
180  void unregisterPlugin(Plugin *pl, ParamMap& param, ParameterGroups& groups);
181  void registerAllPlugins(ParamMap& param, ParameterGroups& groups);
182  void ordered_mono_list(list<Plugin*>& mono, int mode);
183  void ordered_stereo_list(list<Plugin*>& stereo, int mode);
184  void ordered_list(list<Plugin*>& l, bool stereo, int flagmask, int flagvalue);
185  sigc::signal<void,const char*,bool>& signal_insert_remove() { return insert_remove; }
186 #ifndef NDEBUG
187  void printlist(bool ordered = true);
188 #endif
189 };
190 
191 #ifndef NDEBUG
192 void printlist(const char *title, const list<Plugin*>& modules, bool header=true);
193 #else
194 inline void printlist(const char *, const list<Plugin*>&, bool=true) {}
195 #endif
196 
197 } // !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:171
pair< const std::string, Plugin * > map_pair
sigc::signal< void, const char *, bool > & signal_insert_remove()
pluginmap::iterator end()