blob: aaac7adfe946fb25a070a7d00f930ad5e486af79 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
ardour { ["type"] = "Snippet", name = "Fader Automation" }
function factory () return function ()
local playhead = Session:transport_frame ()
local samplerate = Session:nominal_frame_rate ()
-- get selected tracks
rl = Editor:get_selection ().tracks:routelist ()
-- prepare undo operation
Session:begin_reversible_command ("Fancy Fade Out")
local add_undo = false -- keep track if something has changed
-- iterate over selected tracks
for r in rl:iter () do
local ac = r:amp ():gain_control () -- ARDOUR:AutomationControl
local al = ac:alist () -- ARDOUR:AutomationList (state, high-level)
local cl = al:list () -- Evoral:ControlList (actual events)
if cl:isnil () then
goto out
end
-- set automation state to "Touch"
ac:set_automation_state (ARDOUR.AutoState.Touch)
-- query the value at the playhead position
local g = cl:eval (playhead)
-- get state for undo
local before = al:get_state ()
-- delete all events after the playhead...
cl:truncate_end (playhead)
-- ...and generate some new ones.
for i=0,50 do
-- use a sqrt fade-out (the shape is recognizable, and otherwise
-- not be possible to achieve with existing ardour fade shapes)
cl:add (playhead + i * samplerate / 50,
g * (1 - math.sqrt (i / 50)),
false, true)
end
-- remove dense events
cl:thin (20)
-- save undo
local after = al:get_state ()
Session:add_command (al:memento_command (before, after))
add_undo = true
::out::
end
-- all done, commit the combined Undo Operation
if add_undo then
-- the 'nil' Commend here mean to use the collected diffs added above
Session:commit_reversible_command (nil)
else
Session:abort_reversible_command ()
end
end end
|