Skip to content

Commit

Permalink
Release Track Color Layouts v1.0 (#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTalagan authored Oct 29, 2023
1 parent de40dfd commit 40c415b
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Tracks Properties/talagan_Track color layouts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--[[
@description Track color layouts
@version 1.0.0
@author Ben 'Talagan' Babut
@donation https://www.paypal.com/donate/?business=3YEZMY9D6U8NC&no_recurring=1&currency_code=EUR
@license MIT
@changelog
Initial Version
@metapackage
@provides
[nomain] talagan_Track color layouts/talagan_Track color layouts lib.lua
[main=main,midi_editor] . > talagan_Track color layout 1.lua
[main=main,midi_editor] . > talagan_Track color layout 2.lua
[main=main,midi_editor] . > talagan_Track color layout 3.lua
[main=main,midi_editor] . > talagan_Track color layout 4.lua
[data] talagan_Track color layouts/toolbar_talagan_track_color_layout_1.png > toolbar_icons/toolbar_talagan_track_color_layout_1.png
[data] talagan_Track color layouts/toolbar_talagan_track_color_layout_2.png > toolbar_icons/toolbar_talagan_track_color_layout_2.png
[data] talagan_Track color layouts/toolbar_talagan_track_color_layout_3.png > toolbar_icons/toolbar_talagan_track_color_layout_3.png
[data] talagan_Track color layouts/toolbar_talagan_track_color_layout_4.png > toolbar_icons/toolbar_talagan_track_color_layout_4.png
@screenshot
Standard use case https://i.imgur.com/KlOdiwy.gif
The tool in action https://i.imgur.com/LD8x61n.gif
@about
# Purpose
REAPER is by default limited to one color per track. What if we were able to define multiple colors for each track, each color tied to a configuration (or layout), and switch between those layouts in an instant to recolorize the whole project set of tracks ?
For example you could have one track color layout for composing, one for mixing, etc. Depending on the workflow, you could quickly switch from a color scheme to another.
This is what this small extension tries to achieve.
# How to use
Simply call the action "talagan_Track Color Layout N" to switch to Layout number N. That's all ! Now, the current Track Color Layout is N, and all track color modifications will be done in the current layout. Then call "talagan_Track Color Layout M" to switch to Layout number M. And so on.
The default, active layout is Layout 1 (for new projects or projects that have not used layouts yet).
# Saving features
All color pieces of information are stored directly on each track. Saving your project will thus also save your color layouts. They are also saved inside track templates too !
# More layouts
The install is limited to 4 layouts, but you can duplicate the script and change the number at the end to use another layout. You can virtually have as many layouts as you desire.
# Known bugs / limitations
When importing a track template, the new tracks will have the color they had at export time, and the corresponding layout at that time may not match the current project layout (ex : they were saved while being on layout 1, and your current project is currently using layout 2, so they will thus appear with the colors of layout 1 whereas they should appear with the colors of layout 2). There's a security in the script that prevents those new tracks colors from being squashed due to this incoherency and lose their layout configs. To resynchronize these new tracks with the rest of the project, just switch the layout once after import.
--]]

--[[
This file is a generic action for the Track Color Layout library.
You can duplicate it and change the number at the end of its file name
to modify the Track Color Layout to switch to.
]]--

package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path
require "talagan_Track color layouts/talagan_Track color layouts lib"
switchToTrackColorLayout(extractTrackLayoutNumFromActionName())
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
--[[
@noindex
@author Talagan
@license MIT
@about
This is the lib file for the Track Color Layout feature.
See the companion action file for details.
--]]

_DEBUG=false
function DBG(txt)
if _DEBUG then
reaper.ShowConsoleMsg(txt);
end
end

function getProjectCurrentLayoutNum()
local mtrack = reaper.GetMasterTrack();
local succ, str = reaper.GetSetMediaTrackInfo_String(mtrack,
"P_EXT:talagan_track_color_layout_current",
'',
false
);

if not succ or str == nil or str == '' then
str = "1"
end

return tonumber(str);
end

function getTrackCurrentLayoutNum(track)
local succ, str = reaper.GetSetMediaTrackInfo_String(track,
"P_EXT:talagan_track_color_layout_current",
'',
false
);

-- If there's no info of the current track's layer
-- It's probably a new track that has not yet been committed.
-- Use the project's current layout then.

if not succ or str == nil or str == '' then
return getProjectCurrentLayoutNum();
end

return tonumber(str);
end

function setCurrentLayoutNum(layout)
local mtrack = reaper.GetMasterTrack();
local succ, str = reaper.GetSetMediaTrackInfo_String(mtrack,
"P_EXT:talagan_track_color_layout_current",
tostring(layout),
true
);

local tc = reaper.GetNumTracks();
local ti = 0;
for ti = 0, tc - 1, 1 do
local track = reaper.GetTrack(0, ti);

-- Also commit on tracks individually, for later sanity checks
local succ, str = reaper.GetSetMediaTrackInfo_String(track,
"P_EXT:talagan_track_color_layout_current",
tostring(layout),
true
);
end
end

function commitCurrentLayout()

local tc = reaper.GetNumTracks();
local layout = getProjectCurrentLayoutNum();

local ti = 0;
for ti = 0, tc - 1, 1 do
local track = reaper.GetTrack(0, ti);

local trackLayout = getTrackCurrentLayoutNum(track);

if trackLayout == layout then
-- Get current col
local col = reaper.GetMediaTrackInfo_Value(track, "I_CUSTOMCOLOR");

-- Commit into the track's layer slot
local succ, str = reaper.GetSetMediaTrackInfo_String(track,
"P_EXT:talagan_track_color_layout_" .. layout,
tostring(col),
true
);
else
-- There's an incoherency ! The track was not in sync with the project.
-- It probably means that it's an imported template, we want to avoid breaking things
end

end

end

function restoreLayout(layout)
local tc = reaper.GetNumTracks();

local ti = 0;
for ti = 0, tc - 1, 1 do
local track = reaper.GetTrack(0, ti);

-- Commit into the track's layer slot
local succ, str = reaper.GetSetMediaTrackInfo_String(track,
"P_EXT:talagan_track_color_layout_" .. layout,
'',
false
);

local col = 0;
if succ then
col = tonumber(str);
end

-- Set current col
reaper.SetMediaTrackInfo_Value(track, "I_CUSTOMCOLOR", col);

end

setCurrentLayoutNum(layout);
end

function switchToTrackColorLayout(layout)
commitCurrentLayout();
restoreLayout(layout);
end

function extractTrackLayoutNumFromActionName()
local _, sfname = reaper.get_action_context()

-- Get the param inside parenthesis
return sfname.match(sfname,"([0-9]+).lua$")
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 40c415b

Please sign in to comment.