From 93850c202de8b073a1ce1dd8bd246d407bce4e2f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 30 Sep 2008 16:50:21 +0000 Subject: Flatten ingen source directory heirarchy a bit. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@1551 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/ThreadedLoader.cpp | 155 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/gui/ThreadedLoader.cpp (limited to 'src/gui/ThreadedLoader.cpp') diff --git a/src/gui/ThreadedLoader.cpp b/src/gui/ThreadedLoader.cpp new file mode 100644 index 00000000..008b14c4 --- /dev/null +++ b/src/gui/ThreadedLoader.cpp @@ -0,0 +1,155 @@ +/* This file is part of Ingen. + * Copyright (C) 2007 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 +#include +#include "module/global.hpp" +#include "module/World.hpp" +#include "module/Module.hpp" +#include "client/PatchModel.hpp" +#include "App.hpp" +#include "ThreadedLoader.hpp" + +using namespace std; + +namespace Ingen { +namespace GUI { + + +ThreadedLoader::ThreadedLoader(SharedPtr engine) + : _engine(engine) + , _deprecated_loader(engine) +{ + set_name("Loader"); + + if (parser()) + start(); + else + cerr << "WARNING: Failed to load ingen_serialisation module, load disabled." << endl; +} + + +SharedPtr +ThreadedLoader::parser() +{ + if (_parser) + return _parser; + + World* world = App::instance().world(); + if (!world->serialisation_module) + world->serialisation_module = Ingen::Shared::load_module("ingen_serialisation"); + + if (world->serialisation_module) { + Parser* (*new_parser)() = NULL; + + bool found = App::instance().world()->serialisation_module->get_symbol( + "new_parser", (void*&)new_parser); + + if (found) + _parser = SharedPtr(new_parser()); + } + + return _parser; +} + + +void +ThreadedLoader::_whipped() +{ + _mutex.lock(); + + while ( ! _events.empty() ) { + _events.front()(); + _events.pop_front(); + } + + _mutex.unlock(); +} + +void +ThreadedLoader::load_patch(bool merge, + const Glib::ustring& data_base_uri, + const Path& data_path, + GraphObject::Variables engine_data, + optional engine_parent, + optional engine_symbol) +{ + _mutex.lock(); + + // FIXME: Filthy hack to load deprecated patches based on file extension + if (data_base_uri.substr(data_base_uri.length()-3) == ".om") { + _events.push_back(sigc::hide_return(sigc::bind( + sigc::mem_fun(_deprecated_loader, &DeprecatedLoader::load_patch), + data_base_uri, + engine_parent, + (engine_symbol) ? engine_symbol.get() : "", + engine_data, + false))); + } else { + Glib::ustring engine_base = ""; + if (engine_parent) { + if (merge) + engine_base = engine_parent.get(); + else + engine_base = engine_parent.get().base(); + } + + if (merge && (!engine_parent || engine_parent.get() == "/")) + engine_base = engine_base.substr(0, engine_base.find_last_of("/")); + + _events.push_back(sigc::hide_return(sigc::bind( + sigc::mem_fun(_parser.get(), &Ingen::Serialisation::Parser::parse_document), + App::instance().world(), + App::instance().world()->engine.get(), + data_base_uri, // document + data_base_uri + data_path.substr(1), // object URI document + engine_base, + engine_symbol, + engine_data))); + } + + whip(); + + _mutex.unlock(); +} + + +void +ThreadedLoader::save_patch(SharedPtr model, const string& filename) +{ + _mutex.lock(); + + _events.push_back(sigc::hide_return(sigc::bind( + sigc::mem_fun(this, &ThreadedLoader::save_patch_event), + model, filename))); + + _mutex.unlock(); + + whip(); +} + + +void +ThreadedLoader::save_patch_event(SharedPtr model, const string& filename) +{ + if (App::instance().serialiser()) + App::instance().serialiser()->to_file(model, filename); +} + + +} // namespace GUI +} // namespace Ingen -- cgit v1.2.1