Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 10-14-2020, 03:20 PM   #1
Steviebone
Human being with feelings
 
Join Date: Jul 2018
Posts: 753
Default increasing/decreasing the volume envelope on a group of selected and visible tracks

I was about to write a very simple script and I thought before I went to the trouble I would double check that someone hasn't already done the work. I need a script that uses the SWS function of increasing/decreasing the volume envelope on a group of selected and visible tracks... very simple.

The algorithm would look like this:

Code:
loop thru selected and visible tracks (visible in TCP)

    place track in read mode (protect all other envelopes?)	

    select volume envelope for track
    select all points in track or within time selection if exists

    increase/decrease volume envelope by x db (SWS call)		

endloop
Might this already exist somewhere?
Steviebone is offline   Reply With Quote
Old 10-15-2020, 07:34 AM   #2
Steviebone
Human being with feelings
 
Join Date: Jul 2018
Posts: 753
Default

I ended up modifying a script I already had for displaying selected volume envelopes

Code:
-- Script: SK_AdjustVolumeEnvelopesForSelectedTracks.lua
-- this program adjusts a group of volume envelopes for selected tracks up or down using SWS actions
-- note that in this program the use of the word "folder track" is not synonymous with a standard reaper folder.
-- folder track and name track are special types of tracks in my reaper projects 
-- that will be irrelevant to you unless you're using my track naming scheme (you aren't)
-- To use this program change the passed parameter in the main function adjust_vol() to one of the following:
-- down01, down05, down1, down5, down10
-- up01, up02, up1, up5, up10
-- You can also comment out the console messages if you like

function adjust_vol(volmode)

  reaper.ShowConsoleMsg(volmode .. '\n')    

  local sel_tracks = {}
  
  
  -- Check to see if any tracks are selected
  local track_cnt = reaper.CountSelectedTracks(0)
  if track_cnt < 1 then 
    reaper.ShowConsoleMsg('No tracks selected\n')    
    return 
  end
  
  local strackct = 0
  local skipct = 0
  local showct = 0
  
  -- Get selected tracks
 
  for i = track_cnt-1, 0, -1 do
    local track = reaper.GetSelectedTrack(0, i)
    sel_tracks[i+1] = track
    reaper.SetMediaTrackInfo_Value( track, "I_SELECTED", 0 )
    strackct = strackct + 1
  end
  
  reaper.ShowConsoleMsg(tostring(strackct) .. ' tracks selected\n')    
  
  reaper.ShowConsoleMsg('Working...\n')    
  
  -- Get SWS command ID
  
  if volmode == 'down01' then
     SWS_cmd = reaper.NamedCommandLookup("_BR_DEC_VOL_ENV_PT_01db")
  elseif volmode == 'down05' then
     SWS_cmd = reaper.NamedCommandLookup("_BR_DEC_VOL_ENV_PT_05db")
  elseif volmode == 'down1' then
     SWS_cmd = reaper.NamedCommandLookup("_BR_DEC_VOL_ENV_PT_1db")
  elseif volmode == 'down5' then
     SWS_cmd = reaper.NamedCommandLookup("_BR_DEC_VOL_ENV_PT_5db")
  elseif volmode == 'down10' then
     SWS_cmd = reaper.NamedCommandLookup("_BR_DEC_VOL_ENV_PT_10db")
  elseif volmode == 'up01' then  
     SWS_cmd = reaper.NamedCommandLookup("_BR_INC_VOL_ENV_PT_01db")
  elseif volmode == 'up05' then  
     SWS_cmd = reaper.NamedCommandLookup("_BR_INC_VOL_ENV_PT_05db")
  elseif volmode == 'up1' then  
     SWS_cmd = reaper.NamedCommandLookup("_BR_INC_VOL_ENV_PT_1db")
  elseif volmode == 'up5' then  
     SWS_cmd = reaper.NamedCommandLookup("_BR_INC_VOL_ENV_PT_5db")
  elseif volmode == 'up10' then  
     SWS_cmd = reaper.NamedCommandLookup("_BR_INC_VOL_ENV_PT_10db")
  end
  
  -- Check for a command ID error
  
  if SWS_cmd == nil then
    reaper.ShowConsoleMsg('Error...\n')    
    return false
  end
  
  -- Loop through the selected tracks
  
  for i = 1, #sel_tracks do

    local track = sel_tracks[i]

    reaper.SetMediaTrackInfo_Value( track, "I_SELECTED", 1 )
    
    if is_folder_track(track) == false and is_name_track(track) == false then
    
      reaper.Main_OnCommand(41866, 0) -- Select vol envelope
      reaper.Main_OnCommand(40332, 0) -- Select all points
      
      reaper.Main_OnCommand(SWS_cmd,0)
      
      reaper.Main_OnCommand(40331, 0) -- Unselect all points
      
      showct = showct + 1
      
   else
      skipct = skipct + 1
   end  
     
    reaper.SetMediaTrackInfo_Value( track, "I_SELECTED", 0 )
    
  end 

  reaper.ShowConsoleMsg(tostring(showct) .. ' tracks adjusted\n')          
  reaper.ShowConsoleMsg(tostring(skipct) .. ' folders skipped\n')
  
  -- reset 
  for i = 1, #sel_tracks do
    local track = sel_tracks[i]
    reaper.SetMediaTrackInfo_Value(track, "I_SELECTED", 1 )
  end 

end

function is_name_track(vtrack) 

  -- This function checks to see if this is the first track in the project. 
  -- In my projects this is a special track that always displays information about the tracks currently displayed
  -- You can safely comment out this function. It is intended for projects that use a certain naming convention.
  
  local rval = false

  vnum = reaper.GetMediaTrackInfo_Value(vtrack, 'IP_TRACKNUMBER') -- get track number index 
  if vnum == 1.0 then
    reaper.ShowConsoleMsg('Name Track skipped\n')
    rval = true
  else
    rval = false
  end 
  
  return rval

end


function is_folder_track(vtrack)

  -- This function checks to see if this is a folder track in the project. 
  -- In my projects this is a special track that is for visual purposes only
  -- it is NOT a standard reaper folder track
  -- in normal reaper projects this will simply be bypassed
  -- You can safely comment out this function. It is intended for projects that use a certain naming convention.


  local retval, name = reaper.GetTrackName(vtrack, "") -- get track name
  if retval then

    local d, j = string.find(name, '%(F') -- search for tag
    if d ~= nil then
      return true
    else
      return false
    end

  end
    
end


function main()

  -- housekeeping
  reaper.ClearConsole()
  
  -- set undo/refresh
  reaper.Undo_BeginBlock2( 0 )
  reaper.PreventUIRefresh( 1 )
  
  -- set this parameter with the action you want
  -- down01, down05, down1, down5, down10
  -- up01, up02, up1, up5, up10

  adjust_vol('up5')

  reaper.TrackList_AdjustWindows( false )
  reaper.UpdateArrange()
  
  -- reset undo/refresh
  reaper.PreventUIRefresh( -1 )
  reaper.Undo_EndBlock2( 0, "Adjust Vol", 1 )

end

main()
Edit: There was an error that has been corrected: down05 was listed twice instead of down05 and down5, -.5 decibel and -5db respectively

Last edited by Steviebone; 10-17-2020 at 05:51 PM.
Steviebone is offline   Reply With Quote
Old 10-15-2020, 06:44 PM   #3
Steviebone
Human being with feelings
 
Join Date: Jul 2018
Posts: 753
Default

After making a few more minor modifications to the above script to suit my own particular environment I am moving on. This script has allowed me to experiment with different amounts of headroom on a large scale with very little effort.

Avoiding creep in a mix can be difficult, especially when writing and creating the production together on the fly. Kind of impossible for me to know where everything is going until I'm done writing it. This allows me to adjust the overall headroom of a mix very quickly without upsetting the balance. Then as the mix nears completion I can also increase the overall levels before the busses until I get to the sweet spot for final output for mastering. I don't like to depend on the output busses only for this.

This script makes it easier for me to approach these issues in a manner suited to my workflow, which is likely very different than most.

I don't know if this script will be of any use to anyone else in particular, certainly most of the people reading this particular forum will be much more advanced than I, and need no help from me. If on the off chance someone would like me to finish cleaning this up for more generic use just let me know.

Note: To use make 10 copies of the script, changing the parameter at the very bottom for each of the SWS cmds, down01, down05, down5, down10, up01, up05, etc., name them appropriately, load them as scripts in the action pane and then assign them to button or keypresses like any other action. I use my launchpad for this. Works great!

One other note: this script ignores track1 because that is a special track in my projects. That may be a problem for you when you select track1. If you find the script useful just comment out the is_name function. If you need help, PM me and I can get you a revised generic script.

Last edited by Steviebone; 10-17-2020 at 05:57 PM.
Steviebone is offline   Reply With Quote
Old 10-17-2020, 06:03 PM   #4
Steviebone
Human being with feelings
 
Join Date: Jul 2018
Posts: 753
Default

Here is a revised version for generic use. I am not in my studio presently and this revision has NOT been tested. If you find errors let me know. This revision merely comments out references to tracks I need to "ignore automatically" in my setup.

Code:
-- Script: SK_AdjustVolumeEnvelopesForSelectedTracks.lua
-- this program adjusts a group of volume envelopes for selected tracks up or down using SWS actions
-- this is a revised script for use in generic environment
-- I have not tested this script yet but it should work fine.
-- I have removed the references to my name track (track1) and folder tracks which are not typical
-- folder tracks in my projects. Note that if you include fiolder or buss tracks in your selections
-- they will be adjusted as well... probably NOT what your are looking for unless you are working on 
-- ONLY buss tracks..
-- To use this program change the passed parameter in the main function adjust_vol() to one of the following:
-- down01, down05, down1, down5, down10
-- up01, up02, up1, up5, up10
-- You can also comment out the console messages if you like

function adjust_vol(volmode)

  reaper.ShowConsoleMsg(volmode .. '\n')    

  local sel_tracks = {}
  
  
  -- Check to see if any tracks are selected
  local track_cnt = reaper.CountSelectedTracks(0)
  if track_cnt < 1 then 
    reaper.ShowConsoleMsg('No tracks selected\n')    
    return 
  end
  
  local strackct = 0
  local skipct = 0
  local showct = 0
  
  -- Get selected tracks
 
  for i = track_cnt-1, 0, -1 do
    local track = reaper.GetSelectedTrack(0, i)
    sel_tracks[i+1] = track
    reaper.SetMediaTrackInfo_Value( track, "I_SELECTED", 0 )
    strackct = strackct + 1
  end
  
  reaper.ShowConsoleMsg(tostring(strackct) .. ' tracks selected\n')    
  
  reaper.ShowConsoleMsg('Working...\n')    
  
  -- Get SWS command ID
  
  if volmode == 'down01' then
     SWS_cmd = reaper.NamedCommandLookup("_BR_DEC_VOL_ENV_PT_01db")
  elseif volmode == 'down05' then
     SWS_cmd = reaper.NamedCommandLookup("_BR_DEC_VOL_ENV_PT_05db")
  elseif volmode == 'down1' then
     SWS_cmd = reaper.NamedCommandLookup("_BR_DEC_VOL_ENV_PT_1db")
  elseif volmode == 'down5' then
     SWS_cmd = reaper.NamedCommandLookup("_BR_DEC_VOL_ENV_PT_5db")
  elseif volmode == 'down10' then
     SWS_cmd = reaper.NamedCommandLookup("_BR_DEC_VOL_ENV_PT_10db")
  elseif volmode == 'up01' then  
     SWS_cmd = reaper.NamedCommandLookup("_BR_INC_VOL_ENV_PT_01db")
  elseif volmode == 'up05' then  
     SWS_cmd = reaper.NamedCommandLookup("_BR_INC_VOL_ENV_PT_05db")
  elseif volmode == 'up1' then  
     SWS_cmd = reaper.NamedCommandLookup("_BR_INC_VOL_ENV_PT_1db")
  elseif volmode == 'up5' then  
     SWS_cmd = reaper.NamedCommandLookup("_BR_INC_VOL_ENV_PT_5db")
  elseif volmode == 'up10' then  
     SWS_cmd = reaper.NamedCommandLookup("_BR_INC_VOL_ENV_PT_10db")
  end
  
  -- Check for a command ID error
  
  if SWS_cmd == nil then
    reaper.ShowConsoleMsg('Error...\n')    
    return false
  end
  
  -- Loop through the selected tracks
  
  for i = 1, #sel_tracks do

    local track = sel_tracks[i]

    reaper.SetMediaTrackInfo_Value( track, "I_SELECTED", 1 )
    
--    if is_folder_track(track) == false and is_name_track(track) == false then
    
      reaper.Main_OnCommand(41866, 0) -- Select vol envelope
      reaper.Main_OnCommand(40332, 0) -- Select all points
      
      reaper.Main_OnCommand(SWS_cmd,0)
      
      reaper.Main_OnCommand(40331, 0) -- Unselect all points
      
      showct = showct + 1
      
--   else
--      skipct = skipct + 1
--   end  
     
    reaper.SetMediaTrackInfo_Value( track, "I_SELECTED", 0 )
    
  end 

  reaper.ShowConsoleMsg(tostring(showct) .. ' tracks adjusted\n')          
  reaper.ShowConsoleMsg(tostring(skipct) .. ' folders skipped\n')
  
  -- reset 
  for i = 1, #sel_tracks do
    local track = sel_tracks[i]
    reaper.SetMediaTrackInfo_Value(track, "I_SELECTED", 1 )
  end 

end

function is_name_track(vtrack) 

  -- This function checks to see if this is the first track in the project. 
  -- In my projects this is a special track that always displays information about the tracks currently displayed
  -- You can safely comment out this function. It is intended for projects that use a certain naming convention.
  
  local rval = false

  vnum = reaper.GetMediaTrackInfo_Value(vtrack, 'IP_TRACKNUMBER') -- get track number index 
  if vnum == 1.0 then
    reaper.ShowConsoleMsg('Name Track skipped\n')
    rval = true
  else
    rval = false
  end 
  
  return rval

end


function is_folder_track(vtrack)

  -- This function checks to see if this is a folder track in the project. 
  -- In my projects this is a special track that is for visual purposes only
  -- it is NOT a standard reaper folder track
  -- in normal reaper projects this will simply be bypassed
  -- You can safely comment out this function. It is intended for projects that use a certain naming convention.


  local retval, name = reaper.GetTrackName(vtrack, "") -- get track name
  if retval then

    local d, j = string.find(name, '%(F') -- search for tag
    if d ~= nil then
      return true
    else
      return false
    end

  end
    
end


function main()

  -- housekeeping
  reaper.ClearConsole()
  
  -- set undo/refresh
  reaper.Undo_BeginBlock2( 0 )
  reaper.PreventUIRefresh( 1 )
  
  -- set this parameter with the action you want
  -- down01, down05, down1, down5, down10
  -- up01, up02, up1, up5, up10

  adjust_vol('up5')

  reaper.TrackList_AdjustWindows( false )
  reaper.UpdateArrange()
  
  -- reset undo/refresh
  reaper.PreventUIRefresh( -1 )
  reaper.Undo_EndBlock2( 0, "Adjust Vol", 1 )

end

main()
Steviebone is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 10:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.