Quantcast
Channel: Cockos Incorporated Forums
Viewing all articles
Browse latest Browse all 51160

Lua: insert pitch-reset events at start of selected MIDI items

$
0
0
Background: in REAPER 5.1 we changed the way MIDI pitch is handled on MIDI items.
  • in 4.x and 5.0, MIDI pitch was reset to neutral at the end of each item
  • in 5.1+, MIDI pitch is chased to the last MIDI item, and not reset at the end of the item
This can result in projects sounding different (as a side note: the 4.x behavior was far from ideal, because any releasing notes would get their pitch reset at the end of the item, for example).

Here's a script which will insert MIDI reset events (if they don't already exist) at the start of all selected MIDI items, effectively making the projects sound the same on both versions:
Code:

sel = reaper.CountSelectedMediaItems(0)
for itemidx=0,sel-1 do
  item = reaper.GetSelectedMediaItem(0,itemidx)
  if item ~= nil then
    tk = reaper.GetMediaItemTake(item,-1)
    if tk ~= nil then
      for chan=0,15 do
        ok = true
        want = true
        evt_idx=0
        while ok and want do
          ok,sel,mute,pos,msg1,msgchan,msg3,msg4 = reaper.MIDI_GetCC(tk,evt_idx)
          evt_idx=evt_idx+1
          if ok and not mute and msgchan == chan and msg1 == 0xe0 and pos < 1 then
            want = false
          end
        end
        if want then
          reaper.MIDI_InsertCC(tk,false,false,0,0xe0,chan,0x0,0x40);
        end
      end
    end
  end
end


Viewing all articles
Browse latest Browse all 51160

Latest Images

Trending Articles



Latest Images