LMMS
Loading...
Searching...
No Matches
Descriptor.h
Go to the documentation of this file.
1/*
2 Descriptor.h
3
4 Copyright 2004-10 Tim Goetze <tim@quitte.de>
5
6 http://quitte.de/dsp/
7
8 Creating a LADSPA_Descriptor for a CAPS plugin via a C++ template,
9 saving a virtual function call compared to the usual method used
10 for C++ plugins in a C context.
11
12 Descriptor<P> expects P to declare some common methods, like init(),
13 activate() etc, plus a static port_info[] and LADSPA_Data * ports[]
14 and adding_gain. (P should derive from Plugin, too.)
15
16*/
17/*
18 This program is free software; you can redistribute it and/or
19 modify it under the terms of the GNU General Public License
20 as published by the Free Software Foundation; either version 2
21 of the License, or (at your option) any later version.
22
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
27
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31 02111-1307, USA or point your web browser to http://www.gnu.org.
32*/
33
34#ifndef _DESCRIPTOR_H_
35#define _DESCRIPTOR_H_
36
37#ifdef __SSE__
38#include <xmmintrin.h>
39#endif
40#ifdef __SSE3__
41#include <pmmintrin.h>
42#endif
43
44/* common stub for Descriptor makes it possible to delete() without special-
45 * casing for every plugin class.
46 */
48: public LADSPA_Descriptor
49{
50 public:
52 {
53 PortCount = 0;
54 }
55
57 {
58 if (PortCount)
59 {
60 delete [] PortNames;
61 delete [] PortDescriptors;
62 delete [] PortRangeHints;
63 }
64 }
65};
66
67inline void
69{
70 #ifdef __SSE3__
71 /* this one works reliably on a 6600 Core2 */
72 _MM_SET_DENORMALS_ZERO_MODE (_MM_DENORMALS_ZERO_ON);
73 #endif
74
75 #ifdef __SSE__
76 /* this one doesn't ... */
77 _MM_SET_FLUSH_ZERO_MODE (_MM_FLUSH_ZERO_ON);
78 #endif
79}
80
81template <class T>
83: public DescriptorStub
84{
85 public:
87
88 public:
90 ~Descriptor() override = default;
91 void setup();
92
93 void autogen()
94 {
95 PortCount = (sizeof (T::port_info) / sizeof (PortInfo));
96
97 /* unroll PortInfo members */
98 const char ** names = new const char * [PortCount];
101
102 /* could also assign directly but const_cast is ugly. */
103 for (int i = 0; i < (int) PortCount; ++i)
104 {
105 names[i] = T::port_info[i].name;
106 desc[i] = T::port_info[i].descriptor;
107 ranges[i] = T::port_info[i].range;
108 }
109
110 PortNames = names;
111 PortDescriptors = desc;
113
114 /* LADSPA_Descriptor vtable entries */
118 run = _run;
121 deactivate = 0;
123 }
124
126 const struct _LADSPA_Descriptor * d, ulong fs)
127 {
128 T * plugin = new T();
129 int n = (int) d->PortCount;
130
131 LADSPA_PortRangeHint * ranges = ((Descriptor *) d)->ranges;
132 plugin->ranges = ranges;
133
134 plugin->ports = new sample_t * [n];
135
136 /* connect to lower bound as a safety measure */
137 for (int i = 0; i < n; ++i)
138 plugin->ports[i] = &(ranges[i].LowerBound);
139
140 plugin->fs = fs;
141 plugin->normal = NOISE_FLOOR;
142 plugin->init();
143
144 return plugin;
145 }
146
148 {
149 ((T *) h)->ports[i] = p;
150 }
151
153 {
154 T * plugin = (T *) h;
155
156 plugin->first_run = 1;
157
158 /* since none of the plugins do any RT-critical work in
159 * activate(), it's safe to defer the actual call to the
160 * plugin's activate() method for the first run() after
161 * the host called in here.
162 *
163 * It's the simplest way to prevent a parameter smoothing sweep
164 * in the first audio block after activation.
165 plugin->activate();
166 */
167 }
168
169 static void _run (LADSPA_Handle h, ulong n)
170 {
171 T * plugin = (T *) h;
172
173 /* We don't reset the processor flags later, it's true. */
175
176 /* If this is the first audio block after activation,
177 * initialize the plugin from the current set of parameters. */
178 if (plugin->first_run)
179 {
180 plugin->activate();
181 plugin->first_run = 0;
182 }
183
184 plugin->run (n);
185 plugin->normal = -plugin->normal;
186 }
187
189 {
190 T * plugin = (T *) h;
191
192 /* We don't reset the processor flags later, it's true. */
194
195 /* If this is the first audio block after activation,
196 * initialize the plugin from the current set of parameters. */
197 if (plugin->first_run)
198 {
199 plugin->activate();
200 plugin->first_run = 0;
201 }
202
203 plugin->run_adding (n);
204 plugin->normal = -plugin->normal;
205 }
206
208 {
209 T * plugin = (T *) h;
210
211 plugin->adding_gain = g;
212 }
213
215 {
216 T * plugin = (T *) h;
217
218 delete [] plugin->ports;
219 delete plugin;
220 }
221};
222
223#endif /* _DESCRIPTOR_H_ */
unsigned long int ulong
Definition CarlaDefines.h:328
void processor_specific_denormal_measures()
Definition Descriptor.h:68
LADSPA_Data sample_t
Definition basics.h:100
#define NOISE_FLOOR
Definition basics.h:83
~Descriptor() override=default
void autogen()
Definition Descriptor.h:93
static void _activate(LADSPA_Handle h)
Definition Descriptor.h:152
void setup()
LADSPA_PortRangeHint * ranges
Definition Descriptor.h:86
static void _run_adding(LADSPA_Handle h, ulong n)
Definition Descriptor.h:188
static void _cleanup(LADSPA_Handle h)
Definition Descriptor.h:214
Descriptor()
Definition Descriptor.h:89
static LADSPA_Handle _instantiate(const struct _LADSPA_Descriptor *d, ulong fs)
Definition Descriptor.h:125
static void _set_run_adding_gain(LADSPA_Handle h, LADSPA_Data g)
Definition Descriptor.h:207
static void _connect_port(LADSPA_Handle h, ulong i, LADSPA_Data *p)
Definition Descriptor.h:147
static void _run(LADSPA_Handle h, ulong n)
Definition Descriptor.h:169
virtual ~DescriptorStub()
Definition Descriptor.h:56
DescriptorStub()
Definition Descriptor.h:51
unsigned d
Definition inflate.c:940
int g
Definition inflate.c:1573
register unsigned i
Definition inflate.c:1575
struct _LADSPA_PortRangeHint LADSPA_PortRangeHint
int LADSPA_PortDescriptor
Definition ladspa.h:152
float LADSPA_Data
Definition ladspa.h:84
void * LADSPA_Handle
Definition ladspa.h:363
struct _LADSPA_Descriptor LADSPA_Descriptor
Definition ladspa.h:373
void(* set_run_adding_gain)(LADSPA_Handle Instance, LADSPA_Data Gain)
Definition ladspa.h:533
const char *const * PortNames
Definition ladspa.h:415
void(* activate)(LADSPA_Handle Instance)
Definition ladspa.h:489
void(* run_adding)(LADSPA_Handle Instance, unsigned long SampleCount)
Definition ladspa.h:521
void(* connect_port)(LADSPA_Handle Instance, unsigned long Port, LADSPA_Data *DataLocation)
Definition ladspa.h:466
void(* cleanup)(LADSPA_Handle Instance)
Definition ladspa.h:558
void(* run)(LADSPA_Handle Instance, unsigned long SampleCount)
Definition ladspa.h:505
unsigned long PortCount
Definition ladspa.h:406
LADSPA_Handle(* instantiate)(const struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate)
Definition ladspa.h:437
const LADSPA_PortDescriptor * PortDescriptors
Definition ladspa.h:410
const LADSPA_PortRangeHint * PortRangeHints
Definition ladspa.h:419
void(* deactivate)(LADSPA_Handle Instance)
Definition ladspa.h:549
Definition basics.h:94
int n
Definition crypt.c:458
uch * p
Definition crypt.c:594
uch h[RAND_HEAD_LEN]
Definition crypt.c:459
typedef int(UZ_EXP MsgFn)()