From 82c4992b4d7f533104908c0ebe2b213a9c3eaa36 Mon Sep 17 00:00:00 2001 From: chmaha Date: Fri, 3 Jan 2025 11:17:13 +0000 Subject: [PATCH] Add double space before rank --- ReaClassical/ReaClassical_Rank Higher.lua | 12 ++++++++++-- ReaClassical/ReaClassical_Rank Lower.lua | 14 +++++++++++--- ReaClassical/ReaClassical_Remove Ranking.lua | 3 ++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/ReaClassical/ReaClassical_Rank Higher.lua b/ReaClassical/ReaClassical_Rank Higher.lua index c6fa2f97..68cec9d5 100644 --- a/ReaClassical/ReaClassical_Rank Higher.lua +++ b/ReaClassical/ReaClassical_Rank Higher.lua @@ -34,7 +34,7 @@ end function main() Undo_BeginBlock() process_items() - Undo_EndBlock("Add '+' suffix to item name", -1) + Undo_EndBlock("Rank Take Higher", -1) UpdateArrange() end @@ -51,12 +51,20 @@ function modify_item_name(item) if count_minus > 0 then item_name = item_name:sub(1, #item_name - 1) count_minus = count_minus - 1 + if count_minus == 0 then + item_name = item_name:gsub(" $", "") + end else count_plus = item_name:match("%+*$") count_plus = count_plus and #count_plus or 0 if count_plus < 3 then - item_name = item_name .. "+" + -- Ensure two spaces before adding the first '+' + if count_plus == 0 and not item_name:find(" +$") then + item_name = item_name:gsub("%s*$", "") .. " +" + else + item_name = item_name .. "+" + end count_plus = count_plus + 1 end end diff --git a/ReaClassical/ReaClassical_Rank Lower.lua b/ReaClassical/ReaClassical_Rank Lower.lua index c293215e..015eb6dd 100644 --- a/ReaClassical/ReaClassical_Rank Lower.lua +++ b/ReaClassical/ReaClassical_Rank Lower.lua @@ -36,7 +36,7 @@ end function main() Undo_BeginBlock() process_items() - Undo_EndBlock("Add '-' suffix to item name", -1) + Undo_EndBlock("Rank Take Lower", -1) UpdateArrange() end @@ -54,12 +54,20 @@ function modify_item_name(item) if count_plus > 0 then item_name = item_name:sub(1, #item_name - 1) count_plus = count_plus - 1 + if count_plus == 0 then + item_name = item_name:gsub(" $", "") + end else count_minus = item_name:match("%-*$") count_minus = count_minus and #count_minus or 0 if count_minus < 3 then - item_name = item_name .. "-" + -- Ensure two spaces before adding the first '-' + if count_minus == 0 and not item_name:find(" -$") then + item_name = item_name:gsub("%s*$", "") .. " -" + else + item_name = item_name .. "-" + end count_minus = count_minus + 1 end end @@ -78,7 +86,7 @@ function modify_item_name(item) return colors.rank_good end, [0] = function() - return 0 -- Default color + return 0 -- Default color end, [-1] = function() return colors.rank_below_average diff --git a/ReaClassical/ReaClassical_Remove Ranking.lua b/ReaClassical/ReaClassical_Remove Ranking.lua index 2afdc6cd..8a6a93bc 100644 --- a/ReaClassical/ReaClassical_Remove Ranking.lua +++ b/ReaClassical/ReaClassical_Remove Ranking.lua @@ -35,7 +35,7 @@ end function main() reaper.Undo_BeginBlock() process_items() - reaper.Undo_EndBlock("Remove all '+' and '-' from item name", -1) + reaper.Undo_EndBlock("Remove Take Ranking", -1) reaper.UpdateArrange() end @@ -47,6 +47,7 @@ function modify_item_name(item) local _, item_name = reaper.GetSetMediaItemTakeInfo_String(take, "P_NAME", "", false) item_name = item_name:gsub("[%+%-]+$", "") + item_name = item_name:gsub(" $", "") -- remove double space if present reaper.GetSetMediaItemTakeInfo_String(take, "P_NAME", item_name, true)