Skip to content

Commit

Permalink
Add script for changing items' volume linearly
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyBars3k committed Oct 20, 2023
1 parent 54cc2fd commit 2ee6a41
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- @noindex

reaper.Undo_BeginBlock()
reaper.PreventUIRefresh(1)

local num_selected_items, retval, target_volume_str, target_volume, first_item, last_item, first_item_vol, last_item_vol, first_item_pos, last_item_pos, slope

num_selected_items = reaper.CountSelectedMediaItems(0)

if num_selected_items < 2 then
return
end

retval, target_volume_str = reaper.GetUserInputs("Set Volume", 1, "Target Volume for Last Item (dB):", "")

if not retval then
return
end

target_volume = tonumber(target_volume_str)

if target_volume == nil then
return
end

first_item = reaper.GetSelectedMediaItem(0, 0)
last_item = reaper.GetSelectedMediaItem(0, num_selected_items - 1)
first_item_vol = reaper.GetMediaItemInfo_Value(first_item, "D_VOL")
last_item_vol = 10 ^ (target_volume / 20)
first_item_pos = reaper.GetMediaItemInfo_Value(first_item, "D_POSITION")
last_item_pos = reaper.GetMediaItemInfo_Value(last_item, "D_POSITION")
slope = (last_item_vol - first_item_vol) / (last_item_pos - first_item_pos)

for i = 0, num_selected_items - 1 do
local item, item_pos, new_vol

item = reaper.GetSelectedMediaItem(0, i)
item_pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
new_vol = first_item_vol + slope * (item_pos - first_item_pos)

reaper.SetMediaItemInfo_Value(item, "D_VOL", new_vol)
end

reaper.UpdateTimeline()
reaper.PreventUIRefresh(-1)
reaper.Undo_EndBlock("MB_Change selected items' volume linearly from earliest item volume to entered target volume", -1)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
-- @description MB_Utilities: Various utility scripts for Reaper
-- @author MonkeyBars
-- @version 1.4.2
-- @changelog Make edit highest marker script work when only 1 marker
-- @version 1.5
-- @changelog Add script for changing items' volume linearly
-- @provides [main] .
-- [main] MB_Change selected items' volume linearly from earliest item volume to entered target volume.lua
-- [main] MB_Create new autoincremented folder and save project.lua
-- [main] MB_Create new pair of grouped tracks with MIDI & stereo audio routing to & from selected (virtual instrument) tracks.lua
-- [main] MB_Deselect tracks if child track(s) & select their direct parent folder track(s).lua
Expand Down

0 comments on commit 2ee6a41

Please sign in to comment.