I’m trying to write a Lua script that will process selected MIDI notes – just the selected region, not the whole session or clip. I expected to be able to get a list of MIDI notes by starting with ARDOURUI.Selection, but that only works if I select an entire clip, not if I only select a portion of a clip.
The example code I’m working from (Albert Gräf’s meter.lua and umkehr.lua) uses an ARDOUR.NotePtrList obtained from ARDOUR.LuaAPI.note_list(). That method appears to be the only way to obtain a (non-empty) NotePtrList, and it takes as a parameter a MidiModel.
As far as I can tell, a MidiModel can only be obtained from a MidiRegion or a MidiSource.
When I have an entire clip selected, ARDOURUI.Selection contains a Region, and all is well. But when I select just a portion of a clip, ARDOURUI.Selection contains a Range and a Route, but not a Region.
Regions can be obtained from a RegionSelection (which isn’t available in this case) or a Playlist.
The only way I found to obtain a Playlist is from a Track or a Route, but those classes don’t appear to have starting and ending times, and represent entire tracks.
There must be a way to do this. What am I missing?
I believe you meant to say only the selected (time) range, not the whole session or *region.
Yes, thank you for the correction.
Lua only exposes existing C++ APIs and in Ardour all MIDI region operations use the MIDI Model.
I’m not sure what you mean by that; all of the API items I mentioned are listed in the Lua Bindings Class Reference section of the Ardour manual.
Also, I just verified in Ardour that I can select a handful of MIDI notes (in one track, and not all the notes) and edit them with either mouse gestures or with operations from the main menu bar. So there must be an interface for getting the selected notes. Whether it’s exposed to Lua is another question.