1 ardour { ["type"] = "EditorAction", name = "Tom's Loop",
3 author = "Ardour Team",
4 description = [[Bounce the loop-range of all non muted audio tracks, paste N times at playhead]]
7 function action_params ()
8 return { ["times"] = { title = "Number of copies to add", default = "1"}, }
11 function factory (params) return function ()
13 local p = params or {}
14 local n_paste = tonumber (p["times"] or 1)
17 local proc = ARDOUR.LuaAPI.nil_proc () -- bounce w/o processing
18 local itt = ARDOUR.InterThreadInfo () -- bounce progress info (unused)
20 local loop = Session:locations ():auto_loop_location ()
21 local playhead = Session:transport_frame ()
23 -- make sure we have a loop, and the playhead (edit point) is after it
25 print ("A Loop range must be set.")
28 assert (loop:start () < loop:_end ())
29 if loop:_end () >= playhead then
30 print ("The Playhead (paste point) needs to be after the loop.")
34 -- prepare undo operation
35 Session:begin_reversible_command ("Tom's Loop")
36 local add_undo = false -- keep track if something has changed
38 -- prefer solo'ed tracks
39 local soloed_track_found = false
40 for route in Session:get_tracks ():iter () do
41 if route:soloed () then
42 soloed_track_found = true
47 -- count regions that are bounced
48 local n_regions_created = 0
50 -- loop over all tracks in the session
51 for route in Session:get_tracks ():iter () do
52 if soloed_track_found then
53 -- skip not soloed tracks
54 if not route:soloed () then
59 -- skip muted tracks (also applies to soloed + muted)
60 if route:muted () then
64 -- at this point the track is either soloed (if at least one track is soloed)
65 -- or not muted (if no track is soloed)
67 -- test if bouncing is possible
68 local track = route:to_track ()
69 if not track:bounceable (proc, false) then
74 local playlist = track:playlist ()
75 if playlist:data_type ():to_string () ~= "audio" then
79 -- check if there is at least one unmuted region in the loop-range
80 local reg_unmuted_count = 0
81 for reg in playlist:regions_touched (loop:start (), loop:_end ()):iter () do
82 if not reg:muted() then
83 reg_unmuted_count = reg_unmuted_count + 1
87 if reg_unmuted_count < 1 then
91 -- clear existing changes, prepare "diff" of state for undo
92 playlist:to_stateful ():clear_changes ()
95 local region = track:bounce_range (loop:start (), loop:_end (), itt, proc, false)
96 playlist:add_region (region, playhead, n_paste, false)
98 n_regions_created = n_regions_created + 1
100 -- create a diff of the performed work, add it to the session's undo stack
101 -- and check if it is not empty
102 if not Session:add_stateful_diff_command (playlist:to_statefuldestructible ()):empty () then
109 --advance playhead so it's just after the newly added regions
110 if n_regions_created > 0 then
111 Session:request_locate((playhead + loop:length() * n_paste),false)
114 -- all done, commit the combined Undo Operation
116 -- the 'nil' Command here mean to use the collected diffs added above
117 Session:commit_reversible_command (nil)
119 Session:abort_reversible_command ()
122 print ("bounced " .. n_regions_created .. " regions from loop range (" .. loop:length() .. " frames) to playhead @ frame # " .. playhead)