Old 05-22-2019, 10:34 PM   #1
Sonorityscape
Human being with feelings
 
Sonorityscape's Avatar
 
Join Date: Aug 2016
Posts: 34
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
Old 05-23-2019, 03:53 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,822
Default

I already made script for advanced reposotionning :P


https://www.extremraym.com/en/downlo...ce-items-pack/


The Set items pos and order script handle a lot of scenarios like different ways to loop through items (per order selection, time pos or per track) etc... Avoif yourself trouble with complex corner cases and take a look :P
X-Raym is offline   Reply With Quote
Old 05-23-2019, 09:58 AM   #3
Sonorityscape
Human being with feelings
 
Sonorityscape's Avatar
 
Join Date: Aug 2016
Posts: 34
Default

Quote:
Originally Posted by X-Raym View Post
I already made script for advanced reposotionning :P


https://www.extremraym.com/en/downlo...ce-items-pack/


The Set items pos and order script handle a lot of scenarios like different ways to loop through items (per order selection, time pos or per track) etc... Avoif yourself trouble with complex corner cases and take a look :P
Thanks. I'm also doing this to develop my scripting abilities. I'm going to take another crack at it and change some things.
Sonorityscape is offline   Reply With Quote
Old 05-23-2019, 10:21 AM   #4
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,822
Default

What you need is to first store items in a table and then used these stored items for your moving loop. Else, it will break cause order of selected items changes a each iteration.

Here is a template I made:
https://github.com/ReaTeam/ReaScript...%20editing.lua

I planned to made a video reascript on this exact subject but I didnt made it so far.

My scripts are open source so you can analyse their code (even premium ones).
X-Raym is offline   Reply With Quote
Old 05-23-2019, 10:26 AM   #5
Sonorityscape
Human being with feelings
 
Sonorityscape's Avatar
 
Join Date: Aug 2016
Posts: 34
Default

Quote:
Originally Posted by X-Raym View Post
What you need is to first store items in a table and then used these stored items for your moving loop. Else, it will break cause order of selected items changes a each iteration.

Here is a template I made:
https://github.com/ReaTeam/ReaScript...%20editing.lua

I planned to made a video reascript on this exact subject but I didnt made it so far.

My scripts are open source so you can analyse their code (even premium ones).
Haha, I just started a new script 5 minutes ago with a table to better store the items. Like you said, when the items change position, it was messing everything up. Thank you for the link!
Sonorityscape is offline   Reply With Quote
Old 05-23-2019, 11:21 AM   #6
Sonorityscape
Human being with feelings
 
Sonorityscape's Avatar
 
Join Date: Aug 2016
Posts: 34
Default

Wow, it works so much easier with the table.
Sonorityscape is offline   Reply With Quote
Old 05-23-2019, 11:26 AM   #7
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,822
Default

table unocks a lot of things. You can store properties, shuffle them, sort them, etc...
X-Raym is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.