Old 06-14-2010, 10:42 AM   #1
AdamWathan
Human being with feelings
 
AdamWathan's Avatar
 
Join Date: Apr 2008
Location: Cambridge, Ontario
Posts: 2,644
Default First script! (Crossfade splits in selected items)

So I built this today, first real script I've ever created so go easy on me It is not bullet proof and will give some unexpected results if you try and use it in the wrong situation, but as long as you use some common sense and only invoke it when you are trying to get it to do what it is supposed to do it works pretty flawlessy!

Change "fadeLength = 0.008" to whatever value you want your default crossfades to be. 8ms seems to work pretty well for me for just smoothing out splits after doing some vocal time stretching edits for example.

Here's the Python script:
Code:
fadeLength = 0.008;

itemCount = RPR_CountSelectedMediaItems(0);

if itemCount > 1:

	itemID = RPR_GetSelectedMediaItem(0, 0);

	takeCount = RPR_CountTakes(itemID);
	
	takeIndex = 0;

	while takeIndex < takeCount:
		currentTake = RPR_GetMediaItemTake(itemID, takeIndex);
		itemLength = RPR_GetMediaItemInfo_Value(itemID,"D_LENGTH");
		newLength = itemLength + (0.5 * fadeLength);
		RPR_SetMediaItemInfo_Value(itemID, "D_LENGTH", newLength);	
		RPR_SetMediaItemInfo_Value(itemID, "D_FADEOUTLEN", fadeLength);	
		takeIndex = takeIndex + 1;

	if itemCount > 2:

		itemIndex = 1;

		while itemIndex < (itemCount-1):

			itemID = RPR_GetSelectedMediaItem(0, itemIndex);

			takeCount = RPR_CountTakes(itemID);
	
			takeIndex = 0;

			while takeIndex < takeCount:
				currentTake = RPR_GetMediaItemTake(itemID, takeIndex);
				itemLength = RPR_GetMediaItemInfo_Value(itemID,"D_LENGTH");
				itemPosition = RPR_GetMediaItemInfo_Value(itemID,"D_POSITION");
				startOffset = RPR_GetMediaItemTakeInfo_Value(currentTake, "D_STARTOFFS");
				newLength = itemLength + fadeLength;
				newPosition = itemPosition - (0.5 * fadeLength);
				newOffset = startOffset - (0.5 * fadeLength);
				RPR_SetMediaItemInfo_Value(itemID, "D_LENGTH", newLength);
				RPR_SetMediaItemInfo_Value(itemID, "D_POSITION", newPosition);
				RPR_SetMediaItemInfo_Value(itemID, "D_FADEINLEN", fadeLength);	
				RPR_SetMediaItemInfo_Value(itemID, "D_FADEOUTLEN", fadeLength);	
				RPR_SetMediaItemTakeInfo_Value(currentTake, "D_STARTOFFS", newOffset);
				takeIndex = takeIndex + 1;

			itemIndex = itemIndex + 1;

	itemID = RPR_GetSelectedMediaItem(0, (itemCount - 1));

	takeCount = RPR_CountTakes(itemID);
	
	takeIndex = 0;

	while takeIndex < takeCount:
		currentTake = RPR_GetMediaItemTake(itemID, takeIndex);
		itemLength = RPR_GetMediaItemInfo_Value(itemID,"D_LENGTH");
		itemPosition = RPR_GetMediaItemInfo_Value(itemID,"D_POSITION");
		startOffset = RPR_GetMediaItemTakeInfo_Value(currentTake, "D_STARTOFFS");
		newLength = itemLength + (0.5 * fadeLength);
		newPosition = itemPosition - (0.5 * fadeLength);
		newOffset = startOffset - (0.5 * fadeLength);
		RPR_SetMediaItemInfo_Value(itemID, "D_POSITION", newPosition);			
		RPR_SetMediaItemInfo_Value(itemID, "D_LENGTH", newLength);
		RPR_SetMediaItemInfo_Value(itemID, "D_FADEINLEN", fadeLength);	
		RPR_SetMediaItemTakeInfo_Value(currentTake, "D_STARTOFFS", newOffset);
		takeIndex = takeIndex + 1;

	RPR_UpdateItemInProject(itemID);
So to reiterate, this script is meant to take a bunch of splits in an item and put a crossfade at each split. It won't work if the items are already overlapping or if there is a gap between the items, so don't try and use it there because it's not meant to do anything in a situation like that. You wouldn't throw your car in reverse while going forward at 100mph on the freeway right? Same deal here

This is superior to any macros I could come up with because it doesn't alter anything on the left and right sides of the selection, so if the first item and last item have a fade in/out already, they aren't altered at all, it only affects things on the inside of the selection.

Before running script:


After running script (notice the first fade in and pre-existing crossfade at the end of the selection survive unscathed):

Last edited by AdamWathan; 06-14-2010 at 11:22 AM.
AdamWathan is offline   Reply With Quote
Old 06-14-2010, 10:57 AM   #2
EricM
Human being with feelings
 
EricM's Avatar
 
Join Date: Jul 2009
Location: Ljubljana, Slovenia
Posts: 3,801
Default

Awesome job!
EricM is offline   Reply With Quote
Old 12-15-2010, 01:11 PM   #3
proto
Human being with feelings
 
Join Date: Feb 2009
Location: nyc usa
Posts: 121
Default

how can i get this working in reaper?
proto is offline   Reply With Quote
Old 12-15-2010, 01:18 PM   #4
EvilDragon
Human being with feelings
 
EvilDragon's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 24,798
Default

You need to have Python installed.

http://www.activestate.com/activepython-3

After installing, open the Actions list in Reaper, you'll see header "ReaScript", press New/Load, browse to the .py file to add it to Actions list. Now you can use it like any other action.
EvilDragon is offline   Reply With Quote
Old 12-15-2010, 04:01 PM   #5
AdamWathan
Human being with feelings
 
AdamWathan's Avatar
 
Join Date: Apr 2008
Location: Cambridge, Ontario
Posts: 2,644
Default

Just download the SWS extensions, there are newer way better actions that do this in there!
AdamWathan is offline   Reply With Quote
Old 12-16-2010, 11:51 AM   #6
proto
Human being with feelings
 
Join Date: Feb 2009
Location: nyc usa
Posts: 121
Default

this is sweet. thanks guys.
proto 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 12:29 AM.


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