2 terminatorX - realtime audio scratching software
3 Copyright (C) 1999-2004 Alexander König
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 Description: LADSPA_Plugin takes care of loading LADSPA plugins.
22 Most of this code is based on the LADSPA SDK code by
23 Richard W.E. Furse. For more information about ladspa
24 checkout http://www.ladspa.org
27 #include <tX_ladspa.h>
28 #include <tX_ladspa_class.h>
35 std::list <LADSPA_Plugin *> LADSPA_Plugin :: plugin_list;
36 std::list <LADSPA_Stereo_Plugin *> LADSPA_Stereo_Plugin :: stereo_plugin_list;
38 void LADSPA_Plugin :: init ()
40 char *ladspa_path_ptr;
41 char ladspa_path[PATH_MAX];
42 char *start, *end, *buffer;
44 /* Finding the LADSPA Path */
45 ladspa_path_ptr=getenv("LADSPA_PATH");
47 if (!ladspa_path_ptr) {
48 tX_warning("LADSPA_PATH not set. Trying /usr/lib/ladspa:/usr/local/lib/ladspa");
49 strcpy(ladspa_path, "/usr/lib/ladspa:/usr/local/lib/ladspa");
51 else strcpy(ladspa_path, ladspa_path_ptr);
53 /* Scanning every dir in path */
56 while (*start != '\0')
59 while (*end != ':' && *end != '\0') end++;
61 buffer = (char *) malloc(1 + end - start);
62 if (end > start) strncpy(buffer, start, end - start);
64 buffer[end - start] = '\0';
65 LADSPA_Plugin::scandir(buffer);
69 if (*start == ':') start++;
73 /* This routine expects to get *valid* port descriptors.
74 There's no error checking as in the LADSPA SDK's "analyseplugin".
77 void LADSPA_Plugin :: handlelib(void *lib, LADSPA_Descriptor_Function desc_func, char *filename)
81 const LADSPA_Descriptor *descriptor;
82 int in_audio, out_audio, in_ctrl;
84 for (i=0; (descriptor = desc_func(i)) != NULL; i++) {
85 if (LADSPA_IS_INPLACE_BROKEN(descriptor->Properties)) {
86 tX_warning("Plugin \"%s\" [%i] disabled: No in-place processing support.", descriptor->Label, descriptor->UniqueID);
87 } else if (!LADSPA_IS_HARD_RT_CAPABLE(descriptor->Properties)) {
88 tX_warning("Plugin \"%s\" [%i] disabled: Not realtime capable.", descriptor->Label, descriptor->UniqueID);
90 in_audio=0; out_audio=0; in_ctrl=0;
92 for (port = 0; port<descriptor->PortCount; port++) {
93 if (LADSPA_IS_PORT_AUDIO(descriptor->PortDescriptors[port])) {
94 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[port])) in_audio++;
96 if (LADSPA_IS_PORT_OUTPUT(descriptor->PortDescriptors[port])) out_audio++;
98 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[port]) && LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[port])) in_ctrl++;
101 if ((in_audio == 1) && (out_audio == 1)) {
102 new LADSPA_Plugin(descriptor, filename);
103 } if ((in_audio == 2) && (out_audio == 2)) {
104 new LADSPA_Stereo_Plugin(descriptor, filename);
106 else { tX_warning("Plugin \"%s\" [%i] disabled: Neither mono nor stereo.", descriptor->Label, descriptor->UniqueID); }
111 void LADSPA_Plugin :: scandir(char *dirname)
113 int dirlen=strlen(dirname);
116 struct dirent * entry;
119 LADSPA_Descriptor_Function desc_func;
121 if (!dirlen) { tX_error("tX: Error: empty directory name?"); return; };
123 if (dirname[dirlen - 1] != '/') needslash=1;
125 dir = opendir(dirname);
127 if (!dir) { tX_error("tX: Error: couldn't access directory \"%s\".", dirname); return; };
131 if (!entry) { closedir(dir); return; }
133 filename = (char *) malloc (dirlen + strlen(entry->d_name) + 1 + needslash);
135 strcpy(filename, dirname);
136 if (needslash) strcat(filename, "/");
137 strcat(filename, entry->d_name);
139 handle = dlopen(filename, RTLD_LAZY);
145 /* check wether this is a LADSPA lib */
146 desc_func = (LADSPA_Descriptor_Function) dlsym(handle, "ladspa_descriptor");
148 if (dlerror() == NULL && desc_func) {
149 LADSPA_Plugin :: handlelib(handle, desc_func, entry->d_name);
151 tX_error("tX: Error: %s is not a LADSPA plugin library.", filename);
160 void LADSPA_Plugin :: status ()
162 printf ("tX: %i LADSPA plugins available\n", plugin_list.size());
166 void LADSPA_Plugin :: debug_display()
168 std::list <LADSPA_Plugin *> :: iterator plugin;
170 for (plugin=plugin_list.begin(); plugin != plugin_list.end(); plugin++) {
171 printf("plugin: %60s | id: %5li | ports: %2li\n", (*plugin)->getName(), (*plugin)->getUniqueID(), (*plugin)->getPortCount());
175 LADSPA_Plugin :: LADSPA_Plugin (const LADSPA_Descriptor *ld, char *filename)
177 ladspa_descriptor = ld;
179 plugin_list.push_back(this);
180 strcpy(file, filename);
181 sprintf(info_string, "LADSPA-Plugin: %s\nLabel: %s\nFile: %s\nUnique ID: %li\nMaker: %s\nCopyright: %s", ld->Name, ld->Label, file, ld->UniqueID, ld->Maker, ld->Copyright);
182 LADSPA_Class::add_plugin(this);
185 LADSPA_Plugin * LADSPA_Plugin :: getPluginByIndex(int i)
187 std::list <LADSPA_Plugin *> :: iterator plugin;
190 plugin = plugin_list.begin();
191 for (p=0; (p<i) && (plugin != plugin_list.end()); p++, plugin++);
193 if (plugin==plugin_list.end()) return NULL;
195 else return (*plugin);
198 LADSPA_Plugin * LADSPA_Plugin :: getPluginByUniqueID(long ID)
200 std::list <LADSPA_Plugin *> :: iterator plugin;
202 for (plugin=plugin_list.begin(); plugin != plugin_list.end(); plugin++) {
203 if ((*plugin)->getUniqueID()==ID) return (*plugin);
211 LADSPA_Stereo_Plugin :: LADSPA_Stereo_Plugin (const LADSPA_Descriptor *ld, char *filename)
213 ladspa_descriptor = ld;
215 stereo_plugin_list.push_back(this);
216 strcpy(file, filename);
217 sprintf(info_string, "LADSPA-Stereo-Plugin: %s\nLabel: %s\nFile: %s\nUnique ID: %li\nMaker: %s\nCopyright: %s", ld->Name, ld->Label, file, ld->UniqueID, ld->Maker, ld->Copyright);
218 LADSPA_Class::add_stereo_plugin(this);
221 LADSPA_Stereo_Plugin * LADSPA_Stereo_Plugin :: getPluginByIndex(int i)
223 std::list <LADSPA_Stereo_Plugin *> :: iterator plugin;
226 plugin = stereo_plugin_list.begin();
227 for (p=0; (p<i) && (plugin != stereo_plugin_list.end()); p++, plugin++);
229 if (plugin==stereo_plugin_list.end()) return NULL;
231 else return (*plugin);
234 LADSPA_Stereo_Plugin * LADSPA_Stereo_Plugin :: getPluginByUniqueID(long ID)
236 std::list <LADSPA_Stereo_Plugin *> :: iterator plugin;
238 for (plugin=stereo_plugin_list.begin(); plugin != stereo_plugin_list.end(); plugin++) {
239 if ((*plugin)->getUniqueID()==ID) return (*plugin);
245 bool LADSPA_Stereo_Plugin::is_stereo() { return true; }
246 bool LADSPA_Plugin::is_stereo() { return false; }