summaryrefslogtreecommitdiff
path: root/scripts/s_fader_automation.lua
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-04-10 20:57:24 +0200
committerRobin Gareus <robin@gareus.org>2016-04-10 20:57:24 +0200
commitc76ef648703128e0b1dbcbc0790daa25254a1ce4 (patch)
tree8858cf422cd30b84097467c5ef9d37ed5f068080 /scripts/s_fader_automation.lua
parent2b943ea36c128819d808087f853977fdd8e5c09d (diff)
some more example lua scripts
Diffstat (limited to 'scripts/s_fader_automation.lua')
-rw-r--r--scripts/s_fader_automation.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/s_fader_automation.lua b/scripts/s_fader_automation.lua
new file mode 100644
index 0000000000..e1ee2876e4
--- /dev/null
+++ b/scripts/s_fader_automation.lua
@@ -0,0 +1,56 @@
+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 acl = ac:alist() -- ARDOUR:AutomationControlList (state, high-level)
+ local cl = acl:list() -- Evoral:ControlList (actual events)
+
+ ac:set_automation_state(ARDOUR.AutoState.Touch)
+
+ if cl:isnil() then
+ goto out
+ end
+
+ -- query the value at the playhead position
+ local g = cl:eval(playhead)
+
+ -- get state for undo
+ local before = acl:get_state()
+
+ -- delete all events after the playhead...
+ cl:truncate_end (playhead)
+ -- ...and generate some new ones.
+ for i=0,50 do
+ 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 = acl:get_state()
+ Session:add_command (acl: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