refactor: add function annotation and check return value

Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
This commit is contained in:
Christopher Arndt 2024-01-22 14:34:13 +01:00
parent 6a39d65a5b
commit b3593bd713
1 changed files with 13 additions and 10 deletions

View File

@ -9,7 +9,9 @@ ardour {
function factory() function factory()
-- there is currently no direct way to find the track -- there is currently no direct way to find the track
-- corresponding to a [selected] region -- corresponding to a [selected] region
function find_track_for_region(region_id) ---@param region_id ID
---@return Track?
local function find_track_for_region(region_id)
for route in Session:get_tracks():iter() do for route in Session:get_tracks():iter() do
local track = route:to_track() local track = route:to_track()
local pl = track:playlist() local pl = track:playlist()
@ -20,7 +22,7 @@ function factory()
assert(0) -- can't happen, region must be in a playlist assert(0) -- can't happen, region must be in a playlist
end end
return function() return function ()
local sel = Editor:get_selection() -- get current selection local sel = Editor:get_selection() -- get current selection
local loc = Session:locations() -- get locations local loc = Session:locations() -- get locations
@ -30,8 +32,7 @@ function factory()
-- for each selected region... -- for each selected region...
for region in sel.regions:regionlist():iter() do for region in sel.regions:regionlist():iter() do
-- test if it's an audio region -- test if it's an audio region
local ar = region:to_audioregion() if region:to_audioregion():isnil() then
if ar:isnil() then
goto next goto next
end end
@ -48,6 +49,7 @@ function factory()
local track = find_track_for_region(rid) local track = find_track_for_region(rid)
if track then
region:to_stateful():clear_changes() region:to_stateful():clear_changes()
--~ print("Marker label:", mloc:name()) --~ print("Marker label:", mloc:name())
@ -56,6 +58,7 @@ function factory()
-- collect undo data -- collect undo data
Session:add_stateful_diff_command(region:to_statefuldestructible()) Session:add_stateful_diff_command(region:to_statefuldestructible())
end
::next:: ::next::
end end