Guitarix
gx_plugin.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011, 2013 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  * This file is part of the guitarix GUI main class
20  * Note: this header file depends on gx_system.h
21  *
22  * ----------------------------------------------------------------------------
23  */
24 
25 #pragma once
26 
27 #ifndef _GX_PLUGIN_H
28 #define _GX_PLUGIN_H
29 
30 #include "gx_compiler.h"
31 
32 // forward declarations (need not be resolved for plugin definition)
33 struct PluginDef;
34 
35 /*
36 ** helper class for PluginDef::load_ui
37 */
38 
39 #define UI_NUM_TOP 0x01
40 #define UI_NUM_BOTTOM 0x03
41 #define UI_NUM_LEFT 0x05
42 #define UI_NUM_RIGHT 0x07
43 #define UI_NUM_POSITION_MASK 0x07
44 #define UI_NUM_SHOW_ALWAYS 0x08
45 #define UI_LABEL_INVERSE 0x02
46 
47 // Stock Items for Gxw::Switch
48 
49 #define sw_led "led"
50 #define sw_switch "switch"
51 #define sw_switchit "switchit"
52 #define sw_minitoggle "minitoggle"
53 #define sw_button "button"
54 #define sw_pbutton "pbutton"
55 #define sw_rbutton "rbutton"
56 #define sw_prbutton "prbutton"
57 #define sw_fbutton "fbutton"
58 #define sw_frbutton "frbutton"
59 
60 #define UI_FORM_STACK 0x01
61 #define UI_FORM_GLADE 0x02
62 
63 struct UiBuilder {
65  void (*load_glade)(const char *data);
66  void (*load_glade_file)(const char *fname);
67  void (*openTabBox)(const char* label);
68  void (*openVerticalBox)(const char* label);
69  void (*openVerticalBox1)(const char* label);
70  void (*openVerticalBox2)(const char* label);
71  void (*openHorizontalBox)(const char* label);
72  void (*openHorizontalhideBox)(const char* label);
73  void (*openHorizontalTableBox)(const char *label);
74  void (*openFrameBox)(const char *label);
75  void (*openFlipLabelBox)(const char* label);
76  void (*openpaintampBox)(const char* label);
77  void (*closeBox)();
78  void (*insertSpacer)();
79  void (*set_next_flags)(int flags);
80  // methods creating UI elements connected to parameter_id's.
81  // the check_parameter function in dsp2cc identifies these
82  // functions by the prefix create_ so please stick to this
83  // prefix or change the checker
84  void (*create_master_slider)(const char *id, const char *label);
85  void (*create_feedback_slider)(const char *id, const char *label);
86  void (*create_small_rackknob)(const char *id, const char *label);
87  void (*create_big_rackknob)(const char *id, const char *label);
88  void (*create_selector_no_caption)(const char *id);
89  void (*create_switch_no_caption)(const char *sw_type,const char * id);
90  void (*create_feedback_switch)(const char *sw_type,const char * id);
91  void (*create_spin_value)(const char * id, const char *label);
92  void (*create_port_display)(const char * id, const char *label);
93  void (*create_p_display)(const char * id, const char * idl, const char * idh);
94  void (*create_switch)(const char *sw_type,const char * id, const char *label);
95  void (*create_selector)(const char *id, const char *label);
96  void (*create_simple_meter)(const char *id);
97  void (*create_simple_c_meter)(const char *id, const char *idl, const char *label);
98  void (*create_small_rackknobr)(const char *id, const char *label);
99  void (*create_wheel)(const char *id, const char *label);
100  void (*create_simple_spin_value)(const char *id);
101  void (*create_eq_rackslider_no_caption)(const char *id);
102  void (*create_fload_switch)(const char *sw_type,const char * id,const char * idf);
103  void (*create_mid_rackknob)(const char *id, const char *label);
104  // adding additional functions:
105  // If possible don't change the order of the current defintion.
106  // new functions need to be added at the following places:
107  // StackBoxBuilder: decl, real implementation
108  // UiBuilderImpl: decl, assign to pointer, call real implementation
109  // UiBuilderVirt: decl, assign to pointer, write json
110  // GxMachineRemote::load_remote_ui(): call real implementation
111 };
112 
113 /*
114 ** helper class for PluginDef::registerfunc
115 */
116 
117 struct value_pair {
118  const char *value_id;
119  const char *value_label;
120 };
121 
141 struct ParamReg {
143  float *(*registerFloatVar)(
144  const char* id, const char* name, const char* tp,
145  const char* tooltip, float* var, float val,
146  float low, float up, float step, const value_pair* values);
147  int *(*registerIntVar)(
148  const char* id, const char* name, const char* tp,
149  const char* tooltip, int* var, int val,
150  int low, int up, const value_pair* values);
151  bool *(*registerBoolVar)(
152  const char* id, const char* name, const char* tp,
153  const char* tooltip, bool* var, bool val);
154 };
155 
156 /*
157 ** structure for plugin definition
158 */
159 
160 typedef void (*inifunc)(unsigned int samplingFreq, PluginDef *plugin);
161 typedef int (*activatefunc)(bool start, PluginDef *plugin);
162 typedef void (*clearstatefunc)(PluginDef *plugin);
163 // in-place would be a tad more efficient but some plugins have to be cleaned up before
164 //typedef void (*process_mono_audio) (int count, float *buffer, PluginDef *plugin);
165 //typedef void (*process_stereo_audio) (int count, float *buffer1, float *buffer2, PluginDef *plugin);
166 typedef void (*process_mono_audio) (int count, float *input, float *output, PluginDef *plugin);
167 typedef void (*process_stereo_audio) (int count, float *input1, float *input2,
168  float *output1, float *output2, PluginDef *plugin);
169 typedef int (*registerfunc)(const ParamReg& reg);
170 typedef int (*uiloader)(const UiBuilder& builder, int format);
171 typedef void (*deletefunc)(PluginDef *plugin);
172 
173 enum {
174  PGN_STEREO = 0x0001, // stereo plugin (auto set when stereo_audio)
175  PGN_PRE = 0x0002, // (mono) always "pre" position
176  PGN_POST = 0x0004, // (mono) always "post" position
177  PGN_GUI = 0x0008, // register variables for gui (auto set when load_ui)
178  PGN_POST_PRE = 0x0010, // (mono) register post/pre variable (auto set when
179  // gui and not always pre or post)
180  PGN_ALTERNATIVE = 0x0020, // plugin is part of a group of modules
181  // managed by a ModuleSelector
182  PGN_SNOOP = 0x0040, // does not alter audio stream
183  PGN_MODE_NORMAL = 0x0100, // plugin is active in normal mode (default)
184  PGN_MODE_BYPASS = 0x0200, // plugin is active in bypass mode
185  PGN_MODE_MUTE = 0x0400, // plugin is active in mute mode
186  PGN_FIXED_GUI = 0x0800, // user cannot hide plugin GUI
187  PGN_NO_PRESETS = 0x1000,
188  // For additional flags see struct Plugin
189 };
190 
191 #define PLUGINDEF_VERMAJOR_MASK 0xff00
192 #define PLUGINDEF_VERMINOR_MASK 0x00ff
193 #define PLUGINDEF_VERSION 0x0700
194 
195 struct PluginDef {
196  int version; // = PLUGINDEF_VERSION
197  int flags; // PGN_xx flags
198 
199  const char* id; // must be unique
200  const char* name; // displayed name (not translated) (may be 0)
201  const char** groups; // list of alternating group_id, group_name (not translated)
202  // may be 0 (else end with 0 entry)
203  const char* description; // description (tooltip)
204  const char* category;
205  const char* shortname;
206 
207  // maximal one of mono_audio, stereo_audio must be set
208  // all function pointers in PluginDef can be independently set to 0
209  process_mono_audio mono_audio; // function for mono audio processing
210  process_stereo_audio stereo_audio; //function for stereo audio processing
211 
212  inifunc set_samplerate; // called before audio processing and when rate changes
213  activatefunc activate_plugin; // called when taking in / out of pressing chain
214  registerfunc register_params; // called once after module loading (register parameter ids)
215  uiloader load_ui; // called once after module loading (define user interface)
216  clearstatefunc clear_state; // clear internal audio state; may be called
217  // before calling the process function
218  deletefunc delete_instance; // delete this plugin instance
219 };
220 
221 // shared libraries with plugin modules must define
222 // a function "get_gx_plugin" of type plugin_inifunc
223 // return != 0 for error
224 extern "C" typedef int (*plugin_inifunc)(unsigned int idx, PluginDef **p);
225 
226 #endif /* !_GX_PLUGIN_H */
UiBuilder::openHorizontalTableBox
void(* openHorizontalTableBox)(const char *label)
Definition: gx_plugin.h:73
UiBuilder::create_port_display
void(* create_port_display)(const char *id, const char *label)
Definition: gx_plugin.h:92
PluginDef::set_samplerate
inifunc set_samplerate
Definition: gx_plugin.h:212
PluginDef::mono_audio
process_mono_audio mono_audio
Definition: gx_plugin.h:209
UiBuilder::create_wheel
void(* create_wheel)(const char *id, const char *label)
Definition: gx_plugin.h:99
PGN_SNOOP
@ PGN_SNOOP
Definition: gx_plugin.h:182
UiBuilder::openVerticalBox
void(* openVerticalBox)(const char *label)
Definition: gx_plugin.h:68
UiBuilder::create_switch_no_caption
void(* create_switch_no_caption)(const char *sw_type, const char *id)
Definition: gx_plugin.h:89
UiBuilder::create_mid_rackknob
void(* create_mid_rackknob)(const char *id, const char *label)
Definition: gx_plugin.h:103
value_pair
Definition: gx_plugin.h:117
PluginDef::category
const char * category
Definition: gx_plugin.h:204
clearstatefunc
void(* clearstatefunc)(PluginDef *plugin)
Definition: gx_plugin.h:162
PluginDef::register_params
registerfunc register_params
Definition: gx_plugin.h:214
PluginDef::shortname
const char * shortname
Definition: gx_plugin.h:205
PluginDef::version
int version
Definition: gx_plugin.h:196
UiBuilder::create_p_display
void(* create_p_display)(const char *id, const char *idl, const char *idh)
Definition: gx_plugin.h:93
UiBuilder::openVerticalBox2
void(* openVerticalBox2)(const char *label)
Definition: gx_plugin.h:70
ParamReg::plugin
PluginDef * plugin
Definition: gx_plugin.h:142
process_mono_audio
void(* process_mono_audio)(int count, float *input, float *output, PluginDef *plugin)
Definition: gx_plugin.h:166
PluginDef::load_ui
uiloader load_ui
Definition: gx_plugin.h:215
UiBuilder::openpaintampBox
void(* openpaintampBox)(const char *label)
Definition: gx_plugin.h:76
UiBuilder::create_feedback_slider
void(* create_feedback_slider)(const char *id, const char *label)
Definition: gx_plugin.h:85
PluginDef::stereo_audio
process_stereo_audio stereo_audio
Definition: gx_plugin.h:210
PluginDef::name
const char * name
Definition: gx_plugin.h:200
process_stereo_audio
void(* process_stereo_audio)(int count, float *input1, float *input2, float *output1, float *output2, PluginDef *plugin)
Definition: gx_plugin.h:167
PluginDef::delete_instance
deletefunc delete_instance
Definition: gx_plugin.h:218
UiBuilder::openFrameBox
void(* openFrameBox)(const char *label)
Definition: gx_plugin.h:74
uiloader
int(* uiloader)(const UiBuilder &builder, int format)
Definition: gx_plugin.h:170
PluginDef
Definition: gx_plugin.h:195
PGN_POST
@ PGN_POST
Definition: gx_plugin.h:176
PGN_POST_PRE
@ PGN_POST_PRE
Definition: gx_plugin.h:178
UiBuilder::create_fload_switch
void(* create_fload_switch)(const char *sw_type, const char *id, const char *idf)
Definition: gx_plugin.h:102
UiBuilder::create_spin_value
void(* create_spin_value)(const char *id, const char *label)
Definition: gx_plugin.h:91
UiBuilder::load_glade_file
void(* load_glade_file)(const char *fname)
Definition: gx_plugin.h:66
PluginDef::groups
const char ** groups
Definition: gx_plugin.h:201
UiBuilder::create_small_rackknob
void(* create_small_rackknob)(const char *id, const char *label)
Definition: gx_plugin.h:86
PGN_MODE_BYPASS
@ PGN_MODE_BYPASS
Definition: gx_plugin.h:184
UiBuilder::create_feedback_switch
void(* create_feedback_switch)(const char *sw_type, const char *id)
Definition: gx_plugin.h:90
UiBuilder::create_small_rackknobr
void(* create_small_rackknobr)(const char *id, const char *label)
Definition: gx_plugin.h:98
UiBuilder::create_eq_rackslider_no_caption
void(* create_eq_rackslider_no_caption)(const char *id)
Definition: gx_plugin.h:101
PluginDef::clear_state
clearstatefunc clear_state
Definition: gx_plugin.h:216
UiBuilder::create_selector_no_caption
void(* create_selector_no_caption)(const char *id)
Definition: gx_plugin.h:88
PGN_PRE
@ PGN_PRE
Definition: gx_plugin.h:175
UiBuilder::plugin
PluginDef * plugin
Definition: gx_plugin.h:64
PGN_FIXED_GUI
@ PGN_FIXED_GUI
Definition: gx_plugin.h:186
PGN_MODE_NORMAL
@ PGN_MODE_NORMAL
Definition: gx_plugin.h:183
PluginDef::description
const char * description
Definition: gx_plugin.h:203
UiBuilder::closeBox
void(* closeBox)()
Definition: gx_plugin.h:77
UiBuilder::openVerticalBox1
void(* openVerticalBox1)(const char *label)
Definition: gx_plugin.h:69
PluginDef::id
const char * id
Definition: gx_plugin.h:199
value_pair::value_id
const char * value_id
Definition: gx_plugin.h:118
UiBuilder::create_simple_meter
void(* create_simple_meter)(const char *id)
Definition: gx_plugin.h:96
PGN_STEREO
@ PGN_STEREO
Definition: gx_plugin.h:174
PluginDef::flags
int flags
Definition: gx_plugin.h:197
deletefunc
void(* deletefunc)(PluginDef *plugin)
Definition: gx_plugin.h:171
ParamReg
Parameter registration function pointers.
Definition: gx_plugin.h:141
inifunc
void(* inifunc)(unsigned int samplingFreq, PluginDef *plugin)
Definition: gx_plugin.h:160
UiBuilder::openFlipLabelBox
void(* openFlipLabelBox)(const char *label)
Definition: gx_plugin.h:75
UiBuilder::create_simple_spin_value
void(* create_simple_spin_value)(const char *id)
Definition: gx_plugin.h:100
UiBuilder
Definition: gx_plugin.h:63
PGN_MODE_MUTE
@ PGN_MODE_MUTE
Definition: gx_plugin.h:185
PluginDef::activate_plugin
activatefunc activate_plugin
Definition: gx_plugin.h:213
UiBuilder::set_next_flags
void(* set_next_flags)(int flags)
Definition: gx_plugin.h:79
plugin_inifunc
int(* plugin_inifunc)(unsigned int idx, PluginDef **p)
Definition: gx_plugin.h:224
UiBuilder::create_master_slider
void(* create_master_slider)(const char *id, const char *label)
Definition: gx_plugin.h:84
UiBuilder::openHorizontalBox
void(* openHorizontalBox)(const char *label)
Definition: gx_plugin.h:71
PGN_ALTERNATIVE
@ PGN_ALTERNATIVE
Definition: gx_plugin.h:180
UiBuilder::openHorizontalhideBox
void(* openHorizontalhideBox)(const char *label)
Definition: gx_plugin.h:72
PGN_NO_PRESETS
@ PGN_NO_PRESETS
Definition: gx_plugin.h:187
UiBuilder::create_big_rackknob
void(* create_big_rackknob)(const char *id, const char *label)
Definition: gx_plugin.h:87
registerfunc
int(* registerfunc)(const ParamReg &reg)
Definition: gx_plugin.h:169
UiBuilder::create_simple_c_meter
void(* create_simple_c_meter)(const char *id, const char *idl, const char *label)
Definition: gx_plugin.h:97
UiBuilder::load_glade
void(* load_glade)(const char *data)
Definition: gx_plugin.h:65
UiBuilder::openTabBox
void(* openTabBox)(const char *label)
Definition: gx_plugin.h:67
UiBuilder::create_switch
void(* create_switch)(const char *sw_type, const char *id, const char *label)
Definition: gx_plugin.h:94
activatefunc
int(* activatefunc)(bool start, PluginDef *plugin)
Definition: gx_plugin.h:161
PGN_GUI
@ PGN_GUI
Definition: gx_plugin.h:177
value_pair::value_label
const char * value_label
Definition: gx_plugin.h:119
UiBuilder::create_selector
void(* create_selector)(const char *id, const char *label)
Definition: gx_plugin.h:95
gx_compiler.h
UiBuilder::insertSpacer
void(* insertSpacer)()
Definition: gx_plugin.h:78