|
|
|
08-13-2018, 05:42 PM
|
#1
|
Human being with feelings
Join Date: Nov 2008
Location: London, UK
Posts: 2,583
|
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.
|
|
|
08-13-2018, 05:42 PM
|
#2
|
Human being with feelings
Join Date: Nov 2008
Location: London, UK
Posts: 2,583
|
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")
#
|
|
|
08-13-2018, 09:24 PM
|
#3
|
Human being with feelings
Join Date: May 2018
Location: Los Angeles
Posts: 1,721
|
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.
|
|
|
08-13-2018, 09:29 PM
|
#4
|
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
|
I remember red and blue should be interchanged for OSX.
|
|
|
08-13-2018, 09:58 PM
|
#5
|
Human being with feelings
Join Date: May 2018
Location: Los Angeles
Posts: 1,721
|
Quote:
Originally Posted by mpl
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.
|
|
|
08-13-2018, 10:09 PM
|
#6
|
Human being with feelings
Join Date: May 2018
Location: Los Angeles
Posts: 1,721
|
Quote:
Originally Posted by mpl
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.
|
|
|
08-13-2018, 10:32 PM
|
#7
|
Human being with feelings
Join Date: May 2015
Location: Quιbec, Canada
Posts: 4,968
|
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.
|
|
|
08-13-2018, 11:31 PM
|
#8
|
Human being with feelings
Join Date: May 2018
Location: Los Angeles
Posts: 1,721
|
Quote:
Originally Posted by cfillion
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.
|
|
|
08-14-2018, 07:13 AM
|
#10
|
Human being with feelings
Join Date: May 2018
Location: Los Angeles
Posts: 1,721
|
Quote:
Originally Posted by spk77
|
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.
|
|
|
08-14-2018, 11:02 AM
|
#11
|
Human being with feelings
Join Date: Nov 2008
Location: London, UK
Posts: 2,583
|
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.)
|
|
|
08-14-2018, 11:29 AM
|
#12
|
Human being with feelings
Join Date: May 2018
Location: Los Angeles
Posts: 1,721
|
Quote:
Originally Posted by daxliniere
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.
|
|
|
08-14-2018, 11:36 AM
|
#13
|
Human being with feelings
Join Date: May 2015
Location: Quιbec, Canada
Posts: 4,968
|
Quote:
Originally Posted by daxliniere
@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.
|
|
|
08-14-2018, 12:55 PM
|
#14
|
Human being with feelings
Join Date: Nov 2008
Location: London, UK
Posts: 2,583
|
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.
|
|
|
08-16-2018, 07:31 AM
|
#15
|
Human being with feelings
Join Date: May 2018
Location: Los Angeles
Posts: 1,721
|
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.
|
|
|
08-17-2018, 04:27 PM
|
#16
|
Human being with feelings
Join Date: Nov 2008
Location: London, UK
Posts: 2,583
|
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.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 03:43 AM.
|