View Single Post
Old 04-21-2013, 10:39 AM   #109
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by Argitoth View Post
I could use a script for this simple action:

"Move edit cursor to nearest marker"
Move edit cursor to nearest marker:

Code:
# Move edit cursor to nearest marker

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("Move edit cursor to nearest marker"):

    cursorPos = RPR_GetCursorPositionEx(0)

    i = 0
    while RPR_EnumProjectMarkers3(0, i, 0, 0, 0, "", 0, 0)[0] > 0:
        markerPos = RPR_EnumProjectMarkers3(0, i, 0, 0, 0, "", 0, 0)[4]

        if markerPos == cursorPos:
            break

        # seek next marker after edit cursor
        if markerPos > cursorPos:

            # if cursor is between project start and 1. marker -> move to 1. marker
            if i == 0:
                RPR_SetEditCurPos2(0, markerPos, 1, 0)

            # check which one is closer to edit cursor (marker before cursor or marker after cursor)
            elif abs(cursorPos - prevMarkerPos) < abs(cursorPos - markerPos):

                # if marker before cursor is nearest -> move cursor there
                RPR_SetEditCurPos2(0, prevMarkerPos, 1, 0)
            else:
                # if marker after cursor is nearest -> move cursor there
                RPR_SetEditCurPos2(0, markerPos, 1, 0)

            break

        # if cursor is after the last marker -> move cursor to last marker
        elif markerPos < cursorPos and RPR_EnumProjectMarkers3(0, i + 1, 0, 0, 0, "", 0, 0)[0] == 0:
            RPR_SetEditCurPos2(0, markerPos, 1, 0)

        i += 1
        prevMarkerPos = RPR_EnumProjectMarkers3(0, i - 1, 0, 0, 0, "", 0, 0)[4]

Last edited by spk77; 04-21-2013 at 10:53 AM.
spk77 is offline   Reply With Quote