Rfefat pl

From CockosWiki

Jump to: navigation, search

RemoveFileExtFromTakeNames.pl

#
# Item Properties - Remove file extension from active take names.pl
#
 
# Switch on/off messages
my $Verbose = 1;
 
my $Item_Count;
my $Item_ID;
my $Item_Index;
 
my $Current_Take;
my $Take_ID;
my $Take_Name;
 
my $Found = 0;
 
# Get number of media items in current project
$Item_Count = RPR_CountMediaItems(0);
if ($Verbose) {
	RPR_ShowConsoleMsg("Begin scan: ");
	if (! Item_Count) {
		RPR_ShowConsoleMsg("No items in project\n");
		exit;
	} elsif ($Item_Count == 1) {
		RPR_ShowConsoleMsg("1 item in project\n");
	} else {
		RPR_ShowConsoleMsg("$Item_Count items in project\n");
	}
}
 
# Scan each item in project
$Item_Index = 0;
while ($Item_Index < $Item_Count) {
	$Item_ID = RPR_GetMediaItem(0, $Item_Index);
	# Get active take index for current item
	$Current_Take = RPR_GetMediaItemInfo_Value($Item_ID, "I_CURTAKE");
	# Get active take name
	$Take_ID = RPR_GetMediaItemTake($Item_ID, $Current_Take);
	(undef, undef, undef, $Take_Name, undef) = RPR_GetSetMediaItemTakeInfo_String($Take_ID, "P_NAME", undef, 0);
	# Check take name for a recognised file extension
	if ($Take_Name =~ m/(?i)(\.ai(f|ff)|\.bwf|\.flac|\.kar|\.mid|\.mp(2|3)|\.ogg|\.wav|\.w64)$/) {
		$Found++;
		# Rename active take
		RPR_GetSetMediaItemTakeInfo_String($Take_ID, "P_NAME", $`, 1);
		# Show update
		if ($Verbose) {
			RPR_ShowConsoleMsg("Item " . ($Item_Index + 1) . " of $Item_Count: \"$`\" (Removed \"$1\")\n");
		}
	}
	$Item_Index++;
}
 
# Completion message
if ($Verbose) {
	RPR_ShowConsoleMsg("Scan finished: ");
	if (! $Found) {
		RPR_ShowConsoleMsg("No items renamed\n");
	} elsif ($Found == 1) {
		RPR_ShowConsoleMsg("1 item renamed\n");
	} else {
		RPR_ShowConsoleMsg("$Found items renamed\n");
	}
}
Personal tools