-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInsertRegionForSelectedItemsAndAddToMatrix.lua
41 lines (32 loc) · 1.24 KB
/
InsertRegionForSelectedItemsAndAddToMatrix.lua
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
local _, path = reaper.get_action_context()
local folder_path = path:match('^.+[\\/]')
package.path = folder_path .. '?.lua;'
local btk = require 'btk'
local rpr = require 'rpr'
btk.main("InsertRegionForSelectedItemsAndAddToMatrix", function()
local selectedItems = btk.GetSelectedItems()
if #selectedItems == 0 then
return
end
local itemsInfo = btk.GetItemsInfo(selectedItems)
local startPosition = -1
local endPosition = -1
for _, info in ipairs(itemsInfo) do
if startPosition == -1 or info.position < startPosition then
startPosition = info.position
end
if endPosition == -1 or info.position + info.length > endPosition then
endPosition = info.position + info.length
end
end
local defaultName = btk.GetTrackInfo(itemsInfo[1].track).name
local _, regionName = reaper.GetUserInputs("Region name [" .. defaultName .. "]", 1, "", "")
if regionName == "" then
regionName = defaultName
end
local regionIndex = reaper.AddProjectMarker(0, true, startPosition, endPosition, regionName, -1)
for _, info in ipairs(itemsInfo) do
reaper.SetRegionRenderMatrix(0, regionIndex, info.track, 1)
end
btk.GenerateMarkerColors()
end)