Skip to content

Release Copy and paste item below on new track v1.0 #1603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- @description Copy and paste item below on new track
-- @author JoeWishman
-- @version 1.0
-- @about
-- Run the script to copy the selected clip to the track below.
-- If no tracks exist, the script will create one.
-- Cheers

function copyItemDown()
local item = reaper.GetSelectedMediaItem(0, 0)
if not item then return end

local src_track = reaper.GetMediaItemTrack(item)
local src_idx = reaper.GetMediaTrackInfo_Value(src_track, "IP_TRACKNUMBER") - 1
local dest_idx = src_idx + 1

local track_count = reaper.CountTracks(0)
while dest_idx >= track_count do
reaper.InsertTrackAtIndex(track_count, true)
track_count = track_count + 1
end

local dest_track = reaper.GetTrack(0, dest_idx)
if not dest_track then return end

local pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
local len = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")

local new_item = reaper.AddMediaItemToTrack(dest_track)
reaper.SetMediaItemInfo_Value(new_item, "D_POSITION", pos)
reaper.SetMediaItemInfo_Value(new_item, "D_LENGTH", len)

local take = reaper.GetMediaItemTake(item, 0)
if take then
local source = reaper.GetMediaItemTake_Source(take)
local new_take = reaper.AddTakeToMediaItem(new_item)
reaper.SetMediaItemTake_Source(new_take, source)
end

reaper.UpdateArrange()
end

reaper.Undo_BeginBlock()
copyItemDown()
reaper.Undo_EndBlock("Copy Item Down 1 Track", -1)