mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-08 15:54:57 +01:00
update and cleanup lua example scripts
This commit is contained in:
parent
d21f202905
commit
baf6319613
6 changed files with 101 additions and 43 deletions
|
|
@ -1,16 +0,0 @@
|
||||||
ardour {
|
|
||||||
["type"] = "EditorAction",
|
|
||||||
name = "Action Test",
|
|
||||||
license = "MIT",
|
|
||||||
author = "Robin Gareus",
|
|
||||||
email = "robin@gareus.org",
|
|
||||||
site = "http://gareus.org",
|
|
||||||
description = [[ An Example Ardour Editor Action Plugin.]]
|
|
||||||
}
|
|
||||||
|
|
||||||
function factory (params)
|
|
||||||
return function ()
|
|
||||||
for n in pairs(_G) do print(n) end
|
|
||||||
print ("----")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -1,46 +1,53 @@
|
||||||
ardour { ["type"] = "Snippet", name = "fader automation" }
|
ardour { ["type"] = "Snippet", name = "Fader Automation" }
|
||||||
|
|
||||||
function factory () return function ()
|
function factory () return function ()
|
||||||
local playhead = Session:transport_frame ()
|
local playhead = Session:transport_frame ()
|
||||||
local samplerate = Session:nominal_frame_rate ()
|
local samplerate = Session:nominal_frame_rate ()
|
||||||
|
|
||||||
-- get selected tracks
|
-- get selected tracks
|
||||||
rl = Editor:get_selection().tracks:routelist()
|
rl = Editor:get_selection ().tracks:routelist ()
|
||||||
|
|
||||||
-- prepare undo operation
|
-- prepare undo operation
|
||||||
Session:begin_reversible_command ("Fancy Fade Out")
|
Session:begin_reversible_command ("Fancy Fade Out")
|
||||||
local add_undo = false -- keep track if something has changed
|
local add_undo = false -- keep track if something has changed
|
||||||
|
|
||||||
-- iterate over selected tracks
|
-- iterate over selected tracks
|
||||||
for r in rl:iter() do
|
for r in rl:iter () do
|
||||||
local ac = r:amp():gain_control() -- ARDOUR:AutomationControl
|
local ac = r:amp ():gain_control () -- ARDOUR:AutomationControl
|
||||||
local acl = ac:alist() -- ARDOUR:AutomationControlList (state, high-level)
|
local al = ac:alist () -- ARDOUR:AutomationList (state, high-level)
|
||||||
local cl = acl:list() -- Evoral:ControlList (actual events)
|
local cl = al:list () -- Evoral:ControlList (actual events)
|
||||||
|
|
||||||
ac:set_automation_state(ARDOUR.AutoState.Touch)
|
if cl:isnil () then
|
||||||
|
|
||||||
if cl:isnil() then
|
|
||||||
goto out
|
goto out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- set automation state to "Touch"
|
||||||
|
ac:set_automation_state (ARDOUR.AutoState.Touch)
|
||||||
|
|
||||||
-- query the value at the playhead position
|
-- query the value at the playhead position
|
||||||
local g = cl:eval(playhead)
|
local g = cl:eval (playhead)
|
||||||
|
|
||||||
-- get state for undo
|
-- get state for undo
|
||||||
local before = acl:get_state()
|
local before = al:get_state ()
|
||||||
|
|
||||||
-- delete all events after the playhead...
|
-- delete all events after the playhead...
|
||||||
cl:truncate_end (playhead)
|
cl:truncate_end (playhead)
|
||||||
|
|
||||||
-- ...and generate some new ones.
|
-- ...and generate some new ones.
|
||||||
for i=0,50 do
|
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,
|
cl:add (playhead + i * samplerate / 50,
|
||||||
g * (1 - math.sqrt (i / 50)),
|
g * (1 - math.sqrt (i / 50)),
|
||||||
false, true)
|
false, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- remove dense events
|
-- remove dense events
|
||||||
cl:thin(20)
|
cl:thin (20)
|
||||||
|
|
||||||
-- save undo
|
-- save undo
|
||||||
local after = acl:get_state()
|
local after = al:get_state ()
|
||||||
Session:add_command (acl:memento_command(before, after))
|
Session:add_command (al:memento_command (before, after))
|
||||||
add_undo = true
|
add_undo = true
|
||||||
|
|
||||||
::out::
|
::out::
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
ardour { ["type"] = "Snippet", name = "foreach track" }
|
ardour { ["type"] = "Snippet", name = "Foreach Track" }
|
||||||
|
|
||||||
function factory () return function ()
|
function factory () return function ()
|
||||||
for r in Session:get_tracks():iter() do
|
for r in Session:get_tracks():iter() do
|
||||||
print (r:name())
|
print (r:name())
|
||||||
-- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Track
|
-- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Track
|
||||||
-- for available methods e.g.
|
-- for available methods e.g.
|
||||||
--
|
|
||||||
r:set_active (true, nil)
|
r:set_active (true, nil)
|
||||||
end
|
end
|
||||||
end end
|
end end
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,33 @@
|
||||||
ardour { ["type"] = "Snippet", name = "plugin automation2" }
|
ardour { ["type"] = "Snippet", name = "Plugin automation" }
|
||||||
|
|
||||||
function factory () return function ()
|
function factory () return function ()
|
||||||
|
-- query playhead position and session sample-rate
|
||||||
local playhead = Session:transport_frame ()
|
local playhead = Session:transport_frame ()
|
||||||
local samplerate = Session:nominal_frame_rate ()
|
local samplerate = Session:nominal_frame_rate ()
|
||||||
|
|
||||||
|
-- get Track/Bus with RID 3
|
||||||
local r = Session:route_by_remote_id(3)
|
local r = Session:route_by_remote_id(3)
|
||||||
-- get AutomationControList, ControlList and ParameterDescriptor
|
-- make sure the track object exists
|
||||||
local acl, cl, pd = ARDOUR.LuaAPI.plugin_automation (r:nth_plugin (0), 0)
|
assert (not r:isnil ())
|
||||||
|
|
||||||
if not acl:isnil() then
|
-- get AutomationList, ControlList and ParameterDescriptor
|
||||||
|
-- of the first plugin's first parameter
|
||||||
|
-- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:LuaAPI
|
||||||
|
local al, cl, pd = ARDOUR.LuaAPI.plugin_automation (r:nth_plugin (0), 0)
|
||||||
|
|
||||||
|
if not al:isnil () then
|
||||||
print ("Parameter Range", pd.lower, pd.upper)
|
print ("Parameter Range", pd.lower, pd.upper)
|
||||||
print ("Current value", cl:eval(playhead))
|
print ("Current value", cl:eval (playhead))
|
||||||
|
|
||||||
-- prepare undo operation
|
-- prepare undo operation
|
||||||
Session:begin_reversible_command ("Automatix")
|
Session:begin_reversible_command ("Automatix")
|
||||||
local before = acl:get_state()
|
-- remember current AutomationList state
|
||||||
|
local before = al:get_state()
|
||||||
|
|
||||||
-- remove future automation
|
-- remove future automation
|
||||||
cl:truncate_end (playhead)
|
cl:truncate_end (playhead)
|
||||||
|
|
||||||
-- add new data points after the playhead 1 sec min..max
|
-- add new data points after the playhead 1 sec, min..max
|
||||||
-- without guard-points, but with initial (..., false, true)
|
-- without guard-points, but with initial (..., false, true)
|
||||||
for i=0,10 do
|
for i=0,10 do
|
||||||
cl:add (playhead + i * samplerate / 10,
|
cl:add (playhead + i * samplerate / 10,
|
||||||
|
|
@ -28,8 +36,8 @@ function factory () return function ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- save undo
|
-- save undo
|
||||||
local after = acl:get_state()
|
local after = al:get_state()
|
||||||
Session:add_command (acl:memento_command(before, after))
|
Session:add_command (al:memento_command(before, after))
|
||||||
Session:commit_reversible_command (nil)
|
Session:commit_reversible_command (nil)
|
||||||
end
|
end
|
||||||
end end
|
end end
|
||||||
|
|
|
||||||
60
scripts/s_selection.lua
Normal file
60
scripts/s_selection.lua
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
ardour { ["type"] = "Snippet", name = "Editor Selection" }
|
||||||
|
|
||||||
|
function factory () return function ()
|
||||||
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection
|
||||||
|
-- the Ardour Selection can include multiple items
|
||||||
|
-- (regions, tracks, ranges, markers, automation, midi-notes etc)
|
||||||
|
local sel = Editor:get_selection ()
|
||||||
|
|
||||||
|
--
|
||||||
|
-- At the point of writing the following data items are available
|
||||||
|
--
|
||||||
|
|
||||||
|
-- Range selection, total span of all ranges (0, 0 if no time range is selected)
|
||||||
|
if sel.time:start () < sel.time:end_frame () then
|
||||||
|
print ("Total Range:", sel.time:start (), sel.time:end_frame ())
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Range selection, individual ranges.
|
||||||
|
for ar in sel.time:iter () do
|
||||||
|
-- each of the items is a
|
||||||
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:AudioRange
|
||||||
|
print ("Range:", ar.id, ar.start, ar._end)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Track/Bus Selection
|
||||||
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:TrackSelection
|
||||||
|
for r in sel.tracks:routelist ():iter () do
|
||||||
|
-- each of the items is a
|
||||||
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Route
|
||||||
|
print ("Route:", r:name ())
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Region selection
|
||||||
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:RegionSelection
|
||||||
|
for r in sel.regions:regionlist ():iter () do
|
||||||
|
-- each of the items is a
|
||||||
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Region
|
||||||
|
print ("Region:", r:name ())
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Markers
|
||||||
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:MarkerSelection
|
||||||
|
-- Note: Marker selection is not cleared and currently (Ardour-4.7) points
|
||||||
|
-- to the most recently selected marker.
|
||||||
|
for m in sel.markers:iter () do
|
||||||
|
-- each of the items is a
|
||||||
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOURUI::ArdourMarker
|
||||||
|
print ("Marker:", m:name (), m:position(), m:_type())
|
||||||
|
end
|
||||||
|
|
||||||
|
----------------------------------------------------------
|
||||||
|
-- The total time extents of all selected regions and ranges
|
||||||
|
local ok, ext = Editor:get_selection_extents (0, 0)
|
||||||
|
if ok then
|
||||||
|
print ("Selection Extents:", ext[1], ext[2])
|
||||||
|
else
|
||||||
|
print ("No region or range is selected")
|
||||||
|
end
|
||||||
|
|
||||||
|
end end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue