View Single Post
Old 07-10-2020, 02:35 AM   #12
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 218
Default

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.
__________________
Audio VST plugins http://vst.saschart.com

Last edited by SaschArt; 07-10-2020 at 02:46 AM.
SaschArt is offline   Reply With Quote