From b3593bd713a44f593465d665899b861799536870 Mon Sep 17 00:00:00 2001 From: Christopher Arndt Date: Mon, 22 Jan 2024 14:34:13 +0100 Subject: [PATCH] refactor: add function annotation and check return value Signed-off-by: Christopher Arndt --- rename_regions_from_markers.lua | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/rename_regions_from_markers.lua b/rename_regions_from_markers.lua index f8ffe08..a2e0018 100644 --- a/rename_regions_from_markers.lua +++ b/rename_regions_from_markers.lua @@ -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