Old 03-14-2014, 04:26 PM   #1
James HE
Human being with feelings
 
James HE's Avatar
 
Join Date: Mar 2007
Location: I'm in a barn
Posts: 4,467
Default some JS / EEL color stuff...

If you are more comfortable using HEX or standard r,g,b values for color, these functions will make that EZ.

Uses values from 0-255. or if you want to use a HEX code, like from here, http://cloford.com/resources/colours/500col.htm

so for Cobalt, just use:
Code:
setcolor(0x3D59AB);

//or.

setcolor(61,89,171);
also you can set a color to a variable. (perhaps make an index? yeah I'll totally make an index at some point )
Code:
cobalt=pk_rgb(61,89,171);
//or
cobalt=0x3D59AB;


setcolor(cobalt);
EDIT*

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~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Last edited by James HE; 07-07-2015 at 11:03 AM.
James HE is offline   Reply With Quote
Old 05-16-2014, 03:56 PM   #2
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

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;
);
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 05-17-2014, 07:28 PM   #3
James HE
Human being with feelings
 
James HE's Avatar
 
Join Date: Mar 2007
Location: I'm in a barn
Posts: 4,467
Default

fantastic! I'll try this out.

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.

(low res .gif)

Last edited by James HE; 05-17-2014 at 07:36 PM.
James HE is offline   Reply With Quote
Old 05-26-2014, 08:20 AM   #4
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by James HE View Post
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 View Post
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 View Post
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.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 06-19-2014, 02:27 PM   #5
James HE
Human being with feelings
 
James HE's Avatar
 
Join Date: Mar 2007
Location: I'm in a barn
Posts: 4,467
Default

Had to write a function to get the 0-255 values for each color out of the RGBint or HEX values.

...was getting an error where the int value would decrease in the conversion.

ended up adding 1 to the Blue value. It works but i really have no clue why????

Code:
function get_r(rgbint)
(((rgbint>>16)&255)
);
function get_g(rgbint)
(((rgbint>>8)&255)
);
function get_b(rgbint)
(((rgbint)&255)+1
);
James HE is offline   Reply With Quote
Old 06-19-2014, 09:43 PM   #6
Fergler
Human being with feelings
 
Fergler's Avatar
 
Join Date: Jan 2014
Posts: 5,207
Default

http://doc.instantreality.org/tools/color_calculator/

Good calc for normalized values (I used to use this for some game shader design)
Fergler is offline   Reply With Quote
Old 02-11-2015, 03:33 AM   #7
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

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 !

Last edited by X-Raym; 02-11-2015 at 03:57 AM.
X-Raym is offline   Reply With Quote
Old 02-14-2015, 08:03 AM   #8
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

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.

Cheers!
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 02-14-2015, 08:12 AM   #9
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@daxliniere
If you need items to be colored the same color as the track, you can do that with a custom actions. But first, select the track, then
  • select all items in the track,
  • set to default color
  • deselect the items
  • and color the track with Track: apply a custom color...
Items will be colored with track color. :P
X-Raym is offline   Reply With Quote
Old 02-14-2015, 09:14 AM   #10
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

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)

Last edited by spk77; 02-14-2015 at 09:31 AM.
spk77 is offline   Reply With Quote
Old 02-14-2015, 10:09 AM   #11
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by spk77 View Post
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.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 02-14-2015, 10:15 AM   #12
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

And no one played with Hex valued ? ^^
Still didn't fihure out to convert hex value ton int rgb for color track --'
X-Raym is offline   Reply With Quote
Old 02-14-2015, 11:08 AM   #13
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by Banned View Post
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.
Thanks, I'll try to fix the script.

Quote:
Originally Posted by X-Raym View Post
And no one played with Hex valued ? ^^
Still didn't fihure out to convert hex value ton int rgb for color track --'

Maybe this helps:
Code:
color_int_val = GetTrackColor(GetSelectedTrack(0, 0))|16777216;

ShowConsoleMsg("");
ShowConsoleMsg(sprintf(#,"%s%d\n\n", "GetTrackColor(GetSelectedTrack(0, 0))|16777216 returns:\n", color_int_val));

ShowConsoleMsg("Get (extract) RGB:");   
R = color_int_val & 255;
G = (color_int_val >> 8) & 255;
B = (color_int_val >> 16) & 255;
//ShowConsoleMsg(sprintf(#,"RGB: %f,%f,%f\n",R,G,B));

ShowConsoleMsg("\n");

// Show values 0-255
ShowConsoleMsg(sprintf(#,"R: %d\n", R));
ShowConsoleMsg(sprintf(#,"G: %d\n", G));
ShowConsoleMsg(sprintf(#,"B: %d\n", B));

ShowConsoleMsg("\n");

ShowConsoleMsg("Convert int->hex:\n");
// Show hex values 00-FF
ShowConsoleMsg(sprintf(#,"R: %02x\n", R));
ShowConsoleMsg(sprintf(#,"G: %02x\n", G));
ShowConsoleMsg(sprintf(#,"B: %02x\n", B));



ShowConsoleMsg("\n");
back_to_orig = (R + 256 * G + 65536 * B)|16777216;
ShowConsoleMsg("'Join' R,G,B values back together, using (R + 256 * G + 65536 * B)|16777216:\n");
ShowConsoleMsg(sprintf(#,"%d",back_to_orig));
(note: if a track has "default color", R,G and B = 0)
spk77 is offline   Reply With Quote
Old 02-14-2015, 11:33 AM   #14
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@spk77
That's marvellous !
I will be able to share my future working color script online very soon !
X-Raym is offline   Reply With Quote
Old 02-14-2015, 11:34 AM   #15
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by X-Raym View Post
@spk77
That's marvellous !
I will be able to share my future working color script online very soon !
Very nice! Glad I could help
spk77 is offline   Reply With Quote
Old 02-15-2015, 03:11 AM   #16
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

Quote:
Originally Posted by X-Raym View Post
@daxliniere
If you need items to be colored the same color as the track, you can do that with a custom actions. But first, select the track, then
  • select all items in the track,
  • set to default color
  • deselect the items
  • and color the track with Track: apply a custom color...
Items will be colored with track color. :P

Thanks X-Raym, but I would like to use a set of pre-determined coloured (of which I will make toolbar buttons for easy access).

Can anyone help with an example script using values in "R,G,B" format, please?
EEL is preferred, Python is fine, too.

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 02-15-2015, 03:49 AM   #17
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@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)

EDIT :
I just made a template for adding a color button with custom color.
It color selected item and tracks.
Here here the link:
X-Raym_Set selected tracks and takes color.eel

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.

Last edited by X-Raym; 02-15-2015 at 06:52 AM. Reason: No loop in items needed
X-Raym is offline   Reply With Quote
Old 02-16-2015, 08:27 PM   #18
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@spk77
Here is a schema of what you show me on in your scritpt exemple

int=>RGB=>HEX
RGB => INT

My question is... how would you HEX to INT ?
Don't succeed to figure it out ^^
Thanks your attention :P
X-Raym is offline   Reply With Quote
Old 02-16-2015, 11:46 PM   #19
airon
Human being with feelings
 
airon's Avatar
 
Join Date: Aug 2006
Location: Berlin
Posts: 11,817
Default

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 ?
Attached Images
File Type: png Pro_Tools_color_palette_with_click_highlight_.png (1.2 KB, 1007 views)
Attached Files
File Type: zip colour_data.zip (76.9 KB, 190 views)
__________________
Using Latch Preview (Video) - Faderport 16 setup for CSI 1.1 , CSI 3.10
Website
"My ego comes pre-shrunk" - Randy Thom
airon is offline   Reply With Quote
Old 02-16-2015, 11:58 PM   #20
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

Quote:
Originally Posted by airon View Post
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)
__________________
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 02-17-2015, 12:00 AM   #21
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by airon View Post
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.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 02-23-2015, 10:47 PM   #22
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

Quote:
Originally Posted by airon View Post
I'm still dreaming and drooling. Any news on this, Airon?
__________________
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 02-23-2015, 11:51 PM   #23
airon
Human being with feelings
 
airon's Avatar
 
Join Date: Aug 2006
Location: Berlin
Posts: 11,817
Default

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.
__________________
Using Latch Preview (Video) - Faderport 16 setup for CSI 1.1 , CSI 3.10
Website
"My ego comes pre-shrunk" - Randy Thom

Last edited by airon; 02-24-2015 at 01:56 AM.
airon is offline   Reply With Quote
Old 02-24-2015, 07:00 AM   #24
airon
Human being with feelings
 
airon's Avatar
 
Join Date: Aug 2006
Location: Berlin
Posts: 11,817
Default

I've got the colour printing going.



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.
Attached Files
File Type: lua Colour Print.lua (16.9 KB, 157 views)
__________________
Using Latch Preview (Video) - Faderport 16 setup for CSI 1.1 , CSI 3.10
Website
"My ego comes pre-shrunk" - Randy Thom
airon is offline   Reply With Quote
Old 02-24-2015, 07:11 AM   #25
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

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.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 02-24-2015, 07:14 AM   #26
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

Hey cool!
I just opened the .LUA and was quite pleased to see it is easy for a novice to edit the colour matrix sizes and palette.

I've got a FR for later when you've gotten the core stuff sorted out.
There should (could?) be two 'latching' buttons, TRACKS and ITEMS.

Usage:
Enable TRACKS + click a colour swatch = change track colour
Enable ITEMS + click a colour swatch = change item colour
Enable both TRACKS and ITEMS + click a colour swatch = change track and item colour


Also, are you able to make it so the colours can be entered into the code in RGB?

A much later FR would be to be able to edit the colours & colour names from this window.


Thanks again for your time on this, Airon, it would be awesome to have this.


All the best!
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 02-24-2015, 07:17 AM   #27
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

Quote:
Originally Posted by Banned View Post
@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.
__________________
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 02-24-2015, 07:25 AM   #28
airon
Human being with feelings
 
airon's Avatar
 
Join Date: Aug 2006
Location: Berlin
Posts: 11,817
Default

Quote:
Originally Posted by Banned View Post
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.
__________________
Using Latch Preview (Video) - Faderport 16 setup for CSI 1.1 , CSI 3.10
Website
"My ego comes pre-shrunk" - Randy Thom
airon is offline   Reply With Quote
Old 02-24-2015, 07:34 AM   #29
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 7,239
Default

nice color stuff

by the way, where is OP James_HE?
heda is offline   Reply With Quote
Old 02-24-2015, 07:43 AM   #30
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by airon View Post
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.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 02-24-2015, 10:10 AM   #31
airon
Human being with feelings
 
airon's Avatar
 
Join Date: Aug 2006
Location: Berlin
Posts: 11,817
Default

Thanks.

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.
__________________
Using Latch Preview (Video) - Faderport 16 setup for CSI 1.1 , CSI 3.10
Website
"My ego comes pre-shrunk" - Randy Thom
airon is offline   Reply With Quote
Old 02-25-2015, 07:05 AM   #32
airon
Human being with feelings
 
airon's Avatar
 
Join Date: Aug 2006
Location: Berlin
Posts: 11,817
Default

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.
__________________
Using Latch Preview (Video) - Faderport 16 setup for CSI 1.1 , CSI 3.10
Website
"My ego comes pre-shrunk" - Randy Thom
airon is offline   Reply With Quote
Old 02-25-2015, 07:09 AM   #33
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default

Quote:
Originally Posted by airon View Post
I've got the colour printing going.



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 ...
DarkStar is offline   Reply With Quote
Old 02-25-2015, 12:15 PM   #34
airon
Human being with feelings
 
airon's Avatar
 
Join Date: Aug 2006
Location: Berlin
Posts: 11,817
Default

Quote:
Originally Posted by DarkStar View Post
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 got this list of colours from the web page James HE linked to.

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.

The script can be downloaded here: https://stash.reaper.fm/v/23413/Colour%20Swatch.lua

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
__________________
Using Latch Preview (Video) - Faderport 16 setup for CSI 1.1 , CSI 3.10
Website
"My ego comes pre-shrunk" - Randy Thom
airon is offline   Reply With Quote
Old 02-25-2015, 01:12 PM   #35
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

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

Last edited by Argitoth; 02-25-2015 at 01:42 PM.
Argitoth is offline   Reply With Quote
Old 02-26-2015, 02:38 AM   #36
airon
Human being with feelings
 
airon's Avatar
 
Join Date: Aug 2006
Location: Berlin
Posts: 11,817
Default

edit: Scratch that below. I found a Lua version of the script. Thank the imaginary heavens for that. It can be found here: https://github.com/EmmanuelOga/colum...tils/color.lua




Quote:
Originally Posted by Banned View Post
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
__________________
Using Latch Preview (Video) - Faderport 16 setup for CSI 1.1 , CSI 3.10
Website
"My ego comes pre-shrunk" - Randy Thom

Last edited by airon; 02-26-2015 at 04:06 AM.
airon is offline   Reply With Quote
Old 02-26-2015, 03:25 AM   #37
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default

^^^^
I think that that is right.

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 ...
DarkStar is offline   Reply With Quote
Old 02-26-2015, 01:31 PM   #38
airon
Human being with feelings
 
airon's Avatar
 
Join Date: Aug 2006
Location: Berlin
Posts: 11,817
Default

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 .

The script:
https://stash.reaper.fm/v/23433/Colour%20Swatch.lua

Screenshot of the default config:



The important bit of the config section of the script looks like this:
Code:
-- Strong colours
saturation = 1.0 ; luminance_max = 1.0 ; luminance_min = 0.2

-- Dark muted colours
--saturation = 0.8 ; luminance_max = 0.5 ; luminance_min = 0.2

-- Pastel colours
--saturation = 0.6 ; luminance_max = 0.95 ; luminance_min = 0.5

sw_max_x = 23    -- how many swatches horizontally
sw_max_y = 8     -- how many swatches vertically

sw_w = 16        -- swatch width
sw_h = 14        -- swatch height
sw_border = 1    -- empty around the swatches
__________________
Using Latch Preview (Video) - Faderport 16 setup for CSI 1.1 , CSI 3.10
Website
"My ego comes pre-shrunk" - Randy Thom
airon is offline   Reply With Quote
Old 02-26-2015, 01:47 PM   #39
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by airon View Post
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 .

The script:
https://stash.reaper.fm/v/23433/Colour%20Swatch.lua


The important bit of the config section of the script looks like this:
Code:
-- Strong colours
saturation = 1.0 ; luminance_max = 1.0 ; luminance_min = 0.2

-- Dark muted colours
--saturation = 0.8 ; luminance_max = 0.5 ; luminance_min = 0.2

-- Pastel colours
--saturation = 0.6 ; luminance_max = 0.95 ; luminance_min = 0.5

sw_max_x = 23    -- how many swatches horizontally
sw_max_y = 8     -- how many swatches vertically

sw_w = 16        -- swatch width
sw_h = 14        -- swatch height
sw_border = 1    -- empty around the swatches
Very nice!

I think this line
Code:
reaper.SetTrackColor (sel_track, hexcolour)
could also be:
Code:
reaper.SetTrackColor (sel_track, int_r + int_g * 256 + int_b * 65536)
spk77 is offline   Reply With Quote
Old 02-26-2015, 01:48 PM   #40
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Great job, airon!
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned 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 04:26 PM.


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