1 #include <cstdlib>
2 #include <cmath>
3 #include "gx_plugin.h"
4 
5 #define PLUGIN_ID  "dsp"
6 #define PLUGIN_NAME "DSP"
7 
8 #define PARAM(p) (PLUGIN_ID "." p)
9 
10 class Dsp: public PluginDef {
11 private:
12     static void init(unsigned int samplingFreq, PluginDef *plugin);
13     static void process(int count, float *input, float *output, PluginDef *plugin);
14     static int registerparam(const ParamReg& reg);
15     static int uiloader(const UiBuilder& builder, int format);
16     static void del_instance(PluginDef *plugin);
17     //
18     float level;
19 public:
20     Dsp();
21 };
22 
Dsp()23 Dsp::Dsp()
24     : PluginDef() {
25     version = PLUGINDEF_VERSION;
26     id = PLUGIN_ID;
27     name = PLUGIN_NAME;
28     mono_audio = process;
29     set_samplerate = init;
30     register_params = registerparam;
31     load_ui = uiloader;
32     delete_instance = del_instance;
33 }
34 
init(unsigned int samplingFreq,PluginDef * plugin)35 void Dsp::init(unsigned int samplingFreq, PluginDef *plugin) {
36     //Dsp& self = *static_cast<Dsp*>(plugin);
37 }
38 
process(int count,float * input,float * output,PluginDef * plugin)39 void Dsp::process(int count, float *input, float *output, PluginDef *plugin) {
40     Dsp& self = *static_cast<Dsp*>(plugin);
41     for (int i = 0; i < count; ++i) {
42         output[i] = input[i] * self.level;
43     }
44 }
45 
registerparam(const ParamReg & reg)46 int Dsp::registerparam(const ParamReg& reg) {
47     Dsp& self = *static_cast<Dsp*>(reg.plugin);
48     // the numbers are: default, lower, upper, step
49     // (step is not used by the python module)
50     reg.registerFloatVar(PARAM("level"),"Level","S","Output Level",&self.level,5.0,0.1,10.0,0.1,nullptr);
51     return 0;
52 }
53 
uiloader(const UiBuilder & b,int format)54 int Dsp::uiloader(const UiBuilder& b, int format) {
55     //Dsp& self = *static_cast<Dsp*>(b.plugin);
56     if (format & UI_FORM_STACK) {
57         b.openHorizontalhideBox("");
58         b.closeBox();
59         b.create_small_rackknob(PARAM("level"),0);
60         return 0;
61     }
62     return -1;
63 }
64 
del_instance(PluginDef * plugin)65 void Dsp::del_instance(PluginDef *plugin) {
66     delete static_cast<Dsp*>(plugin);
67 }
68 
69 extern "C" __attribute__ ((visibility ("default"))) int
get_gx_plugin(unsigned int idx,PluginDef ** pplugin)70 get_gx_plugin(unsigned int idx, PluginDef **pplugin)
71 {
72     const int count = 1;
73     if (!pplugin) {
74         return count;
75     }
76     switch (idx) {
77     case 0: *pplugin = new Dsp(); return count;
78     default: *pplugin = 0; return -1;
79     }
80 }
81