View Single Post
Old 04-07-2013, 01:32 PM   #68
Human being with feelings
Join Date: Mar 2013
Posts: 28

Originally Posted by Argitoth View Post
In the peak script you are using RPR_Main_OnCommand(RPR_NamedCommandLookup('_SWS_FI NDITEMPEAK'), 0)

using sws extension to do a find peak command.

Does sws have a "find first point above X db?" So, it could potentially place the snap offset point where the media item first reaches a certain db.
Hmm I don't think SWS has anything like that (at least not that I know of).

Not sure if this is what you're looking for, but it's the closest solution I was able to find:

# ---------------------------------------------------
# Set snap offset to threshold dB for selected items
# ---------------------------------------------------

from reaper_python import *


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_cursor = RPR_GetCursorPosition()

	# Transient detection sensitivity/threshold: adjust... (toggle dialog)
	RPR_Main_OnCommand(41208, 0)
	RPR_ShowMessageBox("Adjust transient detection settings.\nClick OK when done.", "Set snap offset to threshold dB", 0)
	RPR_Main_OnCommand(41208, 0)

	# 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)

		# Move cursor to left edge of item
		RPR_SetEditCurPos(RPR_GetMediaItemInfo_Value(itm, "B_POSITION"), False, False)

		# Item navigaton: Move cursor to next transient in items
		RPR_Main_OnCommand(40375, 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)

	RPR_Undo_EndBlock2(0,"Set snap offset to threshold dB for selected items",-1)
Basically, it uses Reaper's transient detection system to set the snap offset at the first transient.
(NOTE1: You may have to set "Sensitivity" to 100%)
(NOTE2: Just realized that on Mac OS, the second dialog box with the "Click OK" prompt prevents adjusting the sliders/settings in the Transient dialog. If this is an issue, then delete the three lines starting with 'RPR_Main_OnCommand(41208, 0)' and simply open the Transient dialog settings on your own before running the script.)

If that's not quite it, then there IS a way to read the samples via ReaScript, but it will be very slow, especially on larger item sizes (or multiple items).

Last edited by Astonisher; 04-07-2013 at 03:54 PM.
Astonisher is offline   Reply With Quote