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 { 64 PluginDef *plugin; 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 /** 123 * Parameter registration function pointers 124 * 125 * All functions expect a character string parameter tp: 126 * 127 * first char: 128 * - S: continuous values, float (Faust vslider, hslider, nentry, vbargraph, hbargraph) 129 * - B: 2 values: 0/1, false/true (Faust checkbox, button) 130 * 131 * following chars (order doesn't matter, there should not be duplicate chars): 132 * - A: aliased (parameter id used by several plugins), (Faust: [alias]) 133 * - L: logarithmic input / output, (Faust: [log]) 134 * - N: no midi controller connection possible, (Faust: [nomidi]) 135 * - o: output parameter (will be polled for changes by plugin) 136 * - s: parameter not saveable in preset / state file 137 * - w: no warning (if a non saveable parameter is found in a preset / state file) 138 * - O: non-savable, no-midi output parameter (same as "Nos"), (Faust: vbargraph, hbargraph) 139 * - M: maxlevel output variable (max value since last poll) 140 */ 141 struct ParamReg { 142 PluginDef *plugin; 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 */ 227