Much simpler code (removed redundant code) and added AUX track layout change (if track has only receives and no items).
The Rec-Arm layout change is disabled for Folder and Aux (I think nobody ever records anything in that tracks)
Code:
-------TRACKS STATE FLAGS------------
--Folder = 1
--Selected = 2
--FX = 4
--Mute = 8
--Solo = 16
--SIP = 32
--RecArm = 64
function Main()
-- COUNT TRACKS
count_tracks = reaper.CountTracks(0)
-- LOOP FOR EVERY TRACK
for i = 0, count_tracks -1 do
track = reaper.GetTrack(0, i)
retval, TrackState = reaper.GetTrackState(track)
count_items_track = reaper.CountTrackMediaItems(track)
Receive = reaper.GetTrackNumSends(track, -1)
----------------TRACK HAS RECEIVES ? ----------------------------
if Receive > 0 then
HasReceive = 1
else
HasReceive = 0
end
-------------------TRACK STATES---------------------------------
-------------------AUX TRACK-----------------------------------
if HasReceive == 1 and (TrackState &4) == 4 then
Aux = 1
else
Aux = 0
end
---------------------------------------------------------------
-------------------FOLDER TRACK--------------------------------
if (TrackState &1) == 1 then
Folder = 1
else
Folder = 0
end
---------------------------------------------------------------
-------------------REC-ARM TRACK-------------------------------
if (TrackState &64) == 64 then
RecArm = 1
else
RecArm = 0
end
---------------------------------------------------------------
-- LOOP FOR EVERY ITEM
for j = 0, count_items_track -1 do
item = reaper.GetTrackMediaItem(track, j)
-- CHECK THE FIRST TAKE OF ITEM TO DETERMINE SOURCE TYPE
take = reaper.GetMediaItemTake(item, 0)
source = reaper.GetMediaItemTake_Source(take)
take_type = reaper.GetMediaSourceType(source, "test")
_G["take_type"..j] = take_type
---- TAKE TYPES -----------------------------------------
if take_type == "MIDI" then
RTakeType = "M"
elseif take_type == "VIDEO" then
RTakeType = "V"
else
RTakeType = "A"
end
---- TRACK TYPES ----------------------------------------
end
item_check = 1 --ITEMS IN TRACK ARE CONSIDERED TO BE ALL SIMILAR
if count_items_track >= 2 then
--CHECK IF SOME ITEMS IN TRACK DON'T MATCH
for l = 0, count_items_track -2 do
m = (l + 1)
if take_type0 ~= _G["take_type"..m] then
reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
item_check = 0
break
end
end
end
--IF ALL THE ITEMS MATCH CHECK THE SOURCE TYPE AND CHANGE TRACK LAYOUT
----------------------------TRACK HAS ITEMS ------------------------------------------
if item_check == 1 and count_items_track > 0 and RecArm == 0 then
---------MIDI---------------------------------------------------------------------
if RTakeType == "M" then
reaper.BR_SetMediaTrackLayouts(track, "", "aa - Standard")
---------VIDEO--------------------------------------------------------------------
elseif RTakeType == "V" then
reaper.BR_SetMediaTrackLayouts(track, "", "ba - Small")
---------AUDIO--------------------------------------------------------------------
elseif RTakeType == "A" then
reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
end
end
----------------------------TRACK HAS ITEMS ------------------------------------------
------------------------NO ITEMS -------------------------------------------------
--------FOLDER--------------------------------------------------------------------
if count_items_track == 0 then
if Folder == 1 then
reaper.BR_SetMediaTrackLayouts(track, "", "ai --- Standard Live Recording")
--------AUX - HAS RECEIVES AND FX-------------------------------------------------
elseif Aux == 1 then
reaper.BR_SetMediaTrackLayouts(track, "", "ag --- Standard Compact")
--------DEFAULT LAYOUT-------------------------------------------------------------
elseif RecArm == 0 then
reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
end
end
-------------------------------**-------------------------------------------------
---------REC ARM LAYOUT------------------------------------------------------------
if count_items_track >= 0 and RecArm == 1 and Folder ~= 1 and Aux ~= 1 then
reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")
end
---------REC ARM LAYOUT------------------------------------------------------------
end
reaper.defer(Main)
end
Main()
Folders and Aux don't change layout on Rec-Arm,so you know what type of track it is