From b71db2874c25cfbc07b5438afaf07cae2f7cae3d Mon Sep 17 00:00:00 2001 From: baydam Date: Thu, 5 Mar 2015 21:37:13 +0000 Subject: [PATCH] Add OSC command to set volume level and play state --- MainWindow.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ MainWindow.h | 2 ++ MediaImpl.h | 2 +- OscInterface.cpp | 14 ++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/MainWindow.cpp b/MainWindow.cpp index 2c2edc1..eb2426c 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -2490,6 +2490,64 @@ bool MainWindow::setTextureRate(int texture_id, double rate) return true; } +bool MainWindow::setTextureVolume(int texture_id, double volume) +{ + 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->setVolume(volume); + videoTimer->start(); + } + else + { + std::cout << "Paint id " << texture_id << " is not a media texture." << std::endl; + return false; + } + } + return true; +} + +void MainWindow::setTexturePlayState(int texture_id, bool played) +{ + Paint::ptr paint = this->mappingManager->getPaintById(texture_id); + if (paint.get() == NULL) + { + std::cout << "No such texture paint id " << texture_id << std::endl; + } + else + { + if (paint->getType() == "media") + { + if (played) + { + videoTimer->stop(); + paint->play(); + videoTimer->start(); + } + else + { + videoTimer->stop(); + paint->pause(); + videoTimer->start(); + } + + } + else + { + std::cout << "Paint id " << texture_id << " is not a media texture." << std::endl; + } + } +} + void MainWindow::quitMapMap() { close(); diff --git a/MainWindow.h b/MainWindow.h index 5b70ebf..0d27c83 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -181,6 +181,8 @@ public slots: public: bool setTextureUri(int texture_id, const std::string &uri); bool setTextureRate(int texture_id, double rate); + bool setTextureVolume(int texture_id, double volume); + void setTexturePlayState(int texture_id, bool played); private: // Internal methods. ////////////////////////////////////////////////////////////////////////////////////// diff --git a/MediaImpl.h b/MediaImpl.h index d7c8a6b..ed88d1d 100644 --- a/MediaImpl.h +++ b/MediaImpl.h @@ -156,7 +156,7 @@ private: void _checkMessages(); void _setMovieReady(bool ready); bool _isMovieReady() const { return _movieReady; } - bool getPlayState() const { return _playState; }; + bool getPlayState() const { return _playState; } void _setFinished(bool finished); // Sends the appropriate seek events to adjust to rate. diff --git a/OscInterface.cpp b/OscInterface.cpp index 1ce270a..d805d52 100644 --- a/OscInterface.cpp +++ b/OscInterface.cpp @@ -225,6 +225,20 @@ void OscInterface::applyOscCommand(MainWindow &main_window, QVariantList & comma //std::cout << "load /mapmap/paint/media/load " << paint_id << " " << image_uri << std::endl; main_window.setTextureRate(paint_id, rate); } + else if (path == "/mapmap/paint/media/volume" && typetags == "if") + { + int paint_id = command.at(2).toInt(); + float volume = command.at(3).toDouble(); + //std::cout << "set /mapmap/paint/media/volume " << paint_id << " " << image_uri << std::endl; + main_window.setTextureVolume(paint_id, volume); + } + else if (path == "/mapmap/paint/media/played" && typetags == "ii") + { + int paint_id = command.at(2).toInt(); + int played = command.at(3).toInt(); + //std::cout << "set /mapmap/paint/media/played " << paint_id << " " << image_uri << std::endl; + main_window.setTexturePlayState(paint_id, played ? true : false); + } else if (path == "/mapmap/mapping/visible" && typetags == "ii") { int mappingId = command.at(2).toInt();