Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 05-17-2019, 08:27 AM   #41
kesson
Human being with feelings
 
Join Date: May 2019
Posts: 13
Default

Yes indeed, this one of the most useful scripts out there and use it on a regular basis ( donation is on the way ).

I do have a suggestion to make though, at least wondering if this is something that might be possible. I am sound designer doing a lot of editing on a lot of items. I often have to remove small unwanted noises, clicks, pops etc.. So what I do is cut that part of the item I'm working on and just blend the two remaining cuts together with a nice little crossfade. SO if my english is not to bad and you guys followed me, I end up with a lot of edited items composed of various cuts. Right now for each item, I have to select all the cuts and glue them to obtain my final item ( time consuming when I have more than a hundred cleand items ). and here is the thing I would LOVE to have: A special batch glue process that would let me select all my edited items and be able to glue together all the cuts for each individual items with single action ( so like a "glue separate items" on steroid, maybe based on crossfades? )

Picture 1: Items after editing and cleaning
Picture 2: The result of the single batch process I'm aiming for

Anyway just a suggestion, thanks for all the hard work!
kesson is offline   Reply With Quote
Old 05-17-2019, 09:37 AM   #42
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

Quote:
Originally Posted by kesson View Post
Yes indeed, this one of the most useful scripts out there and use it on a regular basis ( donation is on the way ).

I do have a suggestion to make though, at least wondering if this is something that might be possible. I am sound designer doing a lot of editing on a lot of items. I often have to remove small unwanted noises, clicks, pops etc.. So what I do is cut that part of the item I'm working on and just blend the two remaining cuts together with a nice little crossfade. SO if my english is not to bad and you guys followed me, I end up with a lot of edited items composed of various cuts. Right now for each item, I have to select all the cuts and glue them to obtain my final item ( time consuming when I have more than a hundred cleand items ). and here is the thing I would LOVE to have: A special batch glue process that would let me select all my edited items and be able to glue together all the cuts for each individual items with single action ( so like a "glue separate items" on steroid, maybe based on crossfades? )

Picture 1: Items after editing and cleaning
Picture 2: The result of the single batch process I'm aiming for

Anyway just a suggestion, thanks for all the hard work!
Something like this? (make sure to read first few lines on how to pick the appropriate glue action)

Code:
-- Globals -------------------------------------------------------------------------------------------------------------

-- set glueActionId by right clicking the wanted glue action in action list, selecting "Copy selected action command ID" 
-- and then pasting that value here between the quotes
local glueActionId          = "_9e42df137af5f746a1224fc4d0505efb" -- Script: Item - Glue items, ignoring time selection (preserve stuff).lua
local skipOnlyAdjacentItems = true                                -- Set this to true if you want to glue only items that are truly overlapped                                                         
                                                                  -- and not just next to each other




-- Misc functions ------------------------------------------------------------------------------------------------------
local function AreOverlapped (start1, end1, start2, end2)
	if start1 > end1 then start1, end1 = end1, start1 end
	if start2 > end2 then start2, end2 = end2, start2 end
	return (start1 <= end2 and start2 <= end1)
end

local function AreOverlappedEx (start1, end1, start2, end2)
	if start1 > end1 then start1, end1 = end1, start1 end
	if start2 > end2 then start2, end2 = end2, start2 end
	return (start1 < end2 and start2 < end1)
end

local function SaveSelectedItemsToTable (table)
	for i = 0, reaper.CountSelectedMediaItems(0)-1 do
		table[i+1] = reaper.GetSelectedMediaItem(0, i)
	end
end

local function RestoreSelectedItemsFromTable (table)
	for _, item in ipairs(table) do
		if reaper.ValidatePtr(item, "MediaItem*") then
			reaper.SetMediaItemInfo_Value(item, "B_UISEL", 1)
		end
	end
end

local function UnselectAllItems ()
	while (reaper.CountSelectedMediaItems(0) > 0) do
		reaper.SetMediaItemSelected(reaper.GetSelectedMediaItem(0, 0), false)
	end
end

local function SetItemSelected (item, unselectOthers)
	if unselectOthers then UnselectAllItems() end
	if reaper.ValidatePtr(item, "MediaItem*") then
		reaper.SetMediaItemSelected(item, true)
	end
end

-- Main ----------------------------------------------------------------------------------------------------------------
function Main ()
	local savedItems = {}
	SaveSelectedItemsToTable(savedItems)

	local doUndo = false
	local itemSelectionToRestore = {}
	local CompareFunction = AreOverlapped
	if skipOnlyAdjacentItems == true then
		CompareFunction =  AreOverlappedEx
	end
	reaper.PreventUIRefresh(1)

	for _, item in ipairs(savedItems) do
		if reaper.ValidatePtr(item, "MediaItem*") then
			local newlySelectedItems = {}
			SetItemSelected(item, true)
			newlySelectedItems[#newlySelectedItems + 1] = item	

			local itemStart = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
			local itemEnd   = reaper.GetMediaItemInfo_Value(item, "D_LENGTH") + itemStart
			local itemTrack = reaper.GetMediaItem_Track(item)

			local doGlue = false
			for i = 0, reaper.CountTrackMediaItems(itemTrack)-1 do

				local currentItem = reaper.GetTrackMediaItem(itemTrack, i)			
				if currentItem ~= item then				
					local currentItemStart = reaper.GetMediaItemInfo_Value(currentItem, "D_POSITION")
					local currentItemEnd   = reaper.GetMediaItemInfo_Value(currentItem, "D_LENGTH") + currentItemStart

					for _, selectedItem in ipairs(newlySelectedItems) do

						local selectedItemStart = reaper.GetMediaItemInfo_Value(selectedItem, "D_POSITION")
						local selectedItemEnd   = reaper.GetMediaItemInfo_Value(selectedItem, "D_LENGTH") + selectedItemStart

						if CompareFunction(currentItemStart, currentItemEnd, selectedItemStart, selectedItemEnd) then
							reaper.SetMediaItemInfo_Value(currentItem, "B_UISEL", 1)
							newlySelectedItems[#newlySelectedItems + 1] = currentItem
							doGlue = true
							break
						end
					end
				end
			end

			if doGlue then
				if doUndo == false then
					doUndo = true 
					reaper.Undo_BeginBlock()
				end
				reaper.Main_OnCommand(reaper.NamedCommandLookup(glueActionId), 0)
				local newItem = reaper.GetSelectedMediaItem(0, 0)
				if newItem ~= nil then
					itemSelectionToRestore[#itemSelectionToRestore + 1] = newItem
				end
			end
		end
	end

	if doUndo == true then
		RestoreSelectedItemsFromTable(itemSelectionToRestore)
		reaper.Undo_EndBlock("Glue selected overlapped items separately", -1)
	else
		RestoreSelectedItemsFromTable(savedItems)
	end
	reaper.PreventUIRefresh(-1)
	reaper.UpdateArrange()
end

Main()
function NoUndoPoint () end -- Makes sure there is no unnecessary undo point created, see more
reaper.defer(NoUndoPoint)   -- here: http://forum.cockos.com/showpost.php?p=1523953&postcount=67
Attached Files
File Type: lua Glue selected overlapped items separately.lua (4.6 KB, 244 views)

Last edited by Breeder; 05-17-2019 at 09:57 AM.
Breeder is offline   Reply With Quote
Old 05-18-2019, 03:54 AM   #43
kesson
Human being with feelings
 
Join Date: May 2019
Posts: 13
Default Thanks big times !

That's awesome, works like a charm thanks so much !
kesson is offline   Reply With Quote
Old 05-22-2019, 11:34 PM   #44
Infrabass
Human being with feelings
 
Join Date: Apr 2014
Posts: 398
Default

Thanks so much breeder!
It's a reascript I had in head for a long time.
Hope you received my virtual beer!
Cheers
Infrabass is offline   Reply With Quote
Old 01-09-2020, 07:00 PM   #45
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

Just to let you know that I noticed that REAPER preserves muted MIDI events by itself now so I omitted that part of the code from the script - this is important because due to both REAPER and the script doing the same thing result is duplicate muted MIDI events xD
Breeder is offline   Reply With Quote
Old 01-16-2020, 05:04 PM   #46
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,583
Default

Thanks man
__________________
Puzzle Factory Sound Studios, London [Website] [Instagram]
[AMD 5800X, 32Gb RAM, Win10x64, NVidia GTX1080ti, UAD2-OCTO, FireFaceUCX, REAPER x64]
[Feature request: More details in Undo History]
daxliniere is offline   Reply With Quote
Old 01-31-2020, 09:32 PM   #47
Joe90
Human being with feelings
 
Join Date: Aug 2019
Posts: 855
Default 'Intelligent' Glue?

Hi Breeder,

Thanks so much for these scripts, glue 'preserve stuff' is my main glue script and it gets used countless times a session.

I have a question, perhaps this is possible already with the glue scripts you've created, but I haven't figured it out.

I'm trying to find a glue option that will glue adjacent items together, but if they are not adjacent or very close to each other (perhaps a distance we can define within the script) then they glue into separate items.

So when you glue this -
https://forum.cockos.com/attachment....1&d=1580529693

You get this -
https://forum.cockos.com/attachment....1&d=1580529707

Ideally it would also do all the helpful 'preserve stuff' that your main glue action also does. If it's not currently possible then hopefully it's something you might consider looking at at some point.

I assume it wouldn't be a HUGE tweak, as it just needs to check how close the selected items are to each other, and glue ('preserving stuff' as you put it) the items that are within a certain distance of each other into their own separate items. I don't script though, so perhaps I'm wrong.

I know in the example I've posted I can just select one 'clump' of items, glue, then select the other, but this is no good for custom actions.

For example - I have a custom action for rendering selected items to a new track with all track and take FX applied, but preserving fader level, sends/child status and position, and track colour/name. Say I have three VSTi drum fills on a track that are spread throughout a song, and each fill is comprised of 2 or 3 midi items that are next to each other (maybe it's been split or edited for some reason) and I want to render them with this custom action, there are other fills on the track I don't want to render, just these three.

Gluing the midi items individually before rendering to audio doesn't work in this custom action, because it's rendering the audio items separately so the drum fills end up segmented and drum tails get cut off, I can glue the whole lot into one file, but then I end up with a massive wasteful piece of audio the size of the whole song for three tiny drums fills. It's messy and it makes it more difficult if I want to edit them all together, like fade out the last hit on each one for example.

A script for glueing clumps of items 'intelligently' would provide an elegant solution for this, and you seemed like the person to ask about it.

Of course, no worries if not, and thanks again for your great work.
Attached Images
File Type: png pre glue example.png (24.5 KB, 315 views)
File Type: png post glue.png (21.2 KB, 233 views)
Joe90 is offline   Reply With Quote
Old 04-20-2020, 03:12 PM   #48
SonicAxiom
Human being with feelings
 
SonicAxiom's Avatar
 
Join Date: Dec 2012
Location: Germany
Posts: 3,039
Default

would it be possible to add an option that allows to glue audio items preserving their original audio format (Wave, mp3, WavPack, etc.)? Currently, items will get glued to the global format preset in project preferences. The other glueing options should also work (if checked) when preserving the audio format (like glueing items separately).

.
__________________
Check out AVConvert (free, super-fast media file manipulation via the right-click context-menu in Windows Explorer) and my free VST plugins.
My Reaper tutorials and studio related videos on youtube.
SonicAxiom is offline   Reply With Quote
Old 07-30-2020, 03:23 PM   #49
seten
Human being with feelings
 
Join Date: Jun 2020
Posts: 6
Default Possible bug

First off thanks! Super useful. The GUI works fine but for some reason all of the individual actions give this error code:

GlueTools.lua:249: attempt to call a nil value (field 'BR_IsTakeMidi')

No big deal because I can just use the GUI but would be nice to get glue items separately (preserve stuff) on a single hotkey.

Also just out of curiosity - if I have a single take thats been chopped up a lot due to past takes, is there any way to get that to be a single glued file so theres not tiny fade ins/outs in the middle of the take?
seten is offline   Reply With Quote
Old 07-31-2020, 03:24 PM   #50
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,108
Default

Quote:
Originally Posted by seten View Post
The GUI works fine but for some reason all of the individual actions give this error code:

GlueTools.lua:249: attempt to call a nil value (field 'BR_IsTakeMidi')

No big deal because I can just use the GUI but would be nice to get glue items separately (preserve stuff) on a single hotkey.
This is a function provided by SWS extension.
If you haven't installed it already, get it here (official) or here (beta).
I'd suggest latest beta version as it contains support for some Reaper v6 features.
nofish is offline   Reply With Quote
Old 09-14-2020, 07:51 AM   #51
tomtjes
Human being with feelings
 
Join Date: Sep 2016
Posts: 10
Default Find adjacent items and glue or create region

Quote:
Originally Posted by Joe90 View Post
I'm trying to find a glue option that will glue adjacent items together, but if they are not adjacent or very close to each other (perhaps a distance we can define within the script) then they glue into separate items.
I needed this as well, because I want to render and automatically number media items. So I wrote this script:
tomtjes_Glue adjacent items on track.lua



However, while working on this I realized I'd prefer to use regions instead of glueing. So in the repository, you'll also find scripts that create regions over adjacent items:
tomtjes_Create regions from adjacent items on same track.lua
tomtjes_Create regions from adjacent items across tracks.lua
tomtjes is offline   Reply With Quote
Old 05-13-2021, 12:18 AM   #52
_iU
Human being with feelings
 
Join Date: Nov 2008
Posts: 25
Default

Quote:
Originally Posted by airon View Post
Thanks guys, this is awesome. I was going to write my own but this is miles better.

edit: aaand unfortunately it doesn't work on empty items. I might have to customize this a bit .
Anybody found a way to make it work with empty items?
_iU is offline   Reply With Quote
Old 05-13-2021, 08:53 AM   #53
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,108
Default

Quote:
Originally Posted by _iU View Post
Anybody found a way to make it work with empty items?
Hm..is it actually possible to glue empty items onto themselves I wonder?
Here when I try to glue an empty item (surprisingly for me) Reaper makes it a .wav.
But then again I'm not sure what should happen instead when doing this.
nofish is offline   Reply With Quote
Old 08-26-2022, 06:40 AM   #54
binbinhfr
Human being with feelings
 
binbinhfr's Avatar
 
Join Date: Oct 2021
Location: France
Posts: 363
Default

thanks for this very useful script.
I'm using it to "clean up / trim" my audio media item, deleting invisible parts. The only problem is that it applies media FX. Would it be possible to add an option called "apply FX".
It could disable the FX before gluing (if any), and re-enable them atferwards ?
__________________
Reaper's lunatic
Reapack repository / GitHub / SoundCloud / Donate
binbinhfr is offline   Reply With Quote
Old 02-02-2024, 11:00 PM   #55
barbaroja
Human being with feelings
 
barbaroja's Avatar
 
Join Date: Jul 2009
Posts: 429
Default

I was having problems with High DPI 4K screen, set to 200% on windows. Changing font size to 25 solved it but I'd love to have a solution that is actually DPI aware.
barbaroja 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 10:02 AM.


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