zaibuyidao / ReaScripts

REAPER, ReaScripts, MIDI Editor
22 stars 5 forks source link

Move (WITH SEEKING) Play/Edit Cursor to Mouse Cursor in MIDI Editor #13

Closed ARkaine2 closed 1 year ago

ARkaine2 commented 1 year ago

Please help make what is decribed in subj.

By default there are no actions in Reaper to do it (and I checked many scripts -- they don't do it too).

Only this one script moves cursor in such "way" that I need (with "seeking"), but in another direction (to start of first note):

-- @description Move edit cursor to first note of active MIDI editor take
-- @version 1.01
-- @author MPL
-- @website http://forum.cockos.com/showthread.php?t=188335
-- @changelog
--    # ReaPack header, name 

  function main()
    MIDIEditor = reaper.MIDIEditor_GetActive()
    if MIDIEditor == nil then return end
    take = reaper.MIDIEditor_GetTake(MIDIEditor)
    if take == nil then return end
    if reaper.TakeIsMIDI(take) == false then return end
    fngtake = reaper.FNG_AllocMidiTake(take)
    note = reaper.FNG_GetMidiNote(fngtake, 0)

    note_pos = reaper.FNG_GetMidiNoteIntProperty(note, 'POSITION')

    pos = reaper.MIDI_GetProjTimeFromPPQPos(take, note_pos)
    reaper.SetEditCurPos(pos, true, true)
  end

  main()

I need to move edit cursor to mouse cursor with "seeking".

This means that when project is playing after moving cursor in such way project will play from new/moved cursor position.

I will be grateful.

zaibuyidao commented 1 year ago

Okay, you can try this.

function main()
midieditor = reaper.MIDIEditor_GetActive()
if midieditor == nil then return end
take = reaper.MIDIEditor_GetTake(midieditor)
if take == nil then return end
if reaper.TakeIsMIDI(take) == false then return end
reaper.MIDIEditor_OnCommand( midieditor, 40443 )
pos = reaper.GetCursorPositionEx(0)
reaper.SetEditCurPos(pos, true, true)
end

main()
ARkaine2 commented 1 year ago

zaibuyidao, It works perfect! Thanks a lot. :)