Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- USER VARIABLES
- colorOffset = -30
- -- the offset to apply to the color of each track for each generation down the hierarchy.
- -- Set to negative colors to make children darker than parents and vice versa.
- -- NAME
- local scriptName = ({reaper. get_action_context()})[2]:match("([^/\\]+)%.lua$") -- generate default scriptName from file
- --FUNCTIONS FOR DEBUG
- function msg(msg)
- reaper.ShowConsoleMsg(tostring(msg) .. "\n")
- end
- --- FUNCTIONS
- function getSelectedTracks()
- local tracks = {}
- local tCount = reaper.CountSelectedTracks(0)
- for i = 1, tCount do
- tracks[i] = reaper.GetSelectedTrack(0, i - 1)
- end
- return tracks
- end
- function getTrackLevel(track) -- get how many "levels" down the hiearchy the track is; 0 for parents, 1 for first-generation children etc.
- local level = 0
- local found = false
- local cur = track
- while not found do
- local up = reaper.GetParentTrack(cur)
- if up == nil then -- if parent doesn't exist
- found = true
- return level
- else
- level = level + 1
- cur = up
- end
- end
- end
- function offsetTrackColor(track, offset)
- local prevColorNative = reaper.GetTrackColor(track)
- local prevColorR, prevColorG, prevColorB = reaper.ColorFromNative(prevColorNative)
- local newColorR = math.max(math.min(prevColorR + offset, 255), 0)
- local newColorG = math.max(math.min(prevColorG + offset, 255), 0)
- local newColorB = math.max(math.min(prevColorB + offset, 255), 0)
- local newColorNative = reaper.ColorToNative(newColorR, newColorG, newColorB)
- reaper.SetTrackColor(track, newColorNative)
- end
- ----- END OF FUNCTIONS
- function main()
- reaper.Undo_BeginBlock()
- for i = 0, reaper.CountSelectedTracks(0) - 1 do
- local tr = reaper.GetSelectedTrack(0, i)
- local trLvl = getTrackLevel(tr)
- offsetTrackColor(tr, trLvl * colorOffset)
- end
- reaper.Undo_EndBlock(scriptName, -1)
- end
- reaper.PreventUIRefresh(1)
- main()
- reaper.PreventUIRefresh(-1)
- reaper.UpdateArrange()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement