Old 08-13-2018, 05:42 PM   #1
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default REQ: Increase/decrease track brightness

Hey guys,
There are a pair of old Python scripts to increase and decrease the brightness of a coloured track, but they seem to be dead. (I guess something in REAPER changed.)

Anyhoo, I was wondering if there is an EEL/LUA equivalent of these scripts somewhere?


Any help appreciated.

Thanks,
Dax.
__________________
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 08-13-2018, 05:42 PM   #2
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

If anyone's curious, the Python script to increase brightness is here:

Code:
def RGBToHTMLColor(rgb_tuple):
    # convert an (R, G, B) tuple to #RRGGBB """
    colorstring = '#%02x%02x%02x' % rgb_tuple
    # that's it! '%02x' means zero-padded, 2-digit hex values
    return colorstring

def HTMLColorToPILColor(colorstring):
    # converts #RRGGBB to PIL-compatible integers"""
    colorstring = colorstring.strip()
    while colorstring[0] == '#': colorstring = colorstring[1:]
    # get bytes in reverse order to deal with PIL quirk
    colorstring = colorstring[-2:] + colorstring[2:4] + colorstring[:2]
    # finally, make it numeric
    color = int(colorstring, 16)
    return color     
	
def PILColorToRGB(pil_color):
    # convert a PIL-compatible integer into an (r, g, b) tuple """
    hexstr = '%06x' % pil_color
    # reverse byte order
    r, g, b = hexstr[4:], hexstr[2:4], hexstr[:2]
    r, g, b = [int(n, 16) for n in (r, g, b)]
    return (r, g, b)
	
def RGBToPILColor(rgb_tuple):
    return HTMLColorToPILColor(RGBToHTMLColor(rgb_tuple))
	

import colorsys

trackcount = RPR_CountSelectedTracks(0)     
trackindex = 0


while trackindex < trackcount: 
	
	TRACK = RPR_GetSelectedTrack(0, trackindex)
	PILColor = RPR_GetTrackColor(TRACK)

	if PILColor < 16777216: #track has no custom color - set to some default
		h, s, v = 1.0, 0.7, 0.6     
		r, g, b = colorsys.hsv_to_rgb(h, s, v)
		r, g, b = r*255,g*255,b*255


	else: #track has custom color
		PILColor = PILColor - 16777216
		r,g,b = PILColorToRGB(PILColor)

		#darn special cases when two colors are zero (cant explain why, but in these cases I always get rgb = (0,0,0) in the next iteration using the "normal" math. For some reason I only found that behavior in "brightness increase" script as of yet):
		size = 17          
		if r == 0 and g == 0:
			if b >= 240 - size:
				b = 32
			else:
				b += size
				
		if r == 0 and b == 0:
			if g >= 240 - size:
				g = 32
			else:
				g += size
			
		if g == 0 and b == 0:
			if r >= 240 - size:
				r = 32
			else:
				r += size
			
		# normal case:     
		else:     
			R, G, B = r/255, g/255, b/255
			(h, s, v) = colorsys.rgb_to_hsv(R, G, B)     

			step = 7
			v = v * 100
			if v >= 100 - step - 10:
				v = v + step - 100 + 21
			else:
				v += step          
			v = v / 100
			# saturation correction because of conversion error
			s = s * 100
			if s <= 0.44:
				s = s
			else:
				s -= 0.44
			s = s / 100
		

			r, g, b = colorsys.hsv_to_rgb(h, s, v)
			r, g, b = r*255,g*255,b*255
	
	New_rgb_tuple = (r, g, b)
	New_Color = RGBToPILColor(New_rgb_tuple)
	RPR_SetTrackColor(TRACK, New_Color | 16777216)
	trackindex +=1



#RPR_ShowConsoleMsg(str(pil_color) + "\n" + "RGB:" + str(r) + ", " + str(g) + ", " + str(b) + "\n" + str(New_pil_color) + "\n")
#RPR_ShowConsoleMsg("HSV:" + str(h) + ", " + str(s) + ", " + str(v) +  "\n")
#RPR_ShowConsoleMsg(str(chunk) + "\n" + str(NewChunk) + "\n")
#
__________________
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 08-13-2018, 09:24 PM   #3
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Hi there,

This sounded like a fun after-dinner project.

Here is a Brighten Selected Tracks script in Lua...

Code:
function MAIN()
  reaper.ClearConsole()
  
  Brightness_Amt = 10
  
  Num_Sel_Trks =  reaper.CountSelectedTracks(0)
  
  Trks = {}
  Trk_Color = {}
  -- Loop Through Selected Tracks and Light
  for i=0, Num_Sel_Trks - 1 do
    Trks = reaper.GetSelectedTrack( 0, i )
    Trk_Color = reaper.GetMediaTrackInfo_Value(  Trks,"I_CUSTOMCOLOR" )
    r, g, b = reaper.ColorFromNative( Trk_Color)
    r=r+Brightness_Amt
    g=g+Brightness_Amt
    b=b+Brightness_Amt
    if r>255 then r = 255 end
    if g>255 then g = 255 end
    if b>255 then b = 255 end
    reaper.SetMediaTrackInfo_Value( Trks, "I_CUSTOMCOLOR",reaper.ColorToNative(r,g,b)|0x1000000 )

  end
   
  
end


MAIN()
Here is a Darken Selected Tracks script in Lua...
Code:
function MAIN()
  reaper.ClearConsole()
  
  Brightness_Amt = -10
  
  Num_Sel_Trks =  reaper.CountSelectedTracks(0)
  
  Trks = {}
  Trk_Color = {}
  -- Loop Through Selected Tracks and Darken
  for i=0, Num_Sel_Trks - 1 do
    Trks = reaper.GetSelectedTrack( 0, i )
    Trk_Color = reaper.GetMediaTrackInfo_Value(  Trks,"I_CUSTOMCOLOR" )
    r, g, b = reaper.ColorFromNative( Trk_Color)
    r=r+Brightness_Amt
    g=g+Brightness_Amt
    b=b+Brightness_Amt
    if r<0 then r = 0 end
    if g<0 then g = 0 end
    if b<0 then b = 0 end
    reaper.SetMediaTrackInfo_Value( Trks, "I_CUSTOMCOLOR",reaper.ColorToNative(r,g,b)|0x1000000 )

  end
   
  
end


MAIN()
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.

Last edited by Thonex; 08-16-2018 at 07:32 AM.
Thonex is offline   Reply With Quote
Old 08-13-2018, 09:29 PM   #4
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

I remember red and blue should be interchanged for OSX.
mpl is offline   Reply With Quote
Old 08-13-2018, 09:58 PM   #5
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by mpl View Post
I remember red and blue should be interchanged for OSX.
Hi mpl,

luckily, since this script just lowers all 3 values by the same amount... I think it won't matter. But I'll look into this... to see if I can confirm.

Thanks mpl!!
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
Thonex is offline   Reply With Quote
Old 08-13-2018, 10:09 PM   #6
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by mpl View Post
I remember red and blue should be interchanged for OSX.
Hi mpl,

I tested with a gray track color and then only push Red up... and it seemed to go towards red. Then I did the same with Blue... and it went blue.

Are you sure about this. I am on OSX.

Also, as a side note, even when I pick a solid neural gray with the OSX Color Picker, Reaper interprets it as somewhat more greenish bluish. So I would agree that Reaper's color conversion is messed up. I do a lot of work in Photoshop and all is good... so this is something with Reaper. My guess is it may be tinted to suit Reaper's UI design aesthetic?
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.

Last edited by Thonex; 08-13-2018 at 11:29 PM.
Thonex is offline   Reply With Quote
Old 08-13-2018, 10:32 PM   #7
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Quιbec, Canada
Posts: 4,937
Default

Color{To,From}Native takes care of that now but these functions were only added in v5.01.

Last edited by cfillion; 08-13-2018 at 10:49 PM.
cfillion is offline   Reply With Quote
Old 08-13-2018, 11:31 PM   #8
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by cfillion View Post
Color{To,From}Native takes care of that now but these functions were only added in v5.01.
Thanks for clarifying cfillion.

That's one thing I've noticed about Reaper... it seems like there's an update every other day. Mind-blowing!!
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
Thonex is offline   Reply With Quote
Old 08-14-2018, 05:55 AM   #9
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Lua: Adjust track colors via mouse wheel (or MIDI CC)
https://forum.cockos.com/showthread.php?t=173884

(I haven't tested these recently)
spk77 is offline   Reply With Quote
Old 08-14-2018, 07:13 AM   #10
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by spk77 View Post
Lua: Adjust track colors via mouse wheel (or MIDI CC)
https://forum.cockos.com/showthread.php?t=173884

(I haven't tested these recently)
Whoa... those are really great spk77!! Nice implementation.

Thanks for sharing.
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
Thonex is offline   Reply With Quote
Old 08-14-2018, 11:02 AM   #11
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

Thanks Andrew! Much appreciated, thanks for your time.

(Do you have a ReaPack stash? or @cfillion, is there a Github account for developers of one-off scripts? I'm sure I'm not the only one who's searched for this script in ReaPack.)
__________________
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 08-14-2018, 11:29 AM   #12
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by daxliniere View Post
Thanks Andrew! Much appreciated, thanks for your time.

(Do you have a ReaPack stash? or @cfillion, is there a Github account for developers of one-off scripts? I'm sure I'm not the only one who's searched for this script in ReaPack.)
I don't have a Repo yet... but I'll be creating one soon. Just project crunch right now.
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
Thonex is offline   Reply With Quote
Old 08-14-2018, 11:36 AM   #13
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Quιbec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by daxliniere View Post
@cfillion, is there a Github account for developers of one-off scripts? I'm sure I'm not the only one who's searched for this script in ReaPack.)
Everybody can submit their work to the ReaTeam repositories.
cfillion is offline   Reply With Quote
Old 08-14-2018, 12:55 PM   #14
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

Thanks Andrew and Christian.

Andrew, the decrease script works a treat, but increase script throws this error: 22:attempt to call a nil value (global 'Msg')
I fixed by removing line 22 (I guess that was for debug?)


Not that it's a big problem since it's just a colouring script, but I notice that once you get to black, coming up back doesn't recover the hue & saturation.
I guess this means REAPER is storing the colour not as HSL, but RGB? If it were HSL, I guess you could leave Hue and Saturation values untouched and only adjust Lightness.

For the sake of interest, the original python script would 'wrap around', meaning that for the decrease script, once you got to maximum darkness, it would go to maximum brightness and decrease again from there. (I don't need this feature, just mentioning it.)


This discussion is all academic to be honest, since the script does exactly what I need. Thank you.
__________________
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 08-16-2018, 07:31 AM   #15
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Yeah, I just did this as a quickie. My guess is if I was to do this seriously, I'd store the relative RGB offset and return to those after reaching the upper and lower RGB limits so that you could always retrieve the original color. But I'd need to learn how to do shared variables in Reaper. LOL. Just started with Reascrip not long ago.

Also, thanks about the bug. I forgot to remove that comment line. I updated it now.
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
Thonex is offline   Reply With Quote
Old 08-17-2018, 04:27 PM   #16
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

Yes, no worries at all, of course. Thank you very much for putting it together.
As I mentioned, it's fine as it is for me.
__________________
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
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 01:23 PM.


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