Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Bug Reports

Reply
 
Thread Tools Display Modes
Old 10-14-2021, 03:57 AM   #1
sockmonkey72
Human being with feelings
 
sockmonkey72's Avatar
 
Join Date: Sep 2021
Location: Berlin
Posts: 941
Default API: TakeFX_GetParamFromIdent returns 1 (FIXED)

AFAICT TakeFX_GetParamFromIdent is always returning 1, rather than the index of the parameter specified by the identifier (":wet" for instance).

TrackFX_GetParamFromIdent is working for me.

Here's a script to test with:

Code:
-- @description amagalma_Toggle wet 0-100% (or current value) for focused FX
-- @author amagalma
-- @version 1.0
-- @about
--   # Toggles wet from 0% to current value (or 100%) for the FX in focus

local reaper, math = reaper, math

local focus, track, item, fx = reaper.GetFocusedFX()

function round(num, numDecimalPlaces)
    local mult = 10^(numDecimalPlaces or 0)
    if num >= 0 then return math.floor(num * mult + 0.5) / mult
    else return math.ceil(num * mult - 0.5) / mult end
end


if focus == 1 then --------------- TRACK FX ---------------

  if track == 0 then
    track = reaper.GetMasterTrack(0)
  else
    track = reaper.GetTrack(0, track-1)
  end
  
  -- check if it is really visible
  local hwnd = reaper.TrackFX_GetFloatingWindow( track, fx )
  local chain_vis = reaper.TrackFX_GetChainVisible( track )
  if hwnd or chain_vis > -1 then
    
    -- this is working on for me
    local wetparam = reaper.TrackFX_GetParamFromIdent( track, fx, ":wet" )
    local val = reaper.TrackFX_GetParam( track, fx, wetparam )
    local fxguid = reaper.TrackFX_GetFXGUID( track, fx )
    local _, name = reaper.TrackFX_GetFXName( track, fx, "" )
    
    if val > 0 then -- store value and set wet to 0%
      reaper.SetExtState( "ToggleWet", fxguid, val, false )
      reaper.TrackFX_SetParam( track, fx, wetparam, 0 )
      reaper.Undo_OnStateChangeEx( "Set " .. name .. " to 0% wet", 2, -1 )
    else -- set to previous value if exists or 100%
      if reaper.HasExtState( "ToggleWet" , fxguid ) then
        val = tonumber(reaper.GetExtState( "ToggleWet", fxguid ))
      else
        val = 1
      end
      reaper.TrackFX_SetParam( track, fx, wetparam, val )
      reaper.DeleteExtState( "ToggleWet", fxguid, false )
      val = round (val * 100)
      reaper.Undo_OnStateChangeEx( "Set " .. name .. " to " .. val .. "% wet", 2, -1 )
    end    
  
  else
  
    reaper.defer(function () end)
    
  end
  
elseif focus == 2 then --------------- TAKE FX ---------------

  item = reaper.GetMediaItem(0, item)
  track = reaper.GetMediaItemTrack(item)
  local take = reaper.GetMediaItemTake(item, fx >> 16)
  -- check if it is really visible
  local hwnd = reaper.TakeFX_GetFloatingWindow( take, fx )
  local chain_vis = reaper.TakeFX_GetChainVisible( take )
  if hwnd or chain_vis > -1 then
  
    -- reaper.TakeFX_GetParamFromIdent is returning 1 rather than the correct index
    -- compare with reaper.TrackFX_GetParamFromIdent, above, which is returning the correct index

    local wetparam = reaper.TakeFX_GetParamFromIdent( take, fx, ":wet" )
    local val = reaper.TakeFX_GetParam( take, fx, wetparam )
    local fxguid = reaper.TakeFX_GetFXGUID( take, fx )
    local _, name = reaper.TakeFX_GetFXName( take, fx, "" )
    
    if val > 0 then -- store value and set wet to 0%
      reaper.SetExtState( "ToggleWet", fxguid, val, false )
      reaper.TakeFX_SetParam( take, fx, wetparam, 0 )
      reaper.Undo_OnStateChangeEx( "Set " .. name .. " to 0% wet", 4, -1 )
    else -- set to previous value if exists or 100%
      if reaper.HasExtState( "ToggleWet" , fxguid ) then
        val = tonumber(reaper.GetExtState( "ToggleWet", fxguid ))
      else
        val = 1
      end
      reaper.TakeFX_SetParam( take, fx, wetparam, val )
      reaper.DeleteExtState( "ToggleWet", fxguid, false )
      val = round (val * 100)
      reaper.Undo_OnStateChangeEx( "Set " .. name .. " to " .. val .. "% wet", 4, -1 )
    end
  
  else
  
  reaper.defer(function () end)
  
  end
  
elseif focus == 0 then

  reaper.defer(function () end)
  
end
sockmonkey72 is offline   Reply With Quote
Old 10-14-2021, 04:03 AM   #2
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 13,708
Default

Yes, that's a bug. Fixing, thanks for the report.
schwa is offline   Reply With Quote
Old 10-14-2021, 09:36 AM   #3
sockmonkey72
Human being with feelings
 
sockmonkey72's Avatar
 
Join Date: Sep 2021
Location: Berlin
Posts: 941
Default

Quote:
Originally Posted by schwa View Post
Yes, that's a bug. Fixing, thanks for the report.
Thanks! Fix confirmed in today's prerelease.
sockmonkey72 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 09:07 PM.


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