View Single Post
Old 04-05-2013, 09:41 AM   #64
Astonisher
Human being with feelings
 
Join Date: Mar 2013
Posts: 28
Default

Quote:
Originally Posted by Argitoth View Post
Yes, that would be perfect!

Ok, I know where the confusion is. See, when I said "move" I actually meant "trim".

Sooo

Script 1: Set snap offset of media item to its highest peak (all selected items)
-Now I can adjust snap offsets where needed, I can "preview" the trim.
Script 2: Trim left edge of media item to its snap offset (all selected items)
-Now I commit to my trim.

It's a "set length of time before highest peak" function, but split up in a few steps.

Edit: I'm going to add a 3rd step

Script 3: Expand left edge of media item by X seconds (input format should be 1 = 1 second, .001 = 1ms)
-Now I don't have to arbitrarily move the left edge of selected items, I can input a specific amount of time.

SCRIPT # 1:
Code:
# -----------------------------------------------
# Set snap offset to highest peak in media item
# -----------------------------------------------

from reaper_python import *

RPR_PreventUIRefresh(1)
RPR_Undo_BeginBlock2(0)

try :	

	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)

		# SWS: Move cursor to item peak sample
		RPR_Main_OnCommand(RPR_NamedCommandLookup('_SWS_FINDITEMPEAK'), 0)
		
		# Item: Set snap offset to cursor
		RPR_Main_OnCommand(40541, 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,"Set snap offset to highest peak for selected items",-1)
	RPR_UpdateTimeline()


SCRIPT #2:
Code:
# -----------------------------------------------
# Trim edge to snap offset for selected items
# -----------------------------------------------


from reaper_python import *

RPR_PreventUIRefresh(1)
RPR_Undo_BeginBlock2(0)

try :	

	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 at snap offset
		pos = RPR_GetMediaItemInfo_Value(itm, "D_POSITION")
		offset = RPR_GetMediaItemInfo_Value(itm, "D_SNAPOFFSET")	
		RPR_SetEditCurPos(pos+offset, False, False)
		
		# Item edit: 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,"Trim edge to snap offset for selected items",-1)
	RPR_UpdateTimeline()

Unfortunately had to do it with selecting items individually and moving the edit cursor around, so it's not completely elegant, but it works as expected.

Regarding SCRIPT #3, how do you want the snap offset to be treated in that case? (preserve where it was at in time before the added length or have it move with the left edge?)
Astonisher is offline   Reply With Quote