RomeoDespres/reapy

reapy.core.Project.selected_items gets non-selected items

Closed this issue · 4 comments

Project.selected_items is returning all items in the project. This may be a bug in reaper since RPR_GetSelectedMediaItems() should only return selected items.

Workaround: use reaper's selected item count as the range, rather than self.n_items:

    return [reapy.Item(RPR.GetSelectedMediaItem(self.id, i))
            for i in range(RPR.CountSelectedMediaItems(self.id))
        ]

Included in #71

returning all items in the project.

Aclually, not all, just a bunch of empty items. But good to know about this)

I think it returns empy items in the place of items that aren't selected. For example, if there are 3 selected items and 5 items in the project, it will return the 3 selected items, and 2 empty items. I have only checked it on a project with a few items.

It looks like RPR.GetSelectedMediaItem(self.id, i) returns '(MediaItem*)0x0000000000000000' for any "i" above the number of selected items, rather than throwing an error. So my "workaround" above is probably the right way to limit it to only selected items.

Thanks @ganttview for the report and @Levitanus for the fix! It's part of the 0.6.0 release, so updating from pip (or from the repo) should solve it.