-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditRegionLength.lua
More file actions
49 lines (36 loc) · 1.4 KB
/
EditRegionLength.lua
File metadata and controls
49 lines (36 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
-- @description My Script
-- @version 1.0
-- @author 1496jun
-- @changelog
-- Initial release
-- @provides
-- [main] Scripts/EditRegionLength.lua
-- Prompt user to input seconds in GUI
local ret, user_input = reaper.GetUserInputs("Change Region Length", 1, "Seconds to extend/shorten (e.g. 2, -1.5)", "")
if not ret then return end
local delta = tonumber(user_input)
if not delta then
reaper.ShowMessageBox("Invalid number input.", "Error", 0)
return
end
-- Begin undo block
reaper.Undo_BeginBlock()
-- Get time selection
local timeSelStart, timeSelEnd = reaper.GetSet_LoopTimeRange(false, false, 0, 0, false)
-- Scan project markers and regions
local numMarkers, numRegions = reaper.CountProjectMarkers(0)
local count_changed = 0
for i = 0, numMarkers + numRegions - 1 do
local retval, isrgn, pos, rgnend, name, markrgnindexnumber, color = reaper.EnumProjectMarkers3(0, i)
if isrgn and pos >= timeSelStart and rgnend <= timeSelEnd then
local newEnd = rgnend + delta
if newEnd > pos then
reaper.SetProjectMarkerByIndex(0, i, true, pos, newEnd, markrgnindexnumber, name, color)
count_changed = count_changed + 1
else
reaper.ShowMessageBox("Skipped region due to non-positive length: " .. name, "Warning", 0)
end
end
end
reaper.Undo_EndBlock("Changed Region Lengths (" .. count_changed .. " modified)", -1)
reaper.UpdateArrange()