Old 06-27-2019, 05:40 PM   #1
Alkamist
Human being with feelings
 
Join Date: Dec 2011
Posts: 458
Default ReaScript: get fx parameter index from envelope?

Hello!

Is there an easy way to get the fx parameter index from an envelope in ReaScript? Right now I have to loop through all of my fx and parameters to compare names and check the indexes. It would be nice if there was an easy way. Thanks for any help!
Alkamist is offline   Reply With Quote
Old 06-27-2019, 06:17 PM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,138
Default

If you already know which effect the envelope is attached to, you can get the parameter index from the envelope state chunk.

Code:
local track = reaper.GetTrack(0, 0)
local env = reaper.GetTrackEnvelope(track, 0)
local _, chunk = reaper.GetEnvelopeStateChunk(env, "", false)

reaper.ShowConsoleMsg(chunk)

--[[ 

spits out:

<PARMENV 4 0.000000 1.000000 0.500000
  ACT 1 -1
  VIS 1 1 1
  LANEHEIGHT 0 0
  ARM 0
  DEFSHAPE 0 -1 -1
  PT 0 0.5 0
  PT 1 0.5 0
  PT 2 0.3 0 0 1
>
]]--
The parameter index is the very first number there, so it's an easy string match:
Code:
local paramIndex = chunk:match("PARMENV (%d+)")
(Don't forget to convert it to a number afterward)
Lokasenna is offline   Reply With Quote
Old 06-27-2019, 06:27 PM   #3
Alkamist
Human being with feelings
 
Join Date: Dec 2011
Posts: 458
Default

Quote:
Originally Posted by Lokasenna View Post
If you already know which effect the envelope is attached to, you can get the parameter index from the envelope state chunk.
Thank you so much, that works perfectly! Any tips on how to get the index of the FX that the envelope is attached to?
Alkamist is offline   Reply With Quote
Old 06-27-2019, 07:41 PM   #4
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,291
Default

Not sure if this is any better, but gets fx index and the fx param index..

Code:
function Index_From_Env(env)
  local track = reaper.Envelope_GetParentTrack(env)
  local fx_count = reaper.TrackFX_GetCount(track)
  for j = 0, fx_count-1 do
    local fxparam_count = reaper.TrackFX_GetNumParams(track, j)
    for k = 0, fxparam_count-1 do
      if reaper.GetFXEnvelope(track, j, k, false) == env then
        return j,k -- returns fx_index and fx_param_index.
      end
    end
  end
end
Edgemeal is offline   Reply With Quote
Old 06-27-2019, 09:02 PM   #5
Alkamist
Human being with feelings
 
Join Date: Dec 2011
Posts: 458
Default

Quote:
Originally Posted by Edgemeal View Post
Not sure if this is any better, but gets fx index and the fx param index..

Code:
function Index_From_Env(env)
  local track = reaper.Envelope_GetParentTrack(env)
  local fx_count = reaper.TrackFX_GetCount(track)
  for j = 0, fx_count-1 do
    local fxparam_count = reaper.TrackFX_GetNumParams(track, j)
    for k = 0, fxparam_count-1 do
      if reaper.GetFXEnvelope(track, j, k, false) == env then
        return j,k -- returns fx_index and fx_param_index.
      end
    end
  end
end
That works really well. Thank you very much!
Alkamist 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 01:17 AM.


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