1 ardour { ["type"] = "Snippet", name = "Fader Automation" }
3 function factory () return function ()
4 local playhead = Session:transport_frame ()
5 local samplerate = Session:nominal_frame_rate ()
8 rl = Editor:get_selection ().tracks:routelist ()
10 -- prepare undo operation
11 Session:begin_reversible_command ("Fancy Fade Out")
12 local add_undo = false -- keep track if something has changed
14 -- iterate over selected tracks
15 for r in rl:iter () do
16 local ac = r:amp ():gain_control () -- ARDOUR:AutomationControl
17 local al = ac:alist () -- ARDOUR:AutomationList (state, high-level)
18 local cl = al:list () -- Evoral:ControlList (actual events)
24 -- set automation state to "Touch"
25 ac:set_automation_state (ARDOUR.AutoState.Touch)
27 -- query the value at the playhead position
28 local g = cl:eval (playhead)
31 local before = al:get_state ()
33 -- delete all events after the playhead...
34 cl:truncate_end (playhead)
36 -- ...and generate some new ones.
38 -- use a sqrt fade-out (the shape is recognizable, and otherwise
39 -- not be possible to achieve with existing ardour fade shapes)
40 cl:add (playhead + i * samplerate / 50,
41 g * (1 - math.sqrt (i / 50)),
45 -- remove dense events
49 local after = al:get_state ()
50 Session:add_command (al:memento_command (before, after))
56 -- all done, commit the combined Undo Operation
58 -- the 'nil' Commend here mean to use the collected diffs added above
59 Session:commit_reversible_command (nil)
61 Session:abort_reversible_command ()