-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveSelectedItemsToDuplicateTracks.lua
More file actions
65 lines (50 loc) · 1.82 KB
/
Copy pathMoveSelectedItemsToDuplicateTracks.lua
File metadata and controls
65 lines (50 loc) · 1.82 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
--[[
* ReaScript Name: MoveSelectedItemsToDuplicateTracks.lua
* Author: Ben Kalman
--]]
local function get_item_track(item)
return reaper.GetMediaItemInfo_Value(item, "P_TRACK")
end
local function get_item_position(item)
return reaper.GetMediaItemInfo_Value(item, "D_POSITION")
end
local function selected_media_items_reversed()
local count = reaper.CountSelectedMediaItems(0)
local items = {}
for i = 0, count - 1 do
items[i + 1] = reaper.GetSelectedMediaItem(0, count - i - 1)
end
return items
end
local function run()
reaper.Undo_BeginBlock()
local selectedItems = selected_media_items_reversed()
if #selectedItems == 0 then
return
end
local firstSelectedItem = reaper.GetSelectedMediaItem(0, 0)
local track = get_item_track(firstSelectedItem)
reaper.SetOnlyTrackSelected(track)
for _, item in ipairs(selectedItems) do
local itemPosition = get_item_position(item)
if get_item_track(item) == track then
reaper.Main_OnCommand(40062, 0) -- Track: Duplicate tracks
local newTrack = reaper.GetSelectedTrack(0, 0)
for _, newItem in ipairs(selected_media_items_reversed()) do
if get_item_track(newItem) == newTrack then
if get_item_position(newItem) == itemPosition then
reaper.SetMediaItemPosition(newItem, get_item_position(firstSelectedItem), false)
else
reaper.DeleteTrackMediaItem(newTrack, newItem)
end
end
end
end
reaper.SetOnlyTrackSelected(track)
end
for _, item in ipairs(selectedItems) do
reaper.SetMediaItemInfo_Value(item, "B_MUTE_ACTUAL", 1)
end
reaper.Undo_EndBlock("MoveSelectedItemsToDuplicateTracks", -1)
end
run()