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.
boolean alreadyRunning()
- honki-bobo
- Posts: 310
- Joined: Sat Nov 09, 2019 1:18 pm
Re: boolean alreadyRunning()
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.
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.
Re: boolean alreadyRunning()
Thanks Martin, yeah, that's where I started from too.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.
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.
- honki-bobo
- Posts: 310
- Joined: Sat Nov 09, 2019 1:18 pm
Re: boolean alreadyRunning()
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
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
Re: boolean alreadyRunning()
Ah, thanks Martin. I'd entirely forgotten about the Destroy() method. That might actually help, also cheers for the other pointers.