summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2020-03-10 23:19:15 +0100
committerRobin Gareus <robin@gareus.org>2020-03-10 23:20:07 +0100
commitf921b4790f9e458d970db8aaefacf958c74af275 (patch)
tree6a26de667155852353866dc2864b25658a71d7b1 /share
parent6569653a3d74e7037513b2b275073084a00b766e (diff)
Add Lua example snippet to set region fades
Diffstat (limited to 'share')
-rw-r--r--share/scripts/s_set_region_fades.lua44
1 files changed, 44 insertions, 0 deletions
diff --git a/share/scripts/s_set_region_fades.lua b/share/scripts/s_set_region_fades.lua
new file mode 100644
index 0000000000..04d94a6eb9
--- /dev/null
+++ b/share/scripts/s_set_region_fades.lua
@@ -0,0 +1,44 @@
+ardour { ["type"] = "Snippet", name = "Set Region Fades" }
+
+function factory () return function ()
+
+ -- ensure sure that fades are used and visible
+ -- (Session > Properties > Fades)
+ assert (Session:cfg():get_use_region_fades())
+ assert (Session:cfg():get_show_region_fades())
+
+ -- get Editor selection
+ -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Editor
+ -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection
+ local sel = Editor:get_selection ()
+ -- query the session's currane sample-rate
+ local sr = Session:nominal_sample_rate ()
+
+ -- iterate over Regions that part of the selection
+ -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:RegionSelection
+ for r in sel.regions:regionlist ():iter () do
+ -- each of the items 'r' is-a
+ -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Region
+
+ -- test if it is an audio region
+ local ar = r:to_audioregion ()
+ if ar:isnil () then goto next end
+
+ -- fade in/out for 500 msec, or half the region-length, whatever is shorter
+ local fadelen = .5 * sr
+ if fadelen > r:length () / 2 then
+ fadelen = r:length () / 2
+ end
+
+ -- https://manual.ardour.org/lua-scripting/class_reference/#ARDOUR.FadeShape
+ ar:set_fade_in_shape (ARDOUR.FadeShape.FadeConstantPower)
+ ar:set_fade_in_length (fadelen)
+ ar:set_fade_in_active (true)
+
+ ar:set_fade_out_shape (ARDOUR.FadeShape.FadeConstantPower)
+ ar:set_fade_out_length (fadelen)
+ ar:set_fade_out_active (true)
+
+ ::next::
+ end
+end end