4
Copyright 2004-5 Tim Goetze <tim@quitte.de>
8
creating a LADSPA_Descriptor for a caps plugin via a C++ template,
9
saves us a virtual function call compared to the usual method used
10
for C++ plugins in a C context.
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 of course 'adding_gain'.
16
maintaining both port_info[] and ports[] is a bit of a bitch, but,
17
hey, "you only do it once (tm)" .. and then you do it over and over
18
again. particularly bothersome is also the necessary unrolling of our
19
PortInfo array to fit into LADSPA_Descriptor's inconsequential way of
20
port data structuring, which results in quite a bit of memory holding
21
duplicated data. oh well.
24
This program is free software; you can redistribute it and/or
25
modify it under the terms of the GNU General Public License
26
as published by the Free Software Foundation; either version 2
27
of the License, or (at your option) any later version.
29
This program is distributed in the hope that it will be useful,
30
but WITHOUT ANY WARRANTY; without even the implied warranty of
31
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32
GNU General Public License for more details.
34
You should have received a copy of the GNU General Public License
35
along with this program; if not, write to the Free Software
36
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
37
02111-1307, USA or point your web browser to http://www.gnu.org.
40
#ifndef _DESCRIPTOR_H_
41
#define _DESCRIPTOR_H_
43
/* common stub for Descriptor makes it possible to delete() without special-
44
* casing for every plugin class.
47
: public LADSPA_Descriptor
60
delete [] PortDescriptors;
61
delete [] PortRangeHints;
68
: public DescriptorStub
71
/* tom szilyagi reports that hosts exist which call activate() before
72
* connect_port(). since caps' plugins expect ports to be valid we
73
* need a safeguard: at instantiation, each port is connected to the
74
* lower bound. When (If?) LADSPA default values are ever fixed, connecting
75
* to the default will be preferred. */
76
LADSPA_PortRangeHint * ranges;
86
PortCount = (sizeof (T::port_info) / sizeof (PortInfo));
88
/* unroll PortInfo members */
89
char ** names = new char * [PortCount];
90
LADSPA_PortDescriptor * desc = new LADSPA_PortDescriptor [PortCount];
91
ranges = new LADSPA_PortRangeHint [PortCount];
93
/* could also assign directly but const_cast is ugly. */
94
for (int i = 0; i < (int) PortCount; ++i)
96
names[i] = T::port_info[i].name;
97
desc[i] = T::port_info[i].descriptor;
98
ranges[i] = T::port_info[i].range;
102
PortDescriptors = desc;
103
PortRangeHints = ranges;
105
/* LADSPA_Descriptor vtable entries */
106
instantiate = _instantiate;
107
connect_port = _connect_port;
108
activate = _activate;
110
run_adding = _run_adding;
111
set_run_adding_gain = _set_run_adding_gain;
116
static LADSPA_Handle _instantiate (
117
const struct _LADSPA_Descriptor * d, ulong fs)
119
T * plugin = new T();
121
/* see comment above at 'ranges' member */
122
for (int i = 0; i < (int) d->PortCount; ++i)
123
plugin->ports[i] = &((Descriptor *) d)->ranges[i].LowerBound;
130
static void _connect_port (LADSPA_Handle h, ulong i, LADSPA_Data * p)
132
((T *) h)->ports[i] = p;
135
static void _activate (LADSPA_Handle h)
137
((T *) h)->activate();
140
static void _run (LADSPA_Handle h, ulong n)
142
/* cannot call template here (g++ 2.95), sigh. */
146
static void _run_adding (LADSPA_Handle h, ulong n)
148
/* cannot call a template here (g++ 2.95), sigh. */
149
((T *) h)->run_adding (n);
152
static void _set_run_adding_gain (LADSPA_Handle h, LADSPA_Data g)
154
((T *) h)->adding_gain = g;
157
static void _cleanup (LADSPA_Handle h)
163
#endif /* _DESCRIPTOR_H_ */