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()
-- there is currently no direct way to find the track
-- 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
local track = route:to_track()
local pl = track:playlist()
@ -20,7 +22,7 @@ function factory()
assert(0) -- can't happen, region must be in a playlist
end
return function()
return function ()
local sel = Editor:get_selection() -- get current selection
local loc = Session:locations() -- get locations
@ -30,8 +32,7 @@ function factory()
-- for each selected region...
for region in sel.regions:regionlist():iter() do
-- test if it's an audio region
local ar = region:to_audioregion()
if ar:isnil() then
if region:to_audioregion():isnil() then
goto next
end
@ -48,14 +49,16 @@ function factory()
local track = find_track_for_region(rid)
region:to_stateful():clear_changes()
if track then
region:to_stateful():clear_changes()
--~ print("Marker label:", mloc:name())
-- rename region to track name + marker label
region:set_name(track:name() .. " " .. mloc:name())
--~ print("Marker label:", mloc:name())
-- rename region to track name + marker label
region:set_name(track:name() .. " " .. mloc:name())
-- collect undo data
Session:add_stateful_diff_command(region:to_statefuldestructible())
-- collect undo data
Session:add_stateful_diff_command(region:to_statefuldestructible())
end
::next::
end