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