aboutsummaryrefslogtreecommitdiff
path: root/src/lib/sharedlibs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/sharedlibs.cpp')
-rw-r--r--src/lib/sharedlibs.cpp332
1 files changed, 332 insertions, 0 deletions
diff --git a/src/lib/sharedlibs.cpp b/src/lib/sharedlibs.cpp
new file mode 100644
index 0000000..32e5fd8
--- /dev/null
+++ b/src/lib/sharedlibs.cpp
@@ -0,0 +1,332 @@
1#include <sharedlibs.h>
2#include <FL/fl_message.H>
3void SmartLoader::SmartFind(const char* filename,const char* absprogpath,char* result)
4{
5/* Find the given file in a clever way:
6 * Search the given path first
7 * (on the Mac, perhaps recursively)
8 * Then the environment PATH variable
9 * and finally any predefined library paths */
10 result[0]=(char)0;
11 hd24utils::findfile(filename,absprogpath,result);
12 if (strlen(result)!=0)
13 {
14 // found it already
15 return;
16 }
17
18 hd24utils::findfile(filename,getenv("PATH"),result);
19 if (strlen(result)!=0)
20 {
21 // found it already
22 return;
23 }
24
25 hd24utils::findfile(filename,DEFAULTLIBPATH,result);
26 if (strlen(result)!=0)
27 {
28 // found it already
29 return;
30 }
31 return;
32};
33
34PortAudioWrapper::PortAudioWrapper(char* absprogpath)
35{
36 libloaded=false;
37 Pa_Initialize=NULL;
38 Pa_Terminate=NULL;
39 char result[2048];
40 SmartFind(LIBFILE_PORTAUDIO,absprogpath,&result[0]);
41
42 string abslib="";
43 abslib+=result;
44 abslib+=LIBFILE_PORTAUDIO;
45 #if (RECORDERDEBUG==1)
46 cout << "Opening from smartpath: " << abslib.c_str() << endl;
47 #endif
48
49 LIBHANDLE_T* handle=dlopen(abslib.c_str(),RTLD_NOW);
50 if (handle==NULL) {
51 #if (RECORDERDEBUG==1)
52 cout << "Fail. Opening from default path instead." << endl;
53 #endif
54
55 handle=dlopen(LIBFILE_PORTAUDIO,RTLD_NOW);
56 if (handle==NULL) {
57 #if (RECORDERDEBUG==1)
58 cout << dlerror() << endl;
59 #endif
60 } else {
61 #if (RECORDERDEBUG==1)
62 cout << dlerror() << endl;
63 cout << "Defining functions from default path." << endl;
64 #endif
65 define_functions(handle);
66
67 }
68 } else {
69 #if (RECORDERDEBUG==1)
70 cout << "Defining functions from smart path." << endl;
71 #endif
72
73 define_functions(handle);
74 }
75}
76
77PortAudioWrapper::~PortAudioWrapper()
78{
79 if (libhandle!=NULL)
80 {
81 dlclose(libhandle);
82 }
83}
84
85void PortAudioWrapper::define_functions(LIBHANDLE_T* handle)
86{
87 if (handle==NULL) return;
88 libhandle=handle;
89 libloaded=false;
90 // Given a handle to a dynamic library, define functions that are in it.
91
92 #if (RECORDERDEBUG==1)
93 cout << "Define Pa_Initialize..." << endl;
94 #endif
95 Pa_Initialize=(PaError (*)(void))dlsym(handle,"Pa_Initialize");
96
97 if (Pa_Initialize==NULL) { fl_message("Error loading Pa_Initialize"); return; }
98 #if (RECORDERDEBUG==1)
99 cout << "Define Pa_Terminate..." << endl;
100 #endif
101
102
103 Pa_Terminate=(PaError (*)(void))dlsym(handle,"Pa_Terminate");
104 if (Pa_Terminate==NULL) { fl_message("Error loading Pa_Terminate"); return; }
105
106 #if (RECORDERDEBUG==1)
107 cout << "Define Pa_StartStream..." << endl;
108 #endif
109
110 Pa_StartStream=(PaError (*)(PaStream*))dlsym(handle,"Pa_StartStream");
111 if (Pa_StartStream==NULL) { fl_message("Error loading Pa_StartStream"); return; }
112
113 #if (RECORDERDEBUG==1)
114 cout << "Define Pa_StopStream..." << endl;
115 #endif
116
117 Pa_StopStream=(PaError (*)(PaStream*))dlsym(handle,"Pa_StopStream");
118 if (Pa_StopStream==NULL) { fl_message("Error loading Pa_StopStream"); return; }
119
120 #if (RECORDERDEBUG==1)
121 cout << "Define Pa_AbortStream..." << endl;
122 #endif
123
124 Pa_AbortStream=(PaError (*)(PaStream*))dlsym(handle,"Pa_AbortStream");
125 if (Pa_AbortStream==NULL) { fl_message("Error loading Pa_AbortStream"); return; }
126
127 #if (RECORDERDEBUG==1)
128 cout << "Define Pa_CloseStream..." << endl;
129 #endif
130
131 Pa_CloseStream=(PaError (*)(PaStream*))dlsym(handle,"Pa_CloseStream");
132 if (Pa_CloseStream==NULL) { fl_message("Error loading Pa_CloseStream"); return; }
133
134 #if (RECORDERDEBUG==1)
135 cout << "Define Pa_GetStreamTime..." << endl;
136 #endif
137
138 Pa_GetStreamTime=(PaTime (*)(PaStream*))dlsym(handle,"Pa_GetStreamTime");
139 if (Pa_GetStreamTime==NULL) { fl_message("Error loading Pa_GetStreamTime"); return; }
140
141 #if (RECORDERDEBUG==1)
142 cout << "Define Pa_StreamActive..." << endl;
143 #endif
144
145 Pa_StreamActive=(PaError (*)(PaStream*))dlsym(handle,"Pa_IsStreamActive");
146 if (Pa_StreamActive==NULL) {
147 Pa_StreamActive=(PaError (*)(PaStream*))dlsym(handle,"Pa_StreamActive");
148 }
149 if (Pa_StreamActive==NULL) {
150 fl_message("Error loading Pa_StreamActive"); return;
151 }
152
153 #if (RECORDERDEBUG==1)
154 cout << "Define Pa_OpenStream..." << endl;
155 #endif
156 Pa_OpenStream=(PaError (*)(PaStream**,
157 const PaStreamParameters*,
158 const PaStreamParameters*,
159 double,
160 unsigned long,
161 PaStreamFlags,
162 PaStreamCallback*,
163 void*))dlsym(handle,"Pa_OpenStream");
164
165 if (Pa_OpenStream==NULL) { fl_message("Error loading Pa_OpenStream"); return; }
166
167 #if (RECORDERDEBUG==1)
168 cout << "Define Pa_GetDeviceCount..." << endl;
169 #endif
170
171 Pa_GetDeviceCount=(int (*)(void))dlsym(handle,"Pa_GetDeviceCount");
172 if (Pa_GetDeviceCount==NULL) { fl_message("Error loading Pa_GetDeviceCount"); return; }
173
174 #if (RECORDERDEBUG==1)
175 cout << "Define Pa_GetDeviceInfo..." << endl;
176 #endif
177
178 Pa_GetDeviceInfo=(const PaDeviceInfo* (*)(int))dlsym(handle,"Pa_GetDeviceInfo");
179 if (Pa_GetDeviceInfo==NULL) { fl_message("Error loading Pa_GetDeviceInfo"); return; }
180
181 #if (RECORDERDEBUG==1)
182 cout << "Define Pa_GetDefaultInputDevice..." << endl;
183 #endif
184
185 Pa_GetDefaultInputDevice=(PaDeviceIndex (*)(void))dlsym(handle,"Pa_GetDefaultInputDevice");
186 if (Pa_GetDefaultInputDevice==NULL) { fl_message("Error loading Pa_GetDefaultInputDevice"); return; }
187
188 #if (RECORDERDEBUG==1)
189 cout << "Define Pa_GetDefaultOutputDevice..." << endl;
190 #endif
191
192 Pa_GetDefaultOutputDevice=(PaDeviceIndex (*)(void))dlsym(handle,"Pa_GetDefaultOutputDevice");
193 if (Pa_GetDefaultOutputDevice==NULL) { fl_message("Error loading Pa_GetDefaultOutputDevice"); return; }
194
195 #if (RECORDERDEBUG==1)
196 cout << "Define Pa_GetVersionText..." << endl;
197 #endif
198
199 Pa_GetVersionText=(const char* (*)(void))dlsym(handle,"Pa_GetVersionText");
200
201 #if (RECORDERDEBUG==1)
202 cout << "Define Pa_GetErrorText..." << endl;
203 #endif
204
205 Pa_GetErrorText=(const char* (*)(PaError))dlsym(handle,"Pa_GetErrorText");
206
207 #if (RECORDERDEBUG==1)
208 PaError initerror=(*(this->Pa_Initialize))();
209 cout << "initerror=" <<initerror << endl;
210 cout << "Portaudio version=" << (*(this->Pa_GetVersionText))() << endl;
211 #endif
212
213 #if (RECORDERDEBUG==1)
214 int devcount=(*(this->Pa_GetDeviceCount))();
215 cout << "Portaudio Device count=" << devcount << endl;
216 cout << "Default Portaudio Input Device =" << (*(this->Pa_GetDefaultInputDevice))() << endl;
217 cout << "Default Portaudio Output Device =" << (*(this->Pa_GetDefaultOutputDevice))() << endl;
218 #endif
219
220 libloaded=true;
221}
222
223SoundFileWrapper::SoundFileWrapper(char* absprogpath)
224{
225 sf_open=NULL;
226 sf_close=NULL;
227 libloaded=false;
228
229 char result[2048];
230// TODO: Was there a reason why this said PORTAUDIO?
231// SmartFind(LIBFILE_PORTAUDIO,absprogpath,&result[0]);
232 SmartFind(LIBFILE_SNDFILE,absprogpath,&result[0]);
233
234 string abslib="";
235 abslib+=result;
236 abslib+=LIBFILE_SNDFILE;
237 LIBHANDLE_T* handle=dlopen(abslib.c_str(),RTLD_NOW);
238 if (handle==NULL) {
239 fl_message("%s",dlerror());
240 }
241 if (handle==NULL) {
242 handle=dlopen(LIBFILE_SNDFILE,RTLD_NOW);
243 if (handle==NULL) {
244 fl_message("%s",dlerror());
245 } else {
246 define_functions(handle);
247 }
248 } else {
249 define_functions(handle);
250 }
251}
252
253SoundFileWrapper::~SoundFileWrapper()
254{
255 if (libhandle!=NULL)
256 {
257 dlclose(libhandle);
258 }
259
260}
261
262void SoundFileWrapper::define_functions(LIBHANDLE_T* handle)
263{
264 if (handle==NULL) return;
265 libhandle=handle;
266 // Given a handle to a dynamic library, define functions that are in it.
267 sf_open=(SNDFILE*(*)(const char*,int,SF_INFO*))dlsym(handle,"sf_open");
268 if (sf_open==NULL) {
269 fl_message("Unable to load libsndfile, file transfers won't work.");
270 }
271 sf_close=(int(*)(SNDFILE*))dlsym(handle,"sf_close");
272 sf_read_int=(sf_count_t(*)(SNDFILE*,int*,sf_count_t))dlsym(handle,"sf_read_int");
273 sf_write_raw=(sf_count_t(*)(SNDFILE*,const void*,sf_count_t))dlsym(handle,"sf_write_raw");
274 sf_write_float=(sf_count_t(*)(SNDFILE*,const void*,sf_count_t))dlsym(handle,"sf_write_float");
275 if (sf_open!=NULL) {
276 libloaded=true;
277 }
278}
279
280JackWrapper::JackWrapper(char* absprogpath)
281{
282 libloaded=false;
283 char result[2048];
284// TODO: Was there a reason why this said PORTAUDIO?
285// SmartFind(LIBFILE_PORTAUDIO,absprogpath,&result[0]);
286 SmartFind(LIBFILE_JACK,absprogpath,&result[0]);
287
288 string abslib="";
289 abslib+=result;
290 abslib+=LIBFILE_JACK;
291 LIBHANDLE_T* handle=dlopen(abslib.c_str(),RTLD_NOW);
292 if (handle==NULL) {
293 handle=dlopen(LIBFILE_JACK,RTLD_NOW);
294 if (handle==NULL) {
295 // cout << dlerror() << endl;
296 } else {
297 define_functions(handle);
298 }
299 } else {
300 define_functions(handle);
301 }
302}
303
304JackWrapper::~JackWrapper()
305{
306 if (libhandle!=NULL)
307 {
308 dlclose(libhandle);
309 }
310
311}
312
313void JackWrapper::define_functions(LIBHANDLE_T* handle)
314{
315 if (handle==NULL) return;
316 libhandle=handle;
317 // Given a handle to a dynamic library, define functions that are in it.
318 jack_client_new=(jack_client_t*(*)(const char*))dlsym(handle,"jack_client_new");
319 jack_set_process_callback=(int(*)(jack_client_t*,JackProcessCallback,void*))dlsym(handle,"jack_set_process_callback");
320 jack_on_shutdown=(void (*)(jack_client_t*,void (*function)(void *), void *))dlsym(handle,"jack_on_shutdown");
321 jack_get_sample_rate=(jack_nframes_t (*)(jack_client_t*))dlsym(handle,"jack_get_sample_rate");
322 jack_port_get_buffer=(void* (*)(jack_port_t*,jack_nframes_t))dlsym(handle,"jack_port_get_buffer");
323 jack_transport_query=(jack_transport_state_t (*)(const jack_client_t*,jack_position_t*))dlsym(handle,"jack_transport_query");
324 jack_port_register=(jack_port_t* (*)(jack_client_t*,const char*,const char*,unsigned long,unsigned long))dlsym(handle,"jack_port_register");
325 jack_activate=(int (*)(jack_client_t*))dlsym(handle,"jack_activate");
326 jack_get_current_transport_frame=(jack_nframes_t (*)(const jack_client_t*))dlsym(handle,"jack_get_current_transport_frame");
327 jack_transport_locate=(int (*)(jack_client_t*,jack_nframes_t))dlsym(handle,"jack_transport_locate");
328 jack_transport_start=(void (*)(jack_client_t*))dlsym(handle,"jack_transport_start");
329 jack_transport_stop=(void (*)(jack_client_t*))dlsym(handle,"jack_transport_stop");
330 libloaded=true;
331}
332