Browse Source

Small optimization to lv2 init/list code

tags/1.9.7
falkTX 8 years ago
parent
commit
a7a2068f4a
2 changed files with 60 additions and 31 deletions
  1. +7
    -9
      source/backend/CarlaUtils.cpp
  2. +53
    -22
      source/utils/CarlaLv2Utils.hpp

+ 7
- 9
source/backend/CarlaUtils.cpp View File

@@ -120,7 +120,6 @@ const char* carla_get_complete_license_text()
"<li>MIDI Sequencer UI code by Perry Nguyen</li>" "<li>MIDI Sequencer UI code by Perry Nguyen</li>"
"<li>MVerb plugin code by Martin Eastwood</li>" "<li>MVerb plugin code by Martin Eastwood</li>"
"<li>Nekobi plugin code based on nekobee by Sean Bolton and others</li>" "<li>Nekobi plugin code based on nekobee by Sean Bolton and others</li>"
"<li>NekoFilter plugin code based on lv2fil by Nedko Arnaudov and Fons Adriaensen</li>"
#ifdef HAVE_ZYN_DEPS #ifdef HAVE_ZYN_DEPS
"<li>ZynAddSubFX plugin code by Mark McCurry and Nasca Octavian Paul</li>" "<li>ZynAddSubFX plugin code by Mark McCurry and Nasca Octavian Paul</li>"
#endif #endif
@@ -237,14 +236,13 @@ uint carla_get_cached_plugin_count(CB::PluginType ptype, const char* pluginPath)
#ifdef CARLA_OS_MAC #ifdef CARLA_OS_MAC
static bool initiated = false; static bool initiated = false;


if (initiated)
return static_cast<uint>(gCachedAuPluginResults.size());

using namespace juce;

initiated = true;
AudioUnitPluginFormat auFormat;
gCachedAuPluginResults = auFormat.searchPathsForPlugins(juce::FileSearchPath(), false);
if (! initiated)
{
using namespace juce;
initiated = true;
AudioUnitPluginFormat auFormat;
gCachedAuPluginResults = auFormat.searchPathsForPlugins(juce::FileSearchPath(), false);
}


return static_cast<uint>(gCachedAuPluginResults.size()); return static_cast<uint>(gCachedAuPluginResults.size());
#else #else


+ 53
- 22
source/utils/CarlaLv2Utils.hpp View File

@@ -248,6 +248,10 @@ public:


bool needsInit; bool needsInit;


const LilvPlugins* allPlugins;
const LilvPlugin** cachedPlugins;
uint pluginCount;

// ------------------------------------------------------------------- // -------------------------------------------------------------------


Lv2WorldClass() Lv2WorldClass()
@@ -365,7 +369,22 @@ public:
rdf_type (new_uri(NS_rdf "type")), rdf_type (new_uri(NS_rdf "type")),
rdfs_label (new_uri(NS_rdfs "label")), rdfs_label (new_uri(NS_rdfs "label")),


needsInit(true) {}
needsInit(true),
allPlugins(nullptr),
cachedPlugins(nullptr),
pluginCount(0) {}

~Lv2WorldClass() override
{
pluginCount = 0;
allPlugins = nullptr;

if (cachedPlugins != nullptr)
{
delete[] cachedPlugins;
cachedPlugins = nullptr;
}
}


static Lv2WorldClass& getInstance() static Lv2WorldClass& getInstance()
{ {
@@ -383,57 +402,69 @@ public:
needsInit = false; needsInit = false;


Lilv::World::load_all(LV2_PATH); Lilv::World::load_all(LV2_PATH);

allPlugins = lilv_world_get_all_plugins(this->me);
CARLA_SAFE_ASSERT_RETURN(allPlugins != nullptr,);

if ((pluginCount = lilv_plugins_size(allPlugins)))
{
cachedPlugins = new const LilvPlugin*[pluginCount+1];
carla_zeroPointers(cachedPlugins, pluginCount+1);

int i = 0;
for (LilvIter* it = lilv_plugins_begin(allPlugins); ! lilv_plugins_is_end(allPlugins, it); it = lilv_plugins_next(allPlugins, it))
cachedPlugins[i++] = lilv_plugins_get(allPlugins, it);
}
} }


void load_bundle(const char* const bundle) void load_bundle(const char* const bundle)
{ {
CARLA_SAFE_ASSERT_RETURN(bundle != nullptr && bundle[0] != '\0',); CARLA_SAFE_ASSERT_RETURN(bundle != nullptr && bundle[0] != '\0',);
CARLA_SAFE_ASSERT_RETURN(needsInit,);


needsInit = false; needsInit = false;
Lilv::World::load_bundle(Lilv::Node(new_uri(bundle))); Lilv::World::load_bundle(Lilv::Node(new_uri(bundle)));

allPlugins = lilv_world_get_all_plugins(this->me);
CARLA_SAFE_ASSERT_RETURN(allPlugins != nullptr,);

if ((pluginCount = lilv_plugins_size(allPlugins)))
{
cachedPlugins = new const LilvPlugin*[pluginCount+1];
carla_zeroPointers(cachedPlugins, pluginCount+1);

int i = 0;
for (LilvIter* it = lilv_plugins_begin(allPlugins); ! lilv_plugins_is_end(allPlugins, it); it = lilv_plugins_next(allPlugins, it))
cachedPlugins[i++] = lilv_plugins_get(allPlugins, it);
}
} }


uint getPluginCount() const uint getPluginCount() const
{ {
CARLA_SAFE_ASSERT_RETURN(! needsInit, 0); CARLA_SAFE_ASSERT_RETURN(! needsInit, 0);


const LilvPlugins* const cPlugins(lilv_world_get_all_plugins(this->me));
CARLA_SAFE_ASSERT_RETURN(cPlugins != nullptr, 0);

return lilv_plugins_size(cPlugins);
return pluginCount;
} }


const LilvPlugin* getPluginFromIndex(const uint index) const const LilvPlugin* getPluginFromIndex(const uint index) const
{ {
CARLA_SAFE_ASSERT_RETURN(! needsInit, nullptr); CARLA_SAFE_ASSERT_RETURN(! needsInit, nullptr);
CARLA_SAFE_ASSERT_RETURN(cachedPlugins != nullptr, nullptr);
CARLA_SAFE_ASSERT_RETURN(index < pluginCount, nullptr);


const LilvPlugins* const cPlugins(lilv_world_get_all_plugins(this->me));
CARLA_SAFE_ASSERT_RETURN(cPlugins != nullptr, nullptr);

uint32_t i=0;
for (LilvIter *it = lilv_plugins_begin(cPlugins); ! lilv_plugins_is_end(cPlugins, it); it = lilv_plugins_next(cPlugins, it), ++i)
{
if (index != i)
continue;

return lilv_plugins_get(cPlugins, it);
}

return nullptr;
return cachedPlugins[index];
} }


const LilvPlugin* getPluginFromURI(const LV2_URI uri) const const LilvPlugin* getPluginFromURI(const LV2_URI uri) const
{ {
CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr); CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr);
CARLA_SAFE_ASSERT_RETURN(! needsInit, nullptr); CARLA_SAFE_ASSERT_RETURN(! needsInit, nullptr);

const LilvPlugins* const cPlugins(lilv_world_get_all_plugins(this->me));
CARLA_SAFE_ASSERT_RETURN(cPlugins != nullptr, nullptr);
CARLA_SAFE_ASSERT_RETURN(allPlugins != nullptr, nullptr);


LilvNode* const uriNode(lilv_new_uri(this->me, uri)); LilvNode* const uriNode(lilv_new_uri(this->me, uri));
CARLA_SAFE_ASSERT_RETURN(uriNode != nullptr, nullptr); CARLA_SAFE_ASSERT_RETURN(uriNode != nullptr, nullptr);


const LilvPlugin* const cPlugin(lilv_plugins_get_by_uri(cPlugins, uriNode));
const LilvPlugin* const cPlugin(lilv_plugins_get_by_uri(allPlugins, uriNode));
lilv_node_free(uriNode); lilv_node_free(uriNode);


return cPlugin; return cPlugin;


Loading…
Cancel
Save