poulhoi

phoi_Select items shorter than x ms.lua

Mar 11th, 2021 (edited)
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. reaper.PreventUIRefresh(1)
  2. reaper.Undo_BeginBlock()
  3.  
  4. local retval, threshold_ms = reaper.GetUserInputs("Select items shorter than x ms", 1, "Selection threshold (ms)", 50)
  5. if not retval then return end
  6. local threshold = threshold_ms * 0.001
  7.  
  8.  
  9. --unselect items first
  10. while reaper.CountSelectedMediaItems(0) > 0 do
  11.     local it = reaper.GetSelectedMediaItem(0, 0)
  12.     reaper.SetMediaItemSelected(it, false)
  13. end
  14.  
  15. for i = 0, reaper.CountMediaItems(0) - 1 do
  16.     local it = reaper.GetMediaItem(0, i)
  17.     local len = reaper.GetMediaItemInfo_Value(it, "D_LENGTH")
  18.     if len < threshold then
  19.         reaper.SetMediaItemSelected(it, true)
  20.     end
  21. end
  22. reaper.Undo_EndBlock("Select items shorter than " .. threshold_ms .. " ms", -1)
  23. reaper.PreventUIRefresh(-1)
  24. reaper.UpdateArrange()
Add Comment
Please, Sign In to add comment