don't special case lua processors, use plugin-manager

This commit is contained in:
Robin Gareus 2016-04-29 02:57:42 +02:00
parent 961e7ecdc8
commit e56c8f0309
9 changed files with 93 additions and 21 deletions

View file

@ -163,7 +163,10 @@ class LIBARDOUR_API LuaPluginInfo : public PluginInfo
PluginPtr load (Session& session);
std::vector<Plugin::PresetRecord> get_presets (bool user_only) const;
bool is_instrument () const { return _is_instrument ; }
bool in_category (const std::string &c) const {
return (category == c);
}
bool is_instrument () const { return _is_instrument; }
bool reconfigurable_io() const { return true; }
bool _is_instrument;

View file

@ -43,10 +43,11 @@ class LIBARDOUR_API LuaScriptInfo {
static std::string type2str (const ScriptType t);
static ScriptType str2type (const std::string& str);
LuaScriptInfo (ScriptType t, const std::string &n, const std::string &p)
LuaScriptInfo (ScriptType t, const std::string &n, const std::string &p, const std::string &uid)
: type (t)
, name (n)
, path (p)
, unique_id (uid)
{ }
virtual ~LuaScriptInfo () { }
@ -54,6 +55,7 @@ class LIBARDOUR_API LuaScriptInfo {
ScriptType type;
std::string name;
std::string path;
std::string unique_id;
std::string author;
std::string license;

View file

@ -50,6 +50,7 @@ class LIBARDOUR_API PluginManager : public boost::noncopyable {
ARDOUR::PluginInfoList &ladspa_plugin_info ();
ARDOUR::PluginInfoList &lv2_plugin_info ();
ARDOUR::PluginInfoList &au_plugin_info ();
ARDOUR::PluginInfoList &lua_plugin_info ();
void refresh (bool cache_only = false);
void cancel_plugin_scan();
@ -112,6 +113,7 @@ class LIBARDOUR_API PluginManager : public boost::noncopyable {
ARDOUR::PluginInfoList* _ladspa_plugin_info;
ARDOUR::PluginInfoList* _lv2_plugin_info;
ARDOUR::PluginInfoList* _au_plugin_info;
ARDOUR::PluginInfoList* _lua_plugin_info;
std::map<uint32_t, std::string> rdf_type;
@ -122,6 +124,8 @@ class LIBARDOUR_API PluginManager : public boost::noncopyable {
bool _cancel_timeout;
void ladspa_refresh ();
void lua_refresh ();
void lua_refresh_cb ();
void windows_vst_refresh (bool cache_only = false);
void lxvst_refresh (bool cache_only = false);
@ -146,6 +150,7 @@ class LIBARDOUR_API PluginManager : public boost::noncopyable {
std::string get_ladspa_category (uint32_t id);
std::vector<uint32_t> ladspa_plugin_whitelist;
PBD::ScopedConnection lua_refresh_connection;
Glib::Threads::Mutex _lock;
static PluginManager* _instance; // singleton

View file

@ -106,6 +106,7 @@ ARDOUR::LuaAPI::new_plugin_info (const string& name, ARDOUR::PluginType type)
PluginManager& manager = PluginManager::instance();
PluginInfoList all_plugs;
all_plugs.insert(all_plugs.end(), manager.ladspa_plugin_info().begin(), manager.ladspa_plugin_info().end());
all_plugs.insert(all_plugs.end(), manager.lua_plugin_info().begin(), manager.lua_plugin_info().end());
#ifdef WINDOWS_VST_SUPPORT
all_plugs.insert(all_plugs.end(), manager.windows_vst_plugin_info().begin(), manager.windows_vst_plugin_info().end());
#endif

View file

@ -1016,7 +1016,7 @@ LuaPluginInfo::LuaPluginInfo (LuaScriptInfoPtr lsi) {
name = lsi->name;
creator = lsi->author;
category = lsi->category;
unique_id = "luascript"; // the interpreter is not unique.
unique_id = lsi->unique_id;
n_inputs.set (DataType::AUDIO, 1);
n_outputs.set (DataType::AUDIO, 1);

View file

@ -33,6 +33,7 @@
#include "LuaBridge/LuaBridge.h"
#include "i18n.h"
#include "sha1.c"
using namespace ARDOUR;
using namespace PBD;
@ -186,6 +187,7 @@ LuaScripting::scan_script (const std::string &fn, const std::string &sc)
"function ardour (entry)"
" ardourluainfo['type'] = assert(entry['type'])"
" ardourluainfo['name'] = assert(entry['name'])"
" ardourluainfo['category'] = entry['category'] or 'Unknown'"
" ardourluainfo['author'] = entry['author'] or 'Unknown'"
" ardourluainfo['license'] = entry['license'] or ''"
" ardourluainfo['description'] = entry['description'] or ''"
@ -236,7 +238,24 @@ LuaScripting::scan_script (const std::string &fn, const std::string &sc)
return LuaScriptInfoPtr();
}
LuaScriptInfoPtr lsi (new LuaScriptInfo (type, name, fn));
char hash[41];
Sha1Digest s;
sha1_init (&s);
if (fn.empty()) {
sha1_write (&s, (const uint8_t *) sc.c_str(), sc.size ());
} else {
try {
std::string script = Glib::file_get_contents (fn);
sha1_write (&s, (const uint8_t *) script.c_str(), script.size ());
} catch (Glib::FileError err) {
return LuaScriptInfoPtr();
}
}
sha1_result_hash (&s, hash);
LuaScriptInfoPtr lsi (new LuaScriptInfo (type, name, fn, hash));
for (luabridge::Iterator i(nfo); !i.isNil (); ++i) {
if (!i.key().isString() || !i.value().isString()) {
@ -248,8 +267,8 @@ LuaScripting::scan_script (const std::string &fn, const std::string &sc)
if (key == "author") { lsi->author = val; }
if (key == "license") { lsi->license = val; }
if (key == "description") { lsi->description = val; }
if (key == "category") { lsi->category = val; }
}
return lsi;
}

View file

@ -164,10 +164,7 @@ ARDOUR::find_plugin(Session& session, string identifier, PluginType type)
switch (type) {
case ARDOUR::Lua:
{
PluginPtr plugin (new LuaProc (session.engine(), session, ""));
return plugin;
}
plugs = mgr.lua_plugin_info();
break;
case ARDOUR::LADSPA:

View file

@ -150,7 +150,6 @@ PluginInsert::set_count (uint32_t num)
void
PluginInsert::set_sinks (const ChanCount& c)
{
bool changed = (_custom_sinks != c) && _custom_cfg;
_custom_sinks = c;
/* no signal, change will only be visible after re-config */
}
@ -2117,6 +2116,19 @@ PluginInsert::set_state(const XMLNode& node, int version)
}
#endif
if (plugin == 0 && type == ARDOUR::Lua) {
/* unique ID (sha1 of script) was not found,
* load the plugin from the serialized version in the
* session-file instead.
*/
boost::shared_ptr<LuaProc> lp (new LuaProc (_session.engine(), _session, ""));
XMLNode *ls = node.child (lp->state_node_name().c_str());
if (ls && lp) {
lp->set_script_from_state (*ls);
plugin = lp;
}
}
if (plugin == 0) {
error << string_compose(
_("Found a reference to a plugin (\"%1\") that is unknown.\n"
@ -2126,15 +2138,6 @@ PluginInsert::set_state(const XMLNode& node, int version)
return -1;
}
if (type == ARDOUR::Lua) {
XMLNode *ls = node.child (plugin->state_node_name().c_str());
// we need to load the script to set the name and parameters.
boost::shared_ptr<LuaProc> lp = boost::dynamic_pointer_cast<LuaProc>(plugin);
if (ls && lp) {
lp->set_script_from_state (*ls);
}
}
// The name of the PluginInsert comes from the plugin, nothing else
_name = plugin->get_info()->name;

View file

@ -67,6 +67,8 @@
#include "ardour/filesystem_paths.h"
#include "ardour/ladspa.h"
#include "ardour/ladspa_plugin.h"
#include "ardour/luascripting.h"
#include "ardour/luaproc.h"
#include "ardour/plugin.h"
#include "ardour/plugin_manager.h"
#include "ardour/rc_configuration.h"
@ -119,6 +121,7 @@ PluginManager::PluginManager ()
, _ladspa_plugin_info(0)
, _lv2_plugin_info(0)
, _au_plugin_info(0)
, _lua_plugin_info(0)
, _cancel_scan(false)
, _cancel_timeout(false)
{
@ -215,6 +218,8 @@ PluginManager::PluginManager ()
}
BootMessage (_("Discovering Plugins"));
LuaScripting::instance().scripts_changed.connect_same_thread (lua_refresh_connection, boost::bind (&PluginManager::lua_refresh_cb, this));
}
@ -227,6 +232,7 @@ PluginManager::~PluginManager()
delete _ladspa_plugin_info;
delete _lv2_plugin_info;
delete _au_plugin_info;
delete _lua_plugin_info;
}
}
@ -244,6 +250,8 @@ PluginManager::refresh (bool cache_only)
BootMessage (_("Scanning LADSPA Plugins"));
ladspa_refresh ();
BootMessage (_("Scanning Lua DSP Processors"));
lua_refresh ();
#ifdef LV2_SUPPORT
BootMessage (_("Scanning LV2 Plugins"));
lv2_refresh ();
@ -452,6 +460,32 @@ PluginManager::clear_au_blacklist ()
#endif
}
void
PluginManager::lua_refresh ()
{
if (_lua_plugin_info) {
_lua_plugin_info->clear ();
} else {
_lua_plugin_info = new ARDOUR::PluginInfoList ();
}
ARDOUR::LuaScriptList & _scripts (LuaScripting::instance ().scripts (LuaScriptInfo::DSP));
for (LuaScriptList::const_iterator s = _scripts.begin(); s != _scripts.end(); ++s) {
LuaPluginInfoPtr lpi (new LuaPluginInfo(*s));
_lua_plugin_info->push_back (lpi);
}
}
void
PluginManager::lua_refresh_cb ()
{
Glib::Threads::Mutex::Lock lm (_lock, Glib::Threads::TRY_LOCK);
if (!lm.locked()) {
return;
}
lua_refresh ();
PluginListChanged (); /* EMIT SIGNAL */
}
void
PluginManager::ladspa_refresh ()
{
@ -1104,8 +1138,7 @@ PluginManager::save_statuses ()
ofs << "LXVST";
break;
case Lua:
assert (0);
continue;
ofs << "Lua";
break;
}
@ -1193,6 +1226,8 @@ PluginManager::load_statuses ()
type = Windows_VST;
} else if (stype == "LXVST") {
type = LXVST;
} else if (stype == "Lua") {
type = Lua;
} else {
error << string_compose (_("unknown plugin type \"%1\" - ignored"), stype)
<< endmsg;
@ -1270,3 +1305,10 @@ PluginManager::au_plugin_info ()
#endif
return _empty_plugin_info;
}
ARDOUR::PluginInfoList&
PluginManager::lua_plugin_info ()
{
assert(_lua_plugin_info);
return *_lua_plugin_info;
}