Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Q&A, Tips, Tricks and Howto

Reply
 
Thread Tools Display Modes
Old 07-29-2021, 05:01 AM   #1
xappn
Human being with feelings
 
Join Date: Feb 2021
Posts: 23
Default How to trim left edge of items to snap offset

Hi yall, I have a bunch of drum tracks that have been splitted, quantized, overlap removed and gap filled.


The gap filling operation obviously created snap offsets to the items along with the fades.

I would like to undo all of that except the original splits.

I am able to remove all the fades, but what's left is the snap offsets.


So basically what I'm looking for is either


trim left edges of items to snap offsets

or

a way to undo "Fill gaps between selected items", to place items' left edges to their original position


Thank you in advance
xappn is offline   Reply With Quote
Old 08-01-2021, 12:22 AM   #2
poulhoi
Human being with feelings
 
Join Date: Apr 2020
Posts: 214
Default

This script should work:

Code:
function UnselectItems()
	while reaper.CountSelectedMediaItems(0) > 0 do
		reaper.SetMediaItemSelected(reaper.GetSelectedMediaItem(0, 0), false)
	end
end

function SetOnlyItemSelected(item)
	UnselectItems()
	reaper.SetMediaItemSelected(item, true)
end

function SetSelectedItems(table)
	UnselectItems()
	for i = 1, #table do
		reaper.SetMediaItemSelected(table[i], true)
	end
end

function main()
	reaper.Undo_BeginBlock()
	local items = {}
	local cursorPos = reaper.GetCursorPosition()
	for i = 1, reaper.CountSelectedMediaItems(0) do
		items[i] = reaper.GetSelectedMediaItem(0, i-1)
	end
	for i = 1, #items do
		local item = items[i]
		local itemPos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
		local snapOffset = reaper.GetMediaItemInfo_Value(item, "D_SNAPOFFSET")
		SetOnlyItemSelected(item)
		reaper.SetEditCurPos(itemPos+snapOffset, false, false)
		reaper.Main_OnCommand(41305, 0) -- trim left edge to cursor
	end
	SetSelectedItems(items)
	reaper.SetEditCurPos(cursorPos, false, false)
	reaper.Undo_EndBlock("Trim left edge of selected items to snap offsets", -1)
end

reaper.PreventUIRefresh(1)
main()
reaper.PreventUIRefresh(-1)
reaper.UpdateArrange()
__________________
My repository of scripts
poulhoi is offline   Reply With Quote
Old 08-01-2021, 06:27 AM   #3
xappn
Human being with feelings
 
Join Date: Feb 2021
Posts: 23
Default

Quote:
Originally Posted by poulhoi View Post
This script should work:

Code:
function UnselectItems()
	while reaper.CountSelectedMediaItems(0) > 0 do
		reaper.SetMediaItemSelected(reaper.GetSelectedMediaItem(0, 0), false)
	end
end

function SetOnlyItemSelected(item)
	UnselectItems()
	reaper.SetMediaItemSelected(item, true)
end

function SetSelectedItems(table)
	UnselectItems()
	for i = 1, #table do
		reaper.SetMediaItemSelected(table[i], true)
	end
end

function main()
	reaper.Undo_BeginBlock()
	local items = {}
	local cursorPos = reaper.GetCursorPosition()
	for i = 1, reaper.CountSelectedMediaItems(0) do
		items[i] = reaper.GetSelectedMediaItem(0, i-1)
	end
	for i = 1, #items do
		local item = items[i]
		local itemPos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
		local snapOffset = reaper.GetMediaItemInfo_Value(item, "D_SNAPOFFSET")
		SetOnlyItemSelected(item)
		reaper.SetEditCurPos(itemPos+snapOffset, false, false)
		reaper.Main_OnCommand(41305, 0) -- trim left edge to cursor
	end
	SetSelectedItems(items)
	reaper.SetEditCurPos(cursorPos, false, false)
	reaper.Undo_EndBlock("Trim left edge of selected items to snap offsets", -1)
end

reaper.PreventUIRefresh(1)
main()
reaper.PreventUIRefresh(-1)
reaper.UpdateArrange()
Wow, thank you ever so much! Works brilliantly.
xappn is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:12 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.