diff --git a/libs/ardour/luabindings.cc b/libs/ardour/luabindings.cc index 6c708c4d27..e8ba48eb8f 100644 --- a/libs/ardour/luabindings.cc +++ b/libs/ardour/luabindings.cc @@ -1327,8 +1327,11 @@ LuaBindings::common (lua_State* L) .addFunction ("scale_amplitude", &AudioRegion::scale_amplitude) .addFunction ("maximum_amplitude", &AudioRegion::maximum_amplitude) .addFunction ("rms", &AudioRegion::rms) + .addFunction ("envelope", &AudioRegion::envelope) + .addFunction ("envelope_active", &AudioRegion::envelope_active) .addFunction ("fade_in_active", &AudioRegion::fade_in_active) .addFunction ("fade_out_active", &AudioRegion::fade_out_active) + .addFunction ("set_envelope_active", &AudioRegion::set_envelope_active) .addFunction ("set_fade_in_active", &AudioRegion::set_fade_in_active) .addFunction ("set_fade_in_shape", &AudioRegion::set_fade_in_shape) .addFunction ("set_fade_in_length", &AudioRegion::set_fade_in_length) diff --git a/share/scripts/s_region_gain_curve.lua b/share/scripts/s_region_gain_curve.lua new file mode 100644 index 0000000000..2a73303568 --- /dev/null +++ b/share/scripts/s_region_gain_curve.lua @@ -0,0 +1,52 @@ +ardour { ["type"] = "Snippet", name = "Set Region Gain Curve" } + +function factory () return function () + -- get Editor GUI Selection + -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection + local sel = Editor:get_selection () + + -- prepare undo operation + Session:begin_reversible_command ("Lua Region Gain Curve") + + -- iterate over selected regions + -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:RegionSelection + for r in sel.regions:regionlist ():iter () do + + -- test if it's an audio region + local ar = r:to_audioregion (); + if ar:isnil () then + goto next + end + + -- get region-gain-curve is-a + -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:AutomationList + local al = ar:envelope () + + -- get state for undo + local before = al:get_state () + + -- delete all current events + al:clear_list () + + -- add some new ones + for i=0,50 do + al:add (i * r:length () / 50, + 1 - math.sqrt (i / 50), + false, true) + end + + -- remove dense events + al:thin (20) + + -- save undo + local after = al:get_state () + Session:add_command (al:memento_command (before, after)) + + ::next:: + end + + if not Session:abort_empty_reversible_command () then + Session:commit_reversible_command (nil) + end + +end end