# Callback when opening and changing to different preset

**URL:** <https://forum.electra.one/t/callback-when-opening-and-changing-to-different-preset/3820>\
**Category:** Developers\
**Created:** [July 17, 2025, 8:24pm UTC](https://forum.electra.one/t/callback-when-opening-and-changing-to-different-preset/3820 "2025-07-17T20:24:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mint-Gecko](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Mint-Gecko](https://forum.electra.one/u/Mint-Gecko)\
**Post date:** [July 17, 2025, 8:24pm UTC](https://forum.electra.one/t/callback-when-opening-and-changing-to-different-preset/3820/1 "2025-07-17T20:24:29Z")

</div>

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](https://docs.electra.one/developers/luaext.html#functions-21) 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.

---

<div class="post-metadata">

**Author:** ![Mint-Gecko](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Mint-Gecko](https://forum.electra.one/u/Mint-Gecko)\
**Post date:** [July 21, 2025, 2:46pm UTC](https://forum.electra.one/t/callback-when-opening-and-changing-to-different-preset/3820/2 "2025-07-21T14:46:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mint-Gecko](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Mint-Gecko](https://forum.electra.one/u/Mint-Gecko)\
**Post date:** [September 4, 2025, 5:31am UTC](https://forum.electra.one/t/callback-when-opening-and-changing-to-different-preset/3820/3 "2025-09-04T05:31:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![martin](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/martin/32/145_2.png) [@martin](https://forum.electra.one/u/martin)\
**Post date:** [September 4, 2025, 6:58pm UTC](https://forum.electra.one/t/callback-when-opening-and-changing-to-different-preset/3820/4 "2025-09-04T18:58:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![NewIgnis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/newignis/32/767_2.png) [@NewIgnis](https://forum.electra.one/u/NewIgnis)\
**Post date:** [September 5, 2025, 6:08am UTC](https://forum.electra.one/t/callback-when-opening-and-changing-to-different-preset/3820/5 "2025-09-05T06:08:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![martin](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/martin/32/145_2.png) [@martin](https://forum.electra.one/u/martin)\
**Post date:** [September 5, 2025, 6:12am UTC](https://forum.electra.one/t/callback-when-opening-and-changing-to-different-preset/3820/6 "2025-09-05T06:12:18Z")

</div>

no, each preset instance is completely independent from others.

---

<div class="post-metadata">

**Author:** ![Mint-Gecko](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Mint-Gecko](https://forum.electra.one/u/Mint-Gecko)\
**Post date:** [September 5, 2025, 6:48am UTC](https://forum.electra.one/t/callback-when-opening-and-changing-to-different-preset/3820/7 "2025-09-05T06:48:04Z")

</div>

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.
