mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-10 00:34:59 +01:00
Add a convenience API to modulate plugin parameters from Lua
This commit is contained in:
parent
998d8c150b
commit
b8bfa55864
3 changed files with 100 additions and 1 deletions
|
|
@ -300,7 +300,15 @@ namespace ARDOUR { namespace LuaAPI {
|
|||
boost::shared_ptr<Evoral::Note<Evoral::Beats> >
|
||||
new_noteptr (uint8_t, Evoral::Beats, Evoral::Beats, uint8_t, uint8_t);
|
||||
|
||||
} } /* namespace */
|
||||
double control_baseline (const Evoral::ControlSet::Controls& ctrlmap, uint32_t port);
|
||||
double control_modulation_delta (const Evoral::ControlSet::Controls& ctrlmap, uint32_t port);
|
||||
double control_modulated_value (const Evoral::ControlSet::Controls& ctrlmap, uint32_t port);
|
||||
|
||||
bool modulate_to (const Evoral::ControlSet::Controls& ctrlmap, uint32_t port, double value);
|
||||
bool modulate_by (const Evoral::ControlSet::Controls& ctrlmap, uint32_t port, double value);
|
||||
bool modulate_range (const Evoral::ControlSet::Controls& ctrlmap, uint32_t port, double value);
|
||||
|
||||
} } /* namespace ARDOUR::LuaAPI */
|
||||
|
||||
namespace ARDOUR { namespace LuaOSC {
|
||||
/** OSC transmitter
|
||||
|
|
|
|||
|
|
@ -820,3 +820,83 @@ LuaAPI::new_noteptr (uint8_t chan, Evoral::Beats beat_time, Evoral::Beats length
|
|||
{
|
||||
return boost::shared_ptr<Evoral::Note<Evoral::Beats> > (new Evoral::Note<Evoral::Beats>(chan, beat_time, length, note, velocity));
|
||||
}
|
||||
|
||||
/* modulation related */
|
||||
|
||||
static boost::shared_ptr<PluginInsert::PluginControl>
|
||||
_lookup_plugin_control (const Evoral::ControlSet::Controls& ctrlmap, uint32_t port)
|
||||
{
|
||||
Evoral::Parameter p (AutomationType::PluginAutomation, 0, port);
|
||||
Evoral::ControlSet::Controls::const_iterator i = ctrlmap.find (p);
|
||||
if (i == ctrlmap.end()) {
|
||||
return boost::shared_ptr<PluginInsert::PluginControl> ();
|
||||
}
|
||||
boost::shared_ptr<PluginInsert::PluginControl> c = boost::dynamic_pointer_cast<PluginInsert::PluginControl> (i->second);
|
||||
return c;
|
||||
}
|
||||
|
||||
bool
|
||||
LuaAPI::modulate_to (const Evoral::ControlSet::Controls& ctrlmap, uint32_t port, double value)
|
||||
{
|
||||
boost::shared_ptr<PluginInsert::PluginControl> c = _lookup_plugin_control (ctrlmap, port);
|
||||
if (!c) {
|
||||
return false;
|
||||
}
|
||||
value = std::min (c->upper(), std::max (c->lower(), value));
|
||||
c->modulate_to (value);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
LuaAPI::modulate_by (const Evoral::ControlSet::Controls& ctrlmap, uint32_t port, double value)
|
||||
{
|
||||
boost::shared_ptr<PluginInsert::PluginControl> c = _lookup_plugin_control (ctrlmap, port);
|
||||
if (!c) {
|
||||
return false;
|
||||
}
|
||||
c->modulate_by (value);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
LuaAPI::modulate_range (const Evoral::ControlSet::Controls& ctrlmap, uint32_t port, double value)
|
||||
{
|
||||
boost::shared_ptr<PluginInsert::PluginControl> c = _lookup_plugin_control (ctrlmap, port);
|
||||
if (!c) {
|
||||
return false;
|
||||
}
|
||||
// value -1 .. + 1, we should take the baseline into account
|
||||
c->modulate_by (value * (c->upper() - c->lower()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
double
|
||||
LuaAPI::control_baseline (const Evoral::ControlSet::Controls& ctrlmap, uint32_t port)
|
||||
{
|
||||
boost::shared_ptr<PluginInsert::PluginControl> c = _lookup_plugin_control (ctrlmap, port);
|
||||
if (!c) {
|
||||
return 0;
|
||||
}
|
||||
return c->get_value ();
|
||||
}
|
||||
|
||||
double
|
||||
LuaAPI::control_modulation_delta (const Evoral::ControlSet::Controls& ctrlmap, uint32_t port)
|
||||
{
|
||||
boost::shared_ptr<PluginInsert::PluginControl> c = _lookup_plugin_control (ctrlmap, port);
|
||||
if (!c) {
|
||||
return 0;
|
||||
}
|
||||
return c->modulation_delta ();
|
||||
}
|
||||
|
||||
double
|
||||
LuaAPI::control_modulated_value (const Evoral::ControlSet::Controls& ctrlmap, uint32_t port)
|
||||
{
|
||||
boost::shared_ptr<PluginInsert::PluginControl> c = _lookup_plugin_control (ctrlmap, port);
|
||||
if (!c) {
|
||||
return 0;
|
||||
}
|
||||
return c->modulated_value ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1969,6 +1969,17 @@ LuaBindings::common (lua_State* L)
|
|||
.addCFunction ("sample_to_timecode", ARDOUR::LuaAPI::sample_to_timecode)
|
||||
.addCFunction ("timecode_to_sample", ARDOUR::LuaAPI::timecode_to_sample)
|
||||
|
||||
// modulation
|
||||
.addFunction ("control_baseline", ARDOUR::LuaAPI::control_baseline)
|
||||
.addFunction ("control_modulation_delta", ARDOUR::LuaAPI::control_modulation_delta)
|
||||
.addFunction ("control_modulated_value", ARDOUR::LuaAPI::control_modulated_value)
|
||||
|
||||
// modulation -- should be RT context, modulation scripts
|
||||
.addFunction ("modulate_to", ARDOUR::LuaAPI::modulate_to)
|
||||
.addFunction ("modulate_by", ARDOUR::LuaAPI::modulate_by)
|
||||
.addFunction ("modulate_range", ARDOUR::LuaAPI::modulate_range)
|
||||
// end RT only
|
||||
|
||||
.beginClass <ARDOUR::LuaAPI::Vamp> ("Vamp")
|
||||
.addConstructor <void (*) (const std::string&, float)> ()
|
||||
.addStaticFunction ("list_plugins", &ARDOUR::LuaAPI::Vamp::list_plugins)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue