From d5e8ce8127784fc67953ab3b6247e911be697cc2 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 9 Dec 2006 07:43:15 +0000 Subject: Preliminary patch loading (just loads nodes from RDF). git-svn-id: http://svn.drobilla.net/lad/ingen@214 a436a847-0d15-0410-975c-d299462d15a1 --- src/progs/ingenuity/App.cpp | 4 +- src/progs/ingenuity/App.h | 8 +- src/progs/ingenuity/LoadPatchWindow.cpp | 6 +- src/progs/ingenuity/LoadSubpatchWindow.cpp | 8 +- src/progs/ingenuity/Loader.cpp | 106 --------------------------- src/progs/ingenuity/Loader.h | 92 ----------------------- src/progs/ingenuity/Makefile.am | 4 +- src/progs/ingenuity/PatchCanvas.cpp | 2 +- src/progs/ingenuity/PatchWindow.cpp | 6 +- src/progs/ingenuity/ThreadedLoader.cpp | 113 +++++++++++++++++++++++++++++ src/progs/ingenuity/ThreadedLoader.h | 95 ++++++++++++++++++++++++ src/progs/patch_loader/patch_loader.cpp | 4 +- 12 files changed, 232 insertions(+), 216 deletions(-) delete mode 100644 src/progs/ingenuity/Loader.cpp delete mode 100644 src/progs/ingenuity/Loader.h create mode 100644 src/progs/ingenuity/ThreadedLoader.cpp create mode 100644 src/progs/ingenuity/ThreadedLoader.h (limited to 'src/progs') diff --git a/src/progs/ingenuity/App.cpp b/src/progs/ingenuity/App.cpp index 4e58a9dd..6470a807 100644 --- a/src/progs/ingenuity/App.cpp +++ b/src/progs/ingenuity/App.cpp @@ -37,7 +37,7 @@ #include "Configuration.h" #include "ConnectWindow.h" #include "Store.h" -#include "Loader.h" +#include "ThreadedLoader.h" #include "WindowFactory.h" #ifdef HAVE_LASH #include "LashController.h" @@ -100,7 +100,7 @@ App::attach(const SharedPtr& engine, const SharedPtrinit(*_store); } diff --git a/src/progs/ingenuity/App.h b/src/progs/ingenuity/App.h index 282958b9..213b572d 100644 --- a/src/progs/ingenuity/App.h +++ b/src/progs/ingenuity/App.h @@ -54,7 +54,7 @@ class PatchTreeView; class PatchTreeWindow; class ConnectWindow; class Configuration; -class Loader; +class ThreadedLoader; class WindowFactory; @@ -90,7 +90,7 @@ public: PatchTreeWindow* patch_tree() const { return _patch_tree_window; } Configuration* configuration() const { return _configuration; } Store* store() const { return _store; } - Loader* loader() const { return _loader; } + ThreadedLoader* loader() const { return _loader; } WindowFactory* window_factory() const { return _window_factory; } const SharedPtr& engine() const { return _engine; } @@ -106,8 +106,8 @@ protected: SharedPtr _engine; SharedPtr _client; - Store* _store; - Loader* _loader; + Store* _store; + ThreadedLoader* _loader; Configuration* _configuration; diff --git a/src/progs/ingenuity/LoadPatchWindow.cpp b/src/progs/ingenuity/LoadPatchWindow.cpp index b3e3068b..0588c6b1 100644 --- a/src/progs/ingenuity/LoadPatchWindow.cpp +++ b/src/progs/ingenuity/LoadPatchWindow.cpp @@ -22,7 +22,7 @@ #include "Configuration.h" #include "PatchModel.h" #include "ModelEngineInterface.h" -#include "Loader.h" +#include "ThreadedLoader.h" using boost::optional; @@ -50,7 +50,9 @@ LoadPatchWindow::LoadPatchWindow(BaseObjectType* cobject, const Glib::RefPtr #include #include +#include #include "App.h" #include "PatchView.h" #include "NodeModel.h" #include "PatchModel.h" #include "Configuration.h" #include "ModelEngineInterface.h" -#include "Loader.h" +#include "ThreadedLoader.h" +using boost::optional; namespace Ingenuity { @@ -52,7 +54,9 @@ LoadSubpatchWindow::LoadSubpatchWindow(BaseObjectType* cobject, const Glib::RefP Gtk::FileFilter filt; filt.add_pattern("*.om"); - filt.set_name("Om patch files (*.om)"); + filt.set_name("Om patch files (DEPRECATED) (*.om)"); + filt.add_pattern("*.ingen.ttl"); + filt.set_name("Ingen patch files (*.ingen.ttl)"); set_filter(filt); // Add global examples directory to "shortcut folders" (bookmarks) diff --git a/src/progs/ingenuity/Loader.cpp b/src/progs/ingenuity/Loader.cpp deleted file mode 100644 index 89245dff..00000000 --- a/src/progs/ingenuity/Loader.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "Loader.h" -#include -#include -#include -#include "Serializer.h" -#include "PatchModel.h" -using std::cout; using std::endl; - -namespace Ingenuity { - - -Loader::Loader(SharedPtr engine) -: _serializer(new Serializer(engine)) -{ - assert(_serializer != NULL); - - // FIXME: rework this so the thread is only present when it's doing something (save mem) - start(); -} - - -Loader::~Loader() -{ - delete _serializer; -} - - -void -Loader::_whipped() -{ - _mutex.lock(); - - while ( ! _events.empty() ) { - _events.front()(); - _events.pop_front(); - } - - _mutex.unlock(); -} - -void -Loader::load_patch(bool merge, - const string& data_base_uri, - const Path& data_path, - MetadataMap engine_data, - optional engine_parent, - optional engine_name, - optional engine_poly) -{ - _mutex.lock(); - - _events.push_back(sigc::hide_return(sigc::bind( - sigc::mem_fun(_serializer, &Serializer::load_patch), - merge, data_base_uri, data_path, - engine_data, engine_parent, engine_name, engine_poly))); - - _mutex.unlock(); - - whip(); -} - - -void -Loader::save_patch(SharedPtr model, const string& filename, bool recursive) -{ - _mutex.lock(); - - _events.push_back(sigc::hide_return(sigc::bind( - sigc::mem_fun(this, &Loader::save_patch_event), - model, filename, recursive))); - - _mutex.unlock(); - - whip(); -} - - -void -Loader::save_patch_event(SharedPtr model, const string& filename, bool recursive) -{ - if (recursive) - cerr << "FIXME: Recursive save." << endl; - - _serializer->start_to_filename(filename); - _serializer->serialize(model); - _serializer->finish(); -} - - -} // namespace Ingenuity diff --git a/src/progs/ingenuity/Loader.h b/src/progs/ingenuity/Loader.h deleted file mode 100644 index 05f97dbb..00000000 --- a/src/progs/ingenuity/Loader.h +++ /dev/null @@ -1,92 +0,0 @@ -/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef LOADERTHREAD_H -#define LOADERTHREAD_H - -#include -#include -#include -#include -#include "raul/Thread.h" -#include "raul/Slave.h" -#include "raul/Mutex.h" -#include "raul/Condition.h" -#include "ModelEngineInterface.h" -#include "ObjectModel.h" -using std::string; -using std::list; -using boost::optional; - -namespace Ingen { namespace Client { - class Serializer; - class PatchModel; -} } -using namespace Ingen::Client; - -namespace Ingenuity { - - -/** Thread for loading patch files. - * - * This is a seperate thread so it can send all the loading message without - * blocking everything else, so the app can respond to the incoming events - * caused as a result of the patch loading, while the patch loads. - * - * Implemented as a slave with a list of closures (events) which processes - * all events in the (mutex protected) list each time it's whipped. - * - * \ingroup Ingenuity - */ -class Loader : public Slave -{ -public: - Loader(SharedPtr engine); - ~Loader(); - - Serializer& serializer() const { return *_serializer; } - - // FIXME: there's a pattern here.... - // (same core interface as Serializer) - - void load_patch(bool merge, - const string& data_base_uri, - const Path& data_path, - MetadataMap engine_data, - optional engine_parent = optional(), - optional engine_name = optional(), - optional engine_poly = optional()); - - void save_patch(SharedPtr model, const string& filename, bool recursive); - -private: - - void save_patch_event(SharedPtr model, const string& filename, bool recursive); - - /** Returns nothing and takes no parameters (because they have all been bound) */ - typedef sigc::slot Closure; - - void _whipped(); - - Serializer* const _serializer; - Mutex _mutex; - list _events; -}; - - -} // namespace Ingenuity - -#endif // LOADERRTHREAD_H diff --git a/src/progs/ingenuity/Makefile.am b/src/progs/ingenuity/Makefile.am index a54f00c8..898a8b83 100644 --- a/src/progs/ingenuity/Makefile.am +++ b/src/progs/ingenuity/Makefile.am @@ -82,8 +82,8 @@ ingenuity_SOURCES = \ ConfigWindow.cpp \ PatchPropertiesWindow.h \ PatchPropertiesWindow.cpp \ - Loader.h \ - Loader.cpp \ + ThreadedLoader.h \ + ThreadedLoader.cpp \ RenameWindow.h \ RenameWindow.cpp \ NodePropertiesWindow.h \ diff --git a/src/progs/ingenuity/PatchCanvas.cpp b/src/progs/ingenuity/PatchCanvas.cpp index b1de8d60..84ec274c 100644 --- a/src/progs/ingenuity/PatchCanvas.cpp +++ b/src/progs/ingenuity/PatchCanvas.cpp @@ -311,7 +311,7 @@ PatchCanvas::destroy_selection() void PatchCanvas::copy_selection() { - Serializer serializer(App::instance().engine()); + Serializer serializer; serializer.start_to_string(); for (list >::iterator m = m_selected_modules.begin(); m != m_selected_modules.end(); ++m) { diff --git a/src/progs/ingenuity/PatchWindow.cpp b/src/progs/ingenuity/PatchWindow.cpp index ef7de264..ccadb9ed 100644 --- a/src/progs/ingenuity/PatchWindow.cpp +++ b/src/progs/ingenuity/PatchWindow.cpp @@ -34,7 +34,7 @@ #include "BreadCrumbBox.h" #include "Store.h" #include "ConnectWindow.h" -#include "Loader.h" +#include "ThreadedLoader.h" #include "WindowFactory.h" #include "PatchView.h" @@ -283,8 +283,8 @@ PatchWindow::event_save_as() if (result == Gtk::RESPONSE_OK) { string filename = dialog.get_filename(); - if (filename.length() < 4 || filename.substr(filename.length()-3) != ".om") - filename += ".om"; + if (filename.length() < 11 || filename.substr(filename.length()-10) != ".ingen.ttl") + filename += ".ingen.ttl"; bool confirm = false; std::fstream fin; diff --git a/src/progs/ingenuity/ThreadedLoader.cpp b/src/progs/ingenuity/ThreadedLoader.cpp new file mode 100644 index 00000000..fbd64d3d --- /dev/null +++ b/src/progs/ingenuity/ThreadedLoader.cpp @@ -0,0 +1,113 @@ +/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. + * + * Ingen is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "ThreadedLoader.h" +#include +#include +#include +#include "Loader.h" +#include "PatchModel.h" +using std::cout; using std::endl; + +namespace Ingenuity { + + +ThreadedLoader::ThreadedLoader(SharedPtr engine) +: _loader(new Loader(engine)) +, _serializer(new Serializer()) +{ + assert(_loader != NULL); + + // FIXME: rework this so the thread is only present when it's doing something (save mem) + start(); +} + + +ThreadedLoader::~ThreadedLoader() +{ + delete _loader; +} + + +void +ThreadedLoader::_whipped() +{ + _mutex.lock(); + + while ( ! _events.empty() ) { + _events.front()(); + _events.pop_front(); + } + + _mutex.unlock(); +} + +void +ThreadedLoader::load_patch(bool merge, + const string& data_base_uri, + const Path& data_path, + MetadataMap engine_data, + optional engine_parent, + optional engine_name, + optional engine_poly) +{ + _mutex.lock(); + + /*_events.push_back(sigc::hide_return(sigc::bind( + sigc::mem_fun(_loader, &Loader::load_patch), + merge, data_base_uri, data_path, + engine_data, engine_parent, engine_name, engine_poly)));*/ + + cerr << "FIXME: load under root only\n"; + + _events.push_back(sigc::bind( + sigc::mem_fun(_loader, &Loader::load), + data_base_uri, "/")); + + _mutex.unlock(); + + whip(); +} + + +void +ThreadedLoader::save_patch(SharedPtr model, const string& filename, bool recursive) +{ + _mutex.lock(); + + _events.push_back(sigc::hide_return(sigc::bind( + sigc::mem_fun(this, &ThreadedLoader::save_patch_event), + model, filename, recursive))); + + _mutex.unlock(); + + whip(); +} + + +void +ThreadedLoader::save_patch_event(SharedPtr model, const string& filename, bool recursive) +{ + if (recursive) + cerr << "FIXME: Recursive save." << endl; + + _serializer->start_to_filename(filename); + _serializer->serialize(model); + _serializer->finish(); +} + + +} // namespace Ingenuity diff --git a/src/progs/ingenuity/ThreadedLoader.h b/src/progs/ingenuity/ThreadedLoader.h new file mode 100644 index 00000000..9212c9c7 --- /dev/null +++ b/src/progs/ingenuity/ThreadedLoader.h @@ -0,0 +1,95 @@ +/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. + * + * Ingen is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef THREADEDLOADER_H +#define THREADEDLOADER_H + +#include +#include +#include +#include +#include "raul/Thread.h" +#include "raul/Slave.h" +#include "raul/Mutex.h" +#include "raul/Condition.h" +#include "ModelEngineInterface.h" +#include "ObjectModel.h" +#include "Serializer.h" +using std::string; +using std::list; +using boost::optional; + +namespace Ingen { namespace Client { + class Loader; + class PatchModel; +} } +using namespace Ingen::Client; + +namespace Ingenuity { + + +/** Thread for loading patch files. + * + * This is a seperate thread so it can send all the loading message without + * blocking everything else, so the app can respond to the incoming events + * caused as a result of the patch loading, while the patch loads. + * + * Implemented as a slave with a list of closures (events) which processes + * all events in the (mutex protected) list each time it's whipped. + * + * \ingroup Ingenuity + */ +class ThreadedLoader : public Slave +{ +public: + ThreadedLoader(SharedPtr engine); + ~ThreadedLoader(); + + Loader& loader() const { return *_loader; } + Serializer& serializer() const { return *_serializer; } + + // FIXME: there's a pattern here.... + // (same core interface as Loader/Serializer) + + void load_patch(bool merge, + const string& data_base_uri, + const Path& data_path, + MetadataMap engine_data, + optional engine_parent = optional(), + optional engine_name = optional(), + optional engine_poly = optional()); + + void save_patch(SharedPtr model, const string& filename, bool recursive); + +private: + + void save_patch_event(SharedPtr model, const string& filename, bool recursive); + + /** Returns nothing and takes no parameters (because they have all been bound) */ + typedef sigc::slot Closure; + + void _whipped(); + + Loader* const _loader; + Serializer* const _serializer; + Mutex _mutex; + list _events; +}; + + +} // namespace Ingenuity + +#endif // LOADERRTHREAD_H diff --git a/src/progs/patch_loader/patch_loader.cpp b/src/progs/patch_loader/patch_loader.cpp index 25fd626f..eb222c33 100644 --- a/src/progs/patch_loader/patch_loader.cpp +++ b/src/progs/patch_loader/patch_loader.cpp @@ -16,7 +16,7 @@ #include "OSCModelEngineInterface.h" -#include "Serializer.h" +//#include "Serializer.h" #include "PatchModel.h" #include "raul/Path.h" #include @@ -53,7 +53,7 @@ int main(int argc, char** argv) SharedPtr engine(new OSCModelEngineInterface(engine_url)); - Serializer serializer(engine); + //Serializer serializer(engine); /* Connect to engine */ engine->attach(-1, client_port); -- cgit v1.2.1