Callback when opening and changing to different preset

I’m looking for a way to get a Lua callback in MyPreset when:

  • users open MyPreset on the E1
  • users change to a different preset than MyPreset

So far, nothing seems to work. The functions here don’t fit the requirements:

  • onReady() is only ever called once in the lifetime of MyPreset and not when changing from a different preset to MyPreset
  • onExit() is not called when changing to a different preset than MyPreset

I have users of my KnobConnector plugin reporting that when they change to a different preset than MyPreset, my preset’s custom sysex handling of incoming messages doesn’t work. It’s likely that the E1 stops calling the preset’s callbacks once the preset is not active anymore. So when they change back to MyPreset, it’s in an inconsistent state. Without a way to detect that the user just switched to MyPreset, its script will be unable to request a full state message.

One workaround would be to let the E1 script continuously send out alive messages to the DAW plugin. There are two caveats, though:

  • the E1’s MIDI out activity indicator will blink even with nonuser interaction at all which will be annoying and confusing to users
  • the E1 already has some issues in keeping up when the changes from the DAW plugin are more substantial (like changing the name, value and range of several controls), causing temporary freezes of up to several seconds in extreme situations. I’m worried that missing to send the alive message in such situations might make those freezes worse as it would cause the DAW plugin to send additional full state updates.

So being able to send out one quick message when leaving MyPreset and when going back to MyPreset still seems to be the cleanest solution which seems to be unsupported by the current Lua API.

@martin since it doesn’t seem possible to do this with the current feature set, any chance for adding this to the next update?

done. preset.onEnter() and preset.onLeave() added to the preset life cycle. I will add them to the documentation. The functions will be included in the upcoming release.

Note, preset.onExit() is called when preset is physically removed from the device by overwriting it or removing it using the web app or a sysex message.

2 Likes

just a question @Martin: could there be situations, when a preset is installed multiple times on the same device (different versions for instance), these commands interfere between these various instances?

no, each preset instance is completely independent from others.

1 Like

Awesome, thank you so much!

Btw., I’d consider renaming “onExit” to “onDelete” or something similar to more accurately reflect its purpose. You can still let onExit exist, but wipe it from the documentation to keep it backwards compatible.