mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-10 16:46:35 +01:00
some more example lua scripts
This commit is contained in:
parent
2b943ea36c
commit
c76ef64870
3 changed files with 92 additions and 4 deletions
56
scripts/s_fader_automation.lua
Normal file
56
scripts/s_fader_automation.lua
Normal file
|
|
@ -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
|
||||||
35
scripts/s_plugin_automation.lua
Normal file
35
scripts/s_plugin_automation.lua
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
ardour { ["type"] = "Snippet", name = "plugin automation2" }
|
||||||
|
|
||||||
|
function factory () return function ()
|
||||||
|
local playhead = Session:transport_frame ()
|
||||||
|
local samplerate = Session:nominal_frame_rate ()
|
||||||
|
|
||||||
|
local r = Session:route_by_remote_id(3)
|
||||||
|
-- get AutomationControList, ControlList and ParameterDescriptor
|
||||||
|
local acl, cl, pd = ARDOUR.LuaAPI.plugin_automation (r:nth_plugin (0), 0)
|
||||||
|
|
||||||
|
if not acl:isnil() then
|
||||||
|
print ("Parameter Range", pd.lower, pd.upper)
|
||||||
|
print ("Current value", cl:eval(playhead))
|
||||||
|
|
||||||
|
-- prepare undo operation
|
||||||
|
Session:begin_reversible_command ("Automatix")
|
||||||
|
local before = acl:get_state()
|
||||||
|
|
||||||
|
-- remove future automation
|
||||||
|
cl:truncate_end (playhead)
|
||||||
|
|
||||||
|
-- add new data points after the playhead 1 sec min..max
|
||||||
|
-- without guard-points, but with initial (..., false, true)
|
||||||
|
for i=0,10 do
|
||||||
|
cl:add (playhead + i * samplerate / 10,
|
||||||
|
pd.lower + math.sqrt (i / 10) * (pd.upper - pd.lower),
|
||||||
|
false, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- save undo
|
||||||
|
local after = acl:get_state()
|
||||||
|
Session:add_command (acl:memento_command(before, after))
|
||||||
|
Session:commit_reversible_command (nil)
|
||||||
|
end
|
||||||
|
end end
|
||||||
|
|
@ -24,8 +24,6 @@ function factory () return function ()
|
||||||
local playhead = Session:transport_frame ()
|
local playhead = Session:transport_frame ()
|
||||||
|
|
||||||
-- make sure we have a loop, and the playhead (edit point) is after it
|
-- make sure we have a loop, and the playhead (edit point) is after it
|
||||||
-- TODO: only print an error and return
|
|
||||||
-- TODO: use the edit-point (not playhead) ? maybe.
|
|
||||||
if not loop then
|
if not loop then
|
||||||
print ("A Loop range must be set.")
|
print ("A Loop range must be set.")
|
||||||
goto errorout
|
goto errorout
|
||||||
|
|
@ -58,8 +56,7 @@ function factory () return function ()
|
||||||
|
|
||||||
-- check if there are any regions in the loop-range of this track
|
-- check if there are any regions in the loop-range of this track
|
||||||
local range = Evoral.Range (loop:start (), loop:_end ())
|
local range = Evoral.Range (loop:start (), loop:_end ())
|
||||||
if playlist:regions_with_start_within (range):empty ()
|
if playlist:regions_touched (range):empty () then
|
||||||
and playlist:regions_with_end_within (range):empty () then
|
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue