void Controller::restart() { if (!m_consumer) return; if (m_producer && m_producer->is_valid() && m_producer->get_speed() != 0) { // Update the real_time property if not paused. m_consumer->set("real_time", realTime()); } const char* position = m_consumer->frames_to_time(m_consumer->position()); double speed = m_producer->get_speed(); QString xml = XML(); stop(); if (!setProducer(new Mlt::Producer(profile(), "xml-string", xml.toUtf8().constData()))) { #ifdef Q_OS_WIN play(speed); if (m_producer && m_producer->is_valid()) m_producer->seek(position); // Windows needs an extra kick here when not paused! if (speed != 0.0) play(speed); #else if (m_producer && m_producer->is_valid()) m_producer->seek(position); play(speed); #endif } }
void Controller::play(double speed) { if (m_producer) m_producer->set_speed(speed); if (m_consumer) { // Restore real_time behavior and work-ahead buffering if (!Settings.playerGPU()) if (m_consumer->get_int("real_time") != realTime()) { m_consumer->set("real_time", realTime()); m_consumer->set("buffer", 25); m_consumer->set("prefill", 1); // Changes to real_time require a consumer restart if running. if (!m_consumer->is_stopped()) m_consumer->stop(); } m_consumer->start(); refreshConsumer(Settings.playerScrubAudio()); } if (m_jackFilter) m_jackFilter->fire_event("jack-start"); setVolume(m_volume); }
void Controller::restart() { if (!m_consumer) return; if (m_producer && m_producer->is_valid() && m_producer->get_speed() != 0) { // Update the real_time property if not paused. m_consumer->set("real_time", realTime()); } if (m_producer && m_producer->is_valid() && Settings.playerGPU()) { const char* position = m_consumer->frames_to_time(m_consumer->position()); double speed = m_producer->get_speed(); QString xml = XML(); close(); if (!setProducer(new Mlt::Producer(profile(), "xml-string", xml.toUtf8().constData()))) { m_producer->seek(position); m_producer->set_speed(speed); m_consumer->start(); } } else { m_consumer->stop(); m_consumer->start(); } }
void Simulator::init(Project &prj, BodyFactory &factory){ initWorld(prj, factory, *this, pairs); initRTS(prj, receivers); std::cout << "number of receivers:" << receivers.size() << std::endl; m_totalTime = prj.totalTime(); m_logTimeStep = prj.logTimeStep(); m_kinematicsOnly = prj.kinematicsOnly(); realTime(prj.realTime()); collisions.length(pairs.size()); for(size_t colIndex=0; colIndex < pairs.size(); ++colIndex){ hrp::ColdetLinkPairPtr linkPair = pairs[colIndex]; hrp::Link *link0 = linkPair->link(0); hrp::Link *link1 = linkPair->link(1); OpenHRP::LinkPair& pair = collisions[colIndex].pair; pair.charName1 = CORBA::string_dup(link0->body->name().c_str()); pair.charName2 = CORBA::string_dup(link1->body->name().c_str()); pair.linkName1 = CORBA::string_dup(link0->name.c_str()); pair.linkName2 = CORBA::string_dup(link1->name.c_str()); } m_nextLogTime = 0; appendLog(); }
TimelineWidget::TimelineWidget(QWidget* parent) : QWidget(parent), m_timelineView(NULL), m_timeRate(1.0), m_paused(true) { m_timelineView = new TimelineView(this); connect(m_timelineView, SIGNAL(currentTimeChanged(double)), this, SIGNAL(currentTimeChanged(double))); QWidget* controls = new QWidget(this); controls->setContentsMargins(0, 0, 0, 0); QHBoxLayout* controlsLayout = new QHBoxLayout(controls); QLabel* zoomLabel = new QLabel(controls); zoomLabel->setText("Zoom: " "<a href=\"0.04167\">1h</a> " "<a href=\"0.08333\">6h</a> " "<a href=\"0.5\">12h</a> " "<a href=\"1\">1d</a> " "<a href=\"5\">5d</a> " "<a href=\"10\">10d</a> " "<a href=\"30\">1m</a> " "<a href=\"180\">6m</a> " "<a href=\"365\">1y</a> " "<a href=\"all\">all</a>"); QToolBar* toolbar = new QToolBar(controls); toolbar->setIconSize(QSize(24, 24)); toolbar->setMaximumHeight(24); toolbar->setMovable(false); toolbar->setFloatable(false); toolbar->setContentsMargins(0, 0, 0, 0); QAction* reverseTimeAction = new QAction(QIcon(":/icons/timeline-reverse.png"), tr("Reverse time"), toolbar); QAction* slowTimeAction = new QAction(QIcon(":/icons/timeline-slower.png"), tr("10x slower"), toolbar); QAction* halfTimeAction = new QAction(QIcon(":/icons/timeline-half.png"), tr("2x slower"), toolbar); QAction* pauseAction = new QAction(QIcon(":/icons/timeline-pause.png"), tr("Pause time"), toolbar); QAction* realTimeAction = new QAction(QIcon(":/icons/timeline-realtime.png"), tr("Real time"), toolbar); QAction* doubleTimeAction = new QAction(QIcon(":/icons/timeline-double.png"), tr("2x faster"), toolbar); QAction* fastTimeAction = new QAction(QIcon(":/icons/timeline-faster.png"), tr("10x faster"), toolbar); connect(reverseTimeAction, SIGNAL(triggered()), this, SLOT(reverseTime())); toolbar->addAction(reverseTimeAction); connect(slowTimeAction, SIGNAL(triggered()), this, SLOT(slowerTime())); toolbar->addAction(slowTimeAction); connect(halfTimeAction, SIGNAL(triggered()), this, SLOT(halfTime())); toolbar->addAction(halfTimeAction); connect(pauseAction, SIGNAL(triggered()), this, SLOT(togglePaused())); toolbar->addAction(pauseAction); connect(realTimeAction, SIGNAL(triggered()), this, SLOT(realTime())); toolbar->addAction(realTimeAction); connect(doubleTimeAction, SIGNAL(triggered()), this, SLOT(doubleTime())); toolbar->addAction(doubleTimeAction); connect(fastTimeAction, SIGNAL(triggered()), this, SLOT(fasterTime())); toolbar->addAction(fastTimeAction); controlsLayout->addWidget(toolbar); controlsLayout->addStretch(1); controlsLayout->addWidget(zoomLabel); controls->setLayout(controlsLayout); connect(zoomLabel, SIGNAL(linkActivated(const QString&)), this, SLOT(setZoom(const QString&))); QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(m_timelineView); layout->addWidget(controls); //layout->addLayout(controlsLayout); layout->setContentsMargins(0, 0, 0, 0); this->setLayout(layout); this->show(); m_timelineView->setTimeRange(0.0, 5.0); }
int main(int argc, char **argv){ const char *zFileToRead = 0; /* Input file. NULL for stdin */ const char *zDbName = 0; /* Name of the database file to create */ int useWithoutRowid = 0; /* True for --without-rowid */ int iMode = MODE_INSERT; /* One of MODE_xxxxx */ int useNocase = 0; /* True for --nocase */ int doTrace = 0; /* True for --trace */ int showStats = 0; /* True for --stats */ int showSummary = 0; /* True for --summary */ int showTimer = 0; /* True for --timer */ int cacheSize = 0; /* Desired cache size. 0 means default */ int pageSize = 0; /* Desired page size. 0 means default */ int commitInterval = 0; /* How often to commit. 0 means never */ int noSync = 0; /* True for --nosync */ const char *zJMode = 0; /* Journal mode */ int nOp = 0; /* Operation counter */ int i, j; /* Loop counters */ sqlite3 *db; /* The SQLite database connection */ char *zSql; /* Constructed SQL statement */ sqlite3_stmt *pInsert = 0; /* The INSERT statement */ sqlite3_stmt *pUpdate = 0; /* The UPDATE statement */ sqlite3_stmt *pSelect = 0; /* The SELECT statement */ sqlite3_stmt *pDelete = 0; /* The DELETE statement */ FILE *in; /* The open input file */ int rc; /* Return code from an SQLite interface */ int iCur, iHiwtr; /* Statistics values, current and "highwater" */ sqlite3_int64 sumCnt = 0; /* Sum in QUERY mode */ sqlite3_int64 startTime; char zInput[2000]; /* A single line of input */ /* Process command-line arguments */ for(i=1; i<argc; i++){ const char *z = argv[i]; if( z[0]=='-' ){ do{ z++; }while( z[0]=='-' ); if( strcmp(z,"without-rowid")==0 ){ useWithoutRowid = 1; }else if( strcmp(z,"replace")==0 ){ iMode = MODE_REPLACE; }else if( strcmp(z,"select")==0 ){ iMode = MODE_SELECT; }else if( strcmp(z,"insert")==0 ){ iMode = MODE_INSERT; }else if( strcmp(z,"update")==0 ){ iMode = MODE_UPDATE; }else if( strcmp(z,"delete")==0 ){ iMode = MODE_DELETE; }else if( strcmp(z,"query")==0 ){ iMode = MODE_QUERY; }else if( strcmp(z,"nocase")==0 ){ useNocase = 1; }else if( strcmp(z,"trace")==0 ){ doTrace = 1; }else if( strcmp(z,"nosync")==0 ){ noSync = 1; }else if( strcmp(z,"stats")==0 ){ showStats = 1; }else if( strcmp(z,"summary")==0 ){ showSummary = 1; }else if( strcmp(z,"timer")==0 ){ showTimer = i; }else if( strcmp(z,"cachesize")==0 && i<argc-1 ){ i++; cacheSize = atoi(argv[i]); }else if( strcmp(z,"pagesize")==0 && i<argc-1 ){ i++; pageSize = atoi(argv[i]); }else if( strcmp(z,"commit")==0 && i<argc-1 ){ i++; commitInterval = atoi(argv[i]); }else if( strcmp(z,"journal")==0 && i<argc-1 ){ zJMode = argv[++i]; }else{ fatal_error("unknown option: %s\n", argv[i]); } }else if( zDbName==0 ){ zDbName = argv[i]; }else if( zFileToRead==0 ){ zFileToRead = argv[i]; }else{ fatal_error("surplus argument: %s\n", argv[i]); } } if( zDbName==0 ){ fatal_error("Usage: %s [--options] DATABASE [INPUTFILE]\n", argv[0]); } startTime = realTime(); /* Open the database and the input file */ if( sqlite3_open(zDbName, &db) ){ fatal_error("Cannot open database file: %s\n", zDbName); } if( zFileToRead ){ in = fopen(zFileToRead, "rb"); if( in==0 ){ fatal_error("Could not open input file \"%s\"\n", zFileToRead); } }else{ in = stdin; } /* Set database connection options */ if( doTrace ) sqlite3_trace(db, traceCallback, 0); if( pageSize ){ zSql = sqlite3_mprintf("PRAGMA page_size=%d", pageSize); sqlite3_exec(db, zSql, 0, 0, 0); sqlite3_free(zSql); } if( cacheSize ){ zSql = sqlite3_mprintf("PRAGMA cache_size=%d", cacheSize); sqlite3_exec(db, zSql, 0, 0, 0); sqlite3_free(zSql); } if( noSync ) sqlite3_exec(db, "PRAGMA synchronous=OFF", 0, 0, 0); if( zJMode ){ zSql = sqlite3_mprintf("PRAGMA journal_mode=%s", zJMode); sqlite3_exec(db, zSql, 0, 0, 0); sqlite3_free(zSql); } /* Construct the "wordcount" table into which to put the words */ if( sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, 0) ){ fatal_error("Could not start a transaction\n"); } zSql = sqlite3_mprintf( "CREATE TABLE IF NOT EXISTS wordcount(\n" " word TEXT PRIMARY KEY COLLATE %s,\n" " cnt INTEGER\n" ")%s", useNocase ? "nocase" : "binary", useWithoutRowid ? " WITHOUT ROWID" : "" ); if( zSql==0 ) fatal_error("out of memory\n"); rc = sqlite3_exec(db, zSql, 0, 0, 0); if( rc ) fatal_error("Could not create the wordcount table: %s.\n", sqlite3_errmsg(db)); sqlite3_free(zSql); /* Prepare SQL statements that will be needed */ if( iMode==MODE_QUERY ){ rc = sqlite3_prepare_v2(db, "SELECT cnt FROM wordcount WHERE word=?1", -1, &pSelect, 0); if( rc ) fatal_error("Could not prepare the SELECT statement: %s\n", sqlite3_errmsg(db)); } if( iMode==MODE_SELECT ){ rc = sqlite3_prepare_v2(db, "SELECT 1 FROM wordcount WHERE word=?1", -1, &pSelect, 0); if( rc ) fatal_error("Could not prepare the SELECT statement: %s\n", sqlite3_errmsg(db)); rc = sqlite3_prepare_v2(db, "INSERT INTO wordcount(word,cnt) VALUES(?1,1)", -1, &pInsert, 0); if( rc ) fatal_error("Could not prepare the INSERT statement: %s\n", sqlite3_errmsg(db)); } if( iMode==MODE_SELECT || iMode==MODE_UPDATE || iMode==MODE_INSERT ){ rc = sqlite3_prepare_v2(db, "UPDATE wordcount SET cnt=cnt+1 WHERE word=?1", -1, &pUpdate, 0); if( rc ) fatal_error("Could not prepare the UPDATE statement: %s\n", sqlite3_errmsg(db)); } if( iMode==MODE_INSERT ){ rc = sqlite3_prepare_v2(db, "INSERT OR IGNORE INTO wordcount(word,cnt) VALUES(?1,1)", -1, &pInsert, 0); if( rc ) fatal_error("Could not prepare the INSERT statement: %s\n", sqlite3_errmsg(db)); } if( iMode==MODE_UPDATE ){ rc = sqlite3_prepare_v2(db, "INSERT OR IGNORE INTO wordcount(word,cnt) VALUES(?1,0)", -1, &pInsert, 0); if( rc ) fatal_error("Could not prepare the INSERT statement: %s\n", sqlite3_errmsg(db)); } if( iMode==MODE_REPLACE ){ rc = sqlite3_prepare_v2(db, "REPLACE INTO wordcount(word,cnt)" "VALUES(?1,coalesce((SELECT cnt FROM wordcount WHERE word=?1),0)+1)", -1, &pInsert, 0); if( rc ) fatal_error("Could not prepare the REPLACE statement: %s\n", sqlite3_errmsg(db)); } if( iMode==MODE_DELETE ){ rc = sqlite3_prepare_v2(db, "DELETE FROM wordcount WHERE word=?1", -1, &pDelete, 0); if( rc ) fatal_error("Could not prepare the DELETE statement: %s\n", sqlite3_errmsg(db)); } /* Process the input file */ while( fgets(zInput, sizeof(zInput), in) ){ for(i=0; zInput[i]; i++){ if( !isalpha(zInput[i]) ) continue; for(j=i+1; isalpha(zInput[j]); j++){} /* Found a new word at zInput[i] that is j-i bytes long. ** Process it into the wordcount table. */ if( iMode==MODE_DELETE ){ sqlite3_bind_text(pDelete, 1, zInput+i, j-i, SQLITE_STATIC); if( sqlite3_step(pDelete)!=SQLITE_DONE ){ fatal_error("DELETE failed: %s\n", sqlite3_errmsg(db)); } sqlite3_reset(pDelete); }else if( iMode==MODE_SELECT ){ sqlite3_bind_text(pSelect, 1, zInput+i, j-i, SQLITE_STATIC); rc = sqlite3_step(pSelect); sqlite3_reset(pSelect); if( rc==SQLITE_ROW ){ sqlite3_bind_text(pUpdate, 1, zInput+i, j-i, SQLITE_STATIC); if( sqlite3_step(pUpdate)!=SQLITE_DONE ){ fatal_error("UPDATE failed: %s\n", sqlite3_errmsg(db)); } sqlite3_reset(pUpdate); }else if( rc==SQLITE_DONE ){ sqlite3_bind_text(pInsert, 1, zInput+i, j-i, SQLITE_STATIC); if( sqlite3_step(pInsert)!=SQLITE_DONE ){ fatal_error("Insert failed: %s\n", sqlite3_errmsg(db)); } sqlite3_reset(pInsert); }else{ fatal_error("SELECT failed: %s\n", sqlite3_errmsg(db)); } }else if( iMode==MODE_QUERY ){ sqlite3_bind_text(pSelect, 1, zInput+i, j-i, SQLITE_STATIC); if( sqlite3_step(pSelect)==SQLITE_ROW ){ sumCnt += sqlite3_column_int64(pSelect, 0); } sqlite3_reset(pSelect); }else{ sqlite3_bind_text(pInsert, 1, zInput+i, j-i, SQLITE_STATIC); if( sqlite3_step(pInsert)!=SQLITE_DONE ){ fatal_error("INSERT failed: %s\n", sqlite3_errmsg(db)); } sqlite3_reset(pInsert); if( iMode==MODE_UPDATE || (iMode==MODE_INSERT && sqlite3_changes(db)==0) ){ sqlite3_bind_text(pUpdate, 1, zInput+i, j-i, SQLITE_STATIC); if( sqlite3_step(pUpdate)!=SQLITE_DONE ){ fatal_error("UPDATE failed: %s\n", sqlite3_errmsg(db)); } sqlite3_reset(pUpdate); } } i = j-1; /* Increment the operation counter. Do a COMMIT if it is time. */ nOp++; if( commitInterval>0 && (nOp%commitInterval)==0 ){ sqlite3_exec(db, "COMMIT; BEGIN IMMEDIATE", 0, 0, 0); } } } sqlite3_exec(db, "COMMIT", 0, 0, 0); if( zFileToRead ) fclose(in); sqlite3_finalize(pInsert); sqlite3_finalize(pUpdate); sqlite3_finalize(pSelect); sqlite3_finalize(pDelete); if( iMode==MODE_QUERY ){ printf("sum of cnt: %lld\n", sumCnt); rc = sqlite3_prepare_v2(db,"SELECT sum(cnt*cnt) FROM wordcount", -1, &pSelect, 0); if( rc==SQLITE_OK && sqlite3_step(pSelect)==SQLITE_ROW ){ printf("double-check: %lld\n", sqlite3_column_int64(pSelect, 0)); } sqlite3_finalize(pSelect); } if( showTimer ){ sqlite3_int64 elapseTime = realTime() - startTime; fprintf(stderr, "%3d.%03d wordcount", (int)(elapseTime/1000), (int)(elapseTime%1000)); for(i=1; i<argc; i++) if( i!=showTimer ) fprintf(stderr, " %s", argv[i]); fprintf(stderr, "\n"); } if( showSummary ){ sqlite3_create_function(db, "checksum", -1, SQLITE_UTF8, 0, 0, checksumStep, checksumFinalize); sqlite3_exec(db, "SELECT 'count(*): ', count(*) FROM wordcount;\n" "SELECT 'sum(cnt): ', sum(cnt) FROM wordcount;\n" "SELECT 'max(cnt): ', max(cnt) FROM wordcount;\n" "SELECT 'avg(cnt): ', avg(cnt) FROM wordcount;\n" "SELECT 'sum(cnt=1):', sum(cnt=1) FROM wordcount;\n" "SELECT 'top 10: ', group_concat(word, ', ') FROM " "(SELECT word FROM wordcount ORDER BY cnt DESC, word LIMIT 10);\n" "SELECT 'checksum: ', checksum(word, cnt) FROM " "(SELECT word, cnt FROM wordcount ORDER BY word);\n" "PRAGMA integrity_check;\n", printResult, 0, 0); } /* Database connection statistics printed after both prepared statements ** have been finalized */ if( showStats ){ sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED, &iCur, &iHiwtr, 0); printf("-- Lookaside Slots Used: %d (max %d)\n", iCur,iHiwtr); sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &iCur, &iHiwtr, 0); printf("-- Successful lookasides: %d\n", iHiwtr); sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, &iCur,&iHiwtr,0); printf("-- Lookaside size faults: %d\n", iHiwtr); sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, &iCur,&iHiwtr,0); printf("-- Lookaside OOM faults: %d\n", iHiwtr); sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, 0); printf("-- Pager Heap Usage: %d bytes\n", iCur); sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1); printf("-- Page cache hits: %d\n", iCur); sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1); printf("-- Page cache misses: %d\n", iCur); sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1); printf("-- Page cache writes: %d\n", iCur); sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, 0); printf("-- Schema Heap Usage: %d bytes\n", iCur); sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, 0); printf("-- Statement Heap Usage: %d bytes\n", iCur); } sqlite3_close(db); /* Global memory usage statistics printed after the database connection ** has closed. Memory usage should be zero at this point. */ if( showStats ){ sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, 0); printf("-- Memory Used (bytes): %d (max %d)\n", iCur,iHiwtr); sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, 0); printf("-- Outstanding Allocations: %d (max %d)\n", iCur,iHiwtr); sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, 0); printf("-- Pcache Overflow Bytes: %d (max %d)\n", iCur,iHiwtr); sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, 0); printf("-- Scratch Overflow Bytes: %d (max %d)\n", iCur,iHiwtr); sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, 0); printf("-- Largest Allocation: %d bytes\n",iHiwtr); sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, 0); printf("-- Largest Pcache Allocation: %d bytes\n",iHiwtr); sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, 0); printf("-- Largest Scratch Allocation: %d bytes\n", iHiwtr); } return 0; }
void AmptekSDD123Detector::onSpectrumPacketEventReceived(AmptekSpectrumPacketEvent* event) { QByteArray spectrumByteArray = event->spectrumByteArray_; int channelCount = event->channelCount_; QByteArray statusDataArray = event->statusDataArray_; AMDSFlatArray *spectrumArray = readSpectrumData(spectrumByteArray, channelCount); readStatusData(statusDataArray); if(spectrumReceiver_) { // qDebug() << "At the AmptekSDD123Detector level: dwellStartTime, dwellEndTime, dwellReplyTime: " << event->dwellStartTime_ << event->dwellEndTime_ << event->dwellReplyTime_; AMDSDwellStatusData statusData(fastCounts(), slowCounts(), detectorTemperature(), accumulationTime(), liveTime(), realTime(), generalPurposeCounter(), event->dwellStartTime_, event->dwellEndTime_, event->dwellReplyTime_); AmptekSpectrumEvent *spectrumEvent = new AmptekSpectrumEvent(); spectrumEvent->detectorSourceName_ = name(); spectrumEvent->spectrum_ = spectrumArray; spectrumEvent->statusData_ = statusData; QCoreApplication::postEvent(spectrumReceiver_, spectrumEvent); } else { AMDSRunTimeSupport::debugMessage(AMDSRunTimeSupport::AlertMsg, this, AMPTEK_ALERT_NO_SPECTRUM_EVENT_RECEIVER, QString("No spectrum receiver")); } }