Change plugin presets with Lua DSP script

No replies
User offline. Last seen 4 days 5 hours ago. Offline
Joined: 2016-03-09

In a quest to find a way to change a plugin preset by means of a MIDI message, I looked into doing this with a Lua script.

(Could not find a way to do this via already built-in functionality or OSC. Please let me know if this is actually possible.)

I managed to create a simple DSP script which changes a plugin's preset. However, I have the following limitations:
1.) You have to specify a specific track by index.
2.) You have to specify a specific plugin, also by index.
3.) You have to specify a plugin preset by label or URI.

For this to just work, I envision being able to insert my preset-change Lua plugin into a mixer strip, right before the plugin which preset you actually want to change. My Lua preset-change plugin would then pass through all MIDI, but on a program change event, would change the preset of the plugin right after it. In this way, when adding new tracks / plugins, the user doesn't have to change settings in the plugin when things get reordered. The plugin will simply just always try to change the preset of the plugin immediately after it.

HOWEVER, to achieve this, I'm currently missing the following functionality in Lua scripting:
a.) Get the current track and current position of the Lua plugin itself.
b.) Change a plugin's preset using an index, rather than name.

Is there a way to get a.) and b.), or to achieve reliable preset changing in some other way?