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

Reply
 
Thread Tools Display Modes
Old 07-01-2020, 03:46 AM   #1
pigstoe
Human being with feelings
 
Join Date: Apr 2020
Posts: 44
Default Still cannot get indices of selected FXs in track FX chain view by ReaScript?[SOLVED]

In my script, indices of selected FXs in track FX chain view are needed. And I found this thread.
https://forum.cockos.com/showthread.php?t=168718

Is there still no functions for this? And still impossible to get this information?

Last edited by pigstoe; 07-09-2020 at 04:48 PM.
pigstoe is offline   Reply With Quote
Old 07-01-2020, 08:06 AM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 3,795
Default

Using CF_GetTrackFXChain and CF_EnumSelectedFX from SWS 2.12:
Code:
function enumSelectedTrackFX(track)
  local fxChain = reaper.CF_GetTrackFXChain(track)
  local i = -1

  return function()
    i = reaper.CF_EnumSelectedFX(fxChain, i)
    if i < 0 then i = nil end
    return i
  end
end

local track = reaper.GetTrack(nil, 0)
for i in enumSelectedTrackFX(track) do
  reaper.ShowConsoleMsg(string.format('%d\n', i))
end

Last edited by cfillion; 07-01-2020 at 08:12 AM.
cfillion is offline   Reply With Quote
Old 07-01-2020, 07:08 PM   #3
pigstoe
Human being with feelings
 
Join Date: Apr 2020
Posts: 44
Default

Quote:
Originally Posted by cfillion View Post
Using CF_GetTrackFXChain and CF_EnumSelectedFX from SWS 2.12:
Code:
function enumSelectedTrackFX(track)
  local fxChain = reaper.CF_GetTrackFXChain(track)
  local i = -1

  return function()
    i = reaper.CF_EnumSelectedFX(fxChain, i)
    if i < 0 then i = nil end
    return i
  end
end

local track = reaper.GetTrack(nil, 0)
for i in enumSelectedTrackFX(track) do
  reaper.ShowConsoleMsg(string.format('%d\n', i))
end
I tested your code and found a bug for CF_EnumSelectedFX() function. If CF_EnumSelectedFX() is used at the track which has track name, it always returns 0. This function works fine only at unnamed track.

Thank you, anyway. I'm going to report it.
pigstoe is offline   Reply With Quote
Old 07-01-2020, 07:13 PM   #4
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 3,795
Default

Update SWS to 2.12. https://www.sws-extension.org/download/pre-release/
cfillion is offline   Reply With Quote
Old 07-01-2020, 07:32 PM   #5
pigstoe
Human being with feelings
 
Join Date: Apr 2020
Posts: 44
Default

Quote:
Originally Posted by cfillion View Post
After updated, It always returns 0, even at unnamed track.
pigstoe is offline   Reply With Quote
Old 07-01-2020, 08:06 PM   #6
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 3,795
Default

Indices are zero-based so a return value of 0 means the first FX is selected (above the given starting index). Is that value incorrect?

Last edited by cfillion; 07-01-2020 at 08:21 PM.
cfillion is offline   Reply With Quote
Old 07-01-2020, 08:36 PM   #7
pigstoe
Human being with feelings
 
Join Date: Apr 2020
Posts: 44
Default

Quote:
Originally Posted by cfillion View Post
Indices are zero-based so a return value of 0 means the first FX is selected (above the given starting index). Is that value incorrect?
Incorrect. When I select nothing, everything, something and even when there is no fx in track, it always returns 0.
pigstoe is offline   Reply With Quote
Old 07-01-2020, 08:47 PM   #8
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 3,795
Default

Mhh... I can't duplicate that here. Can you share a minimal script (assuming it's not exactly as in the snippet above) and/or a minimal project that produce that? (Also, just in case, which OS?)

EDIT: CF_GetTrackFXChain seems to always returns nil now in REAPER 6.12/macOS. Not sure exactly in which version it broke or why, I'll look into it tomorrow. In the case of a nil fx chain, CF_EnumSelectedFX returns -1, not 0 though...

Last edited by cfillion; 07-01-2020 at 08:58 PM.
cfillion is offline   Reply With Quote
Old 07-01-2020, 09:18 PM   #9
pigstoe
Human being with feelings
 
Join Date: Apr 2020
Posts: 44
Default

Quote:
Originally Posted by cfillion View Post
Mhh... I can't duplicate that here. Can you share a minimal script (assuming it's not exactly as in the snippet above) and/or a minimal project that produce that? (Also, just in case, which OS?)

EDIT: CF_GetTrackFXChain seems to always returns nil now in REAPER 6.12/macOS. Not sure exactly in which version it broke or why, I'll look into it tomorrow. In the case of a nil fx chain, CF_EnumSelectedFX returns -1, not 0 though...
Found. In process of minimizing my code to share, I found that PreventUIRefresh(1) prevents CF_EnumSelectedFX works fine. Is that a bug? I can't understand why UI refreshing affects getting indices of selected FXs. But, I should remove preventing to refresh UI in this script.

Anyway, thanks!
pigstoe is offline   Reply With Quote
Old 07-09-2020, 10:43 AM   #10
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 3,795
Default

Quote:
Originally Posted by pigstoe View Post
Found. In process of minimizing my code to share, I found that PreventUIRefresh(1) prevents CF_EnumSelectedFX works fine. Is that a bug? I can't understand why UI refreshing affects getting indices of selected FXs. But, I should remove preventing to refresh UI in this script.
Ah yes. It's a limitation of the way the function asks REAPER to synchronously update the title of the FX chain window. PreventUIRefresh inhibits TrackList_AdjustWindows.

I discovered a better way to do that while fixing it for v6 on non-Windows so, in the next SWS update, CF_GetTrackFXChain will be usable along with PreventUIRefresh.
cfillion is offline   Reply With Quote
Old 07-09-2020, 04:46 PM   #11
pigstoe
Human being with feelings
 
Join Date: Apr 2020
Posts: 44
Default

Good news. I'm looking forward to it. Thank you.
pigstoe 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 11:34 AM.


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