Quote:
Originally Posted by Argitoth
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]