Skip to content

Instantly share code, notes, and snippets.

@mumblequatch
Created May 19, 2026 18:08
Show Gist options
  • Select an option

  • Save mumblequatch/0d4ee38eecafcef574d0625e9f1d7aaf to your computer and use it in GitHub Desktop.

Select an option

Save mumblequatch/0d4ee38eecafcef574d0625e9f1d7aaf to your computer and use it in GitHub Desktop.
Reaper Lua: insert pink-noise track below selected, 1/2 -> 3/4 send
-- Insert a pink-noise calibration track immediately below the selected track.
-- Adds Liteon/pinknoisegen, disables master send, and routes the new track's
-- 1/2 to the selected track's 3/4 (auto-widening the parent to 4ch if needed).
local sel = reaper.GetSelectedTrack(0, 0)
if not sel then
reaper.ShowMessageBox("No track selected.", "Add Pink Noise Track Below", 0)
return
end
reaper.Undo_BeginBlock()
reaper.PreventUIRefresh(1)
local sel_num = reaper.GetMediaTrackInfo_Value(sel, "IP_TRACKNUMBER") -- 1-based
local insert_idx = math.floor(sel_num) -- 0-based insert position = immediately after sel
reaper.InsertTrackAtIndex(insert_idx, true)
local new_tr = reaper.GetTrack(0, insert_idx)
reaper.GetSetMediaTrackInfo_String(new_tr, "P_NAME", "Pink Noise", true)
-- Parent track must have at least 4 channels for 3/4 destination
if reaper.GetMediaTrackInfo_Value(sel, "I_NCHAN") < 4 then
reaper.SetMediaTrackInfo_Value(sel, "I_NCHAN", 4)
end
-- Disable master/parent send on the pink noise track
reaper.SetMediaTrackInfo_Value(new_tr, "B_MAINSEND", 0)
-- Add pink noise generator (Liteon stock JS)
local fx = reaper.TrackFX_AddByName(new_tr, "Liteon/pinknoisegen", false, -1)
if fx < 0 then
fx = reaper.TrackFX_AddByName(new_tr, "pinknoisegen", false, -1)
end
if fx < 0 then
reaper.ShowMessageBox("Could not add pinknoisegen JS effect.", "Add Pink Noise Track Below", 0)
end
-- Send new track 1/2 -> selected track 3/4
local send_idx = reaper.CreateTrackSend(new_tr, sel)
reaper.SetTrackSendInfo_Value(new_tr, 0, send_idx, "I_SRCCHAN", 0) -- 0 = 1/2 stereo
reaper.SetTrackSendInfo_Value(new_tr, 0, send_idx, "I_DSTCHAN", 2) -- 2 = 3/4 stereo
reaper.PreventUIRefresh(-1)
reaper.TrackList_AdjustWindows(false)
reaper.UpdateArrange()
reaper.Undo_EndBlock("Add pink noise track below selected", -1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment