View Single Post
Old 01-31-2020, 12:45 AM   #1965
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 962
Default

Quote:
Originally Posted by MusoBob View Post
Try this in the MIDI Editor:
[CODE]
AMAZING, thank you!

I needed this code to create a legato script, so that the notes slightly overlap each other, but at the same time so that the last notes do not go beyond the boundaries of the item.
Finally:

Code:
    local ME = reaper.MIDIEditor_GetActive();
    if not ME then return end;

    local take = reaper.MIDIEditor_GetTake(ME);
    reaper.MIDIEditor_OnCommand(ME,reaper.NamedCommandLookup("_BR_ME_SAVE_NOTE_SEL_SLOT_1"));--Save note selection
    reaper.Undo_BeginBlock();
    reaper.PreventUIRefresh(1);


local correct
if reaper.GetToggleCommandStateEx(32060, 40681) == 1 then
   reaper.MIDIEditor_LastFocused_OnCommand(40681,0) --Options: Correct overlapping notes while editing
   correct = 1
end



ME = reaper.MIDIEditor_GetActive()

 take = reaper.MIDIEditor_GetTake(ME)
  
 retval, notecnt, ccevtcnt, textsyxevtcnt = reaper.MIDI_CountEvts( take )

 note_pos = 0

 for i = 0, notecnt -1 do
   retval, selected, muted, startppqpos, endppqpos, chan, pitch, vel = reaper.MIDI_GetNote( take, i )
   if selected then
      
      if startppqpos >= note_pos then
         note_pos = startppqpos  
      end
   end
 end   
 
 for i = 0, notecnt -1 do
   retval, selected, muted, startppqpos, endppqpos, chan, pitch, vel = reaper.MIDI_GetNote( take, i )
   if selected and startppqpos == note_pos then
      reaper.MIDI_SetNote( take, i  , false, muted, startppqpos, endppqpos, chan, pitch, vel, true )  
      
   end
 end

    reaper.MIDIEditor_OnCommand(ME,40405);--Set note ends to start of next note (legato)

    local t = {};
    local tSel = {};
    for i = 1,({reaper.MIDI_CountEvts(take)})[2] do;
        local retval,selected,muted,startppqpos,endppqpos,chan,pitch,vel = reaper.MIDI_GetNote(take,i-1);
        ---
        tSel[i-1] = selected;
        ---
    end;
    

    for i = 0, #tSel do;
        if tSel[i] == true then;
            local retval,selected,muted,startppqpos,endppqpos,chan,pitch,vel = reaper.MIDI_GetNote(take,i);
            reaper.MIDI_SetNote(take,i,tSel[i],muted,startppqpos,endppqpos+20,chan,pitch,vel,true);
        end;
    end;

time_start = reaper.time_precise()

local function Main()

    local elapsed = reaper.time_precise() - time_start  --set slowdown timer
    if elapsed >= 0.2 then  --pause 200ms

if correct then 
   reaper.MIDIEditor_LastFocused_OnCommand(40681,0) --Options: Correct overlapping notes while editing
end

        return
    else
        reaper.defer(Main)
    end
    
end

Main()
    reaper.MIDI_Sort(take);
    reaper.MIDIEditor_OnCommand(ME,reaper.NamedCommandLookup("_BR_ME_RESTORE_NOTE_SEL_SLOT_1"));--Restore note selection
    reaper.PreventUIRefresh(-1);
    reaper.Undo_EndBlock("Overlap Notes (legato)",-1);

Last edited by cool; 01-31-2020 at 01:05 AM.
cool is offline   Reply With Quote