Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions Items Properties/Nantho_Item Auto-Gain Staging - Peak vs. RMS.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
--[[
* Provides: [nomain] spk77_Get max peak val and pos from take_function.lua > Nantho_Item Auto-Gain Staging - Peak vs. RMS.lua/spk77_Get max peak val and pos from take_function_Copy1.lua
* ReaScript Name: Item Auto-Gain Staging - Peak vs. RMS
* Links:
Forum Thread http://forum.cockos.com/showthread.php?t=184368
* About:
- Normalize selected items to -x dB RMS/LUFS/LU (x and unit specified by user imput) ;
- If those normalized items have peaks over -y dB (y specified by user), trim them down to peak at -y dB max.
* Instructions: Select items. Run.
* Screenshot:
* Author: Nantho
* Licence: GPL v3
* Forum Thread: REQ: http://forum.cockos.com/showthread.php?t=182701
* Forum Thread URI:
* REAPER: 5.0
* Extensions: spk77 Get max peak val and pos from take (function and example).lua
* Extensions: SWS extension
* Version: 1.0
--]]

--[[
* Changelog:
* v1.0 (2016-11-29)
+ Initial Release
--]]


-- Special thanks to X-Raym

-- USER CONFIG AREA -----------------------------------------------------------

threshold = -10 -- number: Default threshold to select items
direction = "+" -- "+"/"-": Select if over or below the threshold

all_items = false

popup = true -- true/false: display a pop up box

console = true -- true/false: display debug messages in the console

------------------------------------------------------- END OF USER CONFIG AREA


-- INCLUDES -----------------------------------------------------------

local info = debug.getinfo(1,'S');
script_path = info.source:match[[^@?(.*[\/])[^\/]-$]]
dofile(script_path .. "/spk77_Get max peak val and pos from take_function.lua")

-------------------------------------------------------------- INCLUDES


-- UTILITIES -------------------------------------------------------------

-- Display a message in the console for debugging
function Msg(value)
if console then
reaper.ShowConsoleMsg(tostring(value) .. "\n")
end
end


-- Save item selection
function SaveSelectedItems (table)
for i = 0, reaper.CountSelectedMediaItems(0)-1 do
table[i+1] = reaper.GetSelectedMediaItem(0, i)
end
end


--------------------------------------------------------- END OF UTILITIES


-- Main function
function main()

for i, item in ipairs(init_sel_items) do

local take = reaper.GetActiveTake(item)

if take then

local ret, max_peak_val, peak_sample_pos = get_sample_max_val_and_pos(take, true, true, true)

if ret then

if direction_string == "+" then
if max_peak_val < threshold then
reaper.SetMediaItemSelected(item, false)

else

peak = max_peak_val
item_vol = reaper.GetMediaItemTakeInfo_Value(take,"D_VOL")
item_vol_DB = 20 * ( math.log( item_vol, 10 ) )
item_diff_DB = peak - threshold
new_item_vol_DB = item_vol_DB - item_diff_DB
new_item_vol = math.exp( new_item_vol_DB * 0.115129254 )

reaper.SetMediaItemTakeInfo_Value(take ,"D_VOL" , new_item_vol)


end

else
if max_peak_val > threshold then
reaper.SetMediaItemSelected(item, false)

end
end

end

end

end

end


-- INIT

if all_items then
reaper.Main_OnCommand(40182, 0) -- Select all items
end

-- See if there is items selected
count_sel_items = reaper.CountSelectedMediaItems(0)

if count_sel_items > 0 then


if popup then
threshold_string = tostring(threshold)
direction_string = tostring(direction)
retval, retvals_csv = reaper.GetUserInputs("Peak vs. RMS", 2, "Peak Threshold (dB),Under/Over (-/+)?", threshold_string .. "," .. direction_string)

if retval then
threshold_string, direction_string = retvals_csv:match("([^,]+),([^,]+)")

if threshold_string then
threshold = tonumber(threshold_string)
end

end

end

if (retval or not popup) and threshold then

reaper.PreventUIRefresh(1)

reaper.Undo_BeginBlock() -- Begining of the undo block. Leave it at the top of your main function.

reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_NORMRMS"), 0)

init_sel_items = {}
SaveSelectedItems(init_sel_items)

main()

reaper.Undo_EndBlock("Item Auto-Gain Staging - Peak vs. RMS", -1) -- End of the undo block. Leave it at the bottom of your main function.

reaper.UpdateArrange()

reaper.PreventUIRefresh(-1)

end

end
169 changes: 169 additions & 0 deletions Items Properties/Nantho_item Auto Gain Staging - Peak vs. LUFS.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
--[[
* Provides: [nomain] spk77_Get max peak val and pos from take_function.lua > Nantho_Item Auto-Gain Staging - Peak vs. RMS.lua/spk77_Get max peak val and pos from take_function_Copy2.lua
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could go in a "Peak vs. LUFS" folder to match the script's name, rather than both Copy1+Copy2 in one "RMS" directory (and then suffixing with CopyX is no longer necessary).

* ReaScript Name: Item Auto-Gain Staging - Peak vs. LUFS
* Links:
Forum Thread http://forum.cockos.com/showthread.php?t=184368
* About:
- Normalize selected items to -x dB RMS/LUFS/LU (x and unit specified by user imput) ;
- If those normalized items have peaks over -y dB (y specified by user), trim them down to peak at -y dB max.
* Instructions: Select items. Run.
* Screenshot:
* Author: Nantho
* Licence: GPL v3
* Forum Thread: REQ: http://forum.cockos.com/showthread.php?t=182701
* Forum Thread URI:
* REAPER: 5.0
* Extensions: spk77 Get max peak val and pos from take (function and example).lua
* Extensions: SWS extension
* Version: 1.0
--]]

--[[
* Changelog:
* v1.0 (2016-11-29)
+ Initial Release
--]]

-- Special thanks to X-Raym

-- USER CONFIG AREA -----------------------------------------------------------

threshold = -10 -- number: Default threshold to select items
direction = "+" -- "+"/"-": Select if over or below the threshold

all_items = false

popup = true -- true/false: display a pop up box

console = true -- true/false: display debug messages in the console

------------------------------------------------------- END OF USER CONFIG AREA


-- INCLUDES -----------------------------------------------------------

local info = debug.getinfo(1,'S');
script_path = info.source:match[[^@?(.*[\/])[^\/]-$]]
dofile(script_path .. "/spk77_Get max peak val and pos from take_function.lua")
Copy link
Member

@cfillion cfillion May 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be changed to use the new path to the file?


-------------------------------------------------------------- INCLUDES


-- UTILITIES -------------------------------------------------------------

-- Display a message in the console for debugging
function Msg(value)
if console then
reaper.ShowConsoleMsg(tostring(value) .. "\n")
end
end


-- Save item selection
function SaveSelectedItems (table)
for i = 0, reaper.CountSelectedMediaItems(0)-1 do
table[i+1] = reaper.GetSelectedMediaItem(0, i)
end
end


--------------------------------------------------------- END OF UTILITIES


-- Main function
function main()

for i, item in ipairs(init_sel_items) do

local take = reaper.GetActiveTake(item)

if take then

local ret, max_peak_val, peak_sample_pos = get_sample_max_val_and_pos(take, true, true, true)

if ret then

if direction_string == "+" then
if max_peak_val < threshold then
reaper.SetMediaItemSelected(item, false)

else

peak = max_peak_val
item_vol = reaper.GetMediaItemTakeInfo_Value(take,"D_VOL")
item_vol_DB = 20 * ( math.log( item_vol, 10 ) )
item_diff_DB = peak - threshold
new_item_vol_DB = item_vol_DB - item_diff_DB
new_item_vol = math.exp( new_item_vol_DB * 0.115129254 )

reaper.SetMediaItemTakeInfo_Value(take ,"D_VOL" , new_item_vol)


end

else
if max_peak_val > threshold then
reaper.SetMediaItemSelected(item, false)

end
end

end

end

end

end


-- INIT

if all_items then
reaper.Main_OnCommand(40182, 0) -- Select all items
end

-- See if there is items selected
count_sel_items = reaper.CountSelectedMediaItems(0)

if count_sel_items > 0 then


if popup then
threshold_string = tostring(threshold)
direction_string = tostring(direction)
retval, retvals_csv = reaper.GetUserInputs("Peak vs. LUFS", 2, "Peak Threshold (dB),Under/Over (-/+)?", threshold_string .. "," .. direction_string)

if retval then
threshold_string, direction_string = retvals_csv:match("([^,]+),([^,]+)")

if threshold_string then
threshold = tonumber(threshold_string)
end

end

end

if (retval or not popup) and threshold then

reaper.PreventUIRefresh(1)

reaper.Undo_BeginBlock() -- Begining of the undo block. Leave it at the top of your main function.

reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_NORMALIZE_LOUDNESS_ITEMS_LU"), 0)

init_sel_items = {}
SaveSelectedItems(init_sel_items)

main()

reaper.Undo_EndBlock("Item Auto-Gain Staging - Peak vs. LUFS", -1) -- End of the undo block. Leave it at the bottom of your main function.

reaper.UpdateArrange()

reaper.PreventUIRefresh(-1)

end

end
Loading