QMainWidget::QMainWidget(bool remapEnabled, QWidget *parent) :
    QWidget(parent)
{
    createTrayIcon();
    
    controllerWindow = NULL;
    
    controllerRemapper = new ControllerRemapper((HWND)winId(), remapEnabled, NULL);
    controllerRemapper->moveToThread(controllerRemapper);
    connect(controllerRemapper, SIGNAL(initializationError(QString)), this, SLOT(error(QString)));
    controllerRemapper->start();
}
/* Constructor
	
	Input arguments:
		t_nLPC: LPC order
		t_sr: sampling rate of the input signal (Hz)
		t_bufferSize: input buffer size (# of samples)
		t_nFFT: FFT length (must be power of 2)
		t_cepsWinWidth: cepstral liftering window width (dimensionless)
		t_nTracks: Number of formants to be tracked
		t_aFact: alpha parameter in the DP formant tracking algorithm (Xia and Espy-Wilson, 2000)
		t_bFact: beta
		t_gFact: gamma
		t_fn1: prior value of F1 (Hz)
		t_fn2: prior value of F2 (Hz)

		If cepsWinWidth is <= 0, cepstral liftering will be disabled.
*/
LPFormantTracker::LPFormantTracker(const int t_nLPC, const int t_sr, const int t_bufferSize, 					 
								   const int t_nFFT, const int t_cepsWinWidth, 
								   const int t_nTracks, 
								   const dtype t_aFact, const dtype t_bFact, const dtype t_gFact, 
			   					   const dtype t_fn1, const dtype t_fn2, 
								   const bool t_bMWA, const int t_avgLen) :
	nLPC(t_nLPC), sr(t_sr), 
	bufferSize(t_bufferSize), 
	nFFT(t_nFFT), cepsWinWidth(t_cepsWinWidth), 
	nTracks(t_nTracks), 
	aFact(t_aFact), bFact(t_bFact), gFact(t_gFact), 
	fn1(t_fn1), fn2(t_fn2), 
	bMWA(t_bMWA), avgLen(t_avgLen)	
{
	/* Input sanity checks */
	if ( (nLPC <= 0) || (bufferSize <= 0) || (nFFT <= 0) ||
	     (nTracks <= 0) )
		 throw initializationError();

	if (nLPC > maxNLPC)
		throw nLPCTooLargeError();

	bCepsLift = (cepsWinWidth > 0);
	
	winFunc = new dtype[bufferSize];

	/* Initialize window */
	genHanningWindow();

	nLPC_SQR = nLPC * nLPC;

	Acompanion = new dtype[nLPC_SQR];
	AHess = new dtype[nLPC_SQR];

	temp_frame = new dtype[bufferSize + nLPC + 2]; // +2 for playing it safe! TODO: improve
	R = new dtype[nLPC * 2]; // *2 for playing it safe! TODO: improve

	/* Initalize FFT working date fields */
	ftBuf1 = new dtype[nFFT * 2];
	ftBuf2 = new dtype[nFFT * 2];
	fftc = new dtype[nFFT * 2];

	gen_w_r2(fftc, nFFT);

	/* Intermediate data fields */
	lpcAi = new dtype[maxNLPC + 1];
	realRoots = new dtype[maxNLPC];
	imagRoots = new dtype[maxNLPC];

	cumMat = new dtype[maxFmtTrackJump * maxNTracks];
	costMat = new dtype[maxFmtTrackJump * maxNTracks];

	nCands = 6; 
	/* number of possible formant candiates  
	   (should be > ntracks but  < p.nLPC/2!!!! (choose carefully : not fool-proof) 
	   TODO: Implement automatic checks */

	weiMatPhi = new dtype[nTracks * maxAvgLen];
	weiMatBw = new dtype[nTracks * maxAvgLen];
	weiVec = new dtype[maxAvgLen];
	sumWeiPhi = new dtype[nTracks];
	sumWeiBw = new dtype[nTracks];

	trackFF = 0.95;

	radius_us = new dtype[maxNLPC]; /* TODO: Tighten the size */
	phi_us = new dtype[maxNLPC];
	bandwidth_us = new dtype[maxNLPC];
	//phi_s = new dtype[maxNLPC];

	/* Call reset */
	reset();
}