View Single Post
Old 05-15-2018, 11:44 AM   #20
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,569
Default

Quote:
Originally Posted by hopi View Post
I am wondering if it would be hard to adapt a version of it that would work in the Inline Editor?
Sorry that I didn't see this post before.

It would be easy to adapt the script for the inline MIDI editor. The only problem is that scripts don't know which inline editor is focused, so it is not straightforward to run scripts for the inline editor from the Actions list. (Please bump the FR: ReaScript: API functions to get and set focus on an item in the arrange view.) The script must therefore either work with
1) the editor under the mouse, or
2) the selected item(s).

Here are both alternatives:
Code:
-- Quick script that is intended to nudge selected notes in
--    ALL OPEN INLINE MIDI EDITORS IN ALL SELECTED ITEMS
--    by a user-defined number of milliseconds
-- WARNING: Do not use if there are overlapping notes in the take, since 
--    ReaScripts are not compatible with such notes.


repeat
    OKorCancel, userTime = reaper.GetUserInputs("Nudge notes by millisecs", 1, "Time (in milliseconds)", "0")
until OKorCancel == false or (OKorCancel == true and type(tonumber(userTime)) == "number")

if OKorCancel == false then 
    reaper.defer(function() end) -- Prevent unnecessary undo points
    return(0) 
else
    nudgeTime = tonumber(userTime) / 1000
end


reaper.Undo_BeginBlock2(0)

for i = 0, reaper.CountSelectedMediaItems(0)-1 do
    item = reaper.GetSelectedMediaItem(0, i)
    for t = 0, reaper.CountTakes(item)-1 do
        take = reaper.GetTake(item, t)
        if reaper.BR_IsMidiOpenInInlineEditor(take) then     
            reaper.MIDI_Sort(take)
            n = reaper.MIDI_EnumSelNotes(take, -1)
            while n ~= -1 do
                noteOK, selected, _, noteStartPPQ, noteEndPPQ, _, _, _ = reaper.MIDI_GetNote(take, n)
                if noteOK and selected then
                    noteStartTime = reaper.MIDI_GetProjTimeFromPPQPos(take, noteStartPPQ)
                    newNoteStartPPQ = reaper.MIDI_GetPPQPosFromProjTime(take, noteStartTime + nudgeTime)
                    newNoteEndPPQ = newNoteStartPPQ + (noteEndPPQ - noteStartPPQ)
                    reaper.MIDI_SetNote(take, n, nil, nil, newNoteStartPPQ, newNoteEndPPQ, nil, nil, nil, true)
                end
                n = reaper.MIDI_EnumSelNotes(take, n)
            end
            reaper.MIDI_Sort(take)
        end -- if reaper.BR_IsMidiOpenInInlineEditor(take)
    end -- for t = 0, reaper.CountTakes(item)-1
end -- for i = 0, reaper.CountSelectedMediaItems(0)-1


reaper.Undo_EndBlock2(0, "Nudge notes by milliseconds", -1)
Code:
-- Quick script that is intended to nudge selected notes in the 
--    INLINE (OR MAIN) MIDI EDITOR UNDER THE MOUSE
--    by a user-defined number of milliseconds
-- WARNING: Do not use if there are overlapping notes in the take, since 
--    ReaScripts are not compatible with such notes.

reaper.defer(function() end) -- Prevent unnecessary undo points

if not reaper.APIExists("SN_FocusMIDIEditor") then reaper.MB("This script requires a recent version of the SWS extension", "ERROR", 0) return end -- Old versions of SWS have bug in Context function

window, segment, details = reaper.BR_GetMouseCursorContext()
    if window ~= "midi_editor" then return end
editor, inlineEditor = reaper.BR_GetMouseCursorContext_MIDI()
if inlineEditor then
    take = reaper.BR_GetMouseCursorContext_Take()
else
    take = reaper.MIDIEditor_GetTake(editor) -- Also works on main MIDI editor
end


repeat
    OKorCancel, userTime = reaper.GetUserInputs("Nudge notes by millisecs", 1, "Time (in milliseconds)", "0")
until OKorCancel == false or (OKorCancel == true and type(tonumber(userTime)) == "number")

if OKorCancel == false then 
    return(0) 
else
    nudgeTime = tonumber(userTime) / 1000
end


reaper.Undo_BeginBlock2(0)

reaper.MIDI_Sort(take)
i = reaper.MIDI_EnumSelNotes(take, -1)
while i ~= -1 do
    noteOK, selected, _, noteStartPPQ, noteEndPPQ, _, _, _ = reaper.MIDI_GetNote(take, i)
    if noteOK and selected then
        noteStartTime = reaper.MIDI_GetProjTimeFromPPQPos(take, noteStartPPQ)
        newNoteStartPPQ = reaper.MIDI_GetPPQPosFromProjTime(take, noteStartTime + nudgeTime)
        newNoteEndPPQ = newNoteStartPPQ + (noteEndPPQ - noteStartPPQ)
        reaper.MIDI_SetNote(take, i, nil, nil, newNoteStartPPQ, newNoteEndPPQ, nil, nil, nil, true)
    end
    i = reaper.MIDI_EnumSelNotes(take, i)
end

reaper.MIDI_Sort(take)

reaper.Undo_EndBlock2(0, "Nudge notes by milliseconds", -1)

Quote:
The poor little orphan Inline Editor ...so kewl and soooo much in need of some serious DEV love
Indeed. I have tried to adapt my CC editing scripts for the inline MIDI editor, and also uploaded some channel and CC lane scripts.
juliansader is online now   Reply With Quote