1 ardour { ["type"] = "Snippet", name = "Fader Automation" }
3 function factory () return function ()
4 local playhead = Session:transport_sample ()
5 local samplerate = Session:nominal_sample_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)
19 -- set automation state to "Touch"
20 ac:set_automation_state (ARDOUR.AutoState.Touch)
22 -- query the value at the playhead position
23 local g = al:eval (playhead)
26 local before = al:get_state ()
28 -- delete all events after the playhead...
29 al:truncate_end (playhead)
31 -- ...and generate some new ones.
33 -- use a sqrt fade-out (the shape is recognizable, and otherwise
34 -- not be possible to achieve with existing ardour fade shapes)
35 al:add (playhead + i * samplerate / 50,
36 g * (1 - math.sqrt (i / 50)),
40 -- remove dense events
44 local after = al:get_state ()
45 Session:add_command (al:memento_command (before, after))
51 -- all done, commit the combined Undo Operation
53 -- the 'nil' Commend here mean to use the collected diffs added above
54 Session:commit_reversible_command (nil)
56 Session:abort_reversible_command ()