View Single Post
Old 03-07-2013, 12:15 AM   #57
timlloyd
Human being with feelings
 
Join Date: Mar 2010
Posts: 4,713
Default

I haven't tested this, but it should work ...

Code:
# -----------------------------------------------
# Shorten selected media items to X seconds,
# if media item length is greater than X seconds.
# -----------------------------------------------

from reaper_python import *

usr_input = RPR_GetUserInputs("Shorten item(s) if longer than x",
                              1, "x (seconds)", "", 1024)

if usr_input[0]:
    RPR_Undo_BeginBlock2(0)
    for i in range(0, RPR_CountSelectedMediaItems(0)):
        item = RPR_GetSelectedMediaItem(0, i)
        length = RPR_GetMediaItemInfo_Value(item, "D_LENGTH")
        trim_len = float(usr_input[4])
        if length > trim_len:
            RPR_SetMediaItemInfo_Value(item, "D_LENGTH", trim_len)
    RPR_Undo_EndBlock2(0, "Shorten item(s) if longer than x", -1)

RPR_UpdateArrange()
timlloyd is offline   Reply With Quote