RomeoDespres/reapy

Bug - KeyError raised when accessing Track FX by name

Closed this issue · 4 comments

Bug originally reported on the Cockos forum thread here. Just copying it here for easier reference.

I'm having trouble with Track FX, when trying to use an FX name as an index, whereby I got a KeyError.

To further investigate, I tried to duplicate the basic example on page https://python-reapy.readthedocs.io/en/latest/reapy.core.html#reapy.core.FX which is:

Code:

>>> fx_list = track.fxs
>>> fx_list[0]
FX(parent_id="(MediaTrack*)0x0000000006CDEBE0", index=0)
>>> len(fx_list)
1
>>> fx_list["VST: ReaComp (Cockos)"]
FX(parent_id="(MediaTrack*)0x0000000006CDEBE0", index=0)

But my test case fails with:

KeyError: 'No FX named VST: ReaComp (Cockos)'

It was run outside reaper, on a project that had ReaComp as the only FX on a Selected track:

Code:

import reapy, sys

project = reapy.Project()
x = project.selected_tracks
if len(x) != 1: sys.exit(1)
track = x[0]
fx_list = track.fxs
print("Number of FX is", track.n_fxs)
print(fx_list[0])
print(fx_list[0].name)
print(fx_list["VST: ReaComp (Cockos)"])  # Gets KeyError

And here is the output:

Code:

Number of FX is 1
FX(parent_id="(MediaTrack*)0x00000000049C0EE0", index=0)
VST: ReaComp (Cockos)
Traceback (most recent call last):
  File "D:\Work\bug1.py", line 11, in <module>
    print(fx_list["VST: ReaComp (Cockos)"])  # Gets KeyError
  File "C:\Users\Tom Parker\AppData\Local\Programs\Python\Python38\lib\site-packages\reapy\core\fx\fx.py", line 409, in __getitem__
    i = self._get_fx_index(name=i)
  File "C:\Users\Tom Parker\AppData\Local\Programs\Python\Python38\lib\site-packages\reapy\core\fx\fx.py", line 434, in _get_fx_index
    raise KeyError("No FX named {}".format(name))
KeyError: 'No FX named VST: ReaComp (Cockos)'

I'm running Reaper 5.99/x64, Reapy 0.6.0, and Python 3.8.2.

I'm not sure, what the matter, but I've already had the same issue with my jsfx. More than, i've checked within original api call with the same result.
In my case the filename e.g. myjsfx but not the name from the browser e.g. JSFX: awesome jsfx plugin was accepted

The problem is actually that FX.name returns the name prefixed with FX type (e.g. 'VST: ReaComp (Cockos)', while FXList.__getitem__ (and the underlying API function TrackFX_AddByName) need the unprefixed name ('ReaComp (Cockos)').

I think it is not good to have an inconsistency between both. Question is, which of the two following options is better:

  1. Change FX.name so that it returns unprefixed FX name, and maybe add an FX.type property
  2. Change FXList.__getitem__ so that it strips the prefix from the name it receives

I feel the first one is cleaner but the second one is simpler. Not sure which to choose

I decided to go for number 2! I think it makes sense considering that in REAPER UI, FX names are also prefixed.

Maybe the final decision is right 🙂