1ardour { ["type"] = "Snippet", name = "Set Region Fades" } 2 3function factory () return function () 4 5 -- ensure sure that fades are used and visible 6 -- (Session > Properties > Fades) 7 assert (Session:cfg():get_use_region_fades()) 8 assert (Session:cfg():get_show_region_fades()) 9 10 -- get Editor selection 11 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Editor 12 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection 13 local sel = Editor:get_selection () 14 -- query the session's currane sample-rate 15 local sr = Session:nominal_sample_rate () 16 17 -- iterate over Regions that part of the selection 18 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:RegionSelection 19 for r in sel.regions:regionlist ():iter () do 20 -- each of the items 'r' is-a 21 -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Region 22 23 -- test if it is an audio region 24 local ar = r:to_audioregion () 25 if ar:isnil () then goto next end 26 27 -- fade in/out for 500 msec, or half the region-length, whatever is shorter 28 local fadelen = .5 * sr 29 if fadelen > r:length () / 2 then 30 fadelen = r:length () / 2 31 end 32 33 -- https://manual.ardour.org/lua-scripting/class_reference/#ARDOUR.FadeShape 34 ar:set_fade_in_shape (ARDOUR.FadeShape.FadeConstantPower) 35 ar:set_fade_in_length (fadelen) 36 ar:set_fade_in_active (true) 37 38 ar:set_fade_out_shape (ARDOUR.FadeShape.FadeConstantPower) 39 ar:set_fade_out_length (fadelen) 40 ar:set_fade_out_active (true) 41 42 ::next:: 43 end 44end end 45