From a96166710faf2447ed10194d1829db5564b0dff9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 4 May 2007 03:59:38 +0000 Subject: Made engine, serialisation, client library, and GUI all dynamically loaded modules. Combined all executables into a single "ingen" program which can do everything. git-svn-id: http://svn.drobilla.net/lad/ingen@493 a436a847-0d15-0410-975c-d299462d15a1 --- src/progs/ingen/main.cpp | 194 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 src/progs/ingen/main.cpp (limited to 'src/progs/ingen/main.cpp') diff --git a/src/progs/ingen/main.cpp b/src/progs/ingen/main.cpp new file mode 100644 index 00000000..1ca1311a --- /dev/null +++ b/src/progs/ingen/main.cpp @@ -0,0 +1,194 @@ +/* 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 +#include +#include +#include +#include "config.h" +#include "module/Module.h" +#include "engine/Engine.h" +#include "engine/QueuedEngineInterface.h" +#include "serialisation/Loader.h" +#include "cmdline.h" + +using namespace std; +using namespace Ingen; + +SharedPtr engine; + + +void +catch_int(int) +{ + signal(SIGINT, catch_int); + signal(SIGTERM, catch_int); + + cout << "[Main] Ingen interrupted." << endl; + engine->quit(); +} + + +int +main(int argc, char** argv) +{ + /* Parse command line options */ + gengetopt_args_info args; + if (cmdline_parser (argc, argv, &args) != 0) + return 1; + + if (argc <= 1) { + cout << "No arguments provided. Try something like:" << endl << endl; + cout << "Run an engine: ingen -e" << endl; + cout << "Run the GUI: ingen -g" << endl; + cout << "Pring full help: ingen -h" << endl << endl; + cmdline_parser_print_help(); + return 0; + } + + SharedPtr engine_module; + SharedPtr gui_module; + + SharedPtr engine_interface; + + /* Run engine */ + if (args.engine_flag) { + + engine_module = Ingen::Shared::load_module("ingen_engine"); + + if (engine_module) { + /*if (args.engine_port_given) { + bool (*launch_engine)(int) = NULL; + if ( ! module->get_symbol("launch_osc_engine", (void*&)launch_engine)) + module.reset(); + else + launch_engine(args.engine_port_arg); + + } else if (args.gui_given || args.load_given) {*/ + Engine* (*new_engine)() = NULL; + if (engine_module->get_symbol("new_engine", (void*&)new_engine)) { + engine = SharedPtr(new_engine()); + engine->start_jack_driver(); + //engine->launch_osc_interface(args.engine_port_arg); + } else { + engine_module.reset(); + } + engine_interface = engine->new_queued_interface(); + /*} else { + cerr << "Nonsense command line parameters, engine not loaded." << endl; + }*/ + } else { + cerr << "Unable to load engine module, engine not loaded." << endl; + cerr << "Try running ingen_dev or setting INGEN_MODULE_PATH." << endl; + } + + } + + + /* Connect to remote engine */ + if (args.connect_given || (args.load_given && !engine_interface)) { + bool found = false; + SharedPtr client_module + = Ingen::Shared::load_module("ingen_client"); + + SharedPtr (*new_osc_interface)(const std::string&) = NULL; + + if (client_module) + found = client_module->get_symbol("new_osc_interface", (void*&)new_osc_interface); + + if (client_module && found) { + engine_interface = new_osc_interface(args.connect_arg); + } else { + cerr << "Unable to load ingen_client module, aborting." << endl; + return -1; + } + } + + + /* Load a patch */ + if (args.load_given) { + + Raul::RDF::World rdf_world; + rdf_world.add_prefix("xsd", "http://www.w3.org/2001/XMLSchema#"); + rdf_world.add_prefix("ingen", "http://drobilla.net/ns/ingen#"); + rdf_world.add_prefix("ingenuity", "http://drobilla.net/ns/ingenuity#"); + rdf_world.add_prefix("lv2", "http://lv2plug.in/ontology#"); + rdf_world.add_prefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#"); + rdf_world.add_prefix("doap", "http://usefulinc.com/ns/doap#"); + + boost::optional parent_path; + if (args.path_given) + parent_path = args.path_arg; + + bool found = false; + SharedPtr serialisation_module + = Ingen::Shared::load_module("ingen_serialisation"); + + Serialisation::Loader* (*new_loader)() = NULL; + + if (serialisation_module) + found = serialisation_module->get_symbol("new_loader", (void*&)new_loader); + + if (serialisation_module && found) { + SharedPtr loader(new_loader()); + loader->load(engine_interface, &rdf_world, + string("file:") + args.load_arg, parent_path, ""); + } else { + cerr << "Unable to load serialisation module, aborting." << endl; + return -1; + } + } + + + /* Run GUI */ + bool ran_gui = false; + if (args.gui_given) { + gui_module = Ingen::Shared::load_module("ingen_gui"); + void (*run)(int, char**) = NULL; + bool found = gui_module->get_symbol("run", (void*&)run); + + if (found) { + ran_gui = true; + run(argc, argv); + } else { + cerr << "Unable to find GUI module, GUI not loaded." << endl; + cerr << "Try running ingen_dev or setting INGEN_MODULE_PATH." << endl; + } + } + + + /* Didn't run the GUI, do our own main thing. */ + if (engine && !ran_gui) { + + signal(SIGINT, catch_int); + signal(SIGTERM, catch_int); + + engine->start_jack_driver(); + engine->start_osc_driver(args.engine_port_arg); + + engine->activate(); + + engine->main(); + + engine.reset(); + } + + return 0; +} + -- cgit v1.2.1