# Event triggered on DAW startup

**URL:** <https://forum.juce.com/t/event-triggered-on-daw-startup/58553>\
**Category:** Audio Plugins\
**Created:** [October 29, 2023, 4:40pm UTC](https://forum.juce.com/t/event-triggered-on-daw-startup/58553 "2023-10-29T16:40:59Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliverocean](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@oliverocean](https://forum.juce.com/u/oliverocean)\
**Post date:** [October 29, 2023, 4:40pm UTC](https://forum.juce.com/t/event-triggered-on-daw-startup/58553/1 "2023-10-29T16:40:59Z")

</div>

I was wondering if anyone knows a way to have a block of code run when when a session gets opened in a daw.

---

<div class="post-metadata">

**Author:** ![jcomusic](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jcomusic/32/2014_2.png) [@jcomusic](https://forum.juce.com/u/jcomusic)\
**Post date:** [October 29, 2023, 5:57pm UTC](https://forum.juce.com/t/event-triggered-on-daw-startup/58553/2 "2023-10-29T17:57:39Z")

</div>

I don’t think there is a generic solution, but for Reaper you can use the VST extensions and check for changes of the project path in your plugins setState/getState.

---

<div class="post-metadata">

**Author:** ![benvining](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benvining/32/9922_2.png) [@benvining](https://forum.juce.com/u/benvining)\
**Post date:** [October 29, 2023, 8:39pm UTC](https://forum.juce.com/t/event-triggered-on-daw-startup/58553/3 "2023-10-29T20:39:46Z")

</div>

If a user is opening a session that had an instance of your plugin on a track, then this code would basically just be the plugin constructor, right?

---

<div class="post-metadata">

**Author:** ![oliverocean](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@oliverocean](https://forum.juce.com/u/oliverocean)\
**Post date:** [October 29, 2023, 8:54pm UTC](https://forum.juce.com/t/event-triggered-on-daw-startup/58553/4 "2023-10-29T20:54:55Z")

</div>

The plugin constructer would run when the host opens a session with the plugin inserted, but unless I’m mistaken hosts will also destruct and re initialize plugins while the project is running. So the constructer would run when the project is opened but it also runs at other times

---

<div class="post-metadata">

**Author:** ![Stevezee](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Stevezee](https://forum.juce.com/u/Stevezee)\
**Post date:** [October 30, 2023, 8:53am UTC](https://forum.juce.com/t/event-triggered-on-daw-startup/58553/5 "2023-10-30T08:53:52Z")

</div>

If you want to be sure it runs only on the first load, couldn’t you trigger your events in the setState method?

I’m new to this but I think that only runs once.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 30, 2023, 9:16am UTC](https://forum.juce.com/t/event-triggered-on-daw-startup/58553/6 "2023-10-30T09:16:35Z")

</div>

> [@Stevezee](#):
>
> I’m new to this but I think that only runs once.

No, it can run any number of times. And it runs for each instance.

> [@oliverocean](#):
>
> So the constructer would run when the project is opened but it also runs at other times

What you can do is setting a static flag in the constructor initialised with false and set it to true when your initialisation runs the first time.

```auto
static MyProcessor::initialised = false;

MyProcessor::MyProcessor()
{
    if (!initialised)
    {
        initialised = true;
        // do your work
    }
}

```

However, this might also give false positives for hosts like Logic, where the plugins run in a separate processes.

And it will only run once in the lifetime of the DAW process. I.e. if the user loads a new session, the plugins are usually not loaded fresh but remain in memory, so the initialisation won’t happen again.

The DAWs are not designed to tell the plugins their internals.

---

<div class="post-metadata">

**Author:** ![Stevezee](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Stevezee](https://forum.juce.com/u/Stevezee)\
**Post date:** [October 30, 2023, 10:48am UTC](https://forum.juce.com/t/event-triggered-on-daw-startup/58553/7 "2023-10-30T10:48:42Z")

</div>

Ah, good to know… outside of loading the plugin, what else will trigger setState?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 30, 2023, 10:51am UTC](https://forum.juce.com/t/event-triggered-on-daw-startup/58553/8 "2023-10-30T10:51:06Z")

</div>

Some might when doing an UNDO, some like ProTools have an A/B compare button which switches between the previous and current state.

---

<div class="post-metadata">

**Author:** ![oliverocean](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@oliverocean](https://forum.juce.com/u/oliverocean)\
**Post date:** [October 30, 2023, 3:30pm UTC](https://forum.juce.com/t/event-triggered-on-daw-startup/58553/9 "2023-10-30T15:30:36Z")

</div>

Ahh I had an idea. I’ll have the processor poll the local time on a timer (lets say every 5 seconds). If it polls the local time and there is more than a 5 second period since the last poll, it knows that time has passed without the timer running (i.e. the host has been closed).

---

<div class="post-metadata">

**Author:** ![yfede](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yfede/32/506_2.png) [@yfede](https://forum.juce.com/u/yfede)\
**Post date:** [October 31, 2023, 9:00am UTC](https://forum.juce.com/t/event-triggered-on-daw-startup/58553/10 "2023-10-31T09:00:46Z")

</div>

Uhm, but if the host gets closed, then your plug-in also has been fully unloaded from memory, hence it’s not possible for it to keep the time of last poll in a variable in memory. Did you plan to write it to disk every time? that seems a little overkill

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 31, 2023, 9:04am UTC](https://forum.juce.com/t/event-triggered-on-daw-startup/58553/11 "2023-10-31T09:04:40Z")

</div>

It sounds indeed like a fragile workaround.

If you could elaborate your use case it would be easier to give ideas on how to get the information you need.  
But your original question can be answered as:  
No, the standard APIs don’t give you the information when a session is opened or closed.  
You can only deduce with a certain error rate depending on host, more guessing.

---

<div class="post-metadata">

**Author:** ![oliverocean](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@oliverocean](https://forum.juce.com/u/oliverocean)\
**Post date:** [October 31, 2023, 5:02pm UTC](https://forum.juce.com/t/event-triggered-on-daw-startup/58553/12 "2023-10-31T17:02:48Z")

</div>

> [@yfede](#):
>
> Uhm, but if the host gets closed, then your plug-in also has been fully unloaded from memory, hence it’s not possible for it to keep the time of last poll in a variable in memory. Did you plan to write it to disk every time? that seems a little overkill

I’m testing it right now where it writes to a valuetree that i’m loading from AudioProcessor::setStateInformation.

> [@daniel](#):
>
> It sounds indeed like a fragile workaround.

I’m worried about its fragility as well-- but for right now it seems to working in the juce plugin host, logic, and reaper. I only set it up this morning so I still haven’t been able to test it thoroughly. I’ll report back after I test it more.
