add some convenience lua functions for plugin management

This commit is contained in:
Robin Gareus 2016-03-19 16:39:24 +01:00
parent fc988428bc
commit dffdee85a0
3 changed files with 109 additions and 0 deletions

View File

@ -31,6 +31,9 @@
namespace ARDOUR { namespace LuaAPI {
boost::shared_ptr<ARDOUR::Processor> new_luaproc (ARDOUR::Session *s, const std::string&);
boost::shared_ptr<ARDOUR::Processor> new_plugin (ARDOUR::Session *s, const std::string&, ARDOUR::PluginType, const std::string& preset = "");
bool set_processor_param (boost::shared_ptr<Processor> proc, uint32_t which, float val);
bool set_plugin_insert_param (boost::shared_ptr<PluginInsert> pi, uint32_t which, float val);
/**
* OSC is kinda special, lo_address is a void* and lo_send() has varags

View File

@ -26,6 +26,7 @@
#include "ardour/luascripting.h"
#include "ardour/plugin.h"
#include "ardour/plugin_insert.h"
#include "ardour/plugin_manager.h"
#include "i18n.h"
@ -66,6 +67,84 @@ ARDOUR::LuaAPI::new_luaproc (Session *s, const string& name)
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)
{
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());
#ifdef WINDOWS_VST_SUPPORT
all_plugs.insert(all_plugs.end(), manager.windows_vst_plugin_info().begin(), manager.windows_vst_plugin_info().end());
#endif
#ifdef LXVST_SUPPORT
all_plugs.insert(all_plugs.end(), manager.lxvst_plugin_info().begin(), manager.lxvst_plugin_info().end());
#endif
#ifdef AUDIOUNIT_SUPPORT
all_plugs.insert(all_plugs.end(), manager.au_plugin_info().begin(), manager.au_plugin_info().end());
#endif
#ifdef LV2_SUPPORT
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;
}
}
if (!pip) {
return boost::shared_ptr<Processor> ();
}
PluginPtr p = pip->load (*s);
if (!p) {
return boost::shared_ptr<Processor> ();
}
if (!preset.empty()) {
const Plugin::PresetRecord *pr = p->preset_by_label (preset);
if (pr) {
p->load_preset (*pr);
}
}
return boost::shared_ptr<Processor> (new PluginInsert (*s, p));
}
bool
ARDOUR::LuaAPI::set_plugin_insert_param (boost::shared_ptr<PluginInsert> pi, uint32_t which, float val)
{
boost::shared_ptr<Plugin> plugin = pi->plugin();
if (!plugin) { return false; }
bool ok=false;
uint32_t controlid = plugin->nth_parameter (which, ok);
if (!ok) { return false; }
if (!plugin->parameter_is_input (controlid)) { return false; }
ParameterDescriptor pd;
if (plugin->get_parameter_descriptor (controlid, pd) != 0) { return false; }
if (val < pd.lower || val > pd.upper) { return false; }
boost::shared_ptr<AutomationControl> c = pi->automation_control (Evoral::Parameter(PluginAutomation, 0, controlid));
c->set_value (val, PBD::Controllable::NoGroup);
return true;
}
bool
ARDOUR::LuaAPI::set_processor_param (boost::shared_ptr<Processor> proc, uint32_t which, float val)
{
boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (proc);
if (!pi) { return false; }
return set_plugin_insert_param (pi, which, val);
}
int
ARDOUR::LuaAPI::LuaOSCAddress::send (lua_State *L)
{

View File

@ -194,6 +194,11 @@ LuaBindings::common (lua_State* L)
.addFunction ("set_active", &Route::set_active)
.addFunction ("nth_plugin", &Route::nth_plugin)
.addFunction ("add_processor_by_index", &Route::add_processor_by_index)
.addFunction ("remove_processor", &Route::remove_processor)
.addFunction ("replace_processor", &Route::replace_processor)
.addFunction ("n_inputs", &Route::n_inputs)
.addFunction ("n_outputs", &Route::n_outputs)
.addFunction ("set_comment", &Route::set_comment)
.endClass ()
.deriveWSPtrClass <Track, Route> ("Track")
@ -276,6 +281,13 @@ LuaBindings::common (lua_State* L)
.addFunction ("id", &Evoral::Parameter::id)
.endClass ()
.beginClass <Plugin::PresetRecord> ("PresetRecord")
.addData ("uri", &Plugin::PresetRecord::uri, false)
.addData ("label", &Plugin::PresetRecord::label, false)
.addData ("user", &Plugin::PresetRecord::user, false)
.addData ("valid", &Plugin::PresetRecord::valid, false)
.endClass ()
.beginWSPtrClass <Evoral::ControlList> ("EvoralControlList")
.addFunction ("add", &Evoral::ControlList::add)
.endClass ()
@ -325,6 +337,9 @@ LuaBindings::common (lua_State* L)
.addFunction ("maker", &Plugin::maker)
.addFunction ("parameter_count", &Plugin::parameter_count)
.addFunction ("nth_parameter", &Plugin::nth_parameter)
.addFunction ("preset_by_label", &Plugin::preset_by_label)
.addFunction ("preset_by_uri", &Plugin::preset_by_uri)
.addFunction ("load_preset", &Plugin::load_preset)
.addFunction ("parameter_is_input", &Plugin::parameter_is_input)
.addFunction ("get_docs", &Plugin::get_docs)
.addFunction ("get_parameter_docs", &Plugin::get_parameter_docs)
@ -421,6 +436,15 @@ LuaBindings::common (lua_State* L)
.endClass()
/* libardour enums */
.beginNamespace ("PluginType")
.addConst ("AudioUnit", ARDOUR::PluginType(AudioUnit))
.addConst ("LADSPA", ARDOUR::PluginType(LADSPA))
.addConst ("LV2", ARDOUR::PluginType(LV2))
.addConst ("Windows_VST", ARDOUR::PluginType(Windows_VST))
.addConst ("LXVST", ARDOUR::PluginType(LXVST))
.addConst ("Lua", ARDOUR::PluginType(Lua))
.endNamespace ()
.beginNamespace ("Autostyle")
.addConst ("Absolute", ARDOUR::AutoState(Absolute))
.addConst ("Trim", ARDOUR::AutoState(Trim))
@ -563,6 +587,9 @@ LuaBindings::common (lua_State* L)
.beginNamespace ("LuaAPI")
.addFunction ("new_luaproc", ARDOUR::LuaAPI::new_luaproc)
.addFunction ("new_plugin", ARDOUR::LuaAPI::new_plugin)
.addFunction ("set_processor_param", ARDOUR::LuaAPI::set_processor_param)
.addFunction ("set_plugin_insert_param", ARDOUR::LuaAPI::set_plugin_insert_param)
.endNamespace ()
.endNamespace ();// END ARDOUR