Skip to content

Commit

Permalink
Create smandrap_Apply x db to send y on selected tracks.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
smandrap committed Oct 6, 2023
1 parent 82b9917 commit 3e604c7
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Various/smandrap_Apply x db to send y on selected tracks.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- @description Apply x db to send y on selected tracks
-- @author smandrap
-- @version 1.0
-- @donation https://paypal.me/smandrap
-- @about
-- Bassman002 request. https://forum.cockos.com/showthread.php?p=2718351#post2718351
--
-- Db to value (and viceversa) functions are taken from the forums. Can't remember where sorry.
-- If someone can point it out, i will give credit.
--
-- Usage:
-- Duplicate the script and change DB_AMOUNT and SEND_IDX to taste.
--
-- Known issues:
-- Undo doesn't work correctly

---------------------

-- CHANGE THESE:

local DB_AMOUNT = -1
local SEND_IDX = 1 -- Target send, 1 based


---------------------


local LN10_OVER_TWENTY = 0.11512925464970228420089957273422
local TWENTY_OVER_LN10 = 8.6858896380650365530225783783321
local MINUS_INFINITY_TRESHOLD = 0.0000000298023223876953125

local function DbToValue(db) return math.exp(db * LN10_OVER_TWENTY) end

local function ValueToDb(value)
if value < MINUS_INFINITY_TRESHOLD then return -150 end
return math.max(-150, math.log(value) * TWENTY_OVER_LN10)
end

local function main()
local sel_tr_cnt = reaper.CountSelectedTracks()
if sel_tr_cnt == 0 then return end

for i = 0, sel_tr_cnt - 1 do
local tr = reaper.GetSelectedTrack(0, i)
local send_vol = reaper.GetTrackSendInfo_Value(tr, 0, SEND_IDX - 1, 'D_VOL')
local new_vol = DbToValue(ValueToDb(send_vol) + DB_AMOUNT)

reaper.SetTrackSendInfo_Value(tr, 0, SEND_IDX - 1, 'D_VOL', new_vol)
end
end

reaper.Undo_BeginBlock()
main()
reaper.Undo_EndBlock("Apply "..DB_AMOUNT.." db to Send "..SEND_IDX.." on selected tracks", -1)

0 comments on commit 3e604c7

Please sign in to comment.