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()
9 -- prepare undo operation
10 Session:begin_reversible_command ("Fancy Fade Out")
11 local add_undo = false -- keep track if something has changed
12 -- iterate over selected tracks
14 local ac = r:amp():gain_control() -- ARDOUR:AutomationControl
15 local acl = ac:alist() -- ARDOUR:AutomationControlList (state, high-level)
16 local cl = acl:list() -- Evoral:ControlList (actual events)
18 ac:set_automation_state(ARDOUR.AutoState.Touch)
24 -- query the value at the playhead position
25 local g = cl:eval(playhead)
28 local before = acl:get_state()
30 -- delete all events after the playhead...
31 cl:truncate_end (playhead)
32 -- ...and generate some new ones.
34 cl:add (playhead + i * samplerate / 50,
35 g * (1 - math.sqrt (i / 50)),
38 -- remove dense events
42 local after = acl:get_state()
43 Session:add_command (acl:memento_command(before, after))
49 -- all done, commit the combined Undo Operation
51 -- the 'nil' Commend here mean to use the collected diffs added above
52 Session:commit_reversible_command (nil)
54 Session:abort_reversible_command ()