#include "ardour/plugin_insert.h"
#include "ardour/plugin_manager.h"
+#include "LuaBridge/LuaBridge.h"
+
#include "i18n.h"
using namespace ARDOUR;
using namespace PBD;
using namespace std;
+int
+ARDOUR::LuaAPI::datatype_ctor_null (lua_State *L)
+{
+ DataType dt (DataType::NIL);
+ luabridge::Stack <DataType>::push (L, dt);
+ return 1;
+}
+
+int
+ARDOUR::LuaAPI::datatype_ctor_audio (lua_State *L)
+{
+ DataType dt (DataType::AUDIO);
+ // NB luabridge will copy construct the object and manage lifetime.
+ luabridge::Stack <DataType>::push (L, dt);
+ return 1;
+}
+
+int
+ARDOUR::LuaAPI::datatype_ctor_midi (lua_State *L)
+{
+ DataType dt (DataType::MIDI);
+ luabridge::Stack <DataType>::push (L, dt);
+ return 1;
+}
+
+boost::shared_ptr<Processor>
+ARDOUR::LuaAPI::nil_processor ()
+{
+ return boost::shared_ptr<Processor> ();
+}
+
boost::shared_ptr<Processor>
ARDOUR::LuaAPI::new_luaproc (Session *s, const string& name)
{
LuaScriptInfoPtr spi;
ARDOUR::LuaScriptList & _scripts (LuaScripting::instance ().scripts (LuaScriptInfo::DSP));
- for (LuaScriptList::const_iterator s = _scripts.begin(); s != _scripts.end(); ++s) {
- if (name == (*s)->name) {
- spi = *s;
+ for (LuaScriptList::const_iterator i = _scripts.begin(); i != _scripts.end(); ++i) {
+ if (name == (*i)->name) {
+ spi = *i;
break;
}
}
return boost::shared_ptr<Processor> (new PluginInsert (*s, p));
}
-
-boost::shared_ptr<Processor>
-ARDOUR::LuaAPI::new_plugin (Session *s, const string& name, ARDOUR::PluginType type, const string& preset)
+PluginInfoPtr
+ARDOUR::LuaAPI::new_plugin_info (const string& name, ARDOUR::PluginType type)
{
- if (!s) {
- return boost::shared_ptr<Processor> ();
- }
-
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
all_plugs.insert(all_plugs.end(), manager.lv2_plugin_info().begin(), manager.lv2_plugin_info().end());
#endif
- PluginInfoPtr pip;
for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
if (((*i)->name == name || (*i)->unique_id == name) && (*i)->type == type) {
- pip = *i;
- break;
+ return *i;
}
}
+ return PluginInfoPtr ();
+}
+
+boost::shared_ptr<Processor>
+ARDOUR::LuaAPI::new_plugin (Session *s, const string& name, ARDOUR::PluginType type, const string& preset)
+{
+ if (!s) {
+ return boost::shared_ptr<Processor> ();
+ }
+
+ PluginInfoPtr pip = new_plugin_info (name, type);
+
if (!pip) {
return boost::shared_ptr<Processor> ();
}
}
int
-ARDOUR::LuaAPI::LuaOSCAddress::send (lua_State *L)
+ARDOUR::LuaAPI::plugin_automation (lua_State *L)
+{
+ typedef boost::shared_ptr<Processor> T;
+
+ int top = lua_gettop(L);
+ if (top < 2) {
+ return luaL_argerror (L, 1, "invalid number of arguments, :plugin_automation (plugin, parameter_number)");
+ }
+ T* const p = luabridge::Userdata::get<T>(L, 1, false);
+ uint32_t which = luabridge::Stack<uint32_t>::get (L, 2);
+ if (!p) {
+ return luaL_error (L, "Invalid pointer to Ardour:Processor");
+ }
+ boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (*p);
+ if (!pi) {
+ return luaL_error (L, "Given Processor is not a Plugin Insert");
+ }
+ boost::shared_ptr<Plugin> plugin = pi->plugin();
+ if (!plugin) {
+ return luaL_error (L, "Given Processor is not a Plugin");
+ }
+
+ bool ok=false;
+ uint32_t controlid = plugin->nth_parameter (which, ok);
+ if (!ok) {
+ return luaL_error (L, "Invalid Parameter");
+ }
+ if (!plugin->parameter_is_input (controlid)) {
+ return luaL_error (L, "Given Parameter is not an input");
+ }
+
+ ParameterDescriptor pd;
+ if (plugin->get_parameter_descriptor (controlid, pd) != 0) {
+ return luaL_error (L, "Cannot describe parameter");
+ }
+
+ boost::shared_ptr<AutomationControl> c = pi->automation_control (Evoral::Parameter(PluginAutomation, 0, controlid));
+
+ luabridge::Stack<boost::shared_ptr<AutomationList> >::push (L, c->alist());
+ luabridge::Stack<boost::shared_ptr<Evoral::ControlList> >::push (L, c->list());
+ luabridge::Stack<ParameterDescriptor>::push (L, pd);
+ return 3;
+}
+
+int
+ARDOUR::LuaOSC::Address::send (lua_State *L)
{
- LuaOSCAddress * const luaosc = luabridge::Userdata::get <LuaOSCAddress> (L, 1, false);
+ Address * const luaosc = luabridge::Userdata::get <Address> (L, 1, false);
if (!luaosc) {
return luaL_error (L, "Invalid pointer to OSC.Address");
}
int rv = lo_send_message (luaosc->_addr, path, msg);
lo_message_free (msg);
- luabridge::Stack<int>::push (L, rv);
+ luabridge::Stack<bool>::push (L, (rv == 0));
return 1;
}