From bf59519e4bee8b4b18767eec9b3241342487bf88 Mon Sep 17 00:00:00 2001 From: Alexandre Quessy Date: Sun, 5 Jan 2014 18:24:34 -0500 Subject: [PATCH 1/4] OscInterface now calls Facade --- Facade.cpp | 5 ++- MainWindow.cpp | 58 +--------------------------- OscInterface.cpp | 99 +++++++++++++++++++++++++++++++++++------------- OscInterface.h | 24 ++++++++---- 4 files changed, 95 insertions(+), 91 deletions(-) diff --git a/Facade.cpp b/Facade.cpp index 51f7e7a..f23af5f 100644 --- a/Facade.cpp +++ b/Facade.cpp @@ -34,20 +34,23 @@ bool Facade::clearProject() bool Facade::createImagePaint(const char *paint_id, const char *uri) { + std::cout << "TODO: Facade::createImagePaint" << std::endl; } bool Facade::updateImagePaintUri(const char *paint_id, const char *uri) { + std::cout << "TODO: Facade::updateImagePaintUri" << std::endl; } bool Facade::createMeshTextureMapping(const char *mapping_id, const char *paint_id, int n_rows, int n_cols, const QList &src, const QList &dst) { + std::cout << "TODO: Facade::createMeshTextureMapping" << std::endl; } bool Facade::createTriangleTextureMapping(const char *mapping_id, const char *paint_id, const QList &src, const QList &dst) { + std::cout << "TODO: Facade::createTriangleTextureMapping" << std::endl; } - diff --git a/MainWindow.cpp b/MainWindow.cpp index 4b731e2..7f3a0fe 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -688,7 +688,7 @@ void MainWindow::startOscReceiver() int port = config_osc_receive_port; std::ostringstream os; os << port; - osc_interface.reset(new OscInterface(this, os.str())); + osc_interface.reset(new OscInterface(os.str())); if (port != 0) { osc_interface->start(); @@ -702,62 +702,8 @@ void MainWindow::startOscReceiver() void MainWindow::pollOscInterface() { #ifdef HAVE_OSC - osc_interface->consume_commands(); + osc_interface->consume_commands(*_facade); #endif } -void MainWindow::applyOscCommand(QVariantList & command) -{ - bool VERBOSE = true; - - if (VERBOSE) - { - std::cout << "MainWindow::applyOscCommand: 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") - addQuad(); - else if (path == "/add/triangle") - addTriangle(); - else if (path == "/project/save") - save(); - else if (path == "/project/open") - open(); -} diff --git a/OscInterface.cpp b/OscInterface.cpp index fd5e728..67ecd43 100644 --- a/OscInterface.cpp +++ b/OscInterface.cpp @@ -21,14 +21,14 @@ */ #include "OscInterface.h" -#include "MainWindow.h" +#include "Facade.h" #include OscInterface::OscInterface( - MainWindow* owner, +// MainWindow* owner, const std::string &listen_port) : receiver_(listen_port), - owner_(owner), +// owner_(owner), messaging_queue_() { //if (listen_port != OSC_PORT_NONE) @@ -38,7 +38,7 @@ OscInterface::OscInterface( std::cout << "Listening osc.udp://localhost:" << listen_port << std::endl; // receiver_.addHandler("/ping", "", ping_cb, this); // receiver_.addHandler("/pong", "", pong_cb, this); - // receiver_.addHandler("/image/path", "s", image_path_cb, this); + //receiver_.addHandler("/image/path", "ss", image_path_cb, this); receiver_.addHandler(NULL, NULL, genericHandler, this); } } @@ -77,35 +77,17 @@ int OscInterface::ping_cb( return 0; } -int OscInterface::image_path_cb( - const char *path, - const char * /*types*/, - lo_arg **argv, - int /*argc*/, - void * /*data*/, - void *user_data) -{ - OscInterface* context = static_cast(user_data); - std::string file_name(static_cast(&argv[0]->s)); - //if (context->is_verbose()) - std::cout << "Got " << path << " " << file_name << std::endl; - QVariantList message; - message.append(QVariant(QString("image/path"))); - message.append(QVariant(QString(file_name.c_str()))); - context->push_command(message); - return 0; -} - void OscInterface::push_command(QVariantList command) { messaging_queue_.push(command); } + /** * Takes action! * * Should be called when it's time to take action, before rendering a frame, for example. */ -void OscInterface::consume_commands() +void OscInterface::consume_commands(Facade &facade) { bool success = true; while (success) @@ -117,12 +99,13 @@ void OscInterface::consume_commands() //if (is_verbose()) // std::cout << __FUNCTION__ << ": apply " << // command.first().toString().toStdString() << std::endl; - owner_->applyOscCommand(command); + this->applyOscCommand(facade, command); } } } -/** Starts listening if enabled +/** + * Starts listening if enabled */ void OscInterface::start() { @@ -174,3 +157,67 @@ int OscInterface::genericHandler(const char *path, context->push_command(message); return 0; // handled } + +static void printCommand(QVariantList &command) +{ + 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(); +} + +void OscInterface::applyOscCommand(Facade &facade, QVariantList & command) +{ + bool VERBOSE = true; + + if (VERBOSE) + { + std::cout << "OscInterface::applyOscCommand: Receive OSC: " << std::endl; + printCommand(command); + } + + // The two first QVariant objects are: path, typeTags + 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 == "ss") + { + std::string paint_id = command.at(2).toString().toStdString(); + std::string image_uri = command.at(3).toString().toStdString(); + //std::cout << "TODO load /image/uri " << image_id << " " << image_uri << std::endl; + facade.updateImagePaintUri(paint_id.c_str(), image_uri.c_str()); + } + + //else if (path == "/add/quad") + // addQuad(); + //else if (path == "/add/triangle") + // addTriangle(); + //else if (path == "/project/save") + // save(); + //else if (path == "/project/open") + // open(); +} diff --git a/OscInterface.h b/OscInterface.h index 4c19a87..d539c98 100644 --- a/OscInterface.h +++ b/OscInterface.h @@ -28,7 +28,7 @@ #include "OscReceiver.h" #include -class MainWindow; // forward decl +class Facade; // forward decl /** * Open Sound Control sending and receiving for LibreMapping. @@ -38,20 +38,23 @@ class OscInterface public: typedef std::tr1::shared_ptr ptr; OscInterface( - MainWindow* owner, + //MainWindow* owner, const std::string &listen_port); ~OscInterface() {} void start(); - void consume_commands(); - bool is_verbose() { return false; } + /** + * Call this method from the main thread. + * + * Each message is stored as a QVariantList. + * [args] + */ + void consume_commands(Facade &facade); private: + bool is_verbose() { return false; } void push_command(QVariantList command); /** * OSC callback */ - static int image_path_cb(const char *path, - const char *types, lo_arg **argv, - int argc, void *data, void *user_data); static int ping_cb(const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data); @@ -64,8 +67,13 @@ class OscInterface bool receiving_enabled_; OscReceiver receiver_; - MainWindow* owner_; + //MainWindow* owner_; ConcurrentQueue messaging_queue_; + /* + * In the main thread, handles the messages. + */ + void applyOscCommand(Facade &facade, QVariantList & command); }; + #endif /* include guard */ From d9c9816ab6d825ce206e84eeca2504e722443347 Mon Sep 17 00:00:00 2001 From: Alexandre Quessy Date: Sun, 5 Jan 2014 18:37:54 -0500 Subject: [PATCH 2/4] rename organization for preferences saving --- MainWindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MainWindow.cpp b/MainWindow.cpp index 2e9a085..2c89e6b 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -550,7 +550,7 @@ void MainWindow::createStatusBar() void MainWindow::readSettings() { - QSettings settings("OIF", "Libremapping"); + QSettings settings("LibreMapping", "LibreMapping"); restoreGeometry(settings.value("geometry").toByteArray()); mainSplitter->restoreState(settings.value("mainSplitter").toByteArray()); @@ -561,7 +561,7 @@ void MainWindow::readSettings() void MainWindow::writeSettings() { - QSettings settings("OIF", "Libremapping"); + QSettings settings("LibreMapping", "LibreMapping"); settings.setValue("geometry", saveGeometry()); settings.setValue("mainSplitter", mainSplitter->saveState()); From cc57c3b9b021a45bae89b9fd1cf206e7ec48753d Mon Sep 17 00:00:00 2001 From: Alexandre Quessy Date: Sun, 5 Jan 2014 18:38:17 -0500 Subject: [PATCH 3/4] more bugs to fix --- BUGS | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/BUGS b/BUGS index ef8ad2c..ee41393 100644 --- a/BUGS +++ b/BUGS @@ -1,6 +1,9 @@ LibreMapping known bugs ======================= - - * segfaults if OSC receiving port is busy +* should ask for confirmation when we quit if the project has not been saved. +* cannot load state saving +* cannot delete mappings +* cannot delete paints +* cannot remove points in meshes From 81b7e769b3ba90618cf875bc64c46e80e456f5c6 Mon Sep 17 00:00:00 2001 From: Alexandre Quessy Date: Sun, 5 Jan 2014 18:40:00 -0500 Subject: [PATCH 4/4] git ignore more files --- .gitignore | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 952676a..2811ff9 100644 --- a/.gitignore +++ b/.gitignore @@ -17,11 +17,11 @@ prototypes/wx-04-gst/run Debug/ Release/ libremapping -moc_DestinationGLCanvas.cpp -moc_MapperGLCanvas.cpp -moc_MainWindow.cpp -moc_SourceGLCanvas.cpp +moc_*.cpp prototypes/gst/ prototypes/wx-02-input-output/run -qrc_libremapping.cpp +qrc_*.cpp +qteditorfactory.moc +qtpropertymanager.moc +qttreepropertybrowser.moc html/