Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Q&A, Tips, Tricks and Howto

Reply
 
Thread Tools Display Modes
Old 05-03-2017, 01:00 PM   #1
bassburner
Human being with feelings
 
Join Date: Feb 2016
Location: Colorado Springs, CO
Posts: 25
Default SWS Auto Color - Gradient Children

Is it possible to have children tracks auto gradient based off the parent's color? When I set children to gradient it sets anything that is a child (regardless of parent) to a gradient starting with black.

I have rules for my various Master folders to set them to different colors and was hoping to have the children to be set to gradients of that color. Is that possible?
bassburner is offline   Reply With Quote
Old 12-08-2019, 09:16 AM   #2
daeavelwyn
Human being with feelings
 
daeavelwyn's Avatar
 
Join Date: Dec 2014
Posts: 597
Default

UP! (yeah, from the abbyss I know...)
daeavelwyn is offline   Reply With Quote
Old 12-09-2019, 05:20 AM   #3
Greg Savage
Human being with feelings
 
Join Date: Apr 2016
Posts: 653
Default

I'd like to know this as well.
Greg Savage is offline   Reply With Quote
Old 12-10-2019, 08:47 PM   #4
Joe90
Human being with feelings
 
Join Date: Aug 2019
Posts: 853
Default

Bump. I expect this is probably already possible, this thread just hasn't been seen by one of the eight people who understand how to do it yet

What would be good is if you can assign your parent to a custom colour, and then the child tracks gradient FROM that parent custom colour to your next custom colour only. As long as your custom colours are organised in a logical order this should always look nice and tidy.

Hopefully someone will spot this and help us out.
Joe90 is offline   Reply With Quote
Old 12-11-2019, 05:12 AM   #5
daeavelwyn
Human being with feelings
 
daeavelwyn's Avatar
 
Join Date: Dec 2014
Posts: 597
Default

Yes, that would be very cool and handy for non-coding people :-D
daeavelwyn is offline   Reply With Quote
Old 12-11-2019, 07:01 AM   #6
elcalen
Human being with feelings
 
elcalen's Avatar
 
Join Date: Sep 2019
Location: Finland
Posts: 755
Default

Quote:
Originally Posted by bassburner View Post
Is it possible to have children tracks auto gradient based off the parent's color? When I set children to gradient it sets anything that is a child (regardless of parent) to a gradient starting with black.
I was literally just today fiddling with my auto-colour settings and wondering why I couldn't find an option to do this.
__________________
Artist name Ben Enkindle. Making electronic music exclusively with Linux software.

Last edited by elcalen; 12-11-2019 at 07:03 AM. Reason: Clarify what I was referring to
elcalen is online now   Reply With Quote
Old 04-05-2020, 09:23 PM   #7
yimbot
Human being with feelings
 
Join Date: Sep 2008
Location: Adelaide, Australia
Posts: 159
Default

Nice idea!
Would like to see if this could be achieved also!
yimbot is offline   Reply With Quote
Old 12-15-2020, 05:30 AM   #8
marine289
Human being with feelings
 
Join Date: Feb 2018
Posts: 19
Default

Great idea, anyone find a way to do this?
I did find that you have some great gradient customization with Heda's track inspector, but that doesn't have the convenience of SWS auto color. So when you add new tracks, it doesn't update their color automatically.
marine289 is offline   Reply With Quote
Old 01-05-2021, 12:22 PM   #9
composerguy78
Human being with feelings
 
Join Date: Nov 2018
Posts: 155
Default

Did anybody figure this out? I am looking for a solution to this also!
composerguy78 is offline   Reply With Quote
Old 01-09-2021, 06:00 AM   #10
nikki5000
Human being with feelings
 
Join Date: Nov 2020
Posts: 138
Default

oh that would be cool!
nikki5000 is offline   Reply With Quote
Old 01-10-2021, 10:40 AM   #11
composerguy78
Human being with feelings
 
Join Date: Nov 2018
Posts: 155
Default

Anyone? Anyone?
composerguy78 is offline   Reply With Quote
Old 01-10-2021, 11:19 AM   #12
poulhoi
Human being with feelings
 
Join Date: Apr 2020
Posts: 214
Default

I've made something like this for myself. It's not automatic, but it works fine for me. I run it as a component of custom actions for different circumstances.
It only changes the colors of tracks you've selected and it simply offsets the current color values, making them darker. Children of children etc. are progressively darker, while top level folders are unchanged.
It's here: https://pastebin.com/Lze5JL3L

What is perhaps also useful are these two scripts for just offsetting the color values of the selected tracks, making them progressively brighter or darker: https://pastebin.com/aw0781ca and https://pastebin.com/wEARfX8u

Hope that can work for you.
poulhoi is offline   Reply With Quote
Old 01-10-2021, 07:48 PM   #13
composerguy78
Human being with feelings
 
Join Date: Nov 2018
Posts: 155
Default

This looks just like what I am looking for. Thank you so much for sharing!
composerguy78 is offline   Reply With Quote
Old 01-18-2021, 06:08 AM   #14
80icio
Human being with feelings
 
Join Date: Mar 2016
Location: Italy
Posts: 322
Default

Quote:
Originally Posted by poulhoi View Post
I've made something like this for myself. It's not automatic, but it works fine for me. I run it as a component of custom actions for different circumstances.
It only changes the colors of tracks you've selected and it simply offsets the current color values, making them darker. Children of children etc. are progressively darker, while top level folders are unchanged.
It's here: https://pastebin.com/Lze5JL3L

What is perhaps also useful are these two scripts for just offsetting the color values of the selected tracks, making them progressively brighter or darker: https://pastebin.com/aw0781ca and https://pastebin.com/wEARfX8u

Hope that can work for you.

Great Paul!
I was looking for something like that, i started from your script
and modified in a way that you select 1 folder parent and it automatically gradients children tracks, based on the folder track color.
SWS actions needed to make my coding quick.
doesn't work with multiple folders selections for now, but I think I can do it.

Code:
local selchildren = reaper.NamedCommandLookup("_SWS_SELCHILDREN")
local colchildren = reaper.NamedCommandLookup("_SWS_COLCHILDREN")
local gradientstep = -15

function main()
reaper.Main_OnCommandEx(colchildren, 0, 0)
reaper.Main_OnCommandEx(selchildren, 0, 0)
local trackCount = reaper.CountSelectedTracks(0)
 for i = 0, trackCount - 2, 1 do
    local track = reaper.GetSelectedTrack(0, i)
    local nexttrack = reaper.GetSelectedTrack(0, i+1)
    local prevColorNative = reaper.GetTrackColor(track)
    local prevColorR, prevColorG, prevColorB = reaper.ColorFromNative(prevColorNative)
    if prevColorR + gradientstep < 0 then prevColorR = 0 else prevColorR = prevColorR + gradientstep end
    if prevColorG + gradientstep < 0 then prevColorG = 0 else prevColorG = prevColorG + gradientstep end
    if prevColorB + gradientstep < 0 then prevColorB = 0 else prevColorB = prevColorB + gradientstep end
    local newColorR = math.min(prevColorR, 255)
    local newColorG = math.min(prevColorG, 255)
    local newColorB = math.min(prevColorB, 255)
    local newColorNative = reaper.ColorToNative(newColorR, newColorG, newColorB)
    reaper.SetTrackColor(nexttrack, newColorNative)
  end
end

reaper.Undo_BeginBlock()
reaper.PreventUIRefresh(1)
main()
reaper.Main_OnCommandEx(40297, 0, 0)
reaper.PreventUIRefresh(-1)
reaper.Undo_EndBlock( "folder Gradient", 0)
80icio is offline   Reply With Quote
Old 01-18-2021, 10:42 AM   #15
daeavelwyn
Human being with feelings
 
daeavelwyn's Avatar
 
Join Date: Dec 2014
Posts: 597
Default

@80icio : your script works quite well but is there a way to define the gradientStep relatively to the number of children ?
daeavelwyn is offline   Reply With Quote
Old 01-18-2021, 01:30 PM   #16
80icio
Human being with feelings
 
Join Date: Mar 2016
Location: Italy
Posts: 322
Default

Quote:
Originally Posted by daeavelwyn View Post
@80icio : your script works quite well but is there a way to define the gradientStep relatively to the number of children ?
there it is!

the more tracks, the more the color steps get smaller .


Code:
local selchildren = reaper.NamedCommandLookup("_SWS_SELCHILDREN")
local colchildren = reaper.NamedCommandLookup("_SWS_COLCHILDREN")
local itemtotrkcolor = reaper.NamedCommandLookup("_SWS_ITEMTRKCOL")

---Gradient Step ---- positive numbers will gradient to white // negative numbers will gradient to black
local gradientstep = -15 ---- 0 = no gradient 
local coloritem = true -----if true = force to color items in tracks 

function main()
reaper.Main_OnCommandEx(colchildren, 0, 0)
reaper.Main_OnCommandEx(selchildren, 0, 0)
local trackCount = reaper.CountSelectedTracks(0)
local gradientstep =  math.ceil((gradientstep*10)/(trackCount+1)) ----dependent on track count
 for i = 0, trackCount - 2, 1 do
    local track = reaper.GetSelectedTrack(0, i)
    local nexttrack = reaper.GetSelectedTrack(0, i+1)
    local prevColorNative = reaper.GetTrackColor(track)
    local prevColorR, prevColorG, prevColorB = reaper.ColorFromNative(prevColorNative)
    if prevColorR + gradientstep < 0 then prevColorR = 0 else prevColorR = prevColorR + gradientstep end
    if prevColorG + gradientstep < 0 then prevColorG = 0 else prevColorG = prevColorG + gradientstep end
    if prevColorB + gradientstep < 0 then prevColorB = 0 else prevColorB = prevColorB + gradientstep end
    local newColorR = math.min(prevColorR, 255)
    local newColorG = math.min(prevColorG, 255)
    local newColorB = math.min(prevColorB, 255)
    local newColorNative = reaper.ColorToNative(newColorR, newColorG, newColorB)
    reaper.SetTrackColor(nexttrack, newColorNative)
    
  end
 if coloritem == true then
  reaper.Main_OnCommandEx(40718, 0, 0)
  reaper.Main_OnCommandEx(itemtotrkcolor, 0, 0)
  end
end

reaper.Undo_BeginBlock()
reaper.PreventUIRefresh(1)
main()
reaper.Main_OnCommandEx(40769, 0, 0)
reaper.PreventUIRefresh(-1)
reaper.Undo_EndBlock( "folder Gradient", 0)
80icio is offline   Reply With Quote
Old 01-18-2021, 01:47 PM   #17
80icio
Human being with feelings
 
Join Date: Mar 2016
Location: Italy
Posts: 322
Default

Script attached
80icio is offline   Reply With Quote
Old 01-18-2021, 02:07 PM   #18
daeavelwyn
Human being with feelings
 
daeavelwyn's Avatar
 
Join Date: Dec 2014
Posts: 597
Default

Yeah ! Very nice !
Another little behaviour I'd like to avoid, when the script finished, folder track is unselected, is there a way to keep track selected ?
daeavelwyn is offline   Reply With Quote
Old 01-18-2021, 03:42 PM   #19
nait
Human being with feelings
 
nait's Avatar
 
Join Date: Jun 2018
Location: Edmonton, AB, Canada
Posts: 1,391
Default

I downloaded the script and am using it too. Thanks 80icio!
__________________
My Rig (also serves as my gaming PC): MSI Mag X570 Tomahawk Mobo, Ryzen R9 3900X, 32GB RAM, Samsung 960 Evo 500gb NVMe, Crucial 1TB NVMe, NVidia RTX 2080 Super, Arturia Minifuse 2, Nektar Impact LX25+ MIDI Controller Keyboard.
nait is offline   Reply With Quote
Old 01-18-2021, 04:55 PM   #20
80icio
Human being with feelings
 
Join Date: Mar 2016
Location: Italy
Posts: 322
Default

edit: just found another bug... give me a minute!
80icio is offline   Reply With Quote
Old 01-18-2021, 05:06 PM   #21
daeavelwyn
Human being with feelings
 
daeavelwyn's Avatar
 
Join Date: Dec 2014
Posts: 597
Default

80icio, thanks a lot for your work ! Do you plan to release your work throught reapack ?
daeavelwyn is offline   Reply With Quote
Old 01-18-2021, 05:20 PM   #22
80icio
Human being with feelings
 
Join Date: Mar 2016
Location: Italy
Posts: 322
Default

There it is
v1.2

- Multiple folder track selection
- selected tracks stay the same after the script

Depending on the Theme you use color gradient will be more noticeable,
You can open the script and modify the gradient step in case.

let me know if you encounter any bugs.

Happy rainbow mixing!
80icio is offline   Reply With Quote
Old 01-18-2021, 05:38 PM   #23
80icio
Human being with feelings
 
Join Date: Mar 2016
Location: Italy
Posts: 322
Default

Quote:
Originally Posted by daeavelwyn View Post
80icio, thanks a lot for your work ! Do you plan to release your work throught reapack ?
you're welcome!

Honestly I use Reapack to download scripts, but I don't really know how the repository thing works....

If you just select all tracks with ctrl+A the script will automatically get folders and set children track colours


Last edited by 80icio; 01-18-2021 at 05:48 PM.
80icio is offline   Reply With Quote
Old 01-18-2021, 05:45 PM   #24
daeavelwyn
Human being with feelings
 
daeavelwyn's Avatar
 
Join Date: Dec 2014
Posts: 597
Default

Wow ! It's now working like a charm, thanks so much !
daeavelwyn is offline   Reply With Quote
Old 01-18-2021, 05:45 PM   #25
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by 80icio View Post
Honestly I use Reapack to download scripts, but I don't really know how the repository thing works....
https://reapack.com/upload
cfillion is offline   Reply With Quote
Old 01-18-2021, 05:56 PM   #26
80icio
Human being with feelings
 
Join Date: Mar 2016
Location: Italy
Posts: 322
Default

Quote:
Originally Posted by cfillion View Post
Wow! Mr. ReaPack in person!
thanks for the hint!

Before uploading, I might add a function to check if SWS is installed
80icio is offline   Reply With Quote
Old 01-19-2021, 08:18 AM   #27
composerguy78
Human being with feelings
 
Join Date: Nov 2018
Posts: 155
Default

This is fantastic! Thank you so much for creating this script. Exactly what I was looking for!
composerguy78 is offline   Reply With Quote
Old 02-01-2021, 04:17 AM   #28
kovarny
Human being with feelings
 
Join Date: Mar 2018
Posts: 72
Default

Hey 80icio, great script. But if I want colors from normal to brighter what needs to be changed in the code for this?
kovarny is offline   Reply With Quote
Old 02-05-2021, 12:17 AM   #29
80icio
Human being with feelings
 
Join Date: Mar 2016
Location: Italy
Posts: 322
Default

Quote:
Originally Posted by kovarny View Post
Hey 80icio, great script. But if I want colors from normal to brighter what needs to be changed in the code for this?
Thanks!

Code:
local gradientstep = -15
this is the variable you have to change in the script

if number is positive it will color gradient the track towards white.
80icio is offline   Reply With Quote
Old 04-10-2021, 09:44 AM   #30
mendel
Human being with feelings
 
mendel's Avatar
 
Join Date: Oct 2020
Posts: 6
Default Any way to prevent manually colored items from being changed?

I love this script! My only complaint is that it overrides any manual item color settings. I would prefer an option for it to re-color only the items that have not been manually set.

This behaviour seems to be how the command 40421 (Item: Select all items in track) is combined with itemtotrkcolor.

Code:
       if coloritem == true then
          r.Main_OnCommandEx(40421, 0, 0)
          r.Main_OnCommandEx(itemtotrkcolor, 0, 0)
Built-in track coloring actions (EG. 40358 - Track: Set to random colors) re-color both the track, and only items of "default" color.

I'm not yet savvy enough to work out this feature for myself. Do you think it's possible to select items of default color instead of using 40421?


PS. another, likely way larger, feature request would be a way to set the gradient step in HSB independently.

Last edited by mendel; 04-10-2021 at 10:44 AM.
mendel is offline   Reply With Quote
Old 04-11-2021, 01:03 AM   #31
80icio
Human being with feelings
 
Join Date: Mar 2016
Location: Italy
Posts: 322
Default

Quote:
I'm not yet savvy enough to work out this feature for myself. Do you think it's possible to select items of default color instead of using 40421?
You got it already!
Get rid of that line and it'll work the way you're saying, the SWS command which colours items to track color doesn't override your coloring.


try it on a new session with default coloured tracks

If you don't want to cancel that line just put 2 minus signs before the line

Code:
       if coloritem == true then
          --r.Main_OnCommandEx(40421, 0, 0)
          r.Main_OnCommandEx(itemtotrkcolor, 0, 0)


Quote:
PS. another, likely way larger, feature request would be a way to set the gradient step in HSB independently.
I had a quick look on Reaper's API but no trace of access to direct HSB variables. The only way would be to translate RGB values to Hue or Brightness or saturation.
The way the script is working right now adds RGB values the same way every step, so I guess it corresponds to Brightness , not sure if there's any math i can do to translate rgb steps to hue or saturation.
80icio is offline   Reply With Quote
Old 04-11-2021, 06:25 AM   #32
poulhoi
Human being with feelings
 
Join Date: Apr 2020
Posts: 214
Default

Quote:
Originally Posted by 80icio View Post
I had a quick look on Reaper's API but no trace of access to direct HSB variables. The only way would be to translate RGB values to Hue or Brightness or saturation.
The way the script is working right now adds RGB values the same way every step, so I guess it corresponds to Brightness , not sure if there's any math i can do to translate rgb steps to hue or saturation.
X-Raym put together some functions for this; they’re available on ReaPack. I made a new version of my original script using them and it works great.
poulhoi is offline   Reply With Quote
Old 04-11-2021, 08:20 AM   #33
80icio
Human being with feelings
 
Join Date: Mar 2016
Location: Italy
Posts: 322
Default

Quote:
Originally Posted by poulhoi View Post
X-Raym put together some functions for this; they’re available on ReaPack. I made a new version of my original script using them and it works great.
Wow! thanks for sharing!
Having a look right now .
80icio is offline   Reply With Quote
Old 06-13-2021, 04:50 AM   #34
GLD
Human being with feelings
 
Join Date: Jun 2019
Posts: 21
Default Thank you!!

Quote:
Originally Posted by 80icio View Post
There it is
v1.2

- Multiple folder track selection
- selected tracks stay the same after the script

Depending on the Theme you use color gradient will be more noticeable,
You can open the script and modify the gradient step in case.

let me know if you encounter any bugs.

Happy rainbow mixing!
Awesome Script- thank you!

Had a play with this just now and managed to add an offset by adding a second loop and also got it to work with Auto Colors and sub folders etc. so I thought other may find it useful if they stumble across this thread like I did today!

Thanks again,

G

P.S. I attached an image of the action and result in case it is of any use to anyone!

P.P.S.

Offset Loop:

Code:
--gd loop
   for i = 0, trackCount - 1, 1 do
    local track = r.GetSelectedTrack(0, i)
    local ColorNative = r.GetTrackColor(track)
    local ColorR, ColorG, ColorB = r.ColorFromNative(ColorNative)
	if math.max(math.max(ColorR,ColorG),ColorB)+GDOFFSET<256 then
    local newColorR = math.min(ColorR, 255)+GDOFFSET
    local newColorG = math.min(ColorG, 255)+GDOFFSET
    local newColorB = math.min(ColorB, 255)+GDOFFSET
    local newColorNative = r.ColorToNative(newColorR, newColorG, newColorB)
    r.SetTrackColor(track, newColorNative)
       if coloritem == true then
          r.Main_OnCommandEx(40421, 0, 0)
          r.Main_OnCommandEx(itemtotrkcolor, 0, 0)
      end
	end
  end
Attached Images
File Type: png Color Action.PNG (12.3 KB, 139 views)
File Type: png Color Action Tracks.PNG (56.5 KB, 172 views)
GLD is offline   Reply With Quote
Old 06-17-2021, 01:29 PM   #35
bakasound
Human being with feelings
 
bakasound's Avatar
 
Join Date: May 2021
Posts: 2
Default

Quote:
Originally Posted by GLD View Post
Awesome Script- thank you!

Had a play with this just now and managed to add an offset by adding a second loop and also got it to work with Auto Colors and sub folders etc. so I thought other may find it useful if they stumble across this thread like I did today!

Thanks again,

G

P.S. I attached an image of the action and result in case it is of any use to anyone!

P.P.S.

Offset Loop:

Code:
--gd loop
   for i = 0, trackCount - 1, 1 do
    local track = r.GetSelectedTrack(0, i)
    local ColorNative = r.GetTrackColor(track)
    local ColorR, ColorG, ColorB = r.ColorFromNative(ColorNative)
	if math.max(math.max(ColorR,ColorG),ColorB)+GDOFFSET<256 then
    local newColorR = math.min(ColorR, 255)+GDOFFSET
    local newColorG = math.min(ColorG, 255)+GDOFFSET
    local newColorB = math.min(ColorB, 255)+GDOFFSET
    local newColorNative = r.ColorToNative(newColorR, newColorG, newColorB)
    r.SetTrackColor(track, newColorNative)
       if coloritem == true then
          r.Main_OnCommandEx(40421, 0, 0)
          r.Main_OnCommandEx(itemtotrkcolor, 0, 0)
      end
	end
  end
Hi GLD, could you share your updated script please? Thanks in advance
bakasound is offline   Reply With Quote
Old 01-19-2022, 07:41 PM   #36
Sound asleep
Human being with feelings
 
Sound asleep's Avatar
 
Join Date: Nov 2009
Location: Montreal, Canada
Posts: 9,048
Default

Quote:
Originally Posted by poulhoi View Post
I've made something like this for myself. It's not automatic, but it works fine for me. I run it as a component of custom actions for different circumstances.
It only changes the colors of tracks you've selected and it simply offsets the current color values, making them darker. Children of children etc. are progressively darker, while top level folders are unchanged.
It's here: https://pastebin.com/Lze5JL3L

What is perhaps also useful are these two scripts for just offsetting the color values of the selected tracks, making them progressively brighter or darker: https://pastebin.com/aw0781ca and https://pastebin.com/wEARfX8u

Hope that can work for you.

These are very cool, but they're not quite working well for me. I think it's not quite "getting" the current color properly. It seems to work well for subsequent presses, but that first one doesn't seem to start off from the right shade. It has also just gone and given me weird colors out of the blue, pardon the pun.

I was also wondering if it is possible to code it such that each jump in brightness or darkness is dependent on the color the track previously was. Meaning, rather than increasing by 30 each time, when it's black it might only increase by 10, and when it's more pale, it will increase by 50 or something. using a bit of a logarithmic formula or something like that.

Quote:
Originally Posted by 80icio View Post
you're welcome!

Honestly I use Reapack to download scripts, but I don't really know how the repository thing works....

If you just select all tracks with ctrl+A the script will automatically get folders and set children track colours

How difficult would it be to make some thing sort of similar, except, what it does is it goes and changes all Folders, and subfolders to brighter and brighter colors. So, the folders are darker and the children are lighter, and same level folders will be same color, and same level children same color. This way, I get an idea what level I am, just by looking at the children.

Last edited by Sound asleep; 01-19-2022 at 07:52 PM.
Sound asleep is offline   Reply With Quote
Old 02-14-2022, 11:15 AM   #37
Sound asleep
Human being with feelings
 
Sound asleep's Avatar
 
Join Date: Nov 2009
Location: Montreal, Canada
Posts: 9,048
Default

Quote:
Originally Posted by poulhoi View Post
I've made something like this for myself. It's not automatic, but it works fine for me. I run it as a component of custom actions for different circumstances.
It only changes the colors of tracks you've selected and it simply offsets the current color values, making them darker. Children of children etc. are progressively darker, while top level folders are unchanged.
It's here: https://pastebin.com/Lze5JL3L

What is perhaps also useful are these two scripts for just offsetting the color values of the selected tracks, making them progressively brighter or darker: https://pastebin.com/aw0781ca and https://pastebin.com/wEARfX8u

Hope that can work for you.
I really like this, but I would like to make 2 changes to it, if possible. I don't mind finding the values and stuff myself, but I'm not sure how to go about it from a coding standpoint.

What I would like to do is to have a sliding scale by how much a given RGB value will change. For example, if R >240 it reduces by 50. Or, something like that, maybe just a simple fraction of the value would work as well. Like I said, I can figure out the values, as long as I know what's the code I would need to make it make relative changes like that.

The other change I would like to make, is that if the next reduction takes it past zero, it doesn't wrap around, it stays at zero, until all values are zero. So, if you pressed the darker button, it would always eventually become black and settle there. And the same thing for brighter, but the other way, maxing out at 255.

Is it possible to do this?
Sound asleep is offline   Reply With Quote
Old 02-15-2022, 01:54 PM   #38
80icio
Human being with feelings
 
Join Date: Mar 2016
Location: Italy
Posts: 322
Default

Quote:
Originally Posted by Sound asleep View Post
I really like this, but I would like to make 2 changes to it, if possible. I don't mind finding the values and stuff myself, but I'm not sure how to go about it from a coding standpoint.

What I would like to do is to have a sliding scale by how much a given RGB value will change. For example, if R >240 it reduces by 50. Or, something like that, maybe just a simple fraction of the value would work as well. Like I said, I can figure out the values, as long as I know what's the code I would need to make it make relative changes like that.

The other change I would like to make, is that if the next reduction takes it past zero, it doesn't wrap around, it stays at zero, until all values are zero. So, if you pressed the darker button, it would always eventually become black and settle there. And the same thing for brighter, but the other way, maxing out at 255.

Is it possible to do this?
That's already happening on my script
Code:
  if prevColorR + gradientstep < 0 then prevColorR = 0 else prevColorR = prevColorR + gradientstep end
    if prevColorG + gradientstep < 0 then prevColorG = 0 else prevColorG = prevColorG + gradientstep end
    if prevColorB + gradientstep < 0 then prevColorB = 0 else prevColorB = prevColorB + gradientstep end
    local newColorR = math.min(prevColorR, 255)
    local newColorG = math.min(prevColorG, 255)
    local newColorB = math.min(prevColorB, 255)
Here's where the gradient step gets proportional to the number of tracks involved

Code:
local gradientstep =  math.ceil((gradientstep*10)/(trackCount+1)) ----dependent on track count
80icio is offline   Reply With Quote
Old 02-19-2022, 09:43 AM   #39
Sound asleep
Human being with feelings
 
Sound asleep's Avatar
 
Join Date: Nov 2009
Location: Montreal, Canada
Posts: 9,048
Default

Quote:
Originally Posted by 80icio View Post
That's already happening on my script
Code:
  if prevColorR + gradientstep < 0 then prevColorR = 0 else prevColorR = prevColorR + gradientstep end
    if prevColorG + gradientstep < 0 then prevColorG = 0 else prevColorG = prevColorG + gradientstep end
    if prevColorB + gradientstep < 0 then prevColorB = 0 else prevColorB = prevColorB + gradientstep end
    local newColorR = math.min(prevColorR, 255)
    local newColorG = math.min(prevColorG, 255)
    local newColorB = math.min(prevColorB, 255)
Here's where the gradient step gets proportional to the number of tracks involved

Code:
local gradientstep =  math.ceil((gradientstep*10)/(trackCount+1)) ----dependent on track count
I'm gonna see if I can work it out with that information, but as cool as the gradient steps are, I am more just trying to create a keystroke that just makes a track darker by some value, which is proportional to the value it just was. Meaning if the value is near 255, the step will be greater. Like if the step could be PrevcolorR*1/3 So, at 255 the step would be 85 and at 30, the step would be 10 for example. Idk the best fraction or whatever, but something like that.

Maybe I could tell it "local gradientstepR = PrevcolorR * 1/3 ?

and make 3 gradientsteps for RGB?

I'm gonna test this out in a minute.

EDIT: I tried my hand at it, but, for some reason it just always goes to black, no matter what value I put for the gradient. I tried to mix and match your scripts with my limited understanding.


Code:
local gradientstep = -2
local coloritem = true -----if true = force to color items/takes with track color
local trktbl = {}


function main()
  local trackCount = reaper.CountSelectedTracks2(0, 1)
  for i = 0, trackCount - 1, 1 do
   local track = reaper.GetSelectedTrack(0, i)
    local nexttrack = reaper.GetSelectedTrack(0, i+1)
    local prevColorNative = reaper.GetTrackColor(track)
    local prevColorR, prevColorG, prevColorB = reaper.ColorFromNative(prevColorNative)
    if prevColorR + gradientstep < 0 then prevColorR = 0 else prevColorR = prevColorR + gradientstep end
    if prevColorG + gradientstep < 0 then prevColorG = 0 else prevColorG = prevColorG + gradientstep end
    if prevColorB + gradientstep < 0 then prevColorB = 0 else prevColorB = prevColorB + gradientstep end
    local newColorR = math.min(prevColorR, 255)
    local newColorG = math.min(prevColorG, 255)
    local newColorB = math.min(prevColorB, 255)
    local newColorNative = reaper.ColorToNative(newColorR, newColorG, newColorB)
    reaper.SetTrackColor(track, newColorNative)
  end
end

reaper.PreventUIRefresh(1)
main()
reaper.PreventUIRefresh(-1)
reaper.UpdateArrange()
I put -2 just to be sure, but it still went to black, which makes me feel like it believes the < 0 requirements were met. I was wondering also, if it would be possible to put "prevColorR * gradient step" rather than say "+ gradient step"

Last edited by Sound asleep; 02-19-2022 at 12:11 PM.
Sound asleep is offline   Reply With Quote
Old 02-20-2022, 10:50 AM   #40
80icio
Human being with feelings
 
Join Date: Mar 2016
Location: Italy
Posts: 322
Default

You can play around with the gradient step value, this code darken all the selected tracks color by that amount.

Making it proportional is possible (like R G B go down by 10% everytime you run the script)
But I think this script is simpler and makes the job

Code:
----------------ICIO - Darken Track Color-----------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
------------------------------------?:^) written by 80icio -----------------------------------------------
----------------------------------------------------------------------------------------------------------
--- v1.0

local r = reaper
local verifysws = reaper.APIExists( 'CF_GetSWSVersion' )------- my easy way to check if SWS extensions are installed

if verifysws then  

local itemtotrkcolor = r.NamedCommandLookup("_SWS_ITEMTRKCOL")

---Gradient Step ---- positive numbers will gradient to white // negative numbers will gradient to black
local gradientstep = -30 ---- 0 = no gradient 
local coloritem = true -----if true = force to color items/takes with track color
local trktbl = {}

function getseltracktable()
  local trackCount = r.CountSelectedTracks(0)
  if trackCount ~= 0 then 
    for i = 1, trackCount, 1 do
    trktbl[i] = r.GetSelectedTrack(0, i-1)
    end
  end
end

function main()
local trackCount = r.CountSelectedTracks(0)
 for i = 0, trackCount - 1, 1 do
    local track = r.GetSelectedTrack(0, i)
    local prevColorNative = r.GetTrackColor(track)
    local prevColorR, prevColorG, prevColorB = r.ColorFromNative(prevColorNative)
    if prevColorR + gradientstep < 0 then prevColorR = 0 else prevColorR = prevColorR + gradientstep end
    if prevColorG + gradientstep < 0 then prevColorG = 0 else prevColorG = prevColorG + gradientstep end
    if prevColorB + gradientstep < 0 then prevColorB = 0 else prevColorB = prevColorB + gradientstep end
    local newColorR = math.min(prevColorR, 255)
    local newColorG = math.min(prevColorG, 255)
    local newColorB = math.min(prevColorB, 255)
    local newColorNative = r.ColorToNative(newColorR, newColorG, newColorB)
    r.SetTrackColor(track, newColorNative)
       if coloritem == true then
          r.Main_OnCommandEx(40421, 0, 0)
          r.Main_OnCommandEx(itemtotrkcolor, 0, 0)
      end
  end
end

r.Undo_BeginBlock()
--r.PreventUIRefresh(1)

getseltracktable()

if #trktbl ~=0 then
main()
end

r.PreventUIRefresh(-1)
r.Undo_EndBlock( "Darken Track Color", 1)
else
reaper.ShowMessageBox( "SWS/S&M extensions not installed download from https://www.sws-extension.org/", "", 0 )
end
80icio 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 05:11 AM.


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