You can pack up the current values of rgb in JS/EEL into a single variable, However, if b=0, you can run into issues. The solution is to add just a bit of "noise" with, !gfx_b ? gfx_b+=.001;
I mostly use this packing / unpacking within functions, like storing the values and then returning them. just saves a line of code here and there.
like...
Code:
function do_prettystuff()local(_c)
(
_c=pack_rbg();//pack current values
setcolor(prettycolor);
do_some_pretty_stuff();
setcolor(_c);// returns values
);
the functions (i think this is complete )
Code:
//color functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function setcolor(hex)
( gfx_r= ((hex>>16)&255)/255; gfx_g= ((hex>>8)&255)/255; gfx_b= (hex>>0&255)/255; );
function setcolor(hex,a)
( setcolor(hex); gfx_a=a; );
function setcolor(r,g,b)
( gfx_r=r/255; gfx_g=g/255; gfx_b=b/255; );
function setcolor(r,g,b,a)
( setcolor(r,g,b); gfx_a=a );
function pack_rgb()
(!gfx_b?gfx_b+=.001;(((gfx_b*255)+(gfx_g*255)*256+(gfx_r*255)*65536)););
function pack_rgb(r,g,b)
(!b?b+=.001;( (b*255) + (g*255)*256 + (r*255)*65536););
function unpack_r(pack)
(((pack>>16)&255)/255);
function unpack_g(pack)
(((pack>>8)&255)/255);
function unpack_b(pack)
((((pack&255))/255));
//color functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Thanks for sharing, James HE.
On a related note, I'm typically more into setting colors using a combination of hue, lightness, and saturation values (and don't much mind using a 0-1 range). So, I converted some useful functions found on the web to EEL2. For convenience, I made them set the drawing color directly, and I have also adapted the hue range a bit, in order to make it easier to generate complementary color pairs (e.g. red = 0.0; green = red + 0.5). I have already been using them here and there, and found them very useful for programatically setting (ranges of) colors (rainbows FTW!), so I'll share them here for others EEL2 users (and because Google then will make it much easier for me to find them whenever I need them again). Perhaps we can collect a bunch of related stuff and compile an @importable EEL2 generic graphics functions library...
Code:
// some color conversion functions, adapted from <http://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion>
/**
* NB: this adaptation *directly* sets gfx_r, gfx_g, and gfx_b!
* NB: also adapted to make green = 0.5 on hue scale (instead of 0.25) for easier generation of complementary colors
*
* Converts an HSL color value to RGB. Conversion formula adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes h, s, and l are contained in the set [0, 1].
* @param Number h The hue
* @param Number s The saturation
* @param Number l The lightness
*/
function hue2rgb(p, q, t)
(
t < 0 ? t += 1;
t > 1 ? t -= 1;
t < 1/6 ? (
p + (q - p) * 6 * t;
) : (
t < 1/2 ? (
q;
) : (
t < 2/3 ? (
p + (q - p) * (2/3 - t) * 6;
) : p;
);
);
);
function set_gfx_hsl(h,s,l) // local (r g b)
(
h <= 0.5 ? h /= 2
: h = 0.25 + ((h - 0.5) * 1.5); // adaptation to make green = 0.5 hue (instead of 0.25)
s == 0 ? (
r = g = b = l; // achromatic
) :
(
q = l < 0.5 ? l * (1 + s) : l + s - l * s;
p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1/3);
);
gfx_r = r;
gfx_g = g;
gfx_b = b;
);
I might convert the range here to be 0-240, as that is similar to the windows color picker value. (why is it 0-240? seems so arbitrary? might be some reason though)
I hit a wall with the library, I worked on it on snow days, and (thankfully) no more of those. I have about 30 hours worth of train travel ahead of me next week, and I plan to grind out some revisions then.
The knob editor blew my brain apart.... I ended up with a nice UI for this, the "object" (fader, knob) editor just isn't working out, have to pull back and try to go in another way. It's getting over 3k lines of code... wow can't believe I did all that this winter! (a lot of that are similar functions, but with different numbers of inputs)
the background, gradient, and x/y position portion of the editor is working great though! (background will have the ability to select and choose .pngs - but haven't sussed out how those are loaded yet.
There is a whole HEAP of clickable / dragable string functions that have mouse-over highlight details that the editor is built around. Plus there is likely enough mouse handling functions to go with any situation.
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Quote:
Originally Posted by James HE
I might convert the range here to be 0-240, as that is similar to the windows color picker value. (why is it 0-240? seems so arbitrary? might be some reason though)
Seems like 8-bit range minus 16 for some opcodes or something. Or, maybe it's just that the very brightest and prettiest colors can only be displayed on a Mac.
Quote:
Originally Posted by James HE
I hit a wall with the library [...]
I know what that feels like. Yeah, just take a step back, relax, and try again when you feel bored or lucky.
Quote:
Originally Posted by James HE
Plus there is likely enough mouse handling functions to go with any situation.
I haven't even gotten around to playing with mouse functions - except for grabbing modifier *keys*. So I could probably learn a thing or two from looking at what you did there, too. But again, no rush.
Maybe I missed it, but is there a function to return color Hex value from 0x100000 (item color format : I_CUSTOMCOLOR) ? and how to do the opposite ?
It is the final step of my Display color of selected tracks items and takes in the console, all the rest is ready !
As a complete noob, could I ask for an example script which colours the track and all items on the track, please?
I currently use ED's scripts for that, but would like the flexibility to use any colour, not just those set in the SWS palette.
Argitoth and gofer were playing with RGB->HSL->RGB conversions not a very long time ago. I used the formulas they were experimenting with in this "color tool", but never got it working correctly:
(something is wrong with the RGB->HSL->RGB conversion)
(sliders from top to bottom: red=Hue, green=saturation and blue=lightness)
EDIT: The wrong behaviour can be seen at 7s in the gif. That gradient thing at 11s is a desired effect
(ctrl+dragging the Hue slider = gradient)
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Quote:
Originally Posted by spk77
Argitoth and gofer were playing with RGB->HSL->RGB conversions not a very long time ago. I used the formulas they were experimenting with in this "color tool", but never got it working correctly:
(something is wrong with the RGB->HSL->RGB conversion)
Have you tried the HSL to RGB code snippet I posted above? Afaik, this works perfectly - just delete these lines for a standard implementation:
Code:
h <= 0.5 ? h /= 2
: h = 0.25 + ((h - 0.5) * 1.5); // adaptation to make green = 0.5 hue (instead of 0.25)
The StackOverflow link mentioned in the code also includes an example of RGB to HSL, I just didn't need that part myself.
@daxliniere
Oh i see !
Well, you could do something not very different of my first solution :
Call the previous reaper actions (see above) in the script except the last one
Replace the last one by a 'loop through selected track' then 'set track color value'. The desired color value is stored inside the script.
Duplicate your script as many time as needed, rename and change variable value.
Import all that in a toolbar.
Add color icon or explicit name.
Then, you are done :P
(I can make a template for you if you are interested by this)
Color is define in file by user in RGB. HEX is a work in progress (a bit harder).
Don't forget to rename the script every time you create a file from the template.
I've got this colour data and want to provide a colour swatch view from which the user can then pick any colour.
The goal is something like this:
and it needs to be context sensitive if possible.
The illustration shows PTs colour pallete. It's a 16x12 pixel swatch surrounded by an inside bevel. It also has a saturation and brightness slider, but I've got to get this going first. I'm content to draw a 16x16 area of colour, maybe with a black border around everything.
Anyone know how to draw this stuff and scan for mouse clicks ?
The goal is something like this:
and it needs to be context sensitive if possible.
This would make me so happy.
Far easier than having to make toolbar buttons for each colour you want to use!
It would be great if the grid size (rows x columns) was user definable, too. (with presets for lazy people? 1x12, 2x10, 3x4, etc)
Swatch size, too? (I have 2560*1440 monitor)
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Quote:
Originally Posted by airon
Perhaps we can do this easier in LUA now ?
I've got this colour data and want to provide a colour swatch view from which the user can then pick any colour.
The goal is something like this:
and it needs to be context sensitive if possible.
The illustration shows PTs colour pallete. It's a 16x12 pixel swatch surrounded by an inside bevel. It also has a saturation and brightness slider, but I've got to get this going first. I'm content to draw a 16x16 area of colour, maybe with a black border around everything.
Anyone know how to draw this stuff and scan for mouse clicks ?
That looks a lot like the VU meters script I made for OSCII-bot in "rainbow" mode. Just need to add the mouse clicks and conversion to int/hex, really. In any case, HSL seems the thing to use for drawing this. Can have a try in a day or two.
Plate's a bit full. I'll give this a try today with Lua. Just drawing the colour swatches is a thing I have to get done first. If I can't do this, I might ask the SWS Extension authors do make this. C++ is probably a lot more flexible and could do things like a brightness and saturation slider as well.
edit: Currently trying to just print colours on screen.
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
I've also played with the drawing part for a few minutes last weekend, by changing some variable names and removing much code from my VUmeters script:
There's a bunch of useless semi-transparent permanent redrawing (which made a nice visual effect for metering, which needs to be updated continuously, but needs to be removed for drawing simple swatches only when the window size changes). The odd color for the leftmost column also needs to be removed, which was intended to distinguish the master track. Also, the drawing routine still needs to be adapated to draw each row separately.
@Airon: if you want to have a look at my (still messy) code, or use some parts of it (it's in EEL2, but perhaps it's useful anyway), I'll be glad to share it.
@Airon: if you want to have a look at my (still messy) code, or use some parts of it (it's in EEL2, but perhaps it's useful anyway), I'll be glad to share it.
REAPER has the best user community ever. So much love.
I've also played with the drawing part for a few minutes last weekend, by changing some variable names and removing much code from my VUmeters script:
There's a bunch of useless semi-transparent permanent redrawing (which made a nice visual effect for metering, which needs to be updated continuously, but needs to be removed for drawing simple swatches only when the window size changes). The odd color for the leftmost column also needs to be removed, which was intended to distinguish the master track. Also, the drawing routine still needs to be adapated to draw each row separately.
@Airon: if you want to have a look at my (still messy) code, or use some parts of it (it's in EEL2, but perhaps it's useful anyway), I'll be glad to share it.
Nice stuff. I haven't figured out how to react to window size changes yet.
I'd sure like to take a look. I'm looking to include the colour names as tooltips.
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Quote:
Originally Posted by airon
I'd sure like to take a look.
Here you go. Feel free to (re)use anything as you like.
Note that this is written to run in OSCII-bot, which supports a "@timer" section that is automatically called periodically. Perhaps it's easier to copy any useful ideas and rebuild things from the ground up, rather than trying to repurpose it by breaking things down.
I see if your colour generating code is something I should use or not. I was planning on having tooltips show up with the colour name. On the other hand it's easier to generate a nice bunch of colours across the hue spectrum and maybe have a slider to manipulate saturation.
Think I'll ask White Tie what the best thing to do is. It's good to have some code to go on.
Right now I'm studying mouse stuff and figuring out how to calculate what colour swatch was clicked on. Then it's on to the API stuff.
It was working ok, but a freak accident deleted the script and I have a version from this morning. Weird.
The script had worked up to a point.
I was passing hex strings to Reapers track colouring function. They looked like this : 0x00rrggbb.
The results were inaccurate and unpredictable so the colouring functions do not appear to work correctly from Lua. The actual colour that the track ended up having was something completely different, and the script was ok. I checked it with console debugging output every step of the way and it all worked.
Lua and Reapers colour plotting isn't so great either. The values of the swatch sometimes do not match what is on screen, and the values are all sound.
There's some stuff to rebuild now, and I don't have the time for a little while. I'll repost the result when I do.
Being used to Perl pattern matching did not help at all.
Now it's mouse scanning and improving the layout of this thing. the code is in the attachments.
A few questions
-- any reason for the order or colours?
-- why not arrange them in some sort of "logical" (tone / shade / saturation) order? (that would make it easier to find the colour you want)
-- when I ran it here all I saw was a momentary empty window; what did I miss?
__________________ DarkStar ... interesting, if true. . . . Inspired by ...
A few questions
-- any reason for the order or colours?
-- why not arrange them in some sort of "logical" (tone / shade / saturation) order? (that would make it easier to find the colour you want)
I chose it as a basis, not the final thing, because the colours are all named. I've always found named colours easier to remember. They'll be sorted properly, or discarded if deemed inefficient. We'll see.
Quote:
-- when I ran it here all I saw was a momentary empty window; what did I miss?
It was the first test I wrote. It probably didn't run deferred, so you'd have to try it from within the code editor in Reaper to see output.
Here's the preliminary first running version. It runs a bunch of data to the console window for verification purposes. I left that in because Reaper is doing something funny with the colour strings I throw at it.
A screenshot of the current iteration. You can configure this at the start of the script.
Specify how many swatches you want vertically and horizontally with the variables sw_max_x and sw_max_y.
Swatch sizes are configured via sw_w, sw_h and sw_border.
The console output will update depending on the swatch you click on, complete with data on what transformations the data has been put through, including the final colour string sent to Reaper.
An example from the very first swatch of the colour list:
Code:
Mouse x/y : 7.0 31.0
Swatch Zone x/y : 6.0 10.0
Swatch count - X = 1 Y = 1
Swatch table index = 1
Swatch data : Indian red 0.69 0.09 0.121
Normalized data : 0.69 0.09 0.121
Decimal data : 176 23 31
Hexdecimal data : 0x00B0171F
i had an idea for a user-adjustable swatch where you have a few hotkeys
click-drag on a box to change hue
ctrl-click-drag on a box to change lightness
shift-click-drag on a box to change saturation, or maybe a global saturation slider, and/or maybe a few rows with different saturation.
maybe a save/load button for settings.
__________________ Soundemote - Home of the chaosfly and pretty oscilloscope. MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Here you go. Feel free to (re)use anything as you like.
Note that this is written to run in OSCII-bot, which supports a "@timer" section that is automatically called periodically. Perhaps it's easier to copy any useful ideas and rebuild things from the ground up, rather than trying to repurpose it by breaking things down.
I'm trying to use the HSL to RGB conversion code, but I'm stumbling across some very weird stuff as I try to translate it to Lua.
From the set_gfx_hsl(h,s,l) function :
Code:
q = l < 0.5 ? l * (1 + s) : l + s - l * s;
What is this ? Can someone untangle this and write it down either with pure logic or gosh-darnit in Lua ?
EDIT: According to this ReaScript JS documentation (EEL is JS kinda right ?)
Quote:
The ? and ?: operators can also be used as the lvalue of expressions:
(a < 5 ? b : c) = 8; // if a is less than 5, set b to 8, otherwise set c to 8
I translate this EEL code:
Code:
q = l < 0.5 ? l * (1 + s) : l + s - l * s;
in to this Lua code
Code:
if l < 0.5 then
q = l * (1 + s)
else
q = l + s - (l * s)
end
Just to try it out, I tried the following in JS FX:
Code:
l = 0.3; s = 100; q1 = l < 0.5 ? l * (1 + s) : l + s - l * s;
l = 0.4; s = 100; q2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
l = 0.5; s = 100; q3 = l < 0.5 ? l * (1 + s) : l + s - l * s;
l = 0.6; s = 100; q4 = l < 0.5 ? l * (1 + s) : l + s - l * s;
l = 0.7; s = 100; q5 = l < 0.5 ? l * (1 + s) : l + s - l * s;
gfx_x = 20; gfx_y = 100;
gfx_printf("%f %f %f %f %f", q1, q2, q3, q4, q5);
and looked at the results,
__________________ DarkStar ... interesting, if true. . . . Inspired by ...
And here is the first release that features a generated list across all hues, with selectable saturation, and a selectable luminance range via editing the script(for now).
I'll include preset buttons in the future, or perhaps someone who's good at doing buttons can do this .
And here is the first release that features a generated list across all hues, with selectable saturation, and a selectable luminance range via editing the script(for now).
I'll include preset buttons in the future, or perhaps someone who's good at doing buttons can do this .