View Single Post
Old 04-20-2013, 06:59 AM   #104
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,514
Default

Quote:
Originally Posted by Argitoth View Post
Hmm, another simple action is missing. There's an action "Xenakois/SWS: Select items under edit cursor on selected tracks" but I don't want the "on selected tracks" part of it.

I need this:

"Select items under edit cursor"
Select items under edit cursor (unselect other items):

Code:
#Select items under edit cursor (unselect other items)

from reaper_python import *
from contextlib import contextmanager

@contextmanager
def undoable(message):
    RPR_Undo_BeginBlock2(0)
    try:
        yield
    finally:
        RPR_Undo_EndBlock2(0, message, -1)

with undoable("Select items under edit cursor"):

    def msg(m):
        RPR_ShowConsoleMsg(m)

    unSelAllItems = 40289

    RPR_Main_OnCommandEx(unSelAllItems, 0, 0)
    for i in range(RPR_CountMediaItems(0)):
        itemId = RPR_GetMediaItem(0, i)
        itemStartPos = float(RPR_GetMediaItemInfo_Value(itemId, "D_POSITION"))
        itemEndPos = itemStartPos + float(RPR_GetMediaItemInfo_Value(itemId, "D_LENGTH"))
        if itemStartPos <= RPR_GetCursorPositionEx(0) <= itemEndPos:
            RPR_SetMediaItemInfo_Value(itemId, "B_UISEL", 1)

    # update view
    RPR_UpdateArrange()

Last edited by spk77; 04-20-2013 at 11:26 AM.
spk77 is offline   Reply With Quote