13
0

Most PluginManager refactoring is out of the way. Time to begin on AudioUnit support for real.

git-svn-id: svn://localhost/ardour2/trunk@752 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Taybin Rutkin 2006-08-03 17:17:38 +00:00
parent e46924420f
commit 5fdfe49406
17 changed files with 175 additions and 121 deletions

View File

@ -446,7 +446,7 @@ int main (int argc, char *argv[])
try {
engine = new ARDOUR::AudioEngine (jack_client_name);
ARDOUR::init (*engine, use_vst, try_hw_optimization);
ARDOUR::init (use_vst, try_hw_optimization);
ui->set_engine (*engine);
} catch (AudioEngine::NoBackendAvailable& err) {
gui_jack_error ();

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2000 Paul Davis
Copyright (C) 2000-2006 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -48,8 +48,6 @@ PluginSelector::PluginSelector (PluginManager *mgr)
manager = mgr;
session = 0;
o_selected_plug = -1;
i_selected_plug = 0;
current_selection = PluginInfo::LADSPA;
@ -346,7 +344,7 @@ PluginSelector::use_plugin (PluginInfoPtr pi)
return;
}
boost::shared_ptr<Plugin> plugin = manager->load (*session, pi);
PluginPtr plugin = pi->load (*session);
if (plugin) {
PluginCreated (plugin);

View File

@ -30,7 +30,6 @@
namespace ARDOUR {
class Session;
class PluginManager;
class PluginInfo;
}
class PluginSelector : public ArdourDialog
@ -134,12 +133,6 @@ class PluginSelector : public ArdourDialog
void au_display_selection_changed();
#endif //HAVE_COREAUDIO
ARDOUR::PluginInfo* i_selected_plug;
// We need an integer for the output side because
// the name isn't promised to be unique.
gint o_selected_plug;
ARDOUR::PluginManager *manager;
static void _input_refiller (void *);

View File

@ -326,8 +326,8 @@ PluginUI::build (AudioEngine &engine)
}
}
n_ins = plugin->get_info().n_inputs;
n_outs = plugin->get_info().n_outputs;
n_ins = plugin->get_info()->n_inputs;
n_outs = plugin->get_info()->n_outputs;
if (box->children().empty()) {
hpacker.remove (*frame);

View File

@ -378,7 +378,7 @@ RedirectBox::wierd_plugin_dialog (Plugin& p, uint32_t streams, boost::shared_ptr
/* i hate this kind of code */
if (streams > p.get_info().n_inputs) {
if (streams > p.get_info()->n_inputs) {
label.set_text (string_compose (_(
"You attempted to add a plugin (%1).\n"
"The plugin has %2 inputs\n"
@ -388,9 +388,9 @@ RedirectBox::wierd_plugin_dialog (Plugin& p, uint32_t streams, boost::shared_ptr
"This makes no sense - you are throwing away\n"
"part of the signal."),
p.name(),
p.get_info().n_inputs,
p.get_info()->n_inputs,
streams));
} else if (streams < p.get_info().n_inputs) {
} else if (streams < p.get_info()->n_inputs) {
label.set_text (string_compose (_(
"You attempted to add a plugin (%1).\n"
"The plugin has %2 inputs\n"
@ -401,7 +401,7 @@ RedirectBox::wierd_plugin_dialog (Plugin& p, uint32_t streams, boost::shared_ptr
"side-chain inputs. A future version of Ardour will\n"
"support this type of configuration."),
p.name(),
p.get_info().n_inputs,
p.get_info()->n_inputs,
streams));
} else {
label.set_text (string_compose (_(
@ -415,8 +415,8 @@ RedirectBox::wierd_plugin_dialog (Plugin& p, uint32_t streams, boost::shared_ptr
"\n"
"Ardour does not understand what to do in such situations.\n"),
p.name(),
p.get_info().n_inputs,
p.get_info().n_outputs,
p.get_info()->n_inputs,
p.get_info()->n_outputs,
io->n_inputs(),
io->n_outputs(),
streams));

View File

@ -45,7 +45,7 @@ namespace ARDOUR {
static const jack_nframes_t max_frames = JACK_MAX_FRAMES;
int init (AudioEngine&, bool with_vst, bool try_optimization);
int init (bool with_vst, bool try_optimization);
int cleanup ();

View File

@ -31,11 +31,51 @@ struct ComponentDescription;
namespace ARDOUR {
class CAAudioUnit;
class AUPlugin : public ARDOUR::Plugin
{
public:
AUPlugin (AudioEngine& engine, Session& session) : Plugin(engine, session) {};
virtual ~AUPlugin () {};
uint32_t unique_id () const;
const char * label () const;
const char * name () const { return _info->name.c_str(); }
const char * maker () const;
uint32_t parameter_count () const;
float default_value (uint32_t port);
jack_nframes_t latency () const;
void set_parameter (uint32_t which, float val);
float get_parameter (uint32_t which) const;
int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
uint32_t nth_parameter (uint32_t which, bool& ok) const;
void activate ();
void deactivate ();
void set_block_size (jack_nframes_t nframes);
int connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, jack_nframes_t nframes, jack_nframes_t offset);
std::set<uint32_t> automatable() const;
void store_state (ARDOUR::PluginState&);
void restore_state (ARDOUR::PluginState&);
string describe_parameter (uint32_t);
string state_node_name () const;
void print_parameter (uint32_t, char*, uint32_t len) const;
bool parameter_is_audio (uint32_t) const;
bool parameter_is_control (uint32_t) const;
bool parameter_is_input (uint32_t) const;
bool parameter_is_output (uint32_t) const;
bool save_preset (string name);
bool load_preset (const string preset_label);
std::vector<std::string> get_presets ();
bool has_editor () const;
private:
boost::shared_ptr<CAAudioUnit> unit;
};
class AUPluginInfo : public PluginInfo {
@ -48,6 +88,7 @@ class AUPluginInfo : public PluginInfo {
CompDescPtr desc;
static PluginInfoList discover ();
PluginPtr load (Session& session);
private:
static std::string get_name (ComponentDescription&);
@ -58,4 +99,3 @@ typedef boost::shared_ptr<AUPluginInfo> AUPluginInfoPtr;
} // namespace ARDOUR
#endif // __ardour_audio_unit_h__

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2000 Paul Davis
Copyright (C) 2000-2006 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -137,6 +137,17 @@ class LadspaPlugin : public ARDOUR::Plugin
void run (jack_nframes_t nsamples);
void latency_compute_run ();
};
}
class LadspaPluginInfo : public PluginInfo {
public:
LadspaPluginInfo () { };
~LadspaPluginInfo () { };
PluginPtr load (Session& session);
};
typedef boost::shared_ptr<LadspaPluginInfo> LadspaPluginInfoPtr;
} // namespace ARDOUR
#endif /* __ardour_ladspa_plugin_h__ */

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2000 Paul Davis
Copyright (C) 2000-2006 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -18,8 +18,8 @@
$Id$
*/
#ifndef __ardour_ladspa_h__
#define __ardour_ladspa_h__
#ifndef __ardour_plugin_h__
#define __ardour_plugin_h__
#include <boost/shared_ptr.hpp>
#include <sigc++/signal.h>
@ -46,6 +46,9 @@ namespace ARDOUR {
class AudioEngine;
class Session;
class Plugin;
typedef boost::shared_ptr<Plugin> PluginPtr;
class PluginInfo {
public:
enum Type {
@ -54,11 +57,12 @@ class PluginInfo {
VST
};
PluginInfo () { };
PluginInfo () { }
PluginInfo (const PluginInfo &o)
: name(o.name), n_inputs(o.n_inputs), n_outputs(o.n_outputs),
unique_id(o.unique_id), path (o.path), index(o.index) {}
~PluginInfo () { };
virtual ~PluginInfo () { }
string name;
string category;
uint32_t n_inputs;
@ -67,7 +71,9 @@ class PluginInfo {
long unique_id;
private:
virtual PluginPtr load (Session& session) = 0;
protected:
friend class PluginManager;
string path;
uint32_t index;
@ -82,7 +88,7 @@ class Plugin : public Stateful, public sigc::trackable
public:
Plugin (ARDOUR::AudioEngine&, ARDOUR::Session&);
Plugin (const Plugin&);
~Plugin ();
virtual ~Plugin ();
struct ParameterDescriptor {
@ -143,8 +149,8 @@ class Plugin : public Stateful, public sigc::trackable
PBD::Controllable *get_nth_control (uint32_t);
PluginInfo & get_info() { return _info; }
void set_info (const PluginInfo &inf) { _info = inf; }
PluginInfoPtr get_info() { return _info; }
void set_info (const PluginInfoPtr inf) { _info = inf; }
ARDOUR::AudioEngine& engine() const { return _engine; }
ARDOUR::Session& session() const { return _session; }
@ -155,7 +161,7 @@ class Plugin : public Stateful, public sigc::trackable
protected:
ARDOUR::AudioEngine& _engine;
ARDOUR::Session& _session;
PluginInfo _info;
PluginInfoPtr _info;
uint32_t _cycles;
map<string,string> presets;
bool save_preset(string name, string domain /* vst, ladspa etc. */);
@ -182,7 +188,6 @@ class Plugin : public Stateful, public sigc::trackable
};
/* this is actually defined in plugin_manager.cc */
boost::shared_ptr<Plugin> find_plugin(ARDOUR::Session&, string name, long unique_id, PluginInfo::Type);
} // namespace ARDOUR

View File

@ -5,22 +5,19 @@
#include <map>
#include <string>
#include <boost/shared_ptr.hpp>
#include <ardour/types.h>
#include <ardour/plugin.h>
#include <ardour/audio_unit.h>
namespace ARDOUR {
class PluginInfo;
class Plugin;
class Session;
class AudioEngine;
class PluginManager {
public:
PluginManager (ARDOUR::AudioEngine&);
PluginManager ();
~PluginManager ();
ARDOUR::PluginInfoList &vst_plugin_info () { return _vst_plugin_info; }
@ -31,12 +28,9 @@ class PluginManager {
int add_ladspa_directory (std::string dirpath);
int add_vst_directory (std::string dirpath);
boost::shared_ptr<Plugin> load (ARDOUR::Session& s, PluginInfoPtr info);
static PluginManager* the_manager() { return _manager; }
private:
ARDOUR::AudioEngine& _engine;
ARDOUR::PluginInfoList _vst_plugin_info;
ARDOUR::PluginInfoList _ladspa_plugin_info;
std::map<uint32_t, std::string> rdf_type;

View File

@ -104,6 +104,14 @@ class VSTPlugin : public ARDOUR::Plugin
bool been_resumed;
};
}
class VSTPluginInfo : public PluginInfo
{
VSTPluginInfo () {}
~VSTPluginInfo () {}
PluginPtr load (Session& session);
};
} // namespace ARDOUR
#endif /* __ardour_vst_plugin_h__ */

View File

@ -26,6 +26,14 @@
using namespace ARDOUR;
PluginPtr
AUPluginInfo::load (Session& session)
{
return PluginPtr((AUPlugin*)0);
}
PluginInfoList
AUPluginInfo::discover ()
{

View File

@ -190,7 +190,7 @@ setup_midi ()
}
int
ARDOUR::init (AudioEngine& engine, bool use_vst, bool try_optimization)
ARDOUR::init (bool use_vst, bool try_optimization)
{
bool generic_mix_functions = true;
@ -300,7 +300,7 @@ ARDOUR::init (AudioEngine& engine, bool use_vst, bool try_optimization)
}
/* singleton - first object is "it" */
new PluginManager (engine);
new PluginManager ();
/* singleton - first object is "it" */
new ControlProtocolManager ();

View File

@ -186,25 +186,25 @@ PluginInsert::auto_state_changed (uint32_t which)
uint32_t
PluginInsert::output_streams() const
{
return _plugins[0]->get_info().n_outputs * _plugins.size();
return _plugins[0]->get_info()->n_outputs * _plugins.size();
}
uint32_t
PluginInsert::input_streams() const
{
return _plugins[0]->get_info().n_inputs * _plugins.size();
return _plugins[0]->get_info()->n_inputs * _plugins.size();
}
uint32_t
PluginInsert::natural_output_streams() const
{
return _plugins[0]->get_info().n_outputs;
return _plugins[0]->get_info()->n_outputs;
}
uint32_t
PluginInsert::natural_input_streams() const
{
return _plugins[0]->get_info().n_inputs;
return _plugins[0]->get_info()->n_inputs;
}
bool
@ -214,7 +214,7 @@ PluginInsert::is_generator() const
a specific "instrument" flag, for example.
*/
return _plugins[0]->get_info().n_inputs == 0;
return _plugins[0]->get_info()->n_inputs == 0;
}
void
@ -350,7 +350,7 @@ PluginInsert::silence (jack_nframes_t nframes, jack_nframes_t offset)
if (active()) {
for (vector<boost::shared_ptr<Plugin> >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
n = (*i) -> get_info().n_inputs;
n = (*i) -> get_info()->n_inputs;
(*i)->connect_and_run (_session.get_silent_buffers (n), n, in_index, out_index, nframes, offset);
}
}
@ -367,8 +367,8 @@ PluginInsert::run (vector<Sample *>& bufs, uint32_t nbufs, jack_nframes_t nframe
connect_and_run (bufs, nbufs, nframes, offset, false);
}
} else {
uint32_t in = _plugins[0]->get_info().n_inputs;
uint32_t out = _plugins[0]->get_info().n_outputs;
uint32_t in = _plugins[0]->get_info()->n_inputs;
uint32_t out = _plugins[0]->get_info()->n_outputs;
if (out > in) {
@ -524,7 +524,7 @@ PluginInsert::plugin_factory (boost::shared_ptr<Plugin> other)
int32_t
PluginInsert::compute_output_streams (int32_t cnt) const
{
return _plugins[0]->get_info().n_outputs * cnt;
return _plugins[0]->get_info()->n_outputs * cnt;
}
int32_t
@ -536,8 +536,8 @@ PluginInsert::configure_io (int32_t magic, int32_t in, int32_t out)
int32_t
PluginInsert::can_support_input_configuration (int32_t in) const
{
int32_t outputs = _plugins[0]->get_info().n_outputs;
int32_t inputs = _plugins[0]->get_info().n_inputs;
int32_t outputs = _plugins[0]->get_info()->n_outputs;
int32_t inputs = _plugins[0]->get_info()->n_inputs;
if (inputs == 0) {
@ -591,7 +591,7 @@ PluginInsert::state (bool full)
node->add_property("id", string(buf));
if (_plugins[0]->state_node_name() == "ladspa") {
char buf[32];
snprintf (buf, sizeof (buf), "%ld", _plugins[0]->get_info().unique_id);
snprintf (buf, sizeof (buf), "%ld", _plugins[0]->get_info()->unique_id);
node->add_property("unique-id", string(buf));
}
node->add_property("count", string_compose("%1", _plugins.size()));
@ -761,7 +761,7 @@ PluginInsert::set_state(const XMLNode& node)
}
// The name of the PluginInsert comes from the plugin, nothing else
set_name(plugin->get_info().name,this);
set_name(plugin->get_info()->name,this);
return 0;
}

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2000-2002 Paul Davis
Copyright (C) 2000-2006 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -641,3 +641,26 @@ LadspaPlugin::latency_compute_run ()
run (bufsize);
deactivate ();
}
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;
} else {
plugin.reset (new LadspaPlugin (module, session.engine(), session, index, session.frame_rate()));
}
plugin->set_info(PluginInfoPtr(new LadspaPluginInfo(*this)));
return plugin;
}
catch (failed_constructor &err) {
return PluginPtr ((Plugin*) 0);
}
}

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2000-2004 Paul Davis
Copyright (C) 2000-2006 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -49,8 +49,7 @@ using namespace PBD;
PluginManager* PluginManager::_manager = 0;
PluginManager::PluginManager (AudioEngine& e)
: _engine (e)
PluginManager::PluginManager ()
{
char* s;
string lrdf_path;
@ -246,7 +245,7 @@ PluginManager::ladspa_discover (string path)
break;
}
PluginInfoPtr info(new PluginInfo);
PluginInfoPtr info(new LadspaPluginInfo);
info->name = descriptor->Name;
info->category = get_ladspa_category(descriptor->UniqueID);
info->path = path;
@ -276,60 +275,7 @@ PluginManager::ladspa_discover (string path)
return 0;
}
boost::shared_ptr<Plugin>
PluginManager::load (Session& session, PluginInfoPtr info)
{
try {
boost::shared_ptr<Plugin> plugin;
if (info->type == PluginInfo::VST) {
#ifdef VST_SUPPORT
if (Config->get_use_vst()) {
FSTHandle* handle;
if ((handle = fst_load (info->path.c_str())) == 0) {
error << string_compose(_("VST: cannot load module from \"%1\""), info->path) << endmsg;
} else {
plugin.reset (new VSTPlugin (_engine, session, handle));
}
} else {
error << _("You asked ardour to not use any VST plugins") << endmsg;
}
#else // !VST_SUPPORT
error << _("This version of ardour has no support for VST plugins") << endmsg;
return boost::shared_ptr<Plugin> ((Plugin*) 0);
#endif // !VST_SUPPORT
} else if (info->type == PluginInfo::LADSPA) {
void *module;
if ((module = dlopen (info->path.c_str(), RTLD_NOW)) == 0) {
error << string_compose(_("LADSPA: cannot load module from \"%1\""), info->path) << endmsg;
error << dlerror() << endmsg;
} else {
plugin.reset (new LadspaPlugin (module, _engine, session, info->index, session.frame_rate()));
}
} else if (info->type == PluginInfo::AudioUnit) {
#ifdef HAVE_COREAUDIO
#else // !HAVE_COREAUDIO
error << _("This version of ardour has no support for AudioUnit plugins") << endmsg;
return boost::shared_ptr<Plugin> ((Plugin*) 0);
#endif
}
plugin->set_info(*info);
return plugin;
}
catch (failed_constructor &err) {
return boost::shared_ptr<Plugin> ((Plugin*) 0);
}
}
boost::shared_ptr<Plugin>
PluginPtr
ARDOUR::find_plugin(Session& session, string name, long unique_id, PluginInfo::Type type)
{
PluginManager *mgr = PluginManager::the_manager();
@ -355,18 +301,18 @@ ARDOUR::find_plugin(Session& session, string name, long unique_id, PluginInfo::T
#endif
default:
return boost::shared_ptr<Plugin> ((Plugin *) 0);
return PluginPtr ((Plugin *) 0);
}
PluginInfoList::iterator i;
for (i = plugs.begin(); i != plugs.end(); ++i) {
if ((name == "" || (*i)->name == name) &&
(unique_id == 0 || (*i)->unique_id == unique_id)) {
return mgr->load (session, *i);
(unique_id == 0 || (*i)->unique_id == unique_id)) {
return (*i)->load (session);
}
}
return boost::shared_ptr<Plugin> ((Plugin*) 0);
return PluginPtr ((Plugin*) 0);
}
string

View File

@ -479,3 +479,31 @@ VSTPlugin::print_parameter (uint32_t param, char *buf, uint32_t len) const
memmove (buf, first_nonws, strlen (buf) - (first_nonws - buf) + 1);
}
PluginPtr
VSTPluginInfo::load (Session& session)
{
try {
PluginPtr plugin;
if (Config->get_use_vst()) {
FSTHandle* handle;
if ((handle = fst_load (info->path.c_str())) == 0) {
error << string_compose(_("VST: cannot load module from \"%1\""), info->path) << endmsg;
} else {
plugin.reset (new VSTPlugin (session.engine(), session, handle));
}
} else {
error << _("You asked ardour to not use any VST plugins") << endmsg;
return PluginPtr ((Plugin*) 0);
}
plugin->set_info(PluginInfoPtr(new VSTPluginInfo(*this)));
return plugin;
}
catch (failed_constructor &err) {
return PluginPtr ((Plugin*) 0);
}
}