将LUA脚本的“reaper.”屏蔽

关键代码:for key in pairs(reaper) do _G[key]=reaper[key] end 可屏蔽掉 “reaper.”

举个栗子:
加入上面的代码后 MIDI_CountEvts(take) 将等同于 reaper.MIDI_CountEvts(take)

参考脚本【将选中的音符尾巴对齐到光标】:

for key in pairs(reaper) do _G[key]=reaper[key] end

function EndTime()
    local curpos = MIDI_GetPPQPosFromProjTime(take, GetCursorPositionEx(0))
    local _, notecnt, _, _ = MIDI_CountEvts(take)
    local fng_take = FNG_AllocMidiTake(take)
    for i = 1, notecnt do
        local cur_note = FNG_GetMidiNote(fng_take, i - 1)
        local selected = FNG_GetMidiNoteIntProperty(cur_note, "SELECTED") -- 是否有音符被选中
        -- local muted = reaper.FNG_GetMidiNoteIntProperty(cur_note, "MUTED") -- 静音
        -- local ppqpos = reaper.FNG_GetMidiNoteIntProperty(cur_note, "POSITION") -- 起始位置
        -- local chan = reaper.FNG_GetMidiNoteIntProperty(cur_note, "CHANNEL") -- 通道
        -- local pitch = reaper.FNG_GetMidiNoteIntProperty(cur_note, "PITCH") -- 音高
        -- local vel = reaper.FNG_GetMidiNoteIntProperty(cur_note, "VELOCITY") -- 力度

        if selected == 1 then
            local noteppq = FNG_GetMidiNoteIntProperty(cur_note, "POSITION") -- 音符起始位置
            local lenppq = FNG_GetMidiNoteIntProperty(cur_note, "LENGTH") -- 音符长度
            local endpos = curpos - noteppq
            if noteppq < curpos then
                FNG_SetMidiNoteIntProperty(cur_note, "LENGTH", endpos) -- 将音符结束位置应用到光标位置
            end
        end
    end
    FNG_FreeMidiTake(fng_take)
end

function Main()
    Undo_BeginBlock()
    take = MIDIEditor_GetTake(MIDIEditor_GetActive())
    if take == nil then return end
    EndTime()
    UpdateArrange()
    Undo_EndBlock("End Time FNG", -1)
end

Main()