RainbowColours pl

From CockosWiki

Jump to: navigation, search

Select an item in your project, take the seven colours of the rainbow...
Each time the script is called it will cycle to the next color. If the item isn't set to one of the defined colors it gets set it to the first color in the list. If the item is set to the last color, it loops back to the first.

CycleRainbowColors.pl

#
# Item Properties - Cycle rainbow colors.pl
# sfzgeek
#
 
# Define color preset values
$Color[0] = 0x0000FF|0x1000000; # Red
$Color[1] = 0x00A5FF|0x1000000; # Orange
$Color[2] = 0x00FFFF|0x1000000; # Yellow
$Color[3] = 0x008000|0x1000000; # Green
$Color[4] = 0xFF0000|0x1000000; # Blue
$Color[5] = 0x82004B|0x1000000; # Indigo
$Color[6] = 0xEE82EE|0x1000000; # Violet
 
# Get number of items currently selected
$Item_Count = RPR_CountSelectedMediaItems(0);
$Item_Index = 0;
 
# Update color for each selected item
while ($Item_Index < $Item_Count) {
	# Get first selected item pointer
	$Item_ID = RPR_GetSelectedMediaItem(0, $Item_Index);
 
	# Define color for all items based on the first item's color
	if ($Item_Index == 0) {
		# Get current item color
		$Item_Color = RPR_GetMediaItemInfo_Value($Item_ID, "I_CUSTOMCOLOR");
 
		# Assume current item color is not a preset value
		$Preset = -1;
 
		# Check if item color is a preset values
		$Count = 0;
		foreach $Value (@Color) {
			# If item color matches a preset value, exit loop
			if ($Value == $Item_Color) {
				$Preset = $Count;
				last;
			}
			$Count++;
		}
 
		# Reset preset number if item color matches last preset
		if ($Preset == "$#Color") {
			$Preset = 0;
		} else {
			$Preset++;
		}
 
		# New item color code
		$Item_Color = $Color[$Preset];
	}
 
	# Set new item color
	RPR_SetMediaItemInfo_Value($Item_ID, "I_CUSTOMCOLOR", $Item_Color);
 
	# Redraw item
	RPR_UpdateItemInProject($Item_ID);
 
	$Item_Index++
}