Old 01-21-2021, 08:42 PM   #1
Cloudswim
Human being with feelings
 
Join Date: May 2017
Posts: 371
Default Fill space between items with empty items?

Hi was wondering if this is possible?
Cloudswim is offline   Reply With Quote
Old 01-21-2021, 10:55 PM   #2
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 565
Default

Totally. Get the right edge position of the left item, save it as pos1. Get the left edge of the right item, save it as pos2. Add an empty item between pos1 and pos2, then repeat.
dsyrock is offline   Reply With Quote
Old 01-21-2021, 10:56 PM   #3
poulhoi
Human being with feelings
 
Join Date: Apr 2020
Posts: 214
Default

You could probably make a custom action work. Something like “Insert empty item between current item and the next”.
Or do you need to do this for a lot of item at once?
poulhoi is offline   Reply With Quote
Old 01-22-2021, 02:08 AM   #4
Cloudswim
Human being with feelings
 
Join Date: May 2017
Posts: 371
Default

Quote:
Originally Posted by poulhoi View Post
You could probably make a custom action work. Something like “Insert empty item between current item and the next”.
Or do you need to do this for a lot of item at once?
many items....

I've actually got the inserting empty items part figured out.

It goes something like this

1. Duplicate track with items
2. Select items on the duplicated track and extend item right edge to the next item.
3. SPLIT items on the duplicated track against the original track as reference.

here you would have a new track with empty MIDI items in between the original items. But I'm unable to find a way to select only empty MIDI items. This is different compared to an empty audio take item, so the SWS Select only empty item action does not work in this scenario.

Any idea on how I'd go about selecting just media (MIDI) items with no notes?

EDIT: I tried using the SWS Save Item Selection State, and restore state at the end. But since the original Saved Item State was just extended in length it selects everything on the duplicated track that now has the sliced (SPLIT) empty MIDI items in between the original items.
Cloudswim is offline   Reply With Quote
Old 01-22-2021, 05:41 AM   #5
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,874
Default

The custom action way:

I have a script which split slected items according to items and keep only items at "spaces",
so just insert track, create a long empty items on it, use the script, then put the items a track below (in between the items used as reference).


@dsyrock
The script way woudl be more complex cause of possible overlapping items. :P
X-Raym is offline   Reply With Quote
Old 01-22-2021, 05:58 AM   #6
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Code:
-- should work with overlapping items too..

-- 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

local prev_item = reaper.GetSelectedMediaItem( 0, 0 )
local prev_track = reaper.GetMediaItemTrack( prev_item )

local cnt = 0
local added = 0
local new_items = {}

for i = 0, item_cnt - 1 do
  cnt = cnt + 1
  local item = reaper.GetSelectedMediaItem( 0, i )
  local track = reaper.GetMediaItemTrack( item )
  if track == prev_track then
    if cnt > 1 then
      local st = reaper.GetMediaItemInfo_Value( prev_item, "D_POSITION") + reaper.GetMediaItemInfo_Value( prev_item, "D_LENGTH")
      local cur_st = reaper.GetMediaItemInfo_Value( item, "D_POSITION")
      if cur_st > st then
        local len = cur_st - st
        local new_item = reaper.AddMediaItemToTrack( track )
        reaper.SetMediaItemInfo_Value( new_item, "D_POSITION", st )
        reaper.SetMediaItemInfo_Value( new_item, "D_LENGTH", len )
        added = added + 1
        new_items[added] = new_item
      end
    end
  else
    prev_track = track
    cnt = 1
  end
  prev_item = item
end

if added > 0 then
  if select_new_items then
    for i = item_cnt - 1, 0, -1  do
      reaper.SetMediaItemSelected( reaper.GetSelectedMediaItem( 0, i ), false )
    end
    for i = 1, added do
      reaper.SetMediaItemSelected( new_items[i], true )
      if new_items_have_empty_take then
        reaper.AddTakeToMediaItem( new_items[i] )
      end
    end
  end
  reaper.Undo_OnStateChange( "Added ".. added .." empty item" ..
                          (added == 1 and "" or "s") .. " between selected items" )
else
  reaper.defer(function() end)
end
Just wondering.. why would you want that? :P
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 01-22-2021 at 08:18 AM.
amagalma is offline   Reply With Quote
Old 01-22-2021, 06:07 AM   #7
andyp24
Human being with feelings
 
andyp24's Avatar
 
Join Date: Mar 2016
Posts: 1,239
Default

Just wondering if this can be used to insert roomtone between speech which has been cut up...?

I guess you could select all the empty items and then open the Properties and choose a new audio source for them?
andyp24 is offline   Reply With Quote
Old 01-22-2021, 06:13 AM   #8
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Yes, sure.. I can make the script leave only the newly inserted empty items selected for convenience.

Edit: done.. See code above
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 01-22-2021 at 06:22 AM.
amagalma is offline   Reply With Quote
Old 01-22-2021, 06:53 AM   #9
Cloudswim
Human being with feelings
 
Join Date: May 2017
Posts: 371
Default

Quote:
Originally Posted by X-Raym View Post
The custom action way:

I have a script which split slected items according to items and keep only items at "spaces",
so just insert track, create a long empty items on it, use the script, then put the items a track below (in between the items used as reference).


@dsyrock
The script way woudl be more complex cause of possible overlapping items. :P
I tried the one you are mention, but when there are many items it seems towards the end of the collection of items will not align properly. Instead of keeping the empty space it will take it away.

Edit : it seems to be working properly now ! My bad
Cloudswim is offline   Reply With Quote
Old 01-22-2021, 07:36 AM   #10
andyp24
Human being with feelings
 
andyp24's Avatar
 
Join Date: Mar 2016
Posts: 1,239
Default

Quote:
Originally Posted by amagalma View Post
Yes, sure.. I can make the script leave only the newly inserted empty items selected for convenience.

Edit: done.. See code above
Amazing, thanks. I'm stuck working in another DAW at the moment, but when I get back to Reaper I'll give this a try :-)
andyp24 is offline   Reply With Quote
Old 01-22-2021, 08:21 AM   #11
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

I have updated the code above to include two settings (set inside the script):
- set newly inserted items as only selected items (true/false)
- newly inserted items have one empty take (true/false)

Uploaded to ReaPack:
amagalma_Fill space between selected items with empty items
#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
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 01-22-2021 at 08:28 AM.
amagalma is offline   Reply With Quote
Old 01-23-2021, 08:40 AM   #12
Cloudswim
Human being with feelings
 
Join Date: May 2017
Posts: 371
Default

Quote:
Originally Posted by amagalma View Post
I have updated the code above to include two settings (set inside the script):
- set newly inserted items as only selected items (true/false)
- newly inserted items have one empty take (true/false)

Uploaded to ReaPack:
amagalma_Fill space between selected items with empty items
#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
Super ! Thanks!
Cloudswim is offline   Reply With Quote
Old 08-19-2021, 12:45 PM   #13
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 7,416
Default

Thanks for this amagalma, something I had a use for right now. And it works great.

I did one tweak to suit me better, though. I added a take to the new empty item. The reason for this is to get the colors to match the other items.

Between lines 47 and 48, I added
Code:
reaper.SetMediaItemInfo_Value( new_item, "D_LENGTH", len ) -- line 47
reaper.AddTakeToMediaItem(new_item) -- new line to add take
added = added + 1 -- old line 48, new line 49
Next tweak I'll do is for it to put empty items at the beginning and end to match up with the time selection, if any. But that's for later, now I just did that manually.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 08-19-2021, 04:49 PM   #14
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

You didn't have to change anything for this as it is already there

Line 19&20 of the script:
Code:
-- if true then newly inserted items have an empty take
local new_items_have_empty_take = false -- true/false
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 08-20-2021, 10:34 AM   #15
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 7,416
Default

Quote:
Originally Posted by amagalma View Post
You didn't have to change anything for this as it is already there

Line 19&20 of the script:
Code:
-- if true then newly inserted items have an empty take
local new_items_have_empty_take = false -- true/false
Well... I thought that setting that switch true would add a take, but it didn't. I didn't bother to check further, so I just made the edit and though that I had misunderstood what that switch was for.

Looking now in detail at the code, I see that also the switch on line 17 need to be set true for a new take to be added.

Maybe you should change so that those two switches are independent?
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian 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 11:28 PM.


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