diff --git a/MainWindow.cpp b/MainWindow.cpp index 5786143..853b504 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -636,7 +636,7 @@ bool MainWindow::clearProject() } uid MainWindow::createMediaPaint(uid paintId, QString uri, float x, float y, - bool isImage, bool live) + bool isImage, bool live, double rate) { // Cannot create image with already existing id. if (Paint::getUidAllocator().exists(paintId)) @@ -647,8 +647,9 @@ uid MainWindow::createMediaPaint(uid paintId, QString uri, float x, float y, Texture* tex = 0; if (isImage) tex = new Image(uri, paintId); - else - tex = new Media(uri, live, paintId); + else { + tex = new Media(uri, live, rate, paintId); + } // Create new image with corresponding ID. tex->setPosition(x, y); @@ -2110,3 +2111,28 @@ bool MainWindow::setTextureUri(int texture_id, const std::string &uri) return success; } +bool MainWindow::setTextureRate(int texture_id, double rate) +{ + Paint::ptr paint = this->mappingManager->getPaintById(texture_id); + if (paint.get() == NULL) + { + std::cout << "No such texture paint id " << texture_id << std::endl; + return false; + } + else + { + if (paint->getType() == "media") + { + Media *media = (Media *) paint.get(); // FIXME: use sharedptr cast + videoTimer->stop(); + media->setRate(rate); + videoTimer->start(); + } + else + { + std::cout << "Paint id " << texture_id << " is not a media texture." << std::endl; + return false; + } + } + return true; +} diff --git a/MainWindow.h b/MainWindow.h index dd11518..74957c2 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -115,7 +115,7 @@ public slots: bool clearProject(); /// Create or replace a media paint (or image). - uid createMediaPaint(uid paintId, QString uri, float x, float y, bool isImage, bool live); + uid createMediaPaint(uid paintId, QString uri, float x, float y, bool isImage, bool live=false, double rate=1.0); /// Create or replace a color paint. uid createColorPaint(uid paintId, QColor color); @@ -171,6 +171,7 @@ public slots: public: bool setTextureUri(int texture_id, const std::string &uri); + bool setTextureRate(int texture_id, double rate); private: // Internal methods. ////////////////////////////////////////////////////////////////////////////////////// diff --git a/OscInterface.cpp b/OscInterface.cpp index 131e936..34146d4 100644 --- a/OscInterface.cpp +++ b/OscInterface.cpp @@ -218,6 +218,13 @@ void OscInterface::applyOscCommand(MainWindow &main_window, QVariantList & comma //std::cout << "load /mapmap/paint/media/load " << paint_id << " " << image_uri << std::endl; main_window.setTextureUri(paint_id, image_uri); } + else if (path == "/mapmap/paint/media/rate" && typetags == "if") + { + int paint_id = command.at(2).toInt(); + float rate = command.at(3).toDouble(); + //std::cout << "load /mapmap/paint/media/load " << paint_id << " " << image_uri << std::endl; + main_window.setTextureRate(paint_id, rate); + } else { std::cout << "Unhandled OSC message: "; diff --git a/Paint.cpp b/Paint.cpp index 47a6c69..bbf56b2 100644 --- a/Paint.cpp +++ b/Paint.cpp @@ -51,12 +51,13 @@ bool Image::setUri(const QString &uri) /* Implementation of the Video class */ -Media::Media(const QString uri_, bool live, uid id): +Media::Media(const QString uri_, bool live, double rate, uid id): Texture(id), uri(uri_), impl_(NULL) { impl_ = new MediaImpl(uri_, live); + setRate(rate); } // vertigo diff --git a/Paint.h b/Paint.h index 0dc5057..35d6b9f 100644 --- a/Paint.h +++ b/Paint.h @@ -203,7 +203,7 @@ class Media : public Texture protected: QString uri; public: - Media(const QString uri_, bool live, uid id=NULL_UID); + Media(const QString uri_, bool live, double rate, uid id=NULL_UID); virtual ~Media(); const QString getUri() const {