View Single Post
Old 04-06-2013, 12:45 AM   #75
Astonisher
Human being with feelings
 
Join Date: Mar 2013
Posts: 28
Default

Quote:
Originally Posted by Argitoth View Post
Ah yes! Thank you. For the "expand left edge" should not affect snap offset.
Here ya go,

SCRIPT #3
Code:
# -------------------------------------------------------
# Expand left edge of selected media items by X seconds
# -------------------------------------------------------


from reaper_python import *

RPR_PreventUIRefresh(1)
RPR_Undo_BeginBlock2(0)

try :

	inpt = RPR_GetUserInputs("Expand left edge of items",  1, "x (seconds): ", "", 10)
	if inpt[0]:
		try:
			x_sec = float(inpt[4])
		except:
			RPR_ShowMessageBox("Invalid input!", "Error", 0)
			raise
	
		num_selected = RPR_CountSelectedMediaItems(0)
		orig_selection = []	

		# Save original item selection and cursor position
		for i in range(num_selected):
			itm = RPR_GetSelectedMediaItem(0, i)
			orig_selection.append(itm)
		orig_cursor = RPR_GetCursorPosition()

		# Item: Unselect all items
		RPR_Main_OnCommand(40289, 0)	

		# Process each item
		for itm in orig_selection:
			# Select item
			RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 1)

			# Put cursor X seconds to left of media item
			pos = RPR_GetMediaItemInfo_Value(itm, "D_POSITION")
			RPR_SetEditCurPos(pos-x_sec, False, False)
		
			# Item: Trim left edge of item to edit cursor
			RPR_Main_OnCommand(41305, 0)

			# Unselect item
			RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 0)

		# Restore state
		for itm in orig_selection:
			RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 1)
		RPR_SetEditCurPos(orig_cursor, False, False)
		

finally:
	RPR_PreventUIRefresh(-1)
	RPR_Undo_EndBlock2(0,"Expand left edge of items by X second(s)",-1)
	RPR_UpdateTimeline()
Similar method as the first two scripts.
Astonisher is offline   Reply With Quote