Skip to content

Commit

Permalink
Bug fix for children of folder tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
bsmith96 committed Sep 21, 2022
1 parent ff596a1 commit 2c986f5
Showing 1 changed file with 69 additions and 14 deletions.
83 changes: 69 additions & 14 deletions Routing/Toggle routing and solo to master.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
@link
Author https://www.bensmithsound.uk
Repository https://github.com/bsmith96/Reaper-Scripts
@version 1.3
@version 1.4
@changelog
# Added user identifier to provided file names
# Bug fix: successfully routes tracks in folders to master by routing and soloing the folder too
@metapackage
@provides
[main] . > bsmith96_Toggle routing and solo to master.lua
Expand All @@ -20,35 +20,90 @@
]]


-- =========================================================
-- ================= GLOBAL VARIABLES ====================
-- =========================================================

local r = reaper

-- get the script's name and directory
local scriptName = ({r.get_action_context()})[2]:match("([^/\\_]+)%.lua$")
local scriptDirectory = ({r.get_action_context()})[2]:sub(1, ({r.get_action_context()})[2]:find("\\[^\\]*$"))


-- =========================================================
-- ====================== FUNCTIONS ======================
-- =========================================================

function getParent(track)
parents = {}

parent = r.GetParentTrack(track)

while( parent ~= nil )
do
table.insert(parents, parent)
parent = r.GetParentTrack(parent)
end
return parents
end

function toggleRouteAndSolo(track)
if r.GetMediaTrackInfo_Value(track, "B_MAINSEND") == 1 then
r.SetMediaTrackInfo_Value(track, "B_MAINSEND", 0)
r.SetMediaTrackInfo_Value(track, "I_SOLO", 0)
else
r.SetMediaTrackInfo_Value(track, "B_MAINSEND", 1)
r.SetMediaTrackInfo_Value(track, "I_SOLO", 1)
end
end


-- =========================================================
-- ====================== UTILITIES ======================
-- =========================================================

-- Deliver messages and add new line in console
function dbg(dbg)
r.ShowConsoleMsg(tostring(dbg) .. "\n")
end

-- Deliver messages using message box
function msg(msg, title)
local title = title or scriptName
r.MB(tostring(msg), title, 0)
end


-- ==============================================
-- =============== MAIN ROUTINE ===============
-- ==============================================

-- count selected tracks
selectedCount = reaper.CountSelectedTracks(0)
selectedCount = r.CountSelectedTracks(0)

-- create a table for selected tracks
tracks = {}

-- get selected tracks
for i = selectedCount, 0, -1
do
track = reaper.GetSelectedTrack2(0, i, false)
track = r.GetSelectedTrack2(0, i, false)
table.insert(tracks,track)
end

reaper.Undo_BeginBlock()

r.Undo_BeginBlock()
-- toggle master routing + solo
for _, eachTrack in ipairs(tracks) do
-- toggle both based on the current state of the master send
if reaper.GetMediaTrackInfo_Value(eachTrack, "B_MAINSEND") == 1 then
reaper.SetMediaTrackInfo_Value(eachTrack, "B_MAINSEND", 0)
reaper.SetMediaTrackInfo_Value(eachTrack, "I_SOLO", 0)
else
reaper.SetMediaTrackInfo_Value(eachTrack, "B_MAINSEND", 1)
reaper.SetMediaTrackInfo_Value(eachTrack, "I_SOLO", 1)
eachParents = getParent(eachTrack)
-- toggle based on the current state of the master send
toggleRouteAndSolo(eachTrack)
-- toggle all parent tracks
if eachParents[1] ~= nil then
for __, eachParent in ipairs(eachParents) do
toggleRouteAndSolo(eachParent)
end
end
end

reaper.Undo_EndBlock("Route tracks to master", -1)
r.Undo_EndBlock(scriptName, -1)

0 comments on commit 2c986f5

Please sign in to comment.