Make LV2World local to lv2_plugin.cc

git-svn-id: svn://localhost/ardour2/branches/3.0@9513 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2011-05-14 19:55:46 +00:00
parent 8e717d107f
commit ac367e8904
5 changed files with 79 additions and 85 deletions

View file

@ -32,6 +32,8 @@ using namespace Gtk;
using namespace ARDOUR; using namespace ARDOUR;
using namespace PBD; using namespace PBD;
#define NS_UI "http://lv2plug.in/ns/extensions/ui#"
#if defined(HAVE_NEW_SLV2) && defined(HAVE_SUIL) #if defined(HAVE_NEW_SLV2) && defined(HAVE_SUIL)
SuilHost* LV2PluginUI::ui_host = NULL; SuilHost* LV2PluginUI::ui_host = NULL;
#endif #endif
@ -180,14 +182,15 @@ LV2PluginUI::lv2ui_instantiate(const std::string& title)
LV2PluginUI::ui_host = suil_host_new( LV2PluginUI::ui_host = suil_host_new(
LV2PluginUI::lv2_ui_write, NULL, NULL, NULL); LV2PluginUI::lv2_ui_write, NULL, NULL, NULL);
} }
LV2World* lv2_world = ARDOUR::PluginManager::the_manager()->lv2_world(); const char* container_type = (is_external_ui)
SLV2Value container_type = (is_external_ui) ? NS_UI "external"
? lv2_world->external_gui : lv2_world->gtk_gui; : NS_UI "GtkUI";
SLV2UI ui = _lv2->slv2_ui(); SLV2UI ui = _lv2->slv2_ui();
_inst = suil_instance_new( _inst = suil_instance_new(
LV2PluginUI::ui_host, LV2PluginUI::ui_host,
this, this,
slv2_value_as_uri(container_type), container_type,
slv2_value_as_uri(slv2_plugin_get_uri(_lv2->slv2_plugin())), slv2_value_as_uri(slv2_plugin_get_uri(_lv2->slv2_plugin())),
slv2_value_as_uri(slv2_ui_get_uri(ui)), slv2_value_as_uri(slv2_ui_get_uri(ui)),
slv2_value_as_uri(_lv2->ui_type()), slv2_value_as_uri(_lv2->ui_type()),

View file

@ -38,7 +38,6 @@
namespace ARDOUR { namespace ARDOUR {
class AudioEngine; class AudioEngine;
class LV2World;
class Session; class Session;
class LV2Plugin : public ARDOUR::Plugin class LV2Plugin : public ARDOUR::Plugin
@ -46,21 +45,17 @@ class LV2Plugin : public ARDOUR::Plugin
public: public:
LV2Plugin (ARDOUR::AudioEngine& engine, LV2Plugin (ARDOUR::AudioEngine& engine,
ARDOUR::Session& session, ARDOUR::Session& session,
ARDOUR::LV2World& world,
SLV2Plugin plugin, SLV2Plugin plugin,
framecnt_t sample_rate); framecnt_t sample_rate);
LV2Plugin (const LV2Plugin &); LV2Plugin (const LV2Plugin &);
~LV2Plugin (); ~LV2Plugin ();
std::string unique_id () const; std::string unique_id () const;
const char* label () const;
const char* name () const;
const char* maker () const;
const char* label () const { return slv2_value_as_string(_name); } uint32_t parameter_count () const;
const char* name () const { return slv2_value_as_string(_name); }
const char* maker () const {
return _author ? slv2_value_as_string (_author) : "Unknown";
}
uint32_t parameter_count () const { return slv2_plugin_get_num_ports(_plugin); }
float default_value (uint32_t port); float default_value (uint32_t port);
framecnt_t signal_latency () const; framecnt_t signal_latency () const;
void set_parameter (uint32_t port, float val); void set_parameter (uint32_t port, float val);
@ -125,7 +120,6 @@ class LV2Plugin : public ARDOUR::Plugin
private: private:
void* _module; void* _module;
LV2World& _world;
LV2_Feature** _features; LV2_Feature** _features;
SLV2Plugin _plugin; SLV2Plugin _plugin;
SLV2UI _ui; SLV2UI _ui;
@ -178,7 +172,7 @@ class LV2Plugin : public ARDOUR::Plugin
static char* lv2_files_new_file_path (void* host_data, static char* lv2_files_new_file_path (void* host_data,
const char* relative_path); const char* relative_path);
void init (LV2World& world, SLV2Plugin plugin, framecnt_t rate); void init (SLV2Plugin plugin, framecnt_t rate);
void run (pframes_t nsamples); void run (pframes_t nsamples);
void latency_compute_run (); void latency_compute_run ();
@ -189,42 +183,15 @@ class LV2Plugin : public ARDOUR::Plugin
}; };
/** The SLV2World, and various cached (as symbols, fast) URIs.
*
* This object represents everything ardour 'knows' about LV2
* (ie understood extensions/features/etc)
*/
class LV2World {
public:
LV2World ();
~LV2World ();
SLV2World world;
SLV2Value input_class; ///< Input port
SLV2Value output_class; ///< Output port
SLV2Value audio_class; ///< Audio port
SLV2Value control_class; ///< Control port
SLV2Value event_class; ///< Event port
SLV2Value midi_class; ///< MIDI event
SLV2Value in_place_broken;
SLV2Value integer;
SLV2Value toggled;
SLV2Value srate;
SLV2Value gtk_gui;
SLV2Value external_gui;
SLV2Value logarithmic;
};
class LV2PluginInfo : public PluginInfo { class LV2PluginInfo : public PluginInfo {
public: public:
LV2PluginInfo (void* slv2_world, void* slv2_plugin); LV2PluginInfo (void* slv2_plugin);
~LV2PluginInfo (); ~LV2PluginInfo ();
static PluginInfoList* discover (void* slv2_world);
static PluginInfoList* discover ();
PluginPtr load (Session& session); PluginPtr load (Session& session);
void* _lv2_world;
void* _slv2_plugin; void* _slv2_plugin;
}; };

View file

@ -33,10 +33,6 @@
#include "ardour/types.h" #include "ardour/types.h"
#include "ardour/plugin.h" #include "ardour/plugin.h"
#ifdef LV2_SUPPORT
#include "ardour/lv2_plugin.h"
#endif
namespace ARDOUR { namespace ARDOUR {
class Plugin; class Plugin;
@ -56,10 +52,6 @@ class PluginManager : public boost::noncopyable {
int add_ladspa_directory (std::string dirpath); int add_ladspa_directory (std::string dirpath);
int add_vst_directory (std::string dirpath); int add_vst_directory (std::string dirpath);
#ifdef LV2_SUPPORT
LV2World* lv2_world() { return _lv2_world; }
#endif
static PluginManager* the_manager() { return _manager; } static PluginManager* the_manager() { return _manager; }
enum PluginStatusType { enum PluginStatusType {
@ -107,10 +99,6 @@ class PluginManager : public boost::noncopyable {
ARDOUR::PluginInfoList* _lv2_plugin_info; ARDOUR::PluginInfoList* _lv2_plugin_info;
ARDOUR::PluginInfoList* _au_plugin_info; ARDOUR::PluginInfoList* _au_plugin_info;
#ifdef LV2_SUPPORT
LV2World* _lv2_world;
#endif
std::map<uint32_t, std::string> rdf_type; std::map<uint32_t, std::string> rdf_type;
std::string ladspa_path; std::string ladspa_path;

View file

@ -27,6 +27,8 @@
#include <glibmm.h> #include <glibmm.h>
#include <boost/utility.hpp>
#include "pbd/compose.h" #include "pbd/compose.h"
#include "pbd/error.h" #include "pbd/error.h"
#include "pbd/pathscanner.h" #include "pbd/pathscanner.h"
@ -67,26 +69,46 @@ uint32_t LV2Plugin::_midi_event_type = _uri_map.uri_to_id(
"http://lv2plug.in/ns/ext/event", "http://lv2plug.in/ns/ext/event",
"http://lv2plug.in/ns/ext/midi#MidiEvent"); "http://lv2plug.in/ns/ext/midi#MidiEvent");
class LV2World : boost::noncopyable {
public:
LV2World ();
~LV2World ();
SLV2World world;
SLV2Value input_class; ///< Input port
SLV2Value output_class; ///< Output port
SLV2Value audio_class; ///< Audio port
SLV2Value control_class; ///< Control port
SLV2Value event_class; ///< Event port
SLV2Value midi_class; ///< MIDI event
SLV2Value in_place_broken;
SLV2Value integer;
SLV2Value toggled;
SLV2Value srate;
SLV2Value gtk_gui;
SLV2Value external_gui;
SLV2Value logarithmic;
};
static LV2World _world;
LV2Plugin::LV2Plugin (AudioEngine& engine, LV2Plugin::LV2Plugin (AudioEngine& engine,
Session& session, Session& session,
LV2World& world,
SLV2Plugin plugin, SLV2Plugin plugin,
framecnt_t rate) framecnt_t rate)
: Plugin(engine, session) : Plugin(engine, session)
, _world(world)
, _features(NULL) , _features(NULL)
, _insert_id("0") , _insert_id("0")
{ {
init(world, plugin, rate); init(plugin, rate);
} }
LV2Plugin::LV2Plugin (const LV2Plugin& other) LV2Plugin::LV2Plugin (const LV2Plugin& other)
: Plugin(other) : Plugin(other)
, _world(other._world)
, _features(NULL) , _features(NULL)
, _insert_id(other._insert_id) , _insert_id(other._insert_id)
{ {
init(other._world, other._plugin, other._sample_rate); init(other._plugin, other._sample_rate);
for (uint32_t i = 0; i < parameter_count(); ++i) { for (uint32_t i = 0; i < parameter_count(); ++i) {
_control_data[i] = other._shadow_data[i]; _control_data[i] = other._shadow_data[i];
@ -95,11 +117,10 @@ LV2Plugin::LV2Plugin (const LV2Plugin& other)
} }
void void
LV2Plugin::init(LV2World& world, SLV2Plugin plugin, framecnt_t rate) LV2Plugin::init(SLV2Plugin plugin, framecnt_t rate)
{ {
DEBUG_TRACE(DEBUG::LV2, "init\n"); DEBUG_TRACE(DEBUG::LV2, "init\n");
_world = world;
_plugin = plugin; _plugin = plugin;
_ui = NULL; _ui = NULL;
_ui_type = NULL; _ui_type = NULL;
@ -155,7 +176,7 @@ LV2Plugin::init(LV2World& world, SLV2Plugin plugin, framecnt_t rate)
_data_access_extension_data.extension_data = _instance->lv2_descriptor->extension_data; _data_access_extension_data.extension_data = _instance->lv2_descriptor->extension_data;
_data_access_feature.data = &_data_access_extension_data; _data_access_feature.data = &_data_access_extension_data;
if (slv2_plugin_has_feature(plugin, world.in_place_broken)) { if (slv2_plugin_has_feature(plugin, _world.in_place_broken)) {
error << string_compose( error << string_compose(
_("LV2: \"%1\" cannot be used, since it cannot do inplace processing"), _("LV2: \"%1\" cannot be used, since it cannot do inplace processing"),
slv2_value_as_string(_name)) << endmsg; slv2_value_as_string(_name)) << endmsg;
@ -285,6 +306,30 @@ LV2Plugin::unique_id() const
return slv2_value_as_uri(slv2_plugin_get_uri(_plugin)); return slv2_value_as_uri(slv2_plugin_get_uri(_plugin));
} }
const char*
LV2Plugin::label() const
{
return slv2_value_as_string(_name);
}
const char*
LV2Plugin::name() const
{
return slv2_value_as_string(_name);
}
const char*
LV2Plugin::maker() const
{
return _author ? slv2_value_as_string (_author) : "Unknown";
}
uint32_t
LV2Plugin::parameter_count() const
{
return slv2_plugin_get_num_ports(_plugin);
}
float float
LV2Plugin::default_value(uint32_t port) LV2Plugin::default_value(uint32_t port)
{ {
@ -1137,9 +1182,8 @@ LV2World::~LV2World()
slv2_value_free(in_place_broken); slv2_value_free(in_place_broken);
} }
LV2PluginInfo::LV2PluginInfo (void* lv2_world, void* slv2_plugin) LV2PluginInfo::LV2PluginInfo (void* slv2_plugin)
: _lv2_world(lv2_world) : _slv2_plugin(slv2_plugin)
, _slv2_plugin(slv2_plugin)
{ {
type = ARDOUR::LV2; type = ARDOUR::LV2;
} }
@ -1154,7 +1198,7 @@ LV2PluginInfo::load(Session& session)
PluginPtr plugin; PluginPtr plugin;
plugin.reset(new LV2Plugin(session.engine(), session, plugin.reset(new LV2Plugin(session.engine(), session,
*(LV2World*)_lv2_world, (SLV2Plugin)_slv2_plugin, (SLV2Plugin)_slv2_plugin,
session.frame_rate())); session.frame_rate()));
plugin->set_info(PluginInfoPtr(new LV2PluginInfo(*this))); plugin->set_info(PluginInfoPtr(new LV2PluginInfo(*this)));
@ -1167,17 +1211,16 @@ LV2PluginInfo::load(Session& session)
} }
PluginInfoList* PluginInfoList*
LV2PluginInfo::discover(void* lv2_world) LV2PluginInfo::discover()
{ {
PluginInfoList* plugs = new PluginInfoList; PluginInfoList* plugs = new PluginInfoList;
LV2World* world = (LV2World*)lv2_world; SLV2Plugins plugins = slv2_world_get_all_plugins(_world.world);
SLV2Plugins plugins = slv2_world_get_all_plugins(world->world);
cerr << "LV2: Discovering " << slv2_plugins_size(plugins) << " plugins" << endl; cerr << "LV2: Discovering " << slv2_plugins_size(plugins) << " plugins" << endl;
for (unsigned i = 0; i < slv2_plugins_size(plugins); ++i) { for (unsigned i = 0; i < slv2_plugins_size(plugins); ++i) {
SLV2Plugin p = slv2_plugins_get_at(plugins, i); SLV2Plugin p = slv2_plugins_get_at(plugins, i);
LV2PluginInfoPtr info(new LV2PluginInfo(lv2_world, p)); LV2PluginInfoPtr info(new LV2PluginInfo(p));
SLV2Value name = slv2_plugin_get_name(p); SLV2Value name = slv2_plugin_get_name(p);
@ -1203,17 +1246,17 @@ LV2PluginInfo::discover(void* lv2_world)
info->n_inputs.set_audio( info->n_inputs.set_audio(
slv2_plugin_get_num_ports_of_class( slv2_plugin_get_num_ports_of_class(
p, world->input_class, world->audio_class, NULL)); p, _world.input_class, _world.audio_class, NULL));
info->n_inputs.set_midi( info->n_inputs.set_midi(
slv2_plugin_get_num_ports_of_class( slv2_plugin_get_num_ports_of_class(
p, world->input_class, world->event_class, NULL)); p, _world.input_class, _world.event_class, NULL));
info->n_outputs.set_audio( info->n_outputs.set_audio(
slv2_plugin_get_num_ports_of_class( slv2_plugin_get_num_ports_of_class(
p, world->output_class, world->audio_class, NULL)); p, _world.output_class, _world.audio_class, NULL));
info->n_outputs.set_midi( info->n_outputs.set_midi(
slv2_plugin_get_num_ports_of_class( slv2_plugin_get_num_ports_of_class(
p, world->output_class, world->event_class, NULL)); p, _world.output_class, _world.event_class, NULL));
info->unique_id = slv2_value_as_uri(slv2_plugin_get_uri(p)); info->unique_id = slv2_value_as_uri(slv2_plugin_get_uri(p));
info->index = 0; // Meaningless for LV2 info->index = 0; // Meaningless for LV2

View file

@ -133,19 +133,12 @@ PluginManager::PluginManager ()
ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter
} }
#ifdef LV2_SUPPORT
_lv2_world = new LV2World();
#endif
BootMessage (_("Discovering Plugins")); BootMessage (_("Discovering Plugins"));
} }
PluginManager::~PluginManager() PluginManager::~PluginManager()
{ {
#ifdef LV2_SUPPORT
delete _lv2_world;
#endif
} }
@ -475,7 +468,7 @@ void
PluginManager::lv2_refresh () PluginManager::lv2_refresh ()
{ {
delete _lv2_plugin_info; delete _lv2_plugin_info;
_lv2_plugin_info = LV2PluginInfo::discover(_lv2_world); _lv2_plugin_info = LV2PluginInfo::discover();
} }
#endif #endif