don't special case lua processors, use plugin-manager
authorRobin Gareus <robin@gareus.org>
Fri, 29 Apr 2016 00:57:42 +0000 (02:57 +0200)
committerRobin Gareus <robin@gareus.org>
Fri, 29 Apr 2016 00:57:42 +0000 (02:57 +0200)
libs/ardour/ardour/luaproc.h
libs/ardour/ardour/luascripting.h
libs/ardour/ardour/plugin_manager.h
libs/ardour/lua_api.cc
libs/ardour/luaproc.cc
libs/ardour/luascripting.cc
libs/ardour/plugin.cc
libs/ardour/plugin_insert.cc
libs/ardour/plugin_manager.cc

index a0f49d61bbe4e04e16cfc1b20256ff81a007b880..d7c0aea5c5848695960b1384f75a30e4e8106a64 100644 (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;
index b48aaa9a69949e25f6fb8654e64893cb7e7cb72b..1e7833fc543002db095cb97a579f36794652a0cd 100644 (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;
index e25a268b2e1fa5a7c9b3e983f8c6b448be597616..1a925432a08a1dfc5a6aa35ae439f250d2f31706 100644 (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
index e24902999d4d0fe0bfb11a3e9968d243ee32a2b5..911280305af89b0fc379bcef5c3cb1840f285a57 100644 (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
index baeb9409f402efb8468145c93b9c7f6d561b0fcf..6b6f383301bc3acb3f2e46a1cff2b5e0cdb1f5f2 100644 (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);
index 2d3c7d744aa1d4498544bc6186578bee95bfded8..25c139d26a7f15e84c764bb672d75e66801ad8a6 100644 (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;
 }
 
index babc3e441f2344274660d5c59c27d6293dbbd4a6..1ef7650ca9c8e496529b631b64ad50d716226851 100644 (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:
index d92a758adb64246234a2d865c4416bb382f7e717..502f58153253043ecfc6ad977d99adccd828ddc2 100644 (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;
 
index 269cb0d801da45c7e830e4cc9f2f8f9a767a9d7b..49d72f65d6016a36a2d579fb4037206a8f4c0f13 100644 (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;
+}