Implement OSC callback to set video URI

This commit is contained in:
Alexandre Quessy
2014-04-26 19:03:46 +01:00
parent 5a2a1c3ce6
commit 348ffcb37e
6 changed files with 98 additions and 56 deletions
+79 -51
View File
@@ -23,6 +23,7 @@
#include "ProjectReader.h"
#include "Facade.h"
#include <sstream>
#include <string>
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;
}
+4 -1
View File
@@ -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. //////////////////////////////////////////////////////////////////////////////////////
+1 -1
View File
@@ -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();
+3 -3
View File
@@ -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")
+10
View File
@@ -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;
}
+1
View File
@@ -189,6 +189,7 @@ public:
{
return uri;
}
bool setUri(const QString &uri);
virtual void build();
virtual void update();
virtual QString getType() const