This can be a solution:
In plugin h file:
Code:
class VSTCLASS : public IPlug {
public:
.............
static DWORD WINAPI threadProc(LPVOID innerThread) {
VSTCLASS *pThis = reinterpret_cast<VSTCLASS*>(innerThread);
while(pThis->thread_process) {
if (pThis->process_on)
pThis->process_on=false;
else {
//BYPASSED
}
Sleep(100);
}
exit(0);
}
.............
private:
bool process_on;
HANDLE hThread; DWORD ThreadID;
In cpp file:
Code:
CTOR
.............
hThread=CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadProc, (void*)this, 0, &ThreadID);
..............
void VSTCLASS::OnClose() {
thread_process=false;
DWORD dwExitCode;
GetExitCodeThread(hThread, &dwExitCode);
ExitThread(dwExitCode);
}
void VSTCLASS::ProcessDoubleReplacing
..............
process_on=true;
..............
This code works but have only a problem, when close the plugin, the DAW is closed too. I can't find a solution to stop the thread without stopping the whole program. Maybe someone knows how to do it...
Also a code for OSX would be good to do.