-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertNewSiblingTrack.lua
More file actions
39 lines (31 loc) · 1.11 KB
/
InsertNewSiblingTrack.lua
File metadata and controls
39 lines (31 loc) · 1.11 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
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("InsertNewTrackInFolder", function()
local mediaTracksCount = reaper.CountTracks()
if mediaTracksCount <= 1 then
rpr.track_insert_new()
return
end
local selectedTracks = btk.GetSelectedTracks()
if #selectedTracks == 0 then
rpr.track_insert_new()
return
end
local sel = selectedTracks[#selectedTracks]
local selTrackIndex = reaper.GetMediaTrackInfo_Value(sel, "IP_TRACKNUMBER") - 1
local selIsLastTrackInFolder = (
selTrackIndex == reaper.CountTracks() - 1 or
reaper.GetTrackDepth(sel) > reaper.GetTrackDepth(reaper.GetTrack(0, selTrackIndex + 1))
)
if selIsLastTrackInFolder then
reaper.InsertTrackInProject(0, selTrackIndex, 0)
reaper.ReorderSelectedTracks(selTrackIndex, 0)
reaper.SetOnlyTrackSelected(reaper.GetTrack(0, selTrackIndex + 1))
else
rpr.track_insert_new()
end
btk.GenerateMarkerColors()
end)