Use glibmm for modules instead of dlfch.h
This commit is contained in:
parent
058ebf98b9
commit
83ed3d7dcc
@ -23,8 +23,8 @@
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <glibmm/module.h>
|
||||
|
||||
#include "pbd/stateful.h"
|
||||
|
||||
@ -39,7 +39,7 @@ class Session;
|
||||
class LadspaPlugin : public ARDOUR::Plugin
|
||||
{
|
||||
public:
|
||||
LadspaPlugin (void *module, ARDOUR::AudioEngine&, ARDOUR::Session&, uint32_t index, framecnt_t sample_rate);
|
||||
LadspaPlugin (std::string module_path, ARDOUR::AudioEngine&, ARDOUR::Session&, uint32_t index, framecnt_t sample_rate);
|
||||
LadspaPlugin (const LadspaPlugin &);
|
||||
~LadspaPlugin ();
|
||||
|
||||
@ -122,7 +122,8 @@ class LadspaPlugin : public ARDOUR::Plugin
|
||||
void connect_port (uint32_t port, float *ptr) { _descriptor->connect_port (_handle, port, ptr); }
|
||||
|
||||
private:
|
||||
void* _module;
|
||||
std::string _module_path;
|
||||
Glib::Module* _module;
|
||||
const LADSPA_Descriptor* _descriptor;
|
||||
LADSPA_Handle _handle;
|
||||
framecnt_t _sample_rate;
|
||||
@ -134,7 +135,7 @@ class LadspaPlugin : public ARDOUR::Plugin
|
||||
|
||||
void find_presets ();
|
||||
|
||||
void init (void *mod, uint32_t index, framecnt_t rate);
|
||||
void init (std::string module_path, uint32_t index, framecnt_t rate);
|
||||
void run_in_place (pframes_t nsamples);
|
||||
void latency_compute_run ();
|
||||
int set_state_2X (const XMLNode&, int version);
|
||||
|
@ -20,7 +20,8 @@
|
||||
#ifndef __ardour_panner_manager_h__
|
||||
#define __ardour_panner_manager_h__
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <glibmm/module.h>
|
||||
|
||||
#include "ardour/panner.h"
|
||||
#include "ardour/session_handle.h"
|
||||
|
||||
@ -28,15 +29,15 @@ namespace ARDOUR {
|
||||
|
||||
struct PannerInfo {
|
||||
PanPluginDescriptor descriptor;
|
||||
void* module;
|
||||
Glib::Module* module;
|
||||
|
||||
PannerInfo (PanPluginDescriptor& d, void* handle)
|
||||
PannerInfo (PanPluginDescriptor& d, Glib::Module* m)
|
||||
: descriptor (d)
|
||||
, module (handle)
|
||||
, module (m)
|
||||
{}
|
||||
|
||||
~PannerInfo () {
|
||||
dlclose (module);
|
||||
delete module;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
*/
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <glibmm/module.h>
|
||||
|
||||
#include <glibmm/fileutils.h>
|
||||
|
||||
@ -29,8 +29,14 @@
|
||||
|
||||
#include "ardour/debug.h"
|
||||
#include "ardour/control_protocol_manager.h"
|
||||
|
||||
#ifdef SearchPath
|
||||
#undef SearchPath
|
||||
#endif
|
||||
|
||||
#include "ardour/control_protocol_search_path.h"
|
||||
|
||||
|
||||
using namespace ARDOUR;
|
||||
using namespace std;
|
||||
using namespace PBD;
|
||||
@ -179,7 +185,7 @@ ControlProtocolManager::teardown (ControlProtocolInfo& cpi)
|
||||
cpi.protocol = 0;
|
||||
delete cpi.state;
|
||||
cpi.state = 0;
|
||||
dlclose (cpi.descriptor->module);
|
||||
delete (Glib::Module*)cpi.descriptor->module;
|
||||
|
||||
ProtocolStatusChange (&cpi);
|
||||
|
||||
@ -264,7 +270,7 @@ ControlProtocolManager::control_protocol_discover (string path)
|
||||
string_compose(_("Control surface protocol discovered: \"%1\"\n"), cpi->name));
|
||||
}
|
||||
|
||||
dlclose (descriptor->module);
|
||||
delete (Glib::Module*)descriptor->module;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -273,31 +279,31 @@ ControlProtocolManager::control_protocol_discover (string path)
|
||||
ControlProtocolDescriptor*
|
||||
ControlProtocolManager::get_descriptor (string path)
|
||||
{
|
||||
void *module;
|
||||
Glib::Module* module = new Glib::Module(path);
|
||||
ControlProtocolDescriptor *descriptor = 0;
|
||||
ControlProtocolDescriptor* (*dfunc)(void);
|
||||
const char *errstr;
|
||||
void* func = 0;
|
||||
|
||||
if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
|
||||
error << string_compose(_("ControlProtocolManager: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
|
||||
if (!(*module)) {
|
||||
error << string_compose(_("ControlProtocolManager: cannot load module \"%1\" (%2)"), path, Glib::Module::get_last_error()) << endmsg;
|
||||
delete module;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
dfunc = (ControlProtocolDescriptor* (*)(void)) dlsym (module, "protocol_descriptor");
|
||||
|
||||
if ((errstr = dlerror()) != 0) {
|
||||
if (!module->get_symbol("protocol_descriptor", func)) {
|
||||
error << string_compose(_("ControlProtocolManager: module \"%1\" has no descriptor function."), path) << endmsg;
|
||||
error << errstr << endmsg;
|
||||
dlclose (module);
|
||||
error << Glib::Module::get_last_error() << endmsg;
|
||||
delete module;
|
||||
return 0;
|
||||
}
|
||||
|
||||
dfunc = (ControlProtocolDescriptor* (*)(void))func;
|
||||
descriptor = dfunc();
|
||||
|
||||
if (descriptor) {
|
||||
descriptor->module = module;
|
||||
descriptor->module = (void*)module;
|
||||
} else {
|
||||
dlclose (module);
|
||||
delete module;
|
||||
}
|
||||
|
||||
return descriptor;
|
||||
|
@ -51,16 +51,16 @@ using namespace std;
|
||||
using namespace ARDOUR;
|
||||
using namespace PBD;
|
||||
|
||||
LadspaPlugin::LadspaPlugin (void *mod, AudioEngine& e, Session& session, uint32_t index, framecnt_t rate)
|
||||
LadspaPlugin::LadspaPlugin (string module_path, AudioEngine& e, Session& session, uint32_t index, framecnt_t rate)
|
||||
: Plugin (e, session)
|
||||
{
|
||||
init (mod, index, rate);
|
||||
init (module_path, index, rate);
|
||||
}
|
||||
|
||||
LadspaPlugin::LadspaPlugin (const LadspaPlugin &other)
|
||||
: Plugin (other)
|
||||
{
|
||||
init (other._module, other._index, other._sample_rate);
|
||||
init (other._module_path, other._index, other._sample_rate);
|
||||
|
||||
for (uint32_t i = 0; i < parameter_count(); ++i) {
|
||||
_control_data[i] = other._shadow_data[i];
|
||||
@ -69,25 +69,32 @@ LadspaPlugin::LadspaPlugin (const LadspaPlugin &other)
|
||||
}
|
||||
|
||||
void
|
||||
LadspaPlugin::init (void *mod, uint32_t index, framecnt_t rate)
|
||||
LadspaPlugin::init (string module_path, uint32_t index, framecnt_t rate)
|
||||
{
|
||||
void* func;
|
||||
LADSPA_Descriptor_Function dfunc;
|
||||
uint32_t i, port_cnt;
|
||||
const char *errstr;
|
||||
|
||||
_module = mod;
|
||||
_module_path = module_path;
|
||||
_module = new Glib::Module(_module_path);
|
||||
_control_data = 0;
|
||||
_shadow_data = 0;
|
||||
_latency_control_port = 0;
|
||||
_was_activated = false;
|
||||
|
||||
dfunc = (LADSPA_Descriptor_Function) dlsym (_module, "ladspa_descriptor");
|
||||
if (!(*_module)) {
|
||||
error << _("LADSPA: Unable to open module: ") << Glib::Module::get_last_error() << endmsg;
|
||||
delete _module;
|
||||
throw failed_constructor();
|
||||
}
|
||||
|
||||
if ((errstr = dlerror()) != NULL) {
|
||||
if (!_module->get_symbol("ladspa_descriptor", func)) {
|
||||
error << _("LADSPA: module has no descriptor function.") << endmsg;
|
||||
throw failed_constructor();
|
||||
}
|
||||
|
||||
dfunc = (LADSPA_Descriptor_Function)func;
|
||||
|
||||
if ((_descriptor = dfunc (index)) == 0) {
|
||||
error << _("LADSPA: plugin has gone away since discovery!") << endmsg;
|
||||
throw failed_constructor();
|
||||
@ -141,9 +148,8 @@ LadspaPlugin::~LadspaPlugin ()
|
||||
deactivate ();
|
||||
cleanup ();
|
||||
|
||||
/* XXX who should close a plugin? */
|
||||
|
||||
// dlclose (module);
|
||||
// glib has internal reference counting on modules so this is ok
|
||||
delete _module;
|
||||
|
||||
delete [] _control_data;
|
||||
delete [] _shadow_data;
|
||||
@ -700,17 +706,7 @@ PluginPtr
|
||||
LadspaPluginInfo::load (Session& session)
|
||||
{
|
||||
try {
|
||||
PluginPtr plugin;
|
||||
void *module;
|
||||
|
||||
if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
|
||||
error << string_compose(_("LADSPA: cannot load module from \"%1\""), path) << endmsg;
|
||||
error << dlerror() << endmsg;
|
||||
return PluginPtr ((Plugin*) 0);
|
||||
} else {
|
||||
plugin.reset (new LadspaPlugin (module, session.engine(), session, index, session.frame_rate()));
|
||||
}
|
||||
|
||||
PluginPtr plugin (new LadspaPlugin (path, session.engine(), session, index, session.frame_rate()));
|
||||
plugin->set_info(PluginInfoPtr(new LadspaPluginInfo(*this)));
|
||||
return plugin;
|
||||
}
|
||||
|
@ -106,31 +106,33 @@ PannerManager::panner_discover (string path)
|
||||
PannerInfo*
|
||||
PannerManager::get_descriptor (string path)
|
||||
{
|
||||
void *module;
|
||||
Glib::Module* module = new Glib::Module(path);
|
||||
PannerInfo* info = 0;
|
||||
PanPluginDescriptor *descriptor = 0;
|
||||
PanPluginDescriptor* (*dfunc)(void);
|
||||
const char *errstr;
|
||||
void* func = 0;
|
||||
|
||||
if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
|
||||
error << string_compose(_("PannerManager: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
|
||||
if (!module) {
|
||||
error << string_compose(_("PannerManager: cannot load module \"%1\" (%2)"), path,
|
||||
Glib::Module::get_last_error()) << endmsg;
|
||||
delete module;
|
||||
return 0;
|
||||
}
|
||||
|
||||
dfunc = (PanPluginDescriptor* (*)(void)) dlsym (module, "panner_descriptor");
|
||||
|
||||
if ((errstr = dlerror()) != 0) {
|
||||
if (!module->get_symbol("panner_descriptor", func)) {
|
||||
error << string_compose(_("PannerManager: module \"%1\" has no descriptor function."), path) << endmsg;
|
||||
error << errstr << endmsg;
|
||||
dlclose (module);
|
||||
error << Glib::Module::get_last_error() << endmsg;
|
||||
delete module;
|
||||
return 0;
|
||||
}
|
||||
|
||||
dfunc = (PanPluginDescriptor* (*)(void))func;
|
||||
descriptor = dfunc();
|
||||
|
||||
if (descriptor) {
|
||||
info = new PannerInfo (*descriptor, module);
|
||||
} else {
|
||||
dlclose (module);
|
||||
delete module;
|
||||
}
|
||||
|
||||
return info;
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <cstdio>
|
||||
#include <lrdf.h>
|
||||
#include <dlfcn.h>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
|
||||
@ -365,25 +364,26 @@ PluginManager::add_lrdf_data (const string &path)
|
||||
int
|
||||
PluginManager::ladspa_discover (string path)
|
||||
{
|
||||
void *module;
|
||||
Glib::Module module(path);
|
||||
const LADSPA_Descriptor *descriptor;
|
||||
LADSPA_Descriptor_Function dfunc;
|
||||
const char *errstr;
|
||||
void* func = 0;
|
||||
|
||||
if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
|
||||
error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
|
||||
if (!module) {
|
||||
error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"),
|
||||
path, Glib::Module::get_last_error()) << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
|
||||
|
||||
if ((errstr = dlerror()) != 0) {
|
||||
if (!module.get_symbol("ladspa_descriptor", func)) {
|
||||
error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
|
||||
error << errstr << endmsg;
|
||||
dlclose (module);
|
||||
error << Glib::Module::get_last_error() << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dfunc = (LADSPA_Descriptor_Function)func;
|
||||
|
||||
for (uint32_t i = 0; ; ++i) {
|
||||
if ((descriptor = dfunc (i)) == 0) {
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user