diff --git a/MM.cpp b/MM.cpp index 8ad045c..ef5a368 100644 --- a/MM.cpp +++ b/MM.cpp @@ -57,7 +57,7 @@ const qreal MM::VERTEX_LOCKED_RADIUS = 6; const qreal MM::VERTEX_SELECT_STROKE_WIDTH = 1; // Time. -const qreal MM::FRAMES_PER_SECOND = 29.97f; +const qreal MM::DEFAULT_FRAMES_PER_SECOND = 29.97f; // Zoom. const qreal MM::ZOOM_FACTOR = 1.4f; diff --git a/MM.h b/MM.h index 9125877..efda2ec 100644 --- a/MM.h +++ b/MM.h @@ -95,7 +95,7 @@ public: static const qreal VERTEX_SELECT_STROKE_WIDTH; // Time. - static const qreal FRAMES_PER_SECOND; + static const qreal DEFAULT_FRAMES_PER_SECOND; // Zoom. static const qreal ZOOM_FACTOR; diff --git a/MainWindow.cpp b/MainWindow.cpp index c535dda..dd5cb79 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -46,6 +46,9 @@ MainWindow::MainWindow() _hasCurrentMapping = false; currentSelectedItem = NULL; + // Frames per second. + _framesPerSecond = (-1); + // Play state. _isPlaying = false; @@ -82,8 +85,8 @@ MainWindow::MainWindow() // Create and start timer. videoTimer = new QTimer(this); - videoTimer->setInterval( int( 1000 / MM::FRAMES_PER_SECOND ) ); connect(videoTimer, SIGNAL(timeout()), this, SLOT(updateCanvases())); + setFramesPerSecond(MM::DEFAULT_FRAMES_PER_SECOND); videoTimer->start(); // Start playing by default. @@ -2830,6 +2833,12 @@ void MainWindow::enableDisplayControls(bool display) updateCanvases(); } +void MainWindow::setFramesPerSecond(qreal fps) +{ + _framesPerSecond = qMax(fps, 0.0); + videoTimer->setInterval( int( 1000 / _framesPerSecond ) ); +} + void MainWindow::enableDisplayPaintControls(bool display) { _displayPaintControls = display; diff --git a/MainWindow.h b/MainWindow.h index 21eb934..095e4fd 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -217,6 +217,7 @@ public slots: void updateCanvases(); // Editing toggles. + void setFramesPerSecond(qreal fps); void enableDisplayControls(bool display); void enableDisplayPaintControls(bool display); void enableStickyVertices(bool display); @@ -464,6 +465,9 @@ private: bool _hasCurrentMapping; bool _hasCurrentPaint; + // Number of frames per second. + qreal _framesPerSecond; + // True iff the play button is currently pressed. bool _isPlaying; @@ -523,6 +527,9 @@ public: MapperGLCanvas* getSourceCanvas() const { return sourceCanvas; } MapperGLCanvas* getDestinationCanvas() const { return destinationCanvas; } + /// Returns the number of frames per second. + qreal framesPerSecond() const { return _framesPerSecond; } + /// Returns true iff MapMap is currently playing (ie. not in pause). bool isPlaying() const { return _isPlaying; } diff --git a/main.cpp b/main.cpp index 1359b3b..964d9f0 100644 --- a/main.cpp +++ b/main.cpp @@ -117,6 +117,11 @@ int main(int argc, char *argv[]) QCommandLineOption localeOption(QStringList() << "l" << "lang", "Use language .", "lang", "en"); parser.addOption(localeOption); + // --frame-rate option + QCommandLineOption frameRateOption(QStringList() << "r" << "frame-rate", + "Use a framerate of per second.", "frame-rate", QString::number(MM::DEFAULT_FRAMES_PER_SECOND)); + parser.addOption(frameRateOption); + // Positional argument: file parser.addPositionalArgument("file", "Load project from that file."); @@ -205,6 +210,13 @@ int main(int argc, char *argv[]) win->setOscPort(oscPortNumberValue); } + bool optionOk; + qreal fps = parser.value("frame-rate").toDouble(&optionOk); + if (optionOk) + win->setFramesPerSecond(fps); + else + qFatal("Invalid option ."); + #endif