Old 05-16-2018, 02:27 PM   #1
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default Lua: Setting Item color

Hello scripters,

I've been trying to get and set item colors. But nothing I'm doing is working. I'm not getting script errors... just no change of color.

I've been using these commands:

To get item color value (this seems to be working fine):
Code:
 Color_Val = reaper.GetMediaItemInfo_Value(Item, "I_CUSTOMCOLOR" )
And to impose a color value (this seems to not be working for me):
Code:
 reaper.SetMediaItemTakeInfo_Value( Take, "I_CUSTOMCOLOR",88888888.0 )
No matter what I do, I can't re-color an item. Any help on what I'm missing?

Here is my test script:
Code:
function Msg (param)
  reaper.ShowConsoleMsg(tostring (param).."\n")
end

function Main()

  reaper.ClearConsole()
  Num_of_Items = reaper.CountSelectedMediaItems(0)
  Msg("Number of items: ".. Num_of_Items)
  ii = 0
  Note_Num = 0
  
  for i = 0, Num_of_Items - 1 do



    Item = reaper.GetSelectedMediaItem(0,i)   
    Take = reaper.GetMediaItemTake(Item, 0)
    
    Item_Track = reaper.GetMediaItemTrack(Item)
    _, Track_Name = reaper.GetTrackName(Item_Track, "")
    
    _, Take_Name = reaper.GetSetMediaItemTakeInfo_String(Take, "P_NAME", Track_Name.. "Soft_".. Note_Num.. "_rr_".. i % 8 + 1 ,1)
    
  
    
    if i >=  Num_of_Items - 20 then
    Color_Val = reaper.GetMediaItemInfo_Value(Item, "I_CUSTOMCOLOR" )
        ii = ii + 1
        Msg(ii.. ": ".. "Item: ".. i..", "..  Take_Name.. "  color: ".. Color_Val)

    end

  
    
    reaper.SetMediaItemTakeInfo_Value( Take, "I_CUSTOMCOLOR",12345678 )

    

            
  end
      
end
    
Main()
Cheers,

Andrew K

Last edited by Thonex; 05-16-2018 at 02:43 PM.
Thonex is offline   Reply With Quote
Old 05-16-2018, 03:16 PM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Sorry, I'm in a rush:
- Color values are OS dependant; use the helper function.
- You have to bitwise OR with 0x1000000 (the API doc says 0x100000, but it's wrong)
- Try setting the item color, rather than the take.

Code:
    reaper.SetMediaItemInfo_Value( Item, "I_CUSTOMCOLOR",reaper.ColorToNative(255,255,0)|0x1000000 )
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate

Last edited by Lokasenna; 05-16-2018 at 03:48 PM.
Lokasenna is offline   Reply With Quote
Old 05-16-2018, 03:44 PM   #3
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by Lokasenna View Post
Sorry, I'm in a rush:
- Color values are OS dependant; use the helper function.
- You have to bitwise OR with 0x1000000
- Try setting the item color, rather than the take.

Code:
    reaper.SetMediaItemInfo_Value( Item, "I_CUSTOMCOLOR",reaper.ColorToNative(255,255,0)|0x1000000 )
Thanks so much Lokasenna... and even being in a rush.. you are very helpful!

Will look at it now.

Cheers,

Andrew K
Thonex is offline   Reply With Quote
Old 05-16-2018, 03:58 PM   #4
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Fantastic!!!

I had no idea about the OS dependent angle. I think I read somewhere that if you put a value of 0 it will not be black, but rater the default color.

Anyway... I need to read up some more... now that I know where to look. Thanks again. Very helpful and nondestructive.

Cheers,

Andrew K
Thonex is offline   Reply With Quote
Old 05-17-2018, 05:03 AM   #5
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Yeah, the color-management in Reaper is real confusing if you're not familiar with it.
The only thing that's "normal" is using 0 for the default-color.

You can use ColorToNative()to get proper system-dependant color-values, though.
https://www.reaper.fm/sdk/reascript/...#ColorToNative

The returned color-values should(tm) work.
Meo-Ada Mespotine is offline   Reply With Quote
Old 05-17-2018, 03:56 PM   #6
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by mespotine View Post
Yeah, the color-management in Reaper is real confusing if you're not familiar with it.
The only thing that's "normal" is using 0 for the default-color.

You can use ColorToNative()to get proper system-dependant color-values, though.
https://www.reaper.fm/sdk/reascript/...#ColorToNative

The returned color-values should(tm) work.
Thanks for the additional info mespotine!

Thankfully I'm not going after Pantone (tm) accuracy

Cheers,

Andrew K
Thonex is offline   Reply With Quote
Old 11-06-2019, 07:56 PM   #7
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default

Quote:
Originally Posted by Lokasenna View Post
- You have to bitwise OR with 0x1000000 (the API doc says 0x100000, but it's wrong)
Thanks for this, Lokasenna.

Docs are *still* wrong.
tack 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:42 AM.


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