boolean alreadyRunning()

Post Reply
ColinP
Posts: 998
Joined: Mon Aug 03, 2020 7:46 pm

boolean alreadyRunning()

Post by ColinP »

Has anyone managed to come up with a reliable test that can be called during module initialization that determines whether another instance of the current module type is already running?

The application being to prevent more than one instance of a given module running at the same time.
User avatar
honki-bobo
Posts: 310
Joined: Sat Nov 09, 2019 1:18 pm

Re: boolean alreadyRunning()

Post by honki-bobo »

Haven't done this yet, but since modules cannot communicate with each other the only ways I can think of to achieve this are
1. [Get|Set][Global|Manufacturer|User]Property functions or
2. using the file system to leave a mark.
In both cases you will need to take care that the mark is properly removed when the module gets deleted from the patch or when VM crashes.
Image
Monkey Business Audio
Modules - Music - Twitter - YouTube
ColinP
Posts: 998
Joined: Mon Aug 03, 2020 7:46 pm

Re: boolean alreadyRunning()

Post by ColinP »

honki-bobo wrote: Fri Mar 15, 2024 8:06 am Haven't done this yet, but since modules cannot communicate with each other the only ways I can think of to achieve this are
1. [Get|Set][Global|Manufacturer|User]Property functions or
2. using the file system to leave a mark.
In both cases you will need to take care that the mark is properly removed when the module gets deleted from the patch or when VM crashes.
Thanks Martin, yeah, that's where I started from too.

But there's no callback for modules being removed and no callback for VM exiting (either via a fatal exception or more routinely).

Most of my modules use shared memory mechanisms so they can easily communicate with each other but even this doesn't seem much help. I've tried using basic timestamps and a form of active sensing but still can't nail it.

It's a trickier problem than one might think and one needs to be able to handle preset loading, duplications, undo and automatic updates too (where it seems that two instances live side by side during the catalog update even though only one is visible to users).

So far the only half-solutions I've come up with give false positives.

It may well be another one of those things that's impossible to do in VM but I thought it worth asking to see if anyone had cracked it.
User avatar
honki-bobo
Posts: 310
Joined: Sat Nov 09, 2019 1:18 pm

Re: boolean alreadyRunning()

Post by honki-bobo »

Hi Colin,

there is the Destroy() method in VoltageModule class that you can use to "clean up" things. This method is called when a module gets removed or VM is closed (see https://docs.cherryaudio.com/voltage-mo ... -variables).

Maybe it helps if you take a look at master-slave bus communication protocols, like SPI, I2C or ModBus, and draw inspiration from how master arbitration is handled.

Hope this helps. Good luck and best regards,
Martin
Image
Monkey Business Audio
Modules - Music - Twitter - YouTube
ColinP
Posts: 998
Joined: Mon Aug 03, 2020 7:46 pm

Re: boolean alreadyRunning()

Post by ColinP »

Ah, thanks Martin. I'd entirely forgotten about the Destroy() method. That might actually help, also cheers for the other pointers.
Post Reply

Return to “Module Designer”