From 1637c13fbf0e6776ddaf49dfdee2fba1f56a2103 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 25 Jan 2021 14:27:27 -0700 Subject: [PATCH] extend Lua API a little to allow callers to specify time domain for script/plugin automation data --- libs/ardour/ardour/lua_api.h | 12 ++++++++++-- libs/ardour/lua_api.cc | 18 ++++++++++++++---- libs/ardour/luabindings.cc | 2 ++ libs/ardour/session_time.cc | 2 +- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/libs/ardour/ardour/lua_api.h b/libs/ardour/ardour/lua_api.h index 38707ac245..0896b77a8a 100644 --- a/libs/ardour/ardour/lua_api.h +++ b/libs/ardour/ardour/lua_api.h @@ -70,10 +70,14 @@ namespace ARDOUR { namespace LuaAPI { /** create a new Lua Processor (Plugin) * - * @param s Session Handle - * @param p Identifier or Name of the Processor + * @param s Session Handle + * @param p Identifier or Name of the Processor + * @param td Time domain (audio or beats) for any automation data * @returns Processor object (may be nil) */ + boost::shared_ptr new_luaproc_with_time_domain (ARDOUR::Session *s, const std::string& p, Temporal::TimeDomain td); + + /* As above but uses default time domain for the session/application */ boost::shared_ptr new_luaproc (ARDOUR::Session *s, const std::string& p); /** List all installed plugins */ @@ -98,8 +102,12 @@ namespace ARDOUR { namespace LuaAPI { * @param id Plugin Name, ID or URI * @param type Plugin Type * @param preset name of plugin-preset to load, leave empty "" to not load any preset after instantiation + * @param td Time domain for any automation data * @returns Processor or nil */ + boost::shared_ptr new_plugin_with_time_domain (ARDOUR::Session *s, const std::string& id, ARDOUR::PluginType type, Temporal::TimeDomain td, const std::string& preset = ""); + + /* As above but uses default time domain for the session/application */ boost::shared_ptr new_plugin (ARDOUR::Session *s, const std::string& id, ARDOUR::PluginType type, const std::string& preset = ""); /** set a plugin control-input parameter value diff --git a/libs/ardour/lua_api.cc b/libs/ardour/lua_api.cc index 2eaed393dd..f9a39c54d7 100644 --- a/libs/ardour/lua_api.cc +++ b/libs/ardour/lua_api.cc @@ -80,6 +80,12 @@ ARDOUR::LuaAPI::nil_processor () boost::shared_ptr ARDOUR::LuaAPI::new_luaproc (Session *s, const string& name) +{ + return new_luaproc_with_time_domain (s, name, Config->get_default_automation_time_domain()); +} + +boost::shared_ptr +ARDOUR::LuaAPI::new_luaproc_with_time_domain (Session *s, const string& name, Temporal::TimeDomain td) { if (!s) { return boost::shared_ptr (); @@ -108,8 +114,7 @@ ARDOUR::LuaAPI::new_luaproc (Session *s, const string& name) return boost::shared_ptr (); } -#warning NUTEMPO caller should be able to control time domain - return boost::shared_ptr (new PluginInsert (*s, Config->get_default_automation_time_domain(), p)); + return boost::shared_ptr (new PluginInsert (*s, td, p)); } boost::shared_ptr @@ -209,6 +214,12 @@ ARDOUR::LuaAPI::new_plugin_info (const string& name, ARDOUR::PluginType type) boost::shared_ptr ARDOUR::LuaAPI::new_plugin (Session *s, const string& name, ARDOUR::PluginType type, const string& preset) +{ + return new_plugin_with_time_domain (s, name, type, Config->get_default_automation_time_domain(), preset); +} + +boost::shared_ptr +ARDOUR::LuaAPI::new_plugin_with_time_domain (Session *s, const string& name, ARDOUR::PluginType type, Temporal::TimeDomain td, const string& preset) { if (!s) { return boost::shared_ptr (); @@ -232,8 +243,7 @@ ARDOUR::LuaAPI::new_plugin (Session *s, const string& name, ARDOUR::PluginType t } } -#warning NUTEMPO caller should be able to control time domain - return boost::shared_ptr (new PluginInsert (*s, Config->get_default_automation_time_domain(), p)); + return boost::shared_ptr (new PluginInsert (*s, td, p)); } bool diff --git a/libs/ardour/luabindings.cc b/libs/ardour/luabindings.cc index addb934ab4..1f92be1edb 100644 --- a/libs/ardour/luabindings.cc +++ b/libs/ardour/luabindings.cc @@ -2567,10 +2567,12 @@ LuaBindings::common (lua_State* L) .addFunction ("nil_proc", ARDOUR::LuaAPI::nil_processor) .addFunction ("new_luaproc", ARDOUR::LuaAPI::new_luaproc) .addFunction ("new_send", ARDOUR::LuaAPI::new_send) + .addFunction ("new_luaproc_with_time_domain", ARDOUR::LuaAPI::new_luaproc_with_time_domain) .addFunction ("list_plugins", ARDOUR::LuaAPI::list_plugins) .addFunction ("dump_untagged_plugins", ARDOUR::LuaAPI::dump_untagged_plugins) .addFunction ("new_plugin_info", ARDOUR::LuaAPI::new_plugin_info) .addFunction ("new_plugin", ARDOUR::LuaAPI::new_plugin) + .addFunction ("new_plugin_with_time_domain", ARDOUR::LuaAPI::new_plugin_with_time_domain) .addFunction ("set_processor_param", ARDOUR::LuaAPI::set_processor_param) .addFunction ("set_plugin_insert_param", ARDOUR::LuaAPI::set_plugin_insert_param) .addFunction ("reset_processor_to_default", ARDOUR::LuaAPI::reset_processor_to_default) diff --git a/libs/ardour/session_time.cc b/libs/ardour/session_time.cc index b7614937da..e7a2d9a8e2 100644 --- a/libs/ardour/session_time.cc +++ b/libs/ardour/session_time.cc @@ -295,7 +295,7 @@ Session::any_duration_to_samples (samplepos_t position, AnyTime const & duration break; case AnyTime::Seconds: - return (samplecnt_t) floor (duration.seconds * sample_rate()); + return (samplecnt_t) round (duration.seconds * sample_rate()); break; case AnyTime::Samples: