void MainWindow::ApplyEffect()
{
    ui->listWidget->clear();
    TCSaveDialog* d = new TCSaveDialog(this);
#if QT_VERSION>=0x050000 && !defined(Q_OS_UNIX)
    d->setDirectory(lastdir);
#endif
    d->setWindowTitle("Export new audio file");
    d->setNameFilter("WAV Files (*.wav)\nMP3 Files(*.mp3)");
    if(d->exec()){
    QString nf = d->selectedFiles().at(0);
    if(nf.isEmpty())return;
    QFileInfo info(nf);
    lastdir = info.absolutePath();
    s = new AudioReader(filename,nf,ui->mode->currentIndex(),ui->fftsize->value(),ui->wsize->value(),ui->dcoef->value(),ui->postcoef->value(),ui->locut->value(),ui->hicut->value(),ui->decay->value(),ui->overlapf->value());
    ui->pushButton->disconnect();
    connect(s,SIGNAL(TCMessage(QString)),ui->statusBar,SLOT(showMessage(QString)));
    connect(s,SIGNAL(TCMessage(QString)),this,SLOT(showMessage(QString)));
    connect(s,SIGNAL(TCMax(int)),ui->progressBar,SLOT(setMaximum(int)) );
    connect(s,SIGNAL(TCProg(int)),ui->progressBar,SLOT(setValue(int)) );
    connect(s,SIGNAL(TCColor(QString)),ui->statusBar,SLOT(setStyleSheet(QString)) ) ;
    connect(s,SIGNAL(finished()),s,SLOT(terminate()) );
    connect(s,SIGNAL(finished()),SLOT(ProcessDone()) );

    connect(s,SIGNAL(TCProperty(QString)),SLOT(AddFileProperty(QString)) );
    connect(ui->pushButton,SIGNAL(clicked()),s,SLOT(toggleRun()) );
    ui->pushButton->setText(nextText);
    s->start();
      }
void WPSRegistrar::RunWPS()
{
	switch(m_state) {
	case init:
		{
		char buf[40];
		m_regInfo.password.Reset();
		if (m_devPwdId == WSC_DEVICEPWDID_DEFAULT || m_devPwdId == WSC_DEVICEPWDID_PUSH_BTN) {
			sprintf(buf,"%08d", m_defaultPin);
			m_regInfo.password.Append(strlen(buf),(uint8*) buf);
			m_regInfo.p_registrarInfo->devPwdId = m_devPwdId;
		} else { // one of the other password types such as user-defined or machine-defined
			m_regInfo.password.Append(m_devicePassword.Length(), m_devicePassword.GetBuf());
			//m_regInfo.enrolleePwdId = m_devPwdId;
		}
		BufferObj outBuf;
		//outBuf.Append(1, (uint8 *) "");
		SendWPSMessage(this, m_peer, m_callback, outBuf);
		m_state = device_info;
		}
	break;
	case device_info:
		m_state = ProcessM1();
	break;
	case sent_m2d: // The Device has been asked to display its PIN number.  Prompt user to enter it.
		{
		// Should get here only if Device is now ready to proceed (either its PBC button has been pushed,
		// or it has a label-based PIN, or it is currently displaying its dynamic PIN).
		uint32 message_type;
		int err = g_regProtocol.GetMsgType(message_type, m_msgBuffer);
		if(WSC_SUCCESS != err)
		{
			m_state = init; // reset the state machine to recover from error
			return;
		}
		if (message_type == WSC_ID_MESSAGE_ACK) { // Device is ready to run protocol
			if (m_devPwdId == WSC_DEVICEPWDID_PUSH_BTN && 
				m_devPwdId == m_regInfo.p_enrolleeInfo->devPwdId) {
				printf("\n*********\nUsing push-button method...\n");
				m_state = SendM2();
			} else if (m_regInfo.p_enrolleeInfo->devPwdId == WSC_DEVICEPWDID_DEFAULT) {
				m_state = AskForPin(); // Device is using a PIN for its password ID
			} else if (m_regInfo.p_enrolleeInfo->devPwdId == WSC_DEVICEPWDID_PUSH_BTN) { 
				// Device is in PBC mode but Registrar is not. 
				// Automatically switch into PBC mode
				printf("\n******** Device wants to use PBC mode. Is this okay? (Y/N) ");
				char c;
				c = getc(stdin);
				if (c == 'y' || c == 'Y') {
					m_devPwdId = WSC_DEVICEPWDID_PUSH_BTN;
					m_regInfo.p_registrarInfo->devPwdId = m_devPwdId;
					m_regInfo.password.Reset();
					m_regInfo.password.Append(8,(uint8*) "00000000");
					printf("\n*********\nUsing push-button method...\n");
					m_state = SendM2();
				} else {
					m_state = err_build_m2;
					return;
				}
			} else { // Device wants to use some other password type that the Registrar doesn't support
				m_state = err_build_m2;
				return;
			}
		} else if (message_type == WSC_ID_MESSAGE_NACK) { // Device is not ready to run protocol
			printf("got NACK from Device\n");
			if (m_devPwdId == WSC_DEVICEPWDID_PUSH_BTN) {
				printf("\n*********\nUsing push-button method. Please press button on Device now.\n");
				m_state = got_nack_after_m2d; // stay in this state for now
			}
		}
		}
	break;

	// Registrar will not send another message until it sees the Device transition its SetupReady
	// state variable to 1.  At that point, it will call back into the state machine here and continue
	// the setup operation.
	case got_nack_after_m2d: 
		printf("Waiting for button press on Device\n");
		m_state = SendM2();
	break;

	case sent_m2:
		m_state = ProcessM3();
	break;
	case sent_m4:
		m_state = ProcessM5();
	break;
	case sent_m6:
		m_state = ProcessM7();
	break;
	case sent_m8:
		m_state = ProcessDone();
	break;
	case sent_ack:
		m_state = init;
	break;
	}
	if (m_state < init) { // error condition
		printf("Message Processing Error in Registrar state %d\n",m_state); 
		m_state = init;
	}
}