Example #1
0
void timelineWidget::wheelEvent( QWheelEvent *event )
    {
    timeInView( timeInView() - ( (float)event->delta() / 32.0 ) );
    if( timeInView() > ( endTime() - beginTime() ) )
        {
        timeInView( endTime() - beginTime() );
        }
    update();
    }
PaintTileOperation::PaintTileOperation(Tile* tile, TilePainter* painter,
                                       GLWebViewState* state, bool isLowResPrefetch)
    : m_tile(tile)
    , m_painter(painter)
    , m_state(state)
    , m_isLowResPrefetch(isLowResPrefetch)
{
    if (m_tile)
        m_tile->setRepaintPending(true);
    SkSafeRef(m_painter);
#ifdef DEBUG_COUNT
    ClassTracker::instance()->increment("PaintTileOperation");
#endif

#ifdef PROFILE_TEXTURES_GENERATOR_MULTI_CORE
    m_profileWholeTxGenTime = true;
    if (!m_profileWholeTxGenTime)
        m_startTimeMS = 0.0;
    else
        beginTime();
#endif
}
Example #3
0
/**
  @brief 初始化相关信息,获取当前时间
*/
void StatManager::init()
{
    m_bCloseBL = false;
    m_bStarted = false;
        m_Time = new QTime;

    beginTime();
    if(QFile::exists("/Data/setup/lastTime"))
    {
        QFile file("/Data/setup/lastTime");
        file.open(QIODevice::ReadOnly);
        QByteArray ba = file.readAll();
        QString str(ba);
        unsigned int saveTime = str.toUInt();
        if((unsigned int)dure_time_start<saveTime)
        {
            struct timeval tv;
            tv.tv_sec=saveTime;
            tv.tv_usec=0;
            settimeofday(&tv,NULL);
            StatManager::saveHWClockTime();
        }
    }
}
void CRemotePlaybackDlg::OnSearch() 
{
	m_nGetPage=0;
	m_nCurPage=-1;
	m_nTotalPage=-1;
	
	UpdateData();
	
	OnStop();  //查询之前先关闭所有的播放

	int nSelectedIndex = m_cmbDevice.GetCurSel();
	if ( nSelectedIndex <= 0)
	{
		MessageBox(_CS("PlayBack.SelectDevice"));
		return;
	}
	
	ClearResult();
	
	ClearMapResult();
	
	int nChannel = m_cmbChannel.GetCurSel();	//channel No.
	int nFileType = m_cmbType.GetCurSel();		//file type
	
	H264_DVR_TIME StartTime;
	H264_DVR_TIME StopTime;
	
	COleDateTime beginTime(m_begData.GetYear(), m_begData.GetMonth(), m_begData.GetDay(),
		m_begTime.GetHour(), m_begTime.GetMinute(), m_begTime.GetSecond());
	COleDateTime endTime(m_endData.GetYear(), m_endData.GetMonth(), m_endData.GetDay(),
		m_endTime.GetHour(), m_endTime.GetMinute(), m_endTime.GetSecond());
	
	if(beginTime >= endTime)//时间错了
	{
		MessageBox(_CS("PlayBack.TimeERROR"));
		return ;
	} 

	StartTime.dwYear = (WORD)m_begData.GetYear();
	StartTime.dwMonth = (WORD)m_begData.GetMonth();
	StartTime.dwDay = (WORD)m_begData.GetDay();
	StartTime.dwHour = (char)m_begTime.GetHour();
	StartTime.dwMinute = (char)m_begTime.GetMinute();
	StartTime.dwSecond = (char)m_begTime.GetSecond();
	StopTime.dwYear = (WORD)m_endData.GetYear();
	StopTime.dwMonth = (WORD)m_endData.GetMonth();
	StopTime.dwDay = (WORD)m_endData.GetDay();
	StopTime.dwHour = (char)m_endTime.GetHour();
	StopTime.dwMinute = (char)m_endTime.GetMinute();
	StopTime.dwSecond = (char)m_endTime.GetSecond();
	
	DEV_INFO *pDevTemp=(DEV_INFO*)m_cmbDevice.GetItemData(nSelectedIndex);
	
	H264_DVR_FILE_DATA *szSend=new H264_DVR_FILE_DATA[100];
	
	
	if (pDevTemp)
	{
		m_lLoginID=pDevTemp->lLoginID;
		
		int nMaxLen = 100 * sizeof(H264_DVR_FILE_DATA);
		
		const int WAITTIME = 4000;   //waitting time
		int nNum = 0; //number of files return
		
		H264_DVR_FINDINFO searchInfo;
		searchInfo.nChannelN0 = nChannel;
		searchInfo.nFileType = nFileType;
		memcpy( &searchInfo.startTime, &StartTime, sizeof(searchInfo.startTime));
		memcpy( &searchInfo.endTime, &StopTime, sizeof(searchInfo.endTime));
		
		GetDlgItem(IDC_SEARCH)->EnableWindow(FALSE);
		
        int nRet=H264_DVR_FindFile(m_lLoginID,&searchInfo,szSend,100,&nNum);
		
		m_nCurRecNum=nNum;
		
		memcpy(&m_mapTemp[m_mapNum++],&searchInfo,sizeof(H264_DVR_FINDINFO));
		
		if ( nRet > 0 && nNum > 0)  //处理没有录象的情况下
		{
			m_nGetPage ++;
			m_nCurPage = 1;
			
			m_pstrFileVector.reserve(m_nCurRecNum);
			
			for(int i=0;i<m_nCurRecNum;i++)
			{
				m_pstrFileVector.push_back(szSend+i);
			} 
			
			m_nSearchInfo.nChannelN0=nChannel;
			m_nSearchInfo.nFileType=nFileType;
			m_nSearchInfo.startTime.dwYear=szSend[m_nCurRecNum-1].stEndTime.year;
			m_nSearchInfo.startTime.dwMonth=szSend[m_nCurRecNum-1].stEndTime.month;
			m_nSearchInfo.startTime.dwDay=szSend[m_nCurRecNum-1].stEndTime.day;
			m_nSearchInfo.startTime.dwHour=szSend[m_nCurRecNum-1].stEndTime.hour;
			m_nSearchInfo.startTime.dwMinute=szSend[m_nCurRecNum-1].stEndTime.minute;
			m_nSearchInfo.startTime.dwSecond=szSend[m_nCurRecNum-1].stEndTime.second;
			memcpy(&m_nSearchInfo.endTime,&searchInfo.endTime,sizeof(m_nSearchInfo.endTime));
			
			if(nNum<PLAYBACK_MAX_FILE_NUM)
			{
				m_nTotalPage=m_nGetPage;
			}
            
			AddFileListInfo(m_nCurRecNum);//add list item
			SetPageBtnState();
		}else
		{
			if (szSend)
			{
				delete szSend;
				szSend = NULL;
			}
			MessageBox(_CS("PlayBack.SearchFail"));
		}
		GetDlgItem(IDC_SEARCH)->EnableWindow(TRUE);
	}
}
Example #5
0
Real SplineTimeBase::infinityMap(Real t) const
{
	if(isLooping()) return beginTime() + Mod(t-beginTime(), length());
	else return Min(t,endTime());
}
Example #6
0
void timelineWidget::paintEvent( QPaintEvent * )
    {
    if( jLib::math::fcmp( timeInView( ), 0 ) )
        {
        if( endTime() != jLib::floatLimits::infinity() &&
             beginTime() != jLib::floatLimits::infinity() )
            {
            timeInView( endTime() - beginTime() );
            viewCentre( ( endTime() + beginTime() ) / 2 );
            }
        else
            {
            timeInView( 10 );
            viewCentre( 5 );
            }
        }

    QPainter painter(this);
    painter.setRenderHint( QPainter::Antialiasing, TRUE );

    if( timeInView() > ( endTime( ) - beginTime( ) ) )
        {
        timeInView( endTime( ) - beginTime( ) );
        }

    JFLOAT realBeginDrawing = viewCentre() - ( timeInView()/2 );
    JFLOAT realEndDrawing = viewCentre() + ( timeInView()/2 );

    if( realEndDrawing > endTime() )
        {
        realEndDrawing = endTime( );
        realBeginDrawing = endTime( ) - timeInView( );
        viewCentre( endTime( ) - ( timeInView()/2 ) );
        }
    if( realBeginDrawing < beginTime() )
        {
        realBeginDrawing = beginTime( );
        realEndDrawing = beginTime( ) + timeInView( );
        viewCentre( beginTime( ) + ( timeInView()/2 ) );
        }

    JFLOAT timeSpikeIntervals[] = { 0.125, 0.25, 0.5, 1, 1.25, 2.5, 5, 10, 50 };

    JFLOAT timeSpikeInterval = jLib::floatLimits::nan();

    JFLOAT minDist = jLib::floatLimits::infinity();
    for( int x=0; x<9; x++ )
        {
        JFLOAT size = timeToPixel( timeSpikeIntervals[x], 0, ( realEndDrawing - realBeginDrawing ), width() );

        if( ( size - 50.0 ) < minDist )
            {
            timeSpikeInterval = timeSpikeIntervals[x];
            minDist = size;
            }
        }

    if( timeSpikeInterval != timeSpikeInterval )
        {
        timeSpikeInterval = 1.0;
        }

    JFLOAT beginDrawing = realBeginDrawing - fmod( realBeginDrawing, timeSpikeInterval ) - 1;
    JFLOAT endDrawing = realEndDrawing + ( timeSpikeInterval - fmod( realEndDrawing, timeSpikeInterval ) );

    painter.setPen( QApplication::palette().color( QPalette::Text ) );
    for( JFLOAT x=( beginDrawing - timeSpikeInterval ); x<=endDrawing; x+=timeSpikeInterval )
        {
        JFLOAT actualTime = x + 1;
        JFLOAT xMidPos = timeToPixel( actualTime + ( 0.5 * timeSpikeInterval ), realBeginDrawing, realEndDrawing, width() );
        painter.drawLine( QPointF( xMidPos, height() ), QPointF( xMidPos, height() - minorTimeHeight() ) );

        JFLOAT xPos = timeToPixel( actualTime, realBeginDrawing, realEndDrawing, width() );

        painter.drawText( (int)(xPos+2), (int)(height() - majorTimeHeight()-5), formatTime( actualTime ) );
        painter.drawLine( QPointF( xPos, height() ), QPointF( xPos, height() - majorTimeHeight() ) );
        }

    QColor clipColourA( QApplication::palette().color( QPalette::Shadow ) );
    clipColourA.setAlpha( 200 );
    QColor clipColourB( QApplication::palette().color( QPalette::Shadow ) );
    clipColourB.setAlpha(100 );
    QLinearGradient clipGrad( 0, 0, 0, height() );
    clipGrad.setColorAt( 0.0, clipColourA );
    clipGrad.setColorAt( 1.0, clipColourB );

    QPen clipLine( QApplication::palette().color( QPalette::Shadow ) );
    clipLine.setWidthF( 1.5 );
    if( clipBegin() > realBeginDrawing )
        {
        JFLOAT clipBeginPix = timeToPixel( clipBegin(), realBeginDrawing, realEndDrawing, width() );
        painter.setPen( Qt::transparent );
        painter.setBrush( clipGrad );
        painter.drawRect( 0, 0, (int)clipBeginPix, (int)height() );
        painter.setPen( clipLine );
        painter.drawLine( (int)(clipBeginPix+1), 0, (int)(clipBeginPix+1), height() );
        }

    if( clipEnd() < realEndDrawing )
        {
        JFLOAT clipEndPix = timeToPixel( clipEnd(), realBeginDrawing, realEndDrawing, width() );
        if( clipEndPix < 0 )
            {
            clipEndPix = 0;
            }
        painter.setPen( Qt::transparent );
        painter.setBrush( clipGrad );
        painter.drawRect( (int)clipEndPix, 0, width(), height() );
        painter.setPen( clipLine );
        painter.drawLine( (int)clipEndPix, 0, (int)clipEndPix, height() );
        }


    JFLOAT now = timeToPixel( currentTime(), realBeginDrawing, realEndDrawing, width() );
    QColor nowColour = QApplication::palette().color( QPalette::Highlight );
    nowColour.setAlpha( 200 );

    QPen nowPen( nowColour );
    nowPen.setWidthF( 2.5 );
    painter.setPen( nowPen );

    painter.drawLine( QPointF( now, 0 ), QPointF( now, height() ) );
    painter.setPen( QApplication::palette().color( QPalette::Text ) );
    painter.drawText( (int)(now+2), (int)(height() - majorTimeHeight()-20), formatTime( currentTime() ) );

    nowColour.setAlpha( 150 );
    QLinearGradient highlight( now, 0, now-_nowGradientSpread, 0 );
    highlight.setColorAt(0, nowColour );
    highlight.setColorAt(1, Qt::transparent );
    painter.fillRect( QRectF( now-_nowGradientSpread, 0, _nowGradientSpread, height() ), highlight );
    }
QString ConnectionThread::processLine(QTcpSocket & sock,
                                      const QString & line)
{
    Debug() << "Got Line: " << line;
    QStringList toks = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);
    if (toks.size() < 1) return QString::null;
    QString cmd = toks.front();
    toks.pop_front();
    cmd = cmd.toUpper();
    if (cmd == "NOOP") {
        return ""; // noop command alwasy prints OK -- used to test server connectivity and for keepaliveage, etc
    } else if (cmd == "GETTIME") {
        return QString::number(getTime(), 'f', 9);
    } else if (cmd == "GETFRAMENUM") {
        StimPlugin *p = stimApp()->glWin()->runningPlugin();
        if (p) {
            return QString::number(p->getFrameNum());
        } else {
            Error() << "GETFRAMENUM command received but no plugin was running.";
        }
    } else if (cmd == "GETHWFRAMENUM") {
        GetHWFrameCountEvent *e = new GetHWFrameCountEvent();
        GetSetData *d = e->d;
        stimApp()->postEvent(this, e);
        unsigned hwfc = d->getReply<unsigned>();
        delete d;
        return QString::number(hwfc);
    } else if (cmd == "GETREFRESHRATE") {
        unsigned rate = stimApp()->refreshRate();
        return QString::number(rate);
    } else if (cmd == "GETCURRENTRSEED") {
        int s = stimApp()->glWin() 
			    ?  (stimApp()->glWin()->runningPlugin() 
				    ? stimApp()->glWin()->runningPlugin()->currentRSeed() 
				    : 0)
				: 0;
        return QString::number(s);
    } else if (cmd == "GETWIDTH") {
        return QString::number(stimApp()->glWin()->width());
    } else if (cmd == "GETHEIGHT") {
        return QString::number(stimApp()->glWin()->height());
    } else if (cmd == "GETFRAME" && toks.size()) {
        bool ok;
        unsigned framenum = toks[0].toUInt(&ok), numFrames = 1;
		Vec2i co, cs, ds; // params 3,4,5,6,7,8 are crop-origin-x, crop-origin-y, crop-size-width, crop-size-height, downsample-factor-x, downsample-factor-y
        toks.pop_front();
		if (toks.size()) {
			bool ok2;
			numFrames = toks.front().toUInt(&ok2);
			if (ok2) toks.pop_front();
			if (!ok2 || numFrames < 1) numFrames = 1;
			Vec2i *vp[] = { &co, &cs, &ds, 0 };
			for (Vec2i **vcur = vp; *vcur; ++vcur) {				
				Vec2i & v = **vcur;
				v.x = toks.size() ? toks.front().toUInt(&ok2) : 0;
				if (ok2) toks.pop_front();
				if (!ok2 || v.x < 0) v.x = 0;
				v.y = toks.size() ? toks.front().toUInt(&ok2) : 0;
				if (ok2) toks.pop_front();
				if (!ok2 || v.y < 0) v.y = 0;
			}
		}
		if (!ds.x) ds.x = 1;
		if (!ds.y) ds.y = 1;
        int datatype = GL_UNSIGNED_BYTE;
        if (toks.size()) {
            QString s = toks.join(" ").toUpper().trimmed();
            if (s == "BYTE") datatype = GL_BYTE;
            else if (s == "UNSIGNED BYTE") datatype = GL_UNSIGNED_BYTE;
            else if (s == "SHORT") datatype = GL_SHORT;
            else if (s == "UNSIGNED SHORT") datatype = GL_UNSIGNED_SHORT;
            else if (s == "INT") datatype = GL_INT;
            else if (s == "UNSIGNED INT") datatype = GL_UNSIGNED_INT;
            else if (s == "FLOAT") datatype = GL_FLOAT;
            else {
                Error() << "GETFRAME command invalid datatype `" << s << "'.";
                return QString::null;
            }
        }
        if (ok) {
            GetFrameEvent *e = new GetFrameEvent(framenum, numFrames, co, cs, ds, datatype);
            GetSetData *d = e->d;
            stimApp()->postEvent(this, e);
			const double tgen0 = getTime();
            QList<QByteArray> frames (d->getReply<QList<QByteArray> >());
            delete d;
            if (!frames.isEmpty()) {
				const unsigned long fbytes = frames.count()*frames.front().size();
				Debug() << "Generating " << frames.count() << " frames (" << fbytes << " bytes) took " << getTime()-tgen0 << " secs";
                sock.write((QString("BINARY DATA ") + QString::number(fbytes) + "\n").toUtf8());
				const double t0 = getTime();
				for (QList<QByteArray>::const_iterator it = frames.begin(); it != frames.end(); ++it)
					sock.write(*it);
				Debug() << "Sending " << numFrames << " frames (" << fbytes << " bytes) took " << getTime()-t0 << " secs";
                return "";
            }
        }
    } else if (cmd == "LIST") {
        QList<QString> lst = stimApp()->glWin()->plugins();
        QString ret;
        QTextStream ts(&ret, QIODevice::WriteOnly|QIODevice::Truncate);
        for(QList<QString>::const_iterator it = lst.begin(); it != lst.end(); ++it) {
            ts << (*it) << "\n";
        }
        ts.flush();
        return ret;
	} else if (cmd == "GETFRAMEVARS") { 
			QVector<double> data;
			int nrows, ncols;
			FrameVariables::readAllFromLast(data, &nrows, &ncols);
			sock.write(QString().sprintf("MATRIX %d %d\n", nrows, ncols).toUtf8());
			if (data.size()) sock.write(QByteArray::fromRawData(reinterpret_cast<char *>(&data[0]),data.size()*sizeof(double)));
			return "";
	} else if (cmd == "GETFRAMEVARNAMES") {
			QString ret = "";
			QTextStream ts(&ret);
			QStringList hdr = FrameVariables::readHeaderFromLast();
					
			int i = 0;
			for (QStringList::iterator it = hdr.begin(); it != hdr.end(); ++it, ++i) {
					ts << *it << "\n";
			}
			ts.flush();
			return ret;		
    } else if (cmd == "GETSTATS") {
        QString theStr("");
        QTextStream strm(&theStr, QIODevice::WriteOnly/*|QIODevice::Text*/);
        GetSetEvent *e = new GetHWFrameCountEvent();
        GetSetData *d = e->d;
        stimApp()->postEvent(this, e);
        unsigned hwfc = d->getReply<unsigned>();
        delete d;
        e = new IsConsoleHiddenEvent();
        d = e->d;
        stimApp()->postEvent(this, e);
        bool isConsoleHidden = d->getReply<bool>();
        delete d;
        StimPlugin *p = stimApp()->glWin()->runningPlugin();

        strm.setRealNumberPrecision(3);
        strm.setRealNumberNotation(QTextStream::FixedNotation);
        strm << "runningPlugin = " << (p ? p->name() : "") << "\n"
             << "isPaused = " << (stimApp()->glWin()->isPaused() ? "1" : "0") << "\n"
			 << "isInitialized = " << (p ? (p->isInitialized() ? 1 : 0) : 0) << "\n" 
             << "isConsoleWindowHidden = " << (isConsoleHidden ? "1" : "0") << "\n"
             << "statusBarString = " << (p ? p->getSBString() : "") << "\n"
             << "currentTime = " << QDateTime::currentDateTime().toString() << "\n"
             << "beginTime = " << (p ? p->getBeginTime().toString() : "") << "\n"
             << "width = " << stimApp()->glWin()->width() << "\n"
             << "height = " << stimApp()->glWin()->height() << "\n"
             << "fpsAvg = " << (p ? p->getFps() : 0.) << "\n"
             << "fpsMin = " << (p ? p->getFpsMin() : 0.) << "\n"
             << "fpsMax = " << (p ? p->getFpsMax() : 0.) << "\n"
             << "fpsLast = " << (p ? p->getFpsCur() : 0.) << "\n"
             << "frameNum = " << (p ? p->getFrameNum() : -1) << "\n"
             << "hardwareFrameCount = " << hwfc << "\n"
             << "haAccurateHWFrameCount = " << (hasAccurateHWFrameCount() ? "1" : "0") << "\n"
             << "calibraredRefreshRate = " << stimApp()->refreshRate() << "\n"
             << "hwRefreshRate = " << getHWRefreshRate() << "\n"
             << "hasAccurateHWRefreshRate = " << (hasAccurateHWRefreshRate() ? 1 : 0) << "\n"
             << "numMissedFrames = " << (p ? p->getNumMissedFrames() : 0) << "\n";
        QDateTime now(QDateTime::currentDateTime()), beginTime(p ? p->getBeginTime() : now);
        double secs = beginTime.secsTo(now), fskipsPerSec = 0.;
        if (p && secs > 0.) {
            fskipsPerSec = p->getNumMissedFrames() / secs;
        }
        strm << "missedFramesPerSec = " << fskipsPerSec << "\n"
             << "saveDirectory = " << stimApp()->outputDirectory() << "\n"
             << "pluginList = ";
        QList<QString> plugins = stimApp()->glWin()->plugins();
        for (QList<QString>::const_iterator it = plugins.begin(); it != plugins.end(); ++it) {
            if (it != plugins.begin()) strm << ", ";
            strm << *it;
        }
        strm << "\n"
             << "programUptime = " << getTime() << "\n"
             << "nProcessors = " << getNProcessors() << "\n"
             << "hostName = " << getHostName() << "\n"
             << "uptime = " << getUpTime() << "\n";
        
        strm.flush();
        return theStr;
    } else if (cmd == "GETPARAMS" && toks.size()) {
        QString pluginName = toks.join(" ");
        StimPlugin *p;
        if ( (p = stimApp()->glWin()->pluginFind(pluginName)) ) {
            return p->getParams().toString();
        }
    } else if (cmd == "GETPARAMHISTORY" && toks.size()) {
        QString pluginName = toks.join(" ");
        StimPlugin *p;
        if ( (p = stimApp()->glWin()->pluginFind(pluginName)) ) {
            return p->paramHistoryToString() + "\n";
        }
    } else if (cmd == "SETPARAMHISTORY" && toks.size()) {
        QString pluginName = toks.join(" ");
        StimPlugin *p = stimApp()->glWin()->pluginFind(pluginName);
		if (!p) {
			Error() << "SETPARAMHISTORY issued on a non-existant plugin";
		} else if (stimApp()->glWin()->runningPlugin() == p) {
			Error() << "SETPARAMHISTORY cannot be issued on a plugin that is running";
		} else {
            Debug() << "Sending: READY";
            sock.write("READY\n");
            QString paramstr ("");
            QTextStream paramts(&paramstr, QIODevice::WriteOnly/*|QIODevice::Text*/);
            QString line;
            while ( sock.canReadLine() || sock.waitForReadyRead() ) {
                line = sock.readLine().trimmed();
                if (!line.length()) break;
                Debug() << "Got Line: " << line;
                paramts << line << "\n";
            }
            paramts.flush();
			p->setPendingParamHistoryFromString(paramstr);
			p->setSaveParamHistoryOnStopOverride(true); // also tell plugin to save this param history, since it came from an external source
            return "";
		}
	} else if (cmd == "NUMPARAMSQUEUED" && toks.size()) {
        QString pluginName = toks.join(" ");
        StimPlugin *p = stimApp()->glWin()->pluginFind(pluginName);
		if (!p) {
			Error() << "NUMPARAMSQUEUED issued on a non-existant plugin";
		} else {
			return QString::number(p->pendingParamsHistorySize());
		}	
	} else if (cmd == "SETPARAMQUEUE") {
        QString pluginName = toks.join(" ");
        StimPlugin *p = stimApp()->glWin()->pluginFind(pluginName);
		if (!p) {
			Error() << "SETPARAMQUEUE issued on a non-existant plugin";
		} else if (stimApp()->glWin()->runningPlugin() == p) {
			Error() << "SETPARAMQUEUE cannot be issued on a plugin that is running";
		} else {
            Debug() << "Sending: READY";
            sock.write("READY\n");
            QString paramstr ("");
            QTextStream paramts(&paramstr, QIODevice::WriteOnly/*|QIODevice::Text*/);
            QString line;
            while ( sock.canReadLine() || sock.waitForReadyRead() ) {
                line = sock.readLine().trimmed();
                if (!line.length()) break;
                Debug() << "Got Line: " << line;
                paramts << line << "\n";
            }
            paramts.flush();
			if (p->enqueueParamsForPendingParamsHistoryFromString(paramstr)) {
				p->setSaveParamHistoryOnStopOverride(false); // also tell plugin to NOT save this param history, since presumably it can be generated again from calling client code..
				return "";
			} else {
				Error() << "SETPARAMQUEUE failed to enqueue params from specified param-queue";
			}
		}
    } else if (cmd == "SETPARAMS" && toks.size()) {
        QString pluginName = toks.join(" ");
        StimPlugin *p;
        if ( (p = stimApp()->glWin()->pluginFind(pluginName)) ) {
            Debug() << "Sending: READY";
            sock.write("READY\n");
            QString paramstr ("");
            QTextStream paramts(&paramstr, QIODevice::WriteOnly/*|QIODevice::Text*/);
            QString line;
            while ( sock.canReadLine() || sock.waitForReadyRead() ) {
                line = sock.readLine().trimmed();
                if (!line.length()) break;
                Debug() << "Got Line: " << line;
                paramts << line << "\n";
            }
            paramts.flush();
            p->setParams(paramstr, p == stimApp()->glWin()->runningPlugin());
            return "";
        } else if (!p) {
            Error() << "SETPARAMS issued on a non-existant plugin";
        }
    } else if (cmd == "RUNNING") {
        StimPlugin *p = stimApp()->glWin()->runningPlugin();
        if (p) {
            return p->name();
        }
        return "";
    } else if (cmd == "ISPAUSED") {
        return QString::number(stimApp()->glWin()->isPaused());
    } else if (cmd == "ISINITIALIZED") {
        StimPlugin *p = stimApp()->glWin()->runningPlugin();
        if (p) {
			return QString::number(p->isInitialized());
        }
        return "0";
    } else if (cmd == "PAUSE") {
        if (!stimApp()->glWin()->isPaused())
            stimApp()->glWin()->pauseUnpause();
        return "";
    } else if (cmd == "UNPAUSE") {
        if (stimApp()->glWin()->isPaused())
            stimApp()->glWin()->pauseUnpause();
        return "";
    } else if (cmd == "ISCONSOLEHIDDEN") {
        GetSetEvent *e = new IsConsoleHiddenEvent;
        GetSetData *d = e->d;
        stimApp()->postEvent(this, e);
        QString ret = QString::number(int(d->getReply<bool>()));
        delete d;
        return ret;
    } else if (cmd == "CONSOLEHIDE") {
        stimApp()->postEvent(this, new ConsoleHideEvent());
        return "";
    } else if (cmd == "CONSOLEUNHIDE") {
        stimApp()->postEvent(this, new ConsoleUnHideEvent());
        return "";
    } else if (cmd == "ISVSYNCDISABLED") {
        return QString::number(stimApp()->isVSyncDisabled() ? 1 : 0);
    } else if (cmd == "SETVSYNCDISABLED") {
		const bool disabled = toks.join("").toInt();
		stimApp()->postEvent(this, new SetVSyncDisabledEvent(disabled));
		return "";
    } else if (cmd == "START" && toks.size()) {
        // this commands needs to be executed in the main thread
        // to avoid race conditions and also to have a valid opengl context
        QString pluginName = toks.front();
        bool startUnpaused = toks.size() > 1 && toks[1].toInt();
        if ( (stimApp()->glWin()->pluginFind(pluginName)) ) {
            stimApp()->postEvent(this, new StartStopPluginEvent(pluginName, startUnpaused));
            return "";
        }
    } else if (cmd == "STOP") {
        // this commands needs to be executed in the main thread
        // to avoid race conditions and also to have a valid opengl context
        bool doSave = toks.join("").toInt();
        if (stimApp()->glWin()->runningPlugin())
            stimApp()->postEvent(this, new StartStopPluginEvent(doSave)); 
        return "";
    } else if (cmd == "GETSAVEDIR") {
        return stimApp()->outputDirectory();
    } else if (cmd == "SETSAVEDIR") {
        QString dir = toks.join(" ");
        return stimApp()->setOutputDirectory(dir) ? QString("") : QString::null;
    } else if (cmd == "GETVERSION") {
        return VERSION_STR;
    } else if (cmd == "BYE") {
        sock.close();
    } 
    // add more cmds here
    return QString::null;
}