Thanks so much for the code. I got it to do exactly what I needed and this is going to help my workflow tremendously. We do a lot of keyboard midi recording and then do lots of splitting / punching in / editing and every damn time I would have to go back and add a pedal off because the previous notes would just keep sustaining.
Another side effect was tiny orphan notes where the split happened and I found the action to throw those "trailing" notes out. Here is what I got. Thanks so much !! Huge win for me. I hope it helps others and wish it was already built into Reaper as this seems a desirable midi behavior at least for me.
Would you be able to show me how to extend these two to work for multiple selected items (at same mouse/edit cursor position) on separate tracks possibly ? Basically for all midi items under the edit cursor.
This show splitting with no snap first and then with snap. Both cases show how the pedal off is now present.
Code:
-- Script: jb_split pedal off (no snapping).lua
-- split midi item and add pedal offs at split with no snapping
-- credits to mpl for his "mpl_Add CC64 off to channel 0 of active MIDI Editor take"
function main()
saveCursorPos = reaper.NamedCommandLookup("_BR_SAVE_CURSOR_POS_SLOT_1") -- save edit cursor position
reaper.Main_OnCommand(saveCursorPos, 0)
reaper.Main_OnCommand(40514, 0) -- move edit cursor to mouse position
reaper.Main_OnCommand(40746, 0) -- Item: Split item under mouse cursor
reaper.Main_OnCommand(40104, 0) -- View: Move cursor left one pixel
selitem = reaper.NamedCommandLookup("_XENAKIOS_SELITEMSUNDEDCURSELTX") -- select items under mouse
reaper.Main_OnCommand(selitem, 0)
reaper.Main_OnCommand(41729, 0) -- delete trailing notes
reaper.Main_OnCommand(40153, 0) -- Item: Open in built-in MIDI editor (set default behavior in preferences)
actmidieditor = reaper.MIDIEditor_GetActive()
idofpedaloff = reaper.NamedCommandLookup("_RS7d3c_d030d666f7decf53fd1dee3680ec2d970b916137") -- MIDI Editor: mpl_Add CC64 off to channel 0 of active MIDI Editor take.lua
reaper.MIDIEditor_OnCommand(actmidieditor, idofpedaloff)
reaper.MIDIEditor_OnCommand(actmidieditor, 2) -- File: Close window
restoreCursorPos = reaper.NamedCommandLookup("_BR_RESTORE_CURSOR_POS_SLOT_1") -- recall edit cursor position
reaper.Main_OnCommand(restoreCursorPos, 0)
reaper.UpdateArrange()
end
script_title = "Script: BenjyO_Split MIDI item at edit cursor and add CC64 Off-message a few pixels before.lua"
reaper.Undo_BeginBlock()
main()
reaper.Undo_EndBlock(script_title, 0)
Code:
-- Script: jb_split pedal off (snapping).lua
-- split midi item and add pedal offs at split with snapping
-- credits to mpl for his "mpl_Add CC64 off to channel 0 of active MIDI Editor take"
function main()
reaper.Main_OnCommand(40757, 0) -- Item: Split items at edit cursor (no change selection)
reaper.Main_OnCommand(40104, 0) -- View: Move cursor left one pixel
selitem = reaper.NamedCommandLookup("_XENAKIOS_SELITEMSUNDEDCURSELTX") -- select items under mouse
reaper.Main_OnCommand(selitem, 0)
reaper.Main_OnCommand(41729, 0) -- delete trailing notes
reaper.Main_OnCommand(40153, 0) -- Item: Open in built-in MIDI editor (set default behavior in preferences)
actmidieditor = reaper.MIDIEditor_GetActive()
idofpedaloff = reaper.NamedCommandLookup("_RS7d3c_d030d666f7decf53fd1dee3680ec2d970b916137") -- MIDI Editor: mpl_Add CC64 off to channel 0 of active MIDI Editor take.lua
reaper.MIDIEditor_OnCommand(actmidieditor, idofpedaloff)
reaper.MIDIEditor_OnCommand(actmidieditor, 2) -- File: Close window
reaper.UpdateArrange()
end
script_title = "Script: BenjyO_Split MIDI item at edit cursor and add CC64 Off-message a few pixels before.lua"
reaper.Undo_BeginBlock()
main()
reaper.Undo_EndBlock(script_title, 0)