I'm making a managed machine to store/restore machine states (param, attributes and data) like PeerState and it works but sometime it causes Buzz to hang. I guess I need to lock the audio thread while I shuffle state data around but how do I do that in C#? What is the C# equivalent of CMICallbacks::Lock() and Unlock()?
Also, I'm hoping to be able to do this in response to a parameter change as well as from the GUI so how would I do a state capture/restore when a param change is detected without causing a meltdown? Any advice much appreciated.
Thread sync: Managed equivalent to pCB->Lock() ?
Re: Thread sync: Managed equivalent to pCB->Lock() ?
I use this type of lock mechanism in AudioBlock:
This might help with the GUI thread thing:
Can't wait to try your Snapshot machine to save different states of VSTs!
Code: Select all
static object syncLock = new object();
public void Work()
{
lock (syncLock)
{
// Things that need to be safe
}
}
Code: Select all
Application.Current.Dispatcher.BeginInvoke((Action)(() =>
{
// Do stuff here
}));
Re: Thread sync: Managed equivalent to pCB->Lock() ?
yes, this works for synchronizing your own machine's threads, where you can lock all your own threads with your own object. But note that you make your own lock object here, so this will not work for locking the state of OTHER machines and threads which you don't own. The other machines don't know anything about your lock object (and neither does buzz). You need to use THEIR lock objects. that's why machineinterface has the lock functions..there must be some equivalent in the .net api and if not, call the native function from .net.
that said, dispatching to the right buzz thread and doing it there might work... but it has to be the one where buzz calls these functions on usually, and again you should take the same locks buzz takes while calling them..
Re: Thread sync: Managed equivalent to pCB->Lock() ?
Thanks! I'm out of my depth just finding my way around C#, .NET AND WPF. I spent ten minutes poking around BuzzGUI looking for how to implement Tick() until I realised my mistake.
It's amazing! I hadn't considered it before but it doesn't save the VST, it saves PVST which means a snapshot can load an entirely different plugin!
How would I go about doing that?
Whenever I intercept a call from a button click, the thread id is 1 so I guess that's the one I'm aiming for. The invoke thing wde posted above looks promising (and easy) so I'll give that a try first. Wish me luck!
btw. UNZ I think you missed a message but it's not urgent now, since I started doing this. I'd like to get that hack working eventually but it can wait.
Re: Thread sync: Managed equivalent to pCB->Lock() ?
yeah sorry i just saw the message.
i'll take a look one of these days, a bit busy now
i'll take a look one of these days, a bit busy now
Re: Thread sync: Managed equivalent to pCB->Lock() ?
Hmmm, Application doesn't seem to have a 'Current' (different .NET version?) I did find 'BuzzGUI.Common.DispatcherAction' which looks like it does something similar. Nothing happens when I do this but there's a strong chance that I'm doing it completely wrong...wde wrote: ↑Thu Oct 07, 2021 12:57 pm This might help with the GUI thread thing:Code: Select all
Application.Current.Dispatcher.BeginInvoke((Action)(() => { // Do stuff here }));
Code: Select all
var da = new DispatcherAction(() =>
{
MessageBox.Show("Hello!");
});
da.Dispatch(System.Windows.Threading.DispatcherPriority.Normal);
Re: Thread sync: Managed equivalent to pCB->Lock() ?
Ignore that idiot from last night, he doesn't know what he's doing. Must've been missing a reference in a particular file because I just found it while trying stuff elsewhere. Early signs are promising, I just restored a single global param on one machine in response to a slot change and it didn't lock up like it always has done before!
edit: Totally working!