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 
122 struct ParamReg {
124  float *(*registerVar)(const char* id, const char* name, const char* tp,
125  const char* tooltip, float* var, float val,
126  float low, float up, float step);
127  void (*registerBoolVar)(const char* id, const char* name, const char* tp,
128  const char* tooltip, bool* var, bool val);
129  void (*registerNonMidiVar)(const char * id, bool*var, bool preset, bool nosave);
130  void (*registerNonMidiFloatVar)(const char * id, float *var, bool preset, bool nosave,
131  float val, float low, float up, float step);
132  void (*registerEnumVar)(const char *id, const char* name, const char* tp,
133  const char* tooltip, const value_pair* values, float *var, float val,
134  float low, float up, float step);
135  float *(*registerSharedEnumVar)(const char *id, const char* name, const char* tp,
136  const char* tooltip, const value_pair* values, float *var, float val,
137  float low, float up, float step);
138  void (*registerIEnumVar)(const char *id, const char* name, const char* tp,
139  const char* tooltip, const value_pair* values, int *var, int val);
140  float *(*registerNonMidiSharedVar)(const char * id, float *var, bool preset, bool nosave,
141  float val, float low, float up, float step);
142 };
143 
144 /*
145 ** structure for plugin definition
146 */
147 
148 typedef void (*inifunc)(unsigned int samplingFreq, PluginDef *plugin);
149 typedef int (*activatefunc)(bool start, PluginDef *plugin);
150 typedef void (*clearstatefunc)(PluginDef *plugin);
151 // in-place would be a tad more efficient but some plugins have to be cleaned up before
152 //typedef void (*process_mono_audio) (int count, float *buffer, PluginDef *plugin);
153 //typedef void (*process_stereo_audio) (int count, float *buffer1, float *buffer2, PluginDef *plugin);
154 typedef void (*process_mono_audio) (int count, float *input, float *output, PluginDef *plugin);
155 typedef void (*process_stereo_audio) (int count, float *input1, float *input2,
156  float *output1, float *output2, PluginDef *plugin);
157 typedef int (*registerfunc)(const ParamReg& reg);
158 typedef int (*uiloader)(const UiBuilder& builder, int format);
159 typedef void (*deletefunc)(PluginDef *plugin);
160 
161 enum {
162  PGN_STEREO = 0x0001, // stereo plugin (auto set when stereo_audio)
163  PGN_PRE = 0x0002, // (mono) always "pre" position
164  PGN_POST = 0x0004, // (mono) always "post" position
165  PGN_GUI = 0x0008, // register variables for gui (auto set when load_ui)
166  PGN_POST_PRE = 0x0010, // (mono) register post/pre variable (auto set when
167  // gui and not always pre or post)
168  PGN_ALTERNATIVE = 0x0020, // plugin is part of a group of modules
169  // managed by a ModuleSelector
170  PGN_SNOOP = 0x0040, // does not alter audio stream
171  PGN_MODE_NORMAL = 0x0100, // plugin is active in normal mode (default)
172  PGN_MODE_BYPASS = 0x0200, // plugin is active in bypass mode
173  PGN_MODE_MUTE = 0x0400, // plugin is active in mute mode
174  PGN_FIXED_GUI = 0x0800, // user cannot hide plugin GUI
175  PGN_NO_PRESETS = 0x1000,
176  // For additional flags see struct Plugin
177 };
178 
179 #define PLUGINDEF_VERMAJOR_MASK 0xff00
180 #define PLUGINDEF_VERMINOR_MASK 0x00ff
181 #define PLUGINDEF_VERSION 0x0600
182 
183 struct PluginDef {
184  int version; // = PLUGINDEF_VERSION
185  int flags; // PGN_xx flags
186 
187  const char* id; // must be unique
188  const char* name; // displayed name (not translated) (may be 0)
189  const char** groups; // list of alternating group_id, group_name (not translated)
190  // may be 0 (else end with 0 entry)
191  const char* description; // description (tooltip)
192  const char* category;
193  const char* shortname;
194 
195  // maximal one of mono_audio, stereo_audio must be set
196  // all function pointers in PluginDef can be independently set to 0
197  process_mono_audio mono_audio; // function for mono audio processing
198  process_stereo_audio stereo_audio; //function for stereo audio processing
199 
200  inifunc set_samplerate; // called before audio processing and when rate changes
201  activatefunc activate_plugin; // called when taking in / out of pressing chain
202  registerfunc register_params; // called once after module loading (register parameter ids)
203  uiloader load_ui; // called once after module loading (define user interface)
204  clearstatefunc clear_state; // clear internal audio state; may be called
205  // before calling the process function
206  deletefunc delete_instance; // delete this plugin instance
207 };
208 
209 // shared libraries with plugin modules must define
210 // a function "get_gx_plugin" of type plugin_inifunc
211 // return != 0 for error
212 extern "C" typedef int (*plugin_inifunc)(unsigned int idx, PluginDef **p);
213 
214 #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:200
PluginDef::mono_audio
process_mono_audio mono_audio
Definition: gx_plugin.h:197
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:170
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:192
clearstatefunc
void(* clearstatefunc)(PluginDef *plugin)
Definition: gx_plugin.h:150
PluginDef::register_params
registerfunc register_params
Definition: gx_plugin.h:202
PluginDef::shortname
const char * shortname
Definition: gx_plugin.h:193
PluginDef::version
int version
Definition: gx_plugin.h:184
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:123
process_mono_audio
void(* process_mono_audio)(int count, float *input, float *output, PluginDef *plugin)
Definition: gx_plugin.h:154
PluginDef::load_ui
uiloader load_ui
Definition: gx_plugin.h:203
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:198
PluginDef::name
const char * name
Definition: gx_plugin.h:188
process_stereo_audio
void(* process_stereo_audio)(int count, float *input1, float *input2, float *output1, float *output2, PluginDef *plugin)
Definition: gx_plugin.h:155
PluginDef::delete_instance
deletefunc delete_instance
Definition: gx_plugin.h:206
ParamReg::registerEnumVar
void(* registerEnumVar)(const char *id, const char *name, const char *tp, const char *tooltip, const value_pair *values, float *var, float val, float low, float up, float step)
Definition: gx_plugin.h:132
UiBuilder::openFrameBox
void(* openFrameBox)(const char *label)
Definition: gx_plugin.h:74
uiloader
int(* uiloader)(const UiBuilder &builder, int format)
Definition: gx_plugin.h:158
PluginDef
Definition: gx_plugin.h:183
ParamReg::registerIEnumVar
void(* registerIEnumVar)(const char *id, const char *name, const char *tp, const char *tooltip, const value_pair *values, int *var, int val)
Definition: gx_plugin.h:138
PGN_POST
@ PGN_POST
Definition: gx_plugin.h:164
PGN_POST_PRE
@ PGN_POST_PRE
Definition: gx_plugin.h:166
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:189
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:172
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:204
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:163
UiBuilder::plugin
PluginDef * plugin
Definition: gx_plugin.h:64
PGN_FIXED_GUI
@ PGN_FIXED_GUI
Definition: gx_plugin.h:174
PGN_MODE_NORMAL
@ PGN_MODE_NORMAL
Definition: gx_plugin.h:171
PluginDef::description
const char * description
Definition: gx_plugin.h:191
UiBuilder::closeBox
void(* closeBox)()
Definition: gx_plugin.h:77
ParamReg::registerNonMidiVar
void(* registerNonMidiVar)(const char *id, bool *var, bool preset, bool nosave)
Definition: gx_plugin.h:129
UiBuilder::openVerticalBox1
void(* openVerticalBox1)(const char *label)
Definition: gx_plugin.h:69
PluginDef::id
const char * id
Definition: gx_plugin.h:187
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:162
PluginDef::flags
int flags
Definition: gx_plugin.h:185
deletefunc
void(* deletefunc)(PluginDef *plugin)
Definition: gx_plugin.h:159
ParamReg
Definition: gx_plugin.h:122
inifunc
void(* inifunc)(unsigned int samplingFreq, PluginDef *plugin)
Definition: gx_plugin.h:148
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:173
PluginDef::activate_plugin
activatefunc activate_plugin
Definition: gx_plugin.h:201
start
CmdConnection::msg_type start
Definition: jsonrpc.cpp:257
ParamReg::registerNonMidiFloatVar
void(* registerNonMidiFloatVar)(const char *id, float *var, bool preset, bool nosave, float val, float low, float up, float step)
Definition: gx_plugin.h:130
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:212
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:168
UiBuilder::openHorizontalhideBox
void(* openHorizontalhideBox)(const char *label)
Definition: gx_plugin.h:72
PGN_NO_PRESETS
@ PGN_NO_PRESETS
Definition: gx_plugin.h:175
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:157
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:149
PGN_GUI
@ PGN_GUI
Definition: gx_plugin.h:165
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
ParamReg::registerBoolVar
void(* registerBoolVar)(const char *id, const char *name, const char *tp, const char *tooltip, bool *var, bool val)
Definition: gx_plugin.h:127
gx_compiler.h
UiBuilder::insertSpacer
void(* insertSpacer)()
Definition: gx_plugin.h:78