View Single Post
Old 05-22-2019, 10:34 PM   #1
Sonorityscape
Human being with feelings
 
Sonorityscape's Avatar
 
Join Date: Aug 2016
Posts: 42
Default Reposition Selected Items on All Tracks

I've gotten this script to work for the most part, however I've been having problems getting the positioning of items in relation to others. Essentially I am using a while loop to run through the meat of the actions until the items are positioned correctly. The one problem with this is that (as you can see from the third track) the order changes in certain circumstances. If anyone has a better way to make this work, I'm all ears!



Code:
retval, retvals_csv = reaper.GetUserInputs("Reposition Items on All Tracks", 1, "Distance in Seconds", "1" )
distance = string.match(retvals_csv, "([^,]+)")

while tonumber(distance) < 0 do
  
  reaper.ShowConsoleMsg("Choose a value of 0 or greater. \n")
  retval, retvals_csv = reaper.GetUserInputs("Reposition Items on All Tracks", 1, "Distance in Seconds", "1" )
  distance = string.match(retvals_csv, "([^,]+)")

end

distance = string.match(retvals_csv, "([^,]+)")


function set_item_pos(i)

item_prev = reaper.GetSelectedMediaItem(0, i)
item_prev_start = reaper.GetMediaItemInfo_Value(item_prev, "D_POSITION")
item_prev_end = (reaper.GetMediaItemInfo_Value(item_prev, "D_LENGTH")) + (item_prev_start)
    
item_next = reaper.GetSelectedMediaItem(0, i + 1)
item_next_start = reaper.GetMediaItemInfo_Value(item_next, "D_POSITION")
    
reaper.SetMediaItemInfo_Value(item_next, "D_POSITION", item_prev_end + distance)

end

sel_media_items = reaper.CountSelectedMediaItems(0)

for i = 0, sel_media_items - 1 do
  
  if i + 1 > sel_media_items - 1 then
  
    break
    
  else
    
    set_item_pos(i)
    
    while item_next_start < item_prev_end  do
    
      set_item_pos(i)
    
    end
      
  end 
  
end

Last edited by Sonorityscape; 05-22-2019 at 10:43 PM.
Sonorityscape is offline   Reply With Quote