How to detect project switches / changes?

Post Reply New Topic
RELATED
PRODUCTS

Post

Hi,

Disclaimer: I'm completely new to controller scripting. Yesterday, I've stared my first controller script (written in TypeScript) for the Launchpad Pro MK3: https://github.com/Fannon/Launchpad-Pro ... Controller

Right now I'm having a problem where I got stuck: When changing from an existing project to a new or other project, the state of my controller script gets completely confused.
This of course means that I've got my state / lifecycle management not yet figured out correctly, of course.

However, just calling `host.restart();` fixes the issue for me, as then the state seems to be built up anew.

So the question is: How can I detect that my project has been changed / loaded? How to detect that a user switched between projects? If I can add an observer on that, I can at least work around the current bug. Next, I need to figure out how to avoid this issue in the first place, of course :ud:

Thanks!
Find my (music) related software projects here: github.com/Fannon

Post

To put it into a more general question / observation: When you have a lot of state you want to deal with asyncronously / smartly, you may want to start with an "initial load" (of all the state you're interested in) and then you subscribe to all the updates / changes and apply that to your current state. However, this is not easy to get right if you don't understand the complete picture of the state / domain.

So beeing able to do "initial loads" from time to time (when too much state changes, or the situation becomes too difficult) would simply things for me.

Of course this relies on knowing in which situations to do this initial load and how to do it correctly (Is `host.restart();` taking a hammer to the problem?)
Find my (music) related software projects here: github.com/Fannon

Post

Fannon wrote: Mon Oct 11, 2021 5:55 am Hi,

Disclaimer: I'm completely new to controller scripting. Yesterday, I've stared my first controller script (written in TypeScript) for the Launchpad Pro MK3: https://github.com/Fannon/Launchpad-Pro ... Controller

Right now I'm having a problem where I got stuck: When changing from an existing project to a new or other project, the state of my controller script gets completely confused.
This of course means that I've got my state / lifecycle management not yet figured out correctly, of course.

However, just calling `host.restart();` fixes the issue for me, as then the state seems to be built up anew.

So the question is: How can I detect that my project has been changed / loaded? How to detect that a user switched between projects? If I can add an observer on that, I can at least work around the current bug. Next, I need to figure out how to avoid this issue in the first place, of course :ud:

Thanks!
From the first glance this overall sounds like a script architecture problem. Took a brief look and spotted a couple of things: you model and maintain your own state quite extensively and you update that state by parsing raw MIDI from the host — this is unnecessary and error prone. If you drive everything via ObjectProxy observers, hardware bindings and midi matchers, the updates will happen more or less automatically.

For reference, take a look at https://github.com/dozius/TwisterSister or my own https://github.com/unthingable/monster- ... nthingable.

If you still specifically need to follow project changes, I think you could add an observer to Application.projectName property.

Post

@minortom: Yes, I'm aware that the architecture is not ideal at the moment and prone to such errors. Haven't looked into the concepts you mentioned, so that would be a next good step.

For an interim solution, listening to projectName changes and restarting the host did the trick. Thanks!
Find my (music) related software projects here: github.com/Fannon

Post Reply

Return to “Controller Scripting”