Last active
March 14, 2023 14:03
-
-
Save jtackaberry/6d011d233b22806aec9c to your computer and use it in GitHub Desktop.
REAPER script: Toggle FX online, bypass, and track lock for selected tracks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Version 1.1 | |
-- | |
-- This script toggles FX online/offline, FX bypass, and track lock on | |
-- all selected tracks. | |
-- | |
-- SWS cycle actions can be used for toggling only online and lock, but | |
-- not if you also want to include FX bypass. | |
-- SWS is required (http://www.sws-extension.org/) | |
-- | |
-- Released to the public domain. | |
-- Select (1) or unselect (0) the given tracks. | |
function setSelected(tracks, selected) | |
for i, track in ipairs(tracks) do | |
reaper.SetMediaTrackInfo_Value(track, "I_SELECTED", selected) | |
end | |
end | |
function fixRecordArmBug() | |
-- Bug workaround: sometimes, after the FX have loaded, the track does not honor | |
-- automatic record arming. If the track is not record armed, then toggle | |
-- selection to force it. | |
for trackIdx = 0, reaper.CountSelectedTracks(0) - 1 do | |
track = reaper.GetSelectedTrack(0, trackIdx) | |
if reaper.GetMediaTrackInfo_Value(track, "I_RECARM") == 0 then | |
reaper.SetTrackSelected(track, false) | |
reaper.SetTrackSelected(track, true) | |
end | |
end | |
end | |
function main() | |
if reaper.NamedCommandLookup('_SWS_TOGSELMASTER') == 0 then | |
reaper.ShowMessageBox("Error: script requires the SWS extensions (www.sws-extension.org).", | |
"SWS extension missing", 0) | |
return | |
end | |
-- Determine which tracks need to be unlocked and brought online. | |
-- Any track with FX bypassed qualifies. | |
numSelected = reaper.CountSelectedTracks(0) | |
needUnlock = {} | |
for idx = 0, numSelected - 1 do | |
track = reaper.GetSelectedTrack(0, idx) | |
if reaper.GetMediaTrackInfo_Value(track, "I_FXEN") <= 0 then | |
needUnlock[#needUnlock+1] = track | |
end | |
end | |
reaper.PreventUIRefresh(1) | |
reaper.Undo_BeginBlock2(0) | |
-- Unlock all tracks initially. | |
-- Track: Unlock track controls | |
reaper.Main_OnCommandEx(41313, 0, 0) | |
-- Track: Toggle all FX online/offline for selected tracks | |
reaper.Main_OnCommandEx(reaper.NamedCommandLookup('_S&M_FXOFFALL'), 0, 0) | |
-- Track: Toggle FX bypass for selected tracks | |
reaper.Main_OnCommandEx(8, 0, 0) | |
-- Track: Toggle mute for selected tracks | |
reaper.Main_OnCommandEx(6, 0, 0) | |
-- Now we need to lock the tracks that have been offlined. Unfortunately | |
-- there is no API for doing this on individual tracks. The best we can do | |
-- is invoke an existing action. So, here we unselect all tracks that need | |
-- to stay unlocked, invoke the "lock track controls" action, and then reselect | |
-- the temporarily unselected tracks. | |
if #needUnlock < numSelected then | |
setSelected(needUnlock, 0) | |
-- Track: Lock track controls | |
reaper.Main_OnCommandEx(41312, 0, 0) | |
setSelected(needUnlock, 1) | |
end | |
fixRecordArmBug() | |
reaper.Undo_EndBlock2(0, "Toggle FX online/bypass/lock for selected tracks", -1) | |
reaper.PreventUIRefresh(-1) | |
end | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment