Old 04-13-2024, 09:53 AM   #1
Yulian_M
Human being with feelings
 
Yulian_M's Avatar
 
Join Date: Oct 2023
Location: Ukraine
Posts: 30
Default Fill gaps between selected items by moving right edges?

Hello! 👋
Please tell me, is there a script to automatically fill the space between the selected items by simply moving the right edges (ends of the items) to the left edges (starting position) of next items, without changing the item starting positions?

In particular, this script is needed for working with empty and midi items 📄, but it may also be useful for audio clips.
This does not mean stretching, but rather moving the right edge of the element ➡️.

Unfortunately, I was unable to find a script that could fulfill all the above conditions 🤷‍♂️.

I am very grateful to all the scripts authors for your great work, you are doing incredible things!!! 🙌👏👑

There are two great scripts similar to what I'm looking for.
But apparently these are not quite suitable for my task, although they have a relevant name:

1. Lokasenna: Smart fill gaps by stretching item tails
This doesn't work for Empty Items because it evaluates volume. This works for audio items, but is based on audio data rather than the actual position of the item's edge..

2. SWS/AW: Fill gaps between selected items (advanced).
This script worked well for me, except that I could not configure the saving of the starting position, and filling happened more often by moving the left edges of selected items...

Tell me, please, is there perhaps a way to configure the above-mentioned scripts so that they perform the task I described?
Or maybe there are other scripts for this?❓
Thank you for your attention and for any help!😇

Last edited by Yulian_M; 04-13-2024 at 10:03 AM.
Yulian_M is online now   Reply With Quote
Old 04-13-2024, 11:44 AM   #2
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 7,431
Default

This maybe does what you want
Code:
-- MF_FillGap

local function handleItems(track)
  local numitems = reaper.CountTrackMediaItems(track)
  for item = 1, numitems-1 do
    local litem = reaper.GetTrackMediaItem(track, item - 1) -- left item
    local ritem = reaper.GetTrackMediaItem(track, item) -- right item
    local rpos = reaper.GetMediaItemInfo_Value(ritem, "D_POSITION")
    local lpos = reaper.GetMediaItemInfo_Value(litem, "D_POSITION")
    local llen = reaper.GetMediaItemInfo_Value(litem, "D_LENGTH")
    local gap = rpos - lpos - llen
    reaper.SetMediaItemInfo_Value(litem, "D_LENGTH", llen + gap)
  end
    
end

local function handleTracks()
  local numsel = reaper.CountSelectedTracks(0)
  for i = 1, numsel do
    local track = reaper.GetSelectedTrack(0, i - 1)
    handleItems(track)
  end
end

reaper.PreventUIRefresh(1)
handleTracks()
reaper.PreventUIRefresh(-1)
reaper.UpdateArrange()
It goes through all selected tracks, and stretches left items to the border of the next right item. And it seems to work for audio as well as MIDI and empty items.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 04-13-2024, 11:59 AM   #3
Yulian_M
Human being with feelings
 
Yulian_M's Avatar
 
Join Date: Oct 2023
Location: Ukraine
Posts: 30
Default

Quote:
Originally Posted by Fabian View Post
This maybe does what you want

It goes through all selected tracks, and stretches left items to the border of the next right item. And it seems to work for audio as well as MIDI and empty items.
Wow, thank you very much, Fabian, this really works great!!! 🤩⚡️
This is a great script! ✅
The only thing I would also like is to be able to fill empty space not only for the whole track, but also for individual selected items on the track.

When I was watching my thread in this section, I saw another interesting thread: 'Anyone tested any of the 4 ReaScript GPTs yet? (ChatGPT)'.
https://forum.cockos.com/showthread.php?t=287575
I tried to follow the links, but unfortunately all the listed chats require paid GPT v4, which I cannot afford at the moment .
But I decided to try to describe the problem to the free chat GPT v3.5 🤖.
And it seems he was really able to help me)) 🦾
I asked him to adapt for my purposes another script from the user 'Amagalma', called:
'Fill space between selected items with empty items'.
I immediately received an error when I saved the script in Reaper Lua Editor, then described it to the chat ⌨️. He sent me the corrected code and it worked!))
I tested it on both Empty Items and Audio Items - everything is fine
Thanks to the user 'Amagalma', without his open script I couldn't have done anything!)

But if I had waited a little longer, I would have taken your script as a basis, it’s cool script! 📝
Thanks for this, Fabian, it's very helpful too!🎉

Here's what GPT write 👾:

Code:
-- @description Fill space between selected items bt moving right edges
-- @author amagalma
-- @version 1.00
-- @link https://forum.cockos.com/showthread.php?t=248298
-- @donation https://www.paypal.me/amagalma
-- @about
--   #Fills the space between the selected items with empty items
--
--   Inside the script you can set if:
--   - the newly inserted items will be the only selected items
--   - the newly inserted items will have an empty take or be really empty items


-- USER SETTINGS ---------------------------------------------

-- to select only the newly inserted items set to true:
local select_new_items = false -- true/false

-- if true then newly inserted items have an empty take
local new_items_have_empty_take = false -- true/false

--------------------------------------------------------------


local item_cnt = reaper.CountSelectedMediaItems( 0 )
if item_cnt < 2 then return end

for i = 0, item_cnt - 2 do
  local item = reaper.GetSelectedMediaItem( 0, i )
  local next_item = reaper.GetSelectedMediaItem( 0, i+1 )
  local item_pos = reaper.GetMediaItemInfo_Value( item, "D_POSITION" )
  local item_len = reaper.GetMediaItemInfo_Value( item, "D_LENGTH" )
  local next_item_pos = reaper.GetMediaItemInfo_Value( next_item, "D_POSITION" )
  reaper.SetMediaItemInfo_Value( item, "D_LENGTH", next_item_pos - item_pos )
end

if select_new_items then
  for i = 0, item_cnt - 1 do
    reaper.SetMediaItemSelected( reaper.GetSelectedMediaItem( 0, i ), false )
  end
  for i = 0, item_cnt - 2 do
    reaper.SetMediaItemSelected( reaper.GetSelectedMediaItem( 0, i ), true )
    if new_items_have_empty_take then
      reaper.AddTakeToMediaItem( reaper.GetSelectedMediaItem( 0, i ) )
    end
  end
end

reaper.UpdateArrange()
reaper.Undo_OnStateChange( "Moved selected items to fill space" )

Last edited by Yulian_M; 04-13-2024 at 12:06 PM.
Yulian_M is online now   Reply With Quote
Old 04-13-2024, 05:59 PM   #4
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default




These actions have already been shared as propper / tested script package shared via reapack.


And it was even request last week....


Grow item edges to next item boundary (fill gap)


🙄
X-Raym is offline   Reply With Quote
Old 04-13-2024, 09:06 PM   #5
Yulian_M
Human being with feelings
 
Yulian_M's Avatar
 
Join Date: Oct 2023
Location: Ukraine
Posts: 30
Default

Quote:
Originally Posted by X-Raym View Post
Thank you very much for the links and for your reply, and for your beautiful scripts! 💎
Oh, I apologize for being a duplicate... I've been looking for a script like this for almost the whole evening before I wrote a thread on the forum... 😬
It's strange that I couldn't detect this, given that the last similar query was published just recently... 🙈
I will try to search better from now on and litter less on the forum! ✋
"It's all about synonyms", as you said earlier) 🔎✏

Last edited by Yulian_M; 04-13-2024 at 09:11 PM.
Yulian_M is online now   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 03:47 PM.


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