summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile (renamed from src/makefile)49
-rw-r--r--src/gcc_exports.map7
-rw-r--r--src/load.c61
-rw-r--r--src/plugins/amp.c26
-rw-r--r--src/plugins/delay.c24
-rw-r--r--src/plugins/filter.c30
-rw-r--r--src/plugins/noise.c26
-rw-r--r--src/plugins/sine.cpp52
-rw-r--r--src/search.c8
-rw-r--r--src/utils.h33
10 files changed, 193 insertions, 123 deletions
diff --git a/src/makefile b/src/Makefile
index 886237f..c339524 100644
--- a/src/makefile
+++ b/src/Makefile
@@ -15,7 +15,9 @@ INSTALL_BINARY_DIR = /usr/bin/
INCLUDES = -I.
LIBRARIES = -ldl -lm
-CFLAGS = $(INCLUDES) -Wall -Werror -O3 -fPIC
+CFLAGS = $(INCLUDES) -Wall -Werror -O2 -fPIC \
+ -DDEFAULT_LADSPA_PATH=$(INSTALL_PLUGINS_DIR)
+BINFLAGS = -fPIE -pie
CXXFLAGS = $(CFLAGS)
PLUGINS = ../plugins/amp.so \
../plugins/delay.so \
@@ -33,13 +35,27 @@ CPP = c++
# RULES TO BUILD PLUGINS FROM C OR C++ CODE
#
-../plugins/%.so: plugins/%.c ladspa.h
+../plugins/%.so: plugins/%.c ladspa.h gcc_exports.map
$(CC) $(CFLAGS) -o plugins/$*.o -c plugins/$*.c
- $(LD) -o ../plugins/$*.so plugins/$*.o -shared
-
-../plugins/%.so: plugins/%.cpp ladspa.h
+ $(CC) -o ../plugins/$*.so \
+ plugins/$*.o \
+ -shared \
+ $(CFLAGS) \
+ -fvisibility=hidden \
+ -fvisibility-inlines-hidden \
+ -s \
+ -Wl,--version-script=gcc_exports.map
+
+../plugins/%.so: plugins/%.cpp ladspa.h gcc_exports.map
$(CPP) $(CXXFLAGS) -o plugins/$*.o -c plugins/$*.cpp
- $(CPP) -o ../plugins/$*.so plugins/$*.o -shared
+ $(CPP) -o ../plugins/$*.so \
+ plugins/$*.o \
+ -shared \
+ $(CXXFLAGS) \
+ -fvisibility=hidden \
+ -fvisibility-inlines-hidden \
+ -s \
+ -Wl,--version-script=gcc_exports.map
###############################################################################
#
@@ -59,9 +75,9 @@ test: /tmp/test.wav ../snd/noise.wav always
@echo Test complete.
install: targets
- -mkdirhier $(INSTALL_PLUGINS_DIR)
- -mkdirhier $(INSTALL_INCLUDE_DIR)
- -mkdirhier $(INSTALL_BINARY_DIR)
+ -mkdir -p $(INSTALL_PLUGINS_DIR)
+ -mkdir -p $(INSTALL_INCLUDE_DIR)
+ -mkdir -p $(INSTALL_BINARY_DIR)
cp ../plugins/* $(INSTALL_PLUGINS_DIR)
cp ladspa.h $(INSTALL_INCLUDE_DIR)
cp ../bin/* $(INSTALL_BINARY_DIR)
@@ -90,19 +106,22 @@ targets: $(PLUGINS) $(PROGRAMS)
#
../bin/applyplugin: applyplugin.o load.o default.o
- $(CC) $(CFLAGS) $(LIBRARIES) \
+ $(CC) $(CFLAGS) $(BINFLAGS) \
-o ../bin/applyplugin \
- applyplugin.o load.o default.o
+ applyplugin.o load.o default.o \
+ $(LIBRARIES)
../bin/analyseplugin: analyseplugin.o load.o default.o
- $(CC) $(CFLAGS) $(LIBRARIES) \
+ $(CC) $(CFLAGS) $(BINFLAGS) \
-o ../bin/analyseplugin \
- analyseplugin.o load.o default.o
+ analyseplugin.o load.o default.o \
+ $(LIBRARIES)
../bin/listplugins: listplugins.o search.o
- $(CC) $(CFLAGS) $(LIBRARIES) \
+ $(CC) $(CFLAGS) $(BINFLAGS) \
-o ../bin/listplugins \
- listplugins.o search.o
+ listplugins.o search.o \
+ $(LIBRARIES)
###############################################################################
#
diff --git a/src/gcc_exports.map b/src/gcc_exports.map
new file mode 100644
index 0000000..7333e5a
--- /dev/null
+++ b/src/gcc_exports.map
@@ -0,0 +1,7 @@
+LADSPA_SDK
+{
+ global:
+ ladspa_descriptor;
+ local:
+ *;
+};
diff --git a/src/load.c b/src/load.c
index c2a5aa7..fb0bca0 100644
--- a/src/load.c
+++ b/src/load.c
@@ -53,37 +53,36 @@ dlopenLADSPA(const char * pcFilename, int iFlag) {
LD_LIBRARY_PATH, whereas the LADSPA_PATH is the correct place
to search. */
- pcLADSPAPath = getenv("LADSPA_PATH");
-
- if (pcLADSPAPath) {
-
- pcStart = pcLADSPAPath;
- while (*pcStart != '\0') {
- pcEnd = pcStart;
- while (*pcEnd != ':' && *pcEnd != '\0')
- pcEnd++;
-
- pcBuffer = malloc(iFilenameLength + 2 + (pcEnd - pcStart));
- if (pcEnd > pcStart)
- strncpy(pcBuffer, pcStart, pcEnd - pcStart);
- iNeedSlash = 0;
- if (pcEnd > pcStart)
- if (*(pcEnd - 1) != '/') {
- iNeedSlash = 1;
- pcBuffer[pcEnd - pcStart] = '/';
- }
- strcpy(pcBuffer + iNeedSlash + (pcEnd - pcStart), pcFilename);
-
- pvResult = dlopen(pcBuffer, iFlag);
-
- free(pcBuffer);
- if (pvResult != NULL)
- return pvResult;
-
- pcStart = pcEnd;
- if (*pcStart == ':')
- pcStart++;
- }
+ pcLADSPAPath = getenv("LADSPA_PATH");
+ if (pcLADSPAPath == NULL)
+ pcLADSPAPath = EXPAND_AND_STRINGIFY(DEFAULT_LADSPA_PATH);
+
+ pcStart = pcLADSPAPath;
+ while (*pcStart != '\0') {
+ pcEnd = pcStart;
+ while (*pcEnd != ':' && *pcEnd != '\0')
+ pcEnd++;
+
+ pcBuffer = malloc(iFilenameLength + 2 + (pcEnd - pcStart));
+ if (pcEnd > pcStart)
+ strncpy(pcBuffer, pcStart, pcEnd - pcStart);
+ iNeedSlash = 0;
+ if (pcEnd > pcStart)
+ if (*(pcEnd - 1) != '/') {
+ iNeedSlash = 1;
+ pcBuffer[pcEnd - pcStart] = '/';
+ }
+ strcpy(pcBuffer + iNeedSlash + (pcEnd - pcStart), pcFilename);
+
+ pvResult = dlopen(pcBuffer, iFlag);
+
+ free(pcBuffer);
+ if (pvResult != NULL)
+ return pvResult;
+
+ pcStart = pcEnd;
+ if (*pcStart == ':')
+ pcStart++;
}
}
diff --git a/src/plugins/amp.c b/src/plugins/amp.c
index b6d2345..9028b5d 100644
--- a/src/plugins/amp.c
+++ b/src/plugins/amp.c
@@ -16,6 +16,7 @@
/*****************************************************************************/
#include "ladspa.h"
+#include "utils.h"
/*****************************************************************************/
@@ -48,7 +49,7 @@ typedef struct {
/*****************************************************************************/
/* Construct a new plugin instance. */
-LADSPA_Handle
+static LADSPA_Handle
instantiateAmplifier(const LADSPA_Descriptor * Descriptor,
unsigned long SampleRate) {
return malloc(sizeof(Amplifier));
@@ -57,7 +58,7 @@ instantiateAmplifier(const LADSPA_Descriptor * Descriptor,
/*****************************************************************************/
/* Connect a port to a data location. */
-void
+static void
connectPortToAmplifier(LADSPA_Handle Instance,
unsigned long Port,
LADSPA_Data * DataLocation) {
@@ -88,7 +89,7 @@ connectPortToAmplifier(LADSPA_Handle Instance,
/*****************************************************************************/
-void
+static void
runMonoAmplifier(LADSPA_Handle Instance,
unsigned long SampleCount) {
@@ -110,7 +111,7 @@ runMonoAmplifier(LADSPA_Handle Instance,
/*****************************************************************************/
-void
+static void
runStereoAmplifier(LADSPA_Handle Instance,
unsigned long SampleCount) {
@@ -137,8 +138,8 @@ runStereoAmplifier(LADSPA_Handle Instance,
/*****************************************************************************/
-/* Throw away a simple delay line. */
-void
+/* Throw away an amplifier. */
+static void
cleanupAmplifier(LADSPA_Handle Instance) {
free(Instance);
}
@@ -150,10 +151,8 @@ LADSPA_Descriptor * g_psStereoDescriptor = NULL;
/*****************************************************************************/
-/* _init() is called automatically when the plugin library is first
- loaded. */
-void
-_init() {
+/* Called automatically when the plugin library is first loaded. */
+ON_LOAD_ROUTINE {
char ** pcPortNames;
LADSPA_PortDescriptor * piPortDescriptors;
@@ -315,7 +314,7 @@ _init() {
/*****************************************************************************/
-void
+static void
deleteDescriptor(LADSPA_Descriptor * psDescriptor) {
unsigned long lIndex;
if (psDescriptor) {
@@ -334,9 +333,8 @@ deleteDescriptor(LADSPA_Descriptor * psDescriptor) {
/*****************************************************************************/
-/* _fini() is called automatically when the library is unloaded. */
-void
-_fini() {
+/* Called automatically when the library is unloaded. */
+ON_UNLOAD_ROUTINE {
deleteDescriptor(g_psMonoDescriptor);
deleteDescriptor(g_psStereoDescriptor);
}
diff --git a/src/plugins/delay.c b/src/plugins/delay.c
index 8b03979..5b473da 100644
--- a/src/plugins/delay.c
+++ b/src/plugins/delay.c
@@ -18,6 +18,7 @@
/*****************************************************************************/
#include "ladspa.h"
+#include "utils.h"
/*****************************************************************************/
@@ -77,7 +78,7 @@ typedef struct {
/*****************************************************************************/
/* Construct a new plugin instance. */
-LADSPA_Handle
+static LADSPA_Handle
instantiateSimpleDelayLine(const LADSPA_Descriptor * Descriptor,
unsigned long SampleRate) {
@@ -113,7 +114,7 @@ instantiateSimpleDelayLine(const LADSPA_Descriptor * Descriptor,
/*****************************************************************************/
/* Initialise and activate a plugin instance. */
-void
+static void
activateSimpleDelayLine(LADSPA_Handle Instance) {
SimpleDelayLine * psSimpleDelayLine;
@@ -130,7 +131,7 @@ activateSimpleDelayLine(LADSPA_Handle Instance) {
/*****************************************************************************/
/* Connect a port to a data location. */
-void
+static void
connectPortToSimpleDelayLine(LADSPA_Handle Instance,
unsigned long Port,
LADSPA_Data * DataLocation) {
@@ -157,7 +158,7 @@ connectPortToSimpleDelayLine(LADSPA_Handle Instance,
/*****************************************************************************/
/* Run a delay line instance for a block of SampleCount samples. */
-void
+static void
runSimpleDelayLine(LADSPA_Handle Instance,
unsigned long SampleCount) {
@@ -209,7 +210,7 @@ runSimpleDelayLine(LADSPA_Handle Instance,
/*****************************************************************************/
/* Throw away a simple delay line. */
-void
+static void
cleanupSimpleDelayLine(LADSPA_Handle Instance) {
SimpleDelayLine * psSimpleDelayLine;
@@ -222,14 +223,12 @@ cleanupSimpleDelayLine(LADSPA_Handle Instance) {
/*****************************************************************************/
-LADSPA_Descriptor * g_psDescriptor = NULL;
+static LADSPA_Descriptor * g_psDescriptor = NULL;
/*****************************************************************************/
-/* _init() is called automatically when the plugin library is first
- loaded. */
-void
-_init() {
+/* Called automatically when the plugin library is first loaded. */
+ON_LOAD_ROUTINE {
char ** pcPortNames;
LADSPA_PortDescriptor * piPortDescriptors;
@@ -321,9 +320,8 @@ _init() {
/*****************************************************************************/
-/* _fini() is called automatically when the library is unloaded. */
-void
-_fini() {
+/* Called automatically when the library is unloaded. */
+ON_UNLOAD_ROUTINE {
long lIndex;
if (g_psDescriptor) {
free((char *)g_psDescriptor->Label);
diff --git a/src/plugins/filter.c b/src/plugins/filter.c
index 3f50457..b20d506 100644
--- a/src/plugins/filter.c
+++ b/src/plugins/filter.c
@@ -18,6 +18,7 @@
/*****************************************************************************/
#include "ladspa.h"
+#include "utils.h"
/*****************************************************************************/
@@ -56,7 +57,7 @@ typedef struct {
structure can be used for low- or high-pass filters we can get away
with only only writing one of these functions. Normally one would
be required for each plugin type. */
-LADSPA_Handle
+static LADSPA_Handle
instantiateSimpleFilter(const LADSPA_Descriptor * Descriptor,
unsigned long SampleRate) {
@@ -81,7 +82,7 @@ instantiateSimpleFilter(const LADSPA_Descriptor * Descriptor,
/* Initialise and activate a plugin instance. Normally separate
functions would have to be written for the different plugin types,
however we can get away with a single function in this case. */
-void
+static void
activateSimpleFilter(LADSPA_Handle Instance) {
SimpleFilter * psSimpleFilter;
psSimpleFilter = (SimpleFilter *)Instance;
@@ -93,7 +94,7 @@ activateSimpleFilter(LADSPA_Handle Instance) {
/* Connect a port to a data location. Normally separate functions
would have to be written for the different plugin types, however we
can get away with a single function in this case. */
-void
+static void
connectPortToSimpleFilter(LADSPA_Handle Instance,
unsigned long Port,
LADSPA_Data * DataLocation) {
@@ -118,7 +119,7 @@ connectPortToSimpleFilter(LADSPA_Handle Instance,
/*****************************************************************************/
/* Run the LPF algorithm for a block of SampleCount samples. */
-void
+static void
runSimpleLowPassFilter(LADSPA_Handle Instance,
unsigned long SampleCount) {
@@ -177,7 +178,7 @@ runSimpleLowPassFilter(LADSPA_Handle Instance,
/*****************************************************************************/
/* Run the HPF algorithm for a block of SampleCount samples. */
-void
+static void
runSimpleHighPassFilter(LADSPA_Handle Instance,
unsigned long SampleCount) {
@@ -238,22 +239,20 @@ runSimpleHighPassFilter(LADSPA_Handle Instance,
/* Throw away a filter instance. Normally separate functions
would have to be written for the different plugin types, however we
can get away with a single function in this case. */
-void
+static void
cleanupSimpleFilter(LADSPA_Handle Instance) {
free(Instance);
}
/*****************************************************************************/
-LADSPA_Descriptor * g_psLPFDescriptor = NULL;
-LADSPA_Descriptor * g_psHPFDescriptor = NULL;
+static LADSPA_Descriptor * g_psLPFDescriptor = NULL;
+static LADSPA_Descriptor * g_psHPFDescriptor = NULL;
/*****************************************************************************/
-/* _init() is called automatically when the plugin library is first
- loaded. */
-void
-_init() {
+/* Called automatically when the plugin library is first loaded. */
+ON_LOAD_ROUTINE {
char ** pcPortNames;
LADSPA_PortDescriptor * piPortDescriptors;
@@ -411,7 +410,7 @@ _init() {
/*****************************************************************************/
-void
+static void
deleteDescriptor(LADSPA_Descriptor * psDescriptor) {
unsigned long lIndex;
if (psDescriptor) {
@@ -430,9 +429,8 @@ deleteDescriptor(LADSPA_Descriptor * psDescriptor) {
/*****************************************************************************/
-/* _fini() is called automatically when the library is unloaded. */
-void
-_fini() {
+/* Called automatically when the library is unloaded. */
+ON_UNLOAD_ROUTINE {
deleteDescriptor(g_psLPFDescriptor);
deleteDescriptor(g_psHPFDescriptor);
}
diff --git a/src/plugins/noise.c b/src/plugins/noise.c
index 0fdd938..4068b5c 100644
--- a/src/plugins/noise.c
+++ b/src/plugins/noise.c
@@ -16,6 +16,7 @@
/*****************************************************************************/
#include "ladspa.h"
+#include "utils.h"
/*****************************************************************************/
@@ -48,7 +49,7 @@ typedef struct {
/*****************************************************************************/
/* Construct a new plugin instance. */
-LADSPA_Handle
+static LADSPA_Handle
instantiateNoiseSource(const LADSPA_Descriptor * Descriptor,
unsigned long SampleRate) {
return malloc(sizeof(NoiseSource));
@@ -57,7 +58,7 @@ instantiateNoiseSource(const LADSPA_Descriptor * Descriptor,
/*****************************************************************************/
/* Connect a port to a data location. */
-void
+static void
connectPortToNoiseSource(LADSPA_Handle Instance,
unsigned long Port,
LADSPA_Data * DataLocation) {
@@ -74,7 +75,7 @@ connectPortToNoiseSource(LADSPA_Handle Instance,
/*****************************************************************************/
/* Run a delay line instance for a block of SampleCount samples. */
-void
+static void
runNoiseSource(LADSPA_Handle Instance,
unsigned long SampleCount) {
@@ -97,7 +98,7 @@ runNoiseSource(LADSPA_Handle Instance,
/* Run a delay line instance for a block of SampleCount samples. *ADD*
the output to the output buffer. */
-void
+static void
runAddingNoiseSource(LADSPA_Handle Instance,
unsigned long SampleCount) {
@@ -120,7 +121,7 @@ runAddingNoiseSource(LADSPA_Handle Instance,
/*****************************************************************************/
-void
+static void
setNoiseSourceRunAddingGain(LADSPA_Handle Instance,
LADSPA_Data Gain) {
((NoiseSource *)Instance)->m_fRunAddingGain = Gain;
@@ -129,21 +130,19 @@ setNoiseSourceRunAddingGain(LADSPA_Handle Instance,
/*****************************************************************************/
/* Throw away a simple delay line. */
-void
+static void
cleanupNoiseSource(LADSPA_Handle Instance) {
free(Instance);
}
/*****************************************************************************/
-LADSPA_Descriptor * g_psDescriptor;
+static LADSPA_Descriptor * g_psDescriptor;
/*****************************************************************************/
-/* _init() is called automatically when the plugin library is first
- loaded. */
-void
-_init() {
+/* Called automatically when the plugin library is first loaded. */
+ON_LOAD_ROUTINE {
char ** pcPortNames;
LADSPA_PortDescriptor * piPortDescriptors;
@@ -218,9 +217,8 @@ _init() {
/*****************************************************************************/
-/* _fini() is called automatically when the library is unloaded. */
-void
-_fini() {
+/* Called automatically when the library is unloaded. */
+ON_UNLOAD_ROUTINE {
long lIndex;
if (g_psDescriptor) {
free((char *)g_psDescriptor->Label);
diff --git a/src/plugins/sine.cpp b/src/plugins/sine.cpp
index c3d1a6e..012ad8e 100644
--- a/src/plugins/sine.cpp
+++ b/src/plugins/sine.cpp
@@ -15,9 +15,9 @@
/*****************************************************************************/
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
/*****************************************************************************/
@@ -37,12 +37,12 @@
#define SINE_TABLE_BITS 14
#define SINE_TABLE_SHIFT (8 * sizeof(unsigned long) - SINE_TABLE_BITS)
-LADSPA_Data * g_pfSineTable = NULL;
-LADSPA_Data g_fPhaseStepBase = 0;
+static LADSPA_Data * g_pfSineTable = NULL;
+static LADSPA_Data g_fPhaseStepBase = 0;
/*****************************************************************************/
-inline char *
+static inline char *
localStrdup(const char * input) {
char * output = new char[strlen(input) + 1];
strcpy(output, input);
@@ -51,7 +51,7 @@ localStrdup(const char * input) {
/*****************************************************************************/
-void
+static void
initialise_sine_table() {
if (g_pfSineTable == NULL) {
long lTableSize = (1 << SINE_TABLE_BITS);
@@ -68,6 +68,22 @@ initialise_sine_table() {
/*****************************************************************************/
+static LADSPA_Handle instantiateSineOscillator(const LADSPA_Descriptor *,
+ unsigned long SampleRate);
+static void connectPortToSineOscillator(LADSPA_Handle Instance,
+ unsigned long Port,
+ LADSPA_Data * DataLocation);
+static void activateSineOscillator(void * pvHandle);
+static void runSineOscillator_FreqAudio_AmpAudio(LADSPA_Handle Instance,
+ unsigned long SampleCount);
+static void runSineOscillator_FreqAudio_AmpCtrl(LADSPA_Handle Instance,
+ unsigned long SampleCount);
+static void runSineOscillator_FreqCtrl_AmpAudio(LADSPA_Handle Instance,
+ unsigned long SampleCount);
+static void runSineOscillator_FreqCtrl_AmpCtrl(LADSPA_Handle Instance,
+ unsigned long SampleCount);
+static void cleanupSineOscillator(void *pvHandle);
+
class SineOscillator {
private:
@@ -120,7 +136,7 @@ private:
/*****************************************************************************/
-LADSPA_Handle
+static LADSPA_Handle
instantiateSineOscillator(const LADSPA_Descriptor *,
unsigned long SampleRate) {
return new SineOscillator(SampleRate);
@@ -128,7 +144,7 @@ instantiateSineOscillator(const LADSPA_Descriptor *,
/*****************************************************************************/
-void
+static void
connectPortToSineOscillator(LADSPA_Handle Instance,
unsigned long Port,
LADSPA_Data * DataLocation) {
@@ -147,14 +163,14 @@ connectPortToSineOscillator(LADSPA_Handle Instance,
/*****************************************************************************/
-void
+static void
activateSineOscillator(void * pvHandle) {
((SineOscillator *)pvHandle)->m_lPhase = 0;
}
/*****************************************************************************/
-void
+static void
runSineOscillator_FreqAudio_AmpAudio(LADSPA_Handle Instance,
unsigned long SampleCount) {
SineOscillator * poSineOscillator = (SineOscillator *)Instance;
@@ -174,7 +190,7 @@ runSineOscillator_FreqAudio_AmpAudio(LADSPA_Handle Instance,
/*****************************************************************************/
-void
+static void
runSineOscillator_FreqAudio_AmpCtrl(LADSPA_Handle Instance,
unsigned long SampleCount) {
SineOscillator * poSineOscillator = (SineOscillator *)Instance;
@@ -195,7 +211,7 @@ runSineOscillator_FreqAudio_AmpCtrl(LADSPA_Handle Instance,
/*****************************************************************************/
-void
+static void
runSineOscillator_FreqCtrl_AmpAudio(LADSPA_Handle Instance,
unsigned long SampleCount) {
SineOscillator * poSineOscillator = (SineOscillator *)Instance;
@@ -212,7 +228,7 @@ runSineOscillator_FreqCtrl_AmpAudio(LADSPA_Handle Instance,
/*****************************************************************************/
-void
+static void
runSineOscillator_FreqCtrl_AmpCtrl(LADSPA_Handle Instance,
unsigned long SampleCount) {
SineOscillator * poSineOscillator = (SineOscillator *)Instance;
@@ -230,7 +246,7 @@ runSineOscillator_FreqCtrl_AmpCtrl(LADSPA_Handle Instance,
/*****************************************************************************/
-void
+static void
cleanupSineOscillator(void *pvHandle) {
delete (SineOscillator *)pvHandle;
}
@@ -239,7 +255,7 @@ cleanupSineOscillator(void *pvHandle) {
typedef char * char_ptr;
-LADSPA_Descriptor * g_psDescriptors[4] = { NULL, NULL, NULL, NULL };
+static LADSPA_Descriptor * g_psDescriptors[4] = { NULL, NULL, NULL, NULL };
/*****************************************************************************/
@@ -403,7 +419,9 @@ public:
delete [] g_pfSineTable;
}
-} g_oShutdownStartupHandler;
+};
+
+static StartupShutdownHandler g_oShutdownStartupHandler;
/*****************************************************************************/
diff --git a/src/search.c b/src/search.c
index 0006712..7b2eb05 100644
--- a/src/search.c
+++ b/src/search.c
@@ -80,7 +80,7 @@ LADSPADirectoryPluginSearch
}
else {
/* It was a library, but not a LADSPA one. Unload it. */
- dlclose(pcFilename);
+ dlclose(pvPluginHandle);
free(pcFilename);
}
}
@@ -101,8 +101,10 @@ LADSPAPluginSearch(LADSPAPluginSearchCallbackFunction fCallbackFunction) {
if (!pcLADSPAPath) {
fprintf(stderr,
"Warning: You do not have a LADSPA_PATH "
- "environment variable set.\n");
- return;
+ "environment variable set. Defaulting to "
+ EXPAND_AND_STRINGIFY(DEFAULT_LADSPA_PATH)
+ ".\n");
+ pcLADSPAPath = EXPAND_AND_STRINGIFY(DEFAULT_LADSPA_PATH);
}
pcStart = pcLADSPAPath;
diff --git a/src/utils.h b/src/utils.h
index d94c420..050db6c 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -65,6 +65,39 @@ int getLADSPADefault(const LADSPA_PortRangeHint * psPortRangeHint,
const unsigned long lSampleRate,
LADSPA_Data * pfResult);
+
+/*****************************************************************************/
+
+/* During C pre-processing, take a string (passed in from the
+ Makefile) and put quote marks around it. */
+#define RAW_STRINGIFY(x) #x
+#define EXPAND_AND_STRINGIFY(x) RAW_STRINGIFY(x)
+
+/*****************************************************************************/
+
+#ifndef __cplusplus
+/* In C, special incantations are needed to trigger initialisation and
+ cleanup routines when a dynamic plugin library is loaded or
+ unloaded (e.g. with dlopen() or dlclose()). _init() and _fini() are
+ classic exported symbols to achieve this, but these days GNU C
+ likes to do things a different way. Ideally we would check the GNU
+ version as older ones will probably expect the classic behaviour,
+ but for now... */
+# if __GNUC__
+/* Modern GNU C incantations: */
+# define ON_LOAD_ROUTINE static void __attribute__ ((constructor)) init()
+# define ON_UNLOAD_ROUTINE static void __attribute__ ((destructor)) fini()
+# else
+/* Classic incantations: */
+# define ON_LOAD_ROUTINE void _init()
+# define ON_UNLOAD_ROUTINE void _fini()
+# endif
+#else
+/* In C++, we use the constructor/destructor of a static object to
+ manage initialisation and cleanup, so we don't need these
+ routines. */
+#endif
+
/*****************************************************************************/
#endif