Old 06-29-2020, 11:52 AM   #1
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,583
Default Script to set random colour to different source files?

Is there a script or Custom Action that would allow someone to select a bunch of items, and run it to set random colours for each item that has a different source file?

For example, say you had items with source files FileA.WAV FileA.MP3 FileB.WAV FileC.WAV. You chop up the items and put all the pieces onto one track. By default they will all inherit the track's colour.
This script/action would colour each item in the item selection to a different random colour.

For example: FileA.WAV red, FileA.MP3 blue, FileB.WAV green, FileC.WAV purple


Thanks in advance to anyone who has any ideas how to achieve this!

All the best!

UPDATE! Solution here: https://forum.cockos.com/showpost.ph...3&postcount=13
__________________
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]

Last edited by daxliniere; 02-10-2022 at 06:21 AM.
daxliniere is offline   Reply With Quote
Old 06-29-2020, 12:39 PM   #2
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,721
Default

Cool and useful idea... I don't think there is one.
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
Thonex is offline   Reply With Quote
Old 06-29-2020, 01:36 PM   #3
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,583
Default

No worries, thanks Andrew!
__________________
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 06-29-2020, 04:24 PM   #4
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

Script: X-Raym_Color selected items randomly according to their source.lua



It uses a special algorythm where it is not pure random at each items, there is always nice hue contrast/shift between each ones.

Though, it is a premium unreleased script for now... Not sure in which pack I could put it. I made it back in 2017 and there was demand before today ^^
X-Raym is offline   Reply With Quote
Old 06-30-2020, 11:06 AM   #5
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Quote:
Originally Posted by daxliniere View Post
For example: FileA.WAV red, FileA.MP3 blue, FileB.WAV green, FileC.WAV purple
I've been wanting to make a script like that, this is limited to 10 hard coded colors (tweak as needed) and used in the same order (its what I prefer), if it doesn't help then just don't use it (no updates planned). Probably not as versatile as XRaym scripts but it does what I need.

Code:
-- Color selected items of same source file
-- Edgemeal - June 30, 2020
-- Donate: https://www.paypal.me/Edgemeal

-- 10 colors max (Red, Orange, Yellow, Lime, Cyan, Cadet Blue, Purple, Green, Blue, Pink).
local colors = {16777471,16810239,16842751,16842496,33554176,29392896,33489024,16809984,33488896,33521919}
local itemSource = {}

function contains(src)
  for n = 1, #itemSource do
    if itemSource[n].src == src then return true end
  end
end

function ColorItems()
  local itemCount = reaper.CountSelectedMediaItems()
  if itemCount == 0 then return end
  
  reaper.PreventUIRefresh(1)
  local takes = {}
  local colorIndex,takeIndex,sourceIndex = 0,0,0

  for i = 0, itemCount-1 do
    local item = reaper.GetSelectedMediaItem(0,i)
    if item then
      local take = reaper.GetActiveTake(item)
      if take and not reaper.TakeIsMIDI(take) then -- ignore MIDI items!
        local src_file = reaper.GetMediaSourceFileName(reaper.GetMediaItemTake_Source(take), "")
        takeIndex=takeIndex+1 takes[takeIndex] = {take = take, src = src_file}
        if not contains(src_file) then -- associate a color to source file
          colorIndex=colorIndex+1 if colorIndex > #colors then colorIndex = 1 end
          sourceIndex=sourceIndex+1 itemSource[sourceIndex] = {src = src_file, color = colors[colorIndex]}
        end
      end
    end
  end
 
  for i = 1, #takes do
    for j = 1, #itemSource do
      if takes[i].src == itemSource[j].src then
        reaper.SetMediaItemTakeInfo_Value(takes[i].take,"I_CUSTOMCOLOR",itemSource[j].color)
        break
      end
    end
  end
 reaper.UpdateArrange()
 reaper.PreventUIRefresh(-1)
end

ColorItems()
reaper.defer(function () end)
Edgemeal is offline   Reply With Quote
Old 06-30-2020, 05:03 PM   #6
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,583
Default

Hey guys!
Raymond and Edgemeal, thank you both for your efforts.
__________________
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 07-02-2020, 10:53 AM   #7
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,721
Default

Nice one Edgemeal!!

Cheers,

Andrew K
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
Thonex is offline   Reply With Quote
Old 02-07-2022, 09:32 AM   #8
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,583
Default

@Edgemeal, Would it be possible to extend this to operate on takes, too?
__________________
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-07-2022, 11:47 AM   #9
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Quote:
Originally Posted by daxliniere View Post
@Edgemeal, Would it be possible to extend this to operate on takes, too?
I see the above script only colored the active take of selected items, this quick code tweak should color all the takes in an item,..

Code:
-- Color all takes of selected items of same source file
-- Edgemeal - Feb 07, 2022
-- Donate: https://www.paypal.me/Edgemeal

-- 10 colors max (Red, Orange, Yellow, Lime, Cyan, Cadet Blue, Purple, Green, Blue, Pink).
local colors = {16777471,16810239,16842751,16842496,33554176,29392896,33489024,16809984,33488896,33521919}
local itemSource = {}

function contains(src)
  for n = 1, #itemSource do
    if itemSource[n].src == src then return true end
  end
end

function ColorItems()
  local itemCount = reaper.CountSelectedMediaItems()
  if itemCount == 0 then return end
  
  reaper.PreventUIRefresh(1)
  local takes = {}
  local colorIndex,takeIndex,sourceIndex = 0,0,0

  for i = 0, itemCount-1 do
    local item = reaper.GetSelectedMediaItem(0,i)
    if item then
      local take = reaper.GetActiveTake(item)
      if take and not reaper.TakeIsMIDI(take) then -- ignore MIDI items!
        local src_file = reaper.GetMediaSourceFileName(reaper.GetMediaItemTake_Source(take), "")
        takeIndex=takeIndex+1 takes[takeIndex] = {item = item, src = src_file}
        if not contains(src_file) then -- associate a color to source file
          colorIndex=colorIndex+1 if colorIndex > #colors then colorIndex = 1 end
          sourceIndex=sourceIndex+1 itemSource[sourceIndex] = {src = src_file, color = colors[colorIndex]}
        end
      end
    end
  end
 
  for i = 1, #takes do
    for j = 1, #itemSource do
      if takes[i].src == itemSource[j].src then  -- color all takes in item.
        for k = 0, reaper.CountTakes(takes[i].item)-1 do
          local take = reaper.GetTake(takes[i].item, k)
          reaper.SetMediaItemTakeInfo_Value(take, "I_CUSTOMCOLOR",itemSource[j].color)
        end
        break
      end
    end
  end
 reaper.UpdateArrange()
 reaper.PreventUIRefresh(-1)
end

ColorItems()
reaper.defer(function () end)

Last edited by Edgemeal; 02-07-2022 at 11:55 AM. Reason: Date typo
Edgemeal is offline   Reply With Quote
Old 02-07-2022, 12:00 PM   #10
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,583
Default

Thanks so much, man. I just tested it and it does colour all takes now, but all takes within the item are the same colour.

Missed dotting an i or crossing a t?
__________________
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-07-2022, 01:02 PM   #11
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Script just assumes all takes in an item are from the same source file, so all takes in item get same color, I didn't even know takes could be from different source LOL!

Oh well, maybe someone else can help with that, good luck!
Edgemeal is offline   Reply With Quote
Old 02-07-2022, 04:55 PM   #12
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,583
Default

Quote:
Originally Posted by Edgemeal View Post
Oh well, maybe someone else can help with that, good luck!
No worries, man, thanks so much for looking.

Quote:
Originally Posted by Edgemeal View Post
I didn't even know takes could be from different source LOL!
Yes, it's super handy for things like multiple versions of the same part - in mastering it could be an updated mix, in a mixing scenario it could be alternate takes of the same part.
__________________
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-08-2022, 03:48 PM   #13
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,458
Default

Try this:
Code:
local items_cnt = reaper.CountSelectedMediaItems(0)
if items_cnt == 0 then return reaper.defer(function() end) end


local sources = {}
local colors = {"65280", "16711935", "16744448", "33023", "8437632", "10294354", "67251", "14613762", "13533181", "65535", "4355077", "32896", "16472205", "7875814", "16711680", "16571267", "7396610", "8375538", "910731", "3158614", "16711808", "9660782", "10851347", "6522077", "12991492", "11270484", "309293", "14071753", "11009205", "2640315", "6951171", "14129015", "1032664", "12003240", "5044677", "6095247", "14826990", "15187247", "4060226", "1516539", "803086", "4495698", "8608798", "12875960", "32768", "14305869", "3450778", "394344", "8804280", "4877195", "10927683", "12387086", "4306706", "11668214", "7533944", "11205885", "7747443", "4195797", "15799873", "3824381", "1664836", "9610945", "16380995", "3540268", "5455890", "16645564", "14384189", "15388922", "18807", "1737667", "14680773", "8717252", "9329146", "12176899", "16330675", "12635536", "6935366", "16615382", "12537995", "5490112", "16664321", "634735", "4763896", "6107309", "6184020", "387646", "324035", "4120571", "7309346", "7639189", "4247672", "2566035", "10987517", "10681619", "12151564", "13110906", "6619214", "9016151", "13585341", "10699329"}
local colors_cnt = #colors
local colors_used = {}


math.randomseed(reaper.time_precise())
math.random(); math.random(); math.random()


local function CreateColor()
  ::RANDOM::
  local r,g,b = math.random(0,255), math.random(0,255), math.random(0,255)
  if r < 25 and g < 25 and b < 25 then goto RANDOM end
  if r > 220 and g > 220 and b > 220 then goto RANDOM end
  local color = reaper.ColorToNative( r, g, b )
  if colors_used[color] then goto RANDOM end
  colors_used[color] = true
  return color
end


local source_cnt = 0
local function GetColor()
  source_cnt = source_cnt + 1
  if source_cnt <= colors_cnt then
    colors_used[ colors[source_cnt] ] = true
    local col = colors[source_cnt]
    return col
  else
    return CreateColor()
  end
end


-- Main
reaper.Undo_BeginBlock()
reaper.PreventUIRefresh(1)
for i = 0, items_cnt-1 do
  local item = reaper.GetSelectedMediaItem(0,i)
  if item then
    for tk = 0, reaper.CountTakes( item )-1 do
      local take = reaper.GetTake( item , tk )
      if take and not reaper.TakeIsMIDI( take ) then
        local source = reaper.GetMediaItemTake_Source( take )
        if source then
          local source_section = reaper.GetMediaSourceParent( source )
          if source_section then source = source_section end
          local source_filename = reaper.GetMediaSourceFileName( source, "" )
          if not sources[source_filename] then
            sources[source_filename] = GetColor()
          end
          reaper.SetMediaItemTakeInfo_Value(take, "I_CUSTOMCOLOR", sources[source_filename]|0x1000000 )
        end
      end
    end
  end
end
reaper.PreventUIRefresh(-1)
reaper.UpdateArrange()
reaper.ShowConsoleMsg(source_cnt .. " different sources were found and got colored.\n")
reaper.Undo_EndBlock("Color all takes in items based on their source file name", 4)
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 02-10-2022, 06:20 AM   #14
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,583
Default

Quote:
Originally Posted by amagalma View Post
Try this:
Seems to do the job! Thank you, Amagalma! And to you again, Edgemeal.
__________________
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
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 03:01 AM.


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