diff --git a/MainWindow.cpp b/MainWindow.cpp index b864bba..b8b8c74 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -23,6 +23,7 @@ #include "ProjectReader.h" #include "Facade.h" #include +#include MainWindow::MainWindow() { @@ -1480,59 +1481,86 @@ void MainWindow::pollOscInterface() #endif } -void MainWindow::applyOscCommand(const QVariantList& command) +// void MainWindow::applyOscCommand(const QVariantList& command) +// { +// bool VERBOSE = true; +// if (VERBOSE) +// { +// std::cout << "Receive OSC: "; +// for (int i = 0; i < command.size(); ++i) +// { +// if (command.at(i).type() == QVariant::Int) +// { +// std::cout << command.at(i).toInt() << " "; +// } +// else if (command.at(i).type() == QVariant::Double) +// { +// std::cout << command.at(i).toDouble() << " "; +// } +// else if (command.at(i).type() == QVariant::String) +// { +// std::cout << command.at(i).toString().toStdString() << " "; +// } +// else +// { +// std::cout << "??? "; +// } +// } +// std::cout << std::endl; +// std::cout.flush(); +// } +// +// if (command.size() < 2) +// return; +// if (command.at(0).type() != QVariant::String) +// return; +// if (command.at(1).type() != QVariant::String) +// return; +// std::string path = command.at(0).toString().toStdString(); +// std::string typetags = command.at(1).toString().toStdString(); +// +// // Handle all OSC messages here +// if (path == "/image/uri" && typetags == "s") +// { +// std::string image_uri = command.at(2).toString().toStdString(); +// std::cout << "TODO load /image/uri " << image_uri << std::endl; +// } +// else if (path == "/add/quad") +// addMesh(); +// else if (path == "/add/triangle") +// addTriangle(); +// else if (path == "/add/ellipse") +// addEllipse(); +// else if (path == "/project/save") +// save(); +// else if (path == "/project/open") +// open(); +// } + +bool MainWindow::setTextureUri(int texture_id, const std::string &uri) { - bool VERBOSE = true; - if (VERBOSE) - { - std::cout << "Receive OSC: "; - for (int i = 0; i < command.size(); ++i) + // TODO: const QString & + + bool success = false; + Paint::ptr paint = this->mappingManager->getPaintById(texture_id); + if (paint.get() == NULL) { - if (command.at(i).type() == QVariant::Int) - { - std::cout << command.at(i).toInt() << " "; - } - else if (command.at(i).type() == QVariant::Double) - { - std::cout << command.at(i).toDouble() << " "; - } - else if (command.at(i).type() == QVariant::String) - { - std::cout << command.at(i).toString().toStdString() << " "; - } - else - { - std::cout << "??? "; - } + std::cout << "No such texture paint id " << texture_id << std::endl; + success = false; } - std::cout << std::endl; - std::cout.flush(); - } - - if (command.size() < 2) - return; - if (command.at(0).type() != QVariant::String) - return; - if (command.at(1).type() != QVariant::String) - return; - std::string path = command.at(0).toString().toStdString(); - std::string typetags = command.at(1).toString().toStdString(); - - // Handle all OSC messages here - if (path == "/image/uri" && typetags == "s") - { - std::string image_uri = command.at(2).toString().toStdString(); - std::cout << "TODO load /image/uri " << image_uri << std::endl; - } - else if (path == "/add/quad") - addMesh(); - else if (path == "/add/triangle") - addTriangle(); - else if (path == "/add/ellipse") - addEllipse(); - else if (path == "/project/save") - save(); - else if (path == "/project/open") - open(); + else + { + if (paint->getType() == "media") + { + Media *media = (Media *) paint.get(); // FIXME: use sharedptr cast + success = media->setUri(QString(uri.c_str())); + } + else + { + std::cout << "Paint id " << texture_id << " is not a media texture." << std::endl; + return false; + } + } + return success; } diff --git a/MainWindow.h b/MainWindow.h index fe8f9a1..3044a24 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -58,7 +58,7 @@ public: ~MainWindow(); // XXX Unused. - void applyOscCommand(const QVariantList& command); + //void applyOscCommand(const QVariantList& command); protected: // Events /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -147,6 +147,9 @@ public slots: /// Updates all canvases. void updateCanvases(); +public: + bool setTextureUri(int texture_id, const std::string &uri); + private: // Internal methods. ////////////////////////////////////////////////////////////////////////////////////// diff --git a/MediaImpl.h b/MediaImpl.h index e673e72..13739b0 100644 --- a/MediaImpl.h +++ b/MediaImpl.h @@ -56,9 +56,9 @@ public: /// Returns true if the image has changed. bool runVideo(); // void runAudio(); + bool loadMovie(QString filename); protected: - bool loadMovie(QString filename); void unloadMovie(); void freeResources(); void resetMovie(); diff --git a/OscInterface.cpp b/OscInterface.cpp index 54ad6e1..96955dc 100644 --- a/OscInterface.cpp +++ b/OscInterface.cpp @@ -211,13 +211,13 @@ void OscInterface::applyOscCommand(MainWindow &main_window, QVariantList & comma std::string typetags = command.at(1).toString().toStdString(); // Handle all OSC messages here - if (path == "/image/uri" && typetags == "ss") + if (path == "/texture/uri" && typetags == "is") { - std::string paint_id = command.at(2).toString().toStdString(); + int paint_id = command.at(2).toInt(); std::string image_uri = command.at(3).toString().toStdString(); //std::cout << "TODO load /image/uri " << image_id << " " << image_uri << std::endl; // TODO: - //main_window.updateImagePaintUri(paint_id.c_str(), image_uri.c_str()); + main_window.setTextureUri(paint_id, image_uri); } //else if (path == "/add/quad") diff --git a/Paint.cpp b/Paint.cpp index 04ae499..b201781 100644 --- a/Paint.cpp +++ b/Paint.cpp @@ -90,3 +90,13 @@ bool Media::hasVideoSupport() return MediaImpl::hasVideoSupport(); } +bool Media::setUri(const QString &uri) +{ + bool success = false; + this->uri = uri; + success = this->impl_->loadMovie(uri); + if (! success) + qDebug() << "Cannot load movie " << uri << "." << endl; + return success; +} + diff --git a/Paint.h b/Paint.h index fc7633f..19579cb 100644 --- a/Paint.h +++ b/Paint.h @@ -189,6 +189,7 @@ public: { return uri; } + bool setUri(const QString &uri); virtual void build(); virtual void update(); virtual QString getType() const