From 19045ab92aa7e996971584a0dc8780d1d58b498b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 19 Dec 2009 21:37:50 +0000 Subject: New ingen module (library, not e.g. LV2 plugin) design. Much cleaner interface and general usage of Ingen as a library. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2314 a436a847-0d15-0410-975c-d299462d15a1 --- src/ingen/cmdline.c | 687 -------------------------------------------------- src/ingen/cmdline.ggo | 37 --- src/ingen/cmdline.h | 204 --------------- src/ingen/main.cpp | 317 +++++++++-------------- src/ingen/wscript | 2 +- 5 files changed, 117 insertions(+), 1130 deletions(-) delete mode 100644 src/ingen/cmdline.c delete mode 100644 src/ingen/cmdline.ggo delete mode 100644 src/ingen/cmdline.h (limited to 'src/ingen') diff --git a/src/ingen/cmdline.c b/src/ingen/cmdline.c deleted file mode 100644 index 5724160a..00000000 --- a/src/ingen/cmdline.c +++ /dev/null @@ -1,687 +0,0 @@ -/* - File autogenerated by gengetopt - generated with the following command: - gengetopt -g - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include "getopt.h" - -#include "cmdline.h" - -const char *gengetopt_args_info_purpose = "A modular realtime audio processing system"; - -const char *gengetopt_args_info_usage = "Usage: ingen [OPTIONS]..."; - -const char *gengetopt_args_info_description = "Ingen can be run in various configurations. The engine can\nrun as a stand-alone server controlled by OSC, or internal to\nanother process (e.g. the GUI). The GUI can communicate with the engine\nvia either method, and many GUIs (or other things) may connect to an\nengine via OSC.\n\nExamples:\n\n ingen -e - Run an engine, listen for OSC \n ingen -g - Run a GUI, connect via OSC \n ingen -eg - Run an engine and a GUI in one process\n\nThe -l (load) option can be used in all cases:\n \n ingen -el patch.ingen.ttl - Run an engine and load a patch\n ingen -gl patch.ingen.ttl - Run a GUI and load a patch\n ingen -egl patch.ingen.ttl - Run an engine and a GUI and load a patch\n\nOptions:\n"; - -const char *gengetopt_args_info_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " -C, --client-port=INT Client OSC port", - " -c, --connect=STRING Connect to existing engine at URI \n (default=`osc.udp://localhost:16180')", - " -e, --engine Run (JACK) engine (default=off)", - " -E, --engine-port=INT Engine listen port (default=`16180')", - " -n, --engine-name=STRING Engine JACK client name (default=`ingen')", - " -g, --gui Launch the GTK graphical interface (default=off)", - " -l, --load=STRING Load patch", - " -p, --parallelism=INT Number of concurrent process threads (default=`1')", - " -L, --path=STRING Target path for loaded patch", - " -r, --run=STRING Run script", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING - , ARG_INT -} cmdline_parser_arg_type; - -static -void clear_given (struct gengetopt_args_info *args_info); -static -void clear_args (struct gengetopt_args_info *args_info); - -static int -cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error); - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct gengetopt_args_info *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->client_port_given = 0 ; - args_info->connect_given = 0 ; - args_info->engine_given = 0 ; - args_info->engine_port_given = 0 ; - args_info->engine_name_given = 0 ; - args_info->gui_given = 0 ; - args_info->load_given = 0 ; - args_info->parallelism_given = 0 ; - args_info->path_given = 0 ; - args_info->run_given = 0 ; -} - -static -void clear_args (struct gengetopt_args_info *args_info) -{ - args_info->client_port_orig = NULL; - args_info->connect_arg = gengetopt_strdup ("osc.udp://localhost:16180"); - args_info->connect_orig = NULL; - args_info->engine_flag = 0; - args_info->engine_port_arg = 16180; - args_info->engine_port_orig = NULL; - args_info->engine_name_arg = gengetopt_strdup ("ingen"); - args_info->engine_name_orig = NULL; - args_info->gui_flag = 0; - args_info->load_arg = NULL; - args_info->load_orig = NULL; - args_info->parallelism_arg = 1; - args_info->parallelism_orig = NULL; - args_info->path_arg = NULL; - args_info->path_orig = NULL; - args_info->run_arg = NULL; - args_info->run_orig = NULL; - -} - -static -void init_args_info(struct gengetopt_args_info *args_info) -{ - - - args_info->help_help = gengetopt_args_info_help[0] ; - args_info->version_help = gengetopt_args_info_help[1] ; - args_info->client_port_help = gengetopt_args_info_help[2] ; - args_info->connect_help = gengetopt_args_info_help[3] ; - args_info->engine_help = gengetopt_args_info_help[4] ; - args_info->engine_port_help = gengetopt_args_info_help[5] ; - args_info->engine_name_help = gengetopt_args_info_help[6] ; - args_info->gui_help = gengetopt_args_info_help[7] ; - args_info->load_help = gengetopt_args_info_help[8] ; - args_info->parallelism_help = gengetopt_args_info_help[9] ; - args_info->path_help = gengetopt_args_info_help[10] ; - args_info->run_help = gengetopt_args_info_help[11] ; - -} - -void -cmdline_parser_print_version (void) -{ - printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); -} - -static void print_help_common(void) { - cmdline_parser_print_version (); - - if (strlen(gengetopt_args_info_purpose) > 0) - printf("\n%s\n", gengetopt_args_info_purpose); - - if (strlen(gengetopt_args_info_usage) > 0) - printf("\n%s\n", gengetopt_args_info_usage); - - printf("\n"); - - if (strlen(gengetopt_args_info_description) > 0) - printf("%s\n\n", gengetopt_args_info_description); -} - -void -cmdline_parser_print_help (void) -{ - int i = 0; - print_help_common(); - while (gengetopt_args_info_help[i]) - printf("%s\n", gengetopt_args_info_help[i++]); -} - -void -cmdline_parser_init (struct gengetopt_args_info *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); -} - -void -cmdline_parser_params_init(struct cmdline_parser_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_params * -cmdline_parser_params_create(void) -{ - struct cmdline_parser_params *params = - (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); - cmdline_parser_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - - -static void -cmdline_parser_release (struct gengetopt_args_info *args_info) -{ - - free_string_field (&(args_info->client_port_orig)); - free_string_field (&(args_info->connect_arg)); - free_string_field (&(args_info->connect_orig)); - free_string_field (&(args_info->engine_port_orig)); - free_string_field (&(args_info->engine_name_arg)); - free_string_field (&(args_info->engine_name_orig)); - free_string_field (&(args_info->load_arg)); - free_string_field (&(args_info->load_orig)); - free_string_field (&(args_info->parallelism_orig)); - free_string_field (&(args_info->path_arg)); - free_string_field (&(args_info->path_orig)); - free_string_field (&(args_info->run_arg)); - free_string_field (&(args_info->run_orig)); - - - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[]) -{ - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - - -int -cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->client_port_given) - write_into_file(outfile, "client-port", args_info->client_port_orig, 0); - if (args_info->connect_given) - write_into_file(outfile, "connect", args_info->connect_orig, 0); - if (args_info->engine_given) - write_into_file(outfile, "engine", 0, 0 ); - if (args_info->engine_port_given) - write_into_file(outfile, "engine-port", args_info->engine_port_orig, 0); - if (args_info->engine_name_given) - write_into_file(outfile, "engine-name", args_info->engine_name_orig, 0); - if (args_info->gui_given) - write_into_file(outfile, "gui", 0, 0 ); - if (args_info->load_given) - write_into_file(outfile, "load", args_info->load_orig, 0); - if (args_info->parallelism_given) - write_into_file(outfile, "parallelism", args_info->parallelism_orig, 0); - if (args_info->path_given) - write_into_file(outfile, "path", args_info->path_orig, 0); - if (args_info->run_given) - write_into_file(outfile, "run", args_info->run_orig, 0); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_free (struct gengetopt_args_info *args_info) -{ - cmdline_parser_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = NULL; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -int -cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) -{ - return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_ext (int argc, char * const *argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params) -{ - int result; - result = cmdline_parser_internal (argc, argv, args_info, params, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_internal (argc, argv, args_info, ¶ms, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) -{ - return EXIT_SUCCESS; -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_params.check_ambiguity - * @param override @see cmdline_parser_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, char *possible_values[], const char *default_value, - cmdline_parser_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_INT: - if (val) *((int *)field) = strtol (val, &stop_char, 0); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - /* check numeric conversion */ - switch(arg_type) { - case ARG_INT: - if (val && !(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); - return 1; /* failure */ - } - break; - default: - ; - }; - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - - -int -cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - int error = 0; - struct gengetopt_args_info local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - override = params->override; - initialize = params->initialize; - check_required = params->check_required; - check_ambiguity = params->check_ambiguity; - - if (initialize) - cmdline_parser_init (args_info); - - cmdline_parser_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "client-port", 1, NULL, 'C' }, - { "connect", 1, NULL, 'c' }, - { "engine", 0, NULL, 'e' }, - { "engine-port", 1, NULL, 'E' }, - { "engine-name", 1, NULL, 'n' }, - { "gui", 0, NULL, 'g' }, - { "load", 1, NULL, 'l' }, - { "parallelism", 1, NULL, 'p' }, - { "path", 1, NULL, 'L' }, - { "run", 1, NULL, 'r' }, - { NULL, 0, NULL, 0 } - }; - - c = getopt_long (argc, argv, "hVC:c:eE:n:gl:p:L:r:", long_options, &option_index); - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_print_help (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_print_version (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'C': /* Client OSC port. */ - - - if (update_arg( (void *)&(args_info->client_port_arg), - &(args_info->client_port_orig), &(args_info->client_port_given), - &(local_args_info.client_port_given), optarg, 0, 0, ARG_INT, - check_ambiguity, override, 0, 0, - "client-port", 'C', - additional_error)) - goto failure; - - break; - case 'c': /* Connect to existing engine at URI. */ - - - if (update_arg( (void *)&(args_info->connect_arg), - &(args_info->connect_orig), &(args_info->connect_given), - &(local_args_info.connect_given), optarg, 0, "osc.udp://localhost:16180", ARG_STRING, - check_ambiguity, override, 0, 0, - "connect", 'c', - additional_error)) - goto failure; - - break; - case 'e': /* Run (JACK) engine. */ - - - if (update_arg((void *)&(args_info->engine_flag), 0, &(args_info->engine_given), - &(local_args_info.engine_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "engine", 'e', - additional_error)) - goto failure; - - break; - case 'E': /* Engine listen port. */ - - - if (update_arg( (void *)&(args_info->engine_port_arg), - &(args_info->engine_port_orig), &(args_info->engine_port_given), - &(local_args_info.engine_port_given), optarg, 0, "16180", ARG_INT, - check_ambiguity, override, 0, 0, - "engine-port", 'E', - additional_error)) - goto failure; - - break; - case 'n': /* Engine JACK client name. */ - - - if (update_arg( (void *)&(args_info->engine_name_arg), - &(args_info->engine_name_orig), &(args_info->engine_name_given), - &(local_args_info.engine_name_given), optarg, 0, "ingen", ARG_STRING, - check_ambiguity, override, 0, 0, - "engine-name", 'n', - additional_error)) - goto failure; - - break; - case 'g': /* Launch the GTK graphical interface. */ - - - if (update_arg((void *)&(args_info->gui_flag), 0, &(args_info->gui_given), - &(local_args_info.gui_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "gui", 'g', - additional_error)) - goto failure; - - break; - case 'l': /* Load patch. */ - - - if (update_arg( (void *)&(args_info->load_arg), - &(args_info->load_orig), &(args_info->load_given), - &(local_args_info.load_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "load", 'l', - additional_error)) - goto failure; - - break; - case 'p': /* Number of concurrent process threads. */ - - - if (update_arg( (void *)&(args_info->parallelism_arg), - &(args_info->parallelism_orig), &(args_info->parallelism_given), - &(local_args_info.parallelism_given), optarg, 0, "1", ARG_INT, - check_ambiguity, override, 0, 0, - "parallelism", 'p', - additional_error)) - goto failure; - - break; - case 'L': /* Target path for loaded patch. */ - - - if (update_arg( (void *)&(args_info->path_arg), - &(args_info->path_orig), &(args_info->path_given), - &(local_args_info.path_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "path", 'L', - additional_error)) - goto failure; - - break; - case 'r': /* Run script. */ - - - if (update_arg( (void *)&(args_info->run_arg), - &(args_info->run_orig), &(args_info->run_given), - &(local_args_info.run_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "run", 'r', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - - - cmdline_parser_release (&local_args_info); - - if ( error ) - return (EXIT_FAILURE); - - return 0; - -failure: - - cmdline_parser_release (&local_args_info); - return (EXIT_FAILURE); -} diff --git a/src/ingen/cmdline.ggo b/src/ingen/cmdline.ggo deleted file mode 100644 index 2892e65a..00000000 --- a/src/ingen/cmdline.ggo +++ /dev/null @@ -1,37 +0,0 @@ -# Process this file with gengetopt to generate the necessary code (in cmdline.h, cmdline.c) - -package "ingen" -purpose "A modular realtime audio processing system" - -description "Ingen can be run in various configurations. The engine can -run as a stand-alone server controlled by OSC, or internal to -another process (e.g. the GUI). The GUI can communicate with the engine -via either method, and many GUIs (or other things) may connect to an -engine via OSC. - -Examples: - - ingen -e - Run an engine, listen for OSC - ingen -g - Run a GUI, connect via OSC - ingen -eg - Run an engine and a GUI in one process - -The -l (load) option can be used in all cases: - - ingen -el patch.ingen.ttl - Run an engine and load a patch - ingen -gl patch.ingen.ttl - Run a GUI and load a patch - ingen -egl patch.ingen.ttl - Run an engine and a GUI and load a patch - -Options: -" - -option "client-port" C "Client OSC port" int no -option "connect" c "Connect to existing engine at URI" string no default="osc.udp://localhost:16180" -option "engine" e "Run (JACK) engine" flag off -option "engine-port" E "Engine listen port" int no default="16180" -option "engine-name" n "Engine JACK client name" string no default="ingen" -option "gui" g "Launch the GTK graphical interface" flag off -option "load" l "Load patch" string no -option "parallelism" p "Number of concurrent process threads" int no default="1" -option "path" L "Target path for loaded patch" string no -option "run" r "Run script" string no - diff --git a/src/ingen/cmdline.h b/src/ingen/cmdline.h deleted file mode 100644 index 0a798e6c..00000000 --- a/src/ingen/cmdline.h +++ /dev/null @@ -1,204 +0,0 @@ -/** @file cmdline.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt by Lorenzo Bettini */ - -#ifndef CMDLINE_H -#define CMDLINE_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_PACKAGE -/** @brief the program name */ -#define CMDLINE_PARSER_PACKAGE "ingen" -#endif - -#ifndef CMDLINE_PARSER_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_VERSION VERSION -#endif - -/** @brief Where the command line options are stored */ -struct gengetopt_args_info -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - int client_port_arg; /**< @brief Client OSC port. */ - char * client_port_orig; /**< @brief Client OSC port original value given at command line. */ - const char *client_port_help; /**< @brief Client OSC port help description. */ - char * connect_arg; /**< @brief Connect to existing engine at URI (default='osc.udp://localhost:16180'). */ - char * connect_orig; /**< @brief Connect to existing engine at URI original value given at command line. */ - const char *connect_help; /**< @brief Connect to existing engine at URI help description. */ - int engine_flag; /**< @brief Run (JACK) engine (default=off). */ - const char *engine_help; /**< @brief Run (JACK) engine help description. */ - int engine_port_arg; /**< @brief Engine listen port (default='16180'). */ - char * engine_port_orig; /**< @brief Engine listen port original value given at command line. */ - const char *engine_port_help; /**< @brief Engine listen port help description. */ - char * engine_name_arg; /**< @brief Engine JACK client name (default='ingen'). */ - char * engine_name_orig; /**< @brief Engine JACK client name original value given at command line. */ - const char *engine_name_help; /**< @brief Engine JACK client name help description. */ - int gui_flag; /**< @brief Launch the GTK graphical interface (default=off). */ - const char *gui_help; /**< @brief Launch the GTK graphical interface help description. */ - char * load_arg; /**< @brief Load patch. */ - char * load_orig; /**< @brief Load patch original value given at command line. */ - const char *load_help; /**< @brief Load patch help description. */ - int parallelism_arg; /**< @brief Number of concurrent process threads (default='1'). */ - char * parallelism_orig; /**< @brief Number of concurrent process threads original value given at command line. */ - const char *parallelism_help; /**< @brief Number of concurrent process threads help description. */ - char * path_arg; /**< @brief Target path for loaded patch. */ - char * path_orig; /**< @brief Target path for loaded patch original value given at command line. */ - const char *path_help; /**< @brief Target path for loaded patch help description. */ - char * run_arg; /**< @brief Run script. */ - char * run_orig; /**< @brief Run script original value given at command line. */ - const char *run_help; /**< @brief Run script help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int client_port_given ; /**< @brief Whether client-port was given. */ - unsigned int connect_given ; /**< @brief Whether connect was given. */ - unsigned int engine_given ; /**< @brief Whether engine was given. */ - unsigned int engine_port_given ; /**< @brief Whether engine-port was given. */ - unsigned int engine_name_given ; /**< @brief Whether engine-name was given. */ - unsigned int gui_given ; /**< @brief Whether gui was given. */ - unsigned int load_given ; /**< @brief Whether load was given. */ - unsigned int parallelism_given ; /**< @brief Whether parallelism was given. */ - unsigned int path_given ; /**< @brief Whether path was given. */ - unsigned int run_given ; /**< @brief Whether run was given. */ - -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *gengetopt_args_info_purpose; -/** @brief the usage string of the program */ -extern const char *gengetopt_args_info_usage; -/** @brief all the lines making the help output */ -extern const char *gengetopt_args_info_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser (int argc, char * const *argv, - struct gengetopt_args_info *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_ext() instead - */ -int cmdline_parser2 (int argc, char * const *argv, - struct gengetopt_args_info *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_ext (int argc, char * const *argv, - struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_dump(FILE *outfile, - struct gengetopt_args_info *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_file_save(const char *filename, - struct gengetopt_args_info *args_info); - -/** - * Print the help - */ -void cmdline_parser_print_help(void); -/** - * Print the version - */ -void cmdline_parser_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_params_init(struct cmdline_parser_params *params); - -/** - * Allocates dynamically a cmdline_parser_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_params structure - */ -struct cmdline_parser_params *cmdline_parser_params_create(void); - -/** - * Initializes the passed gengetopt_args_info structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_init (struct gengetopt_args_info *args_info); -/** - * Deallocates the string fields of the gengetopt_args_info structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_free (struct gengetopt_args_info *args_info); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_required (struct gengetopt_args_info *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CMDLINE_H */ diff --git a/src/ingen/main.cpp b/src/ingen/main.cpp index 850c398a..715261f3 100644 --- a/src/ingen/main.cpp +++ b/src/ingen/main.cpp @@ -18,29 +18,23 @@ #include "ingen-config.h" #include #include +#include #include #include #include #include #include +#include "raul/Configuration.hpp" #include "raul/Path.hpp" #include "raul/SharedPtr.hpp" #include "redlandmm/World.hpp" +#include "interface/EngineInterface.hpp" #include "shared/runtime_paths.hpp" #include "module/ingen_module.hpp" #include "module/Module.hpp" #include "module/World.hpp" #include "engine/Engine.hpp" -#include "engine/QueuedEngineInterface.hpp" -#include "engine/JackAudioDriver.hpp" #include "serialisation/Parser.hpp" -#include "cmdline.h" -#ifdef HAVE_LIBLO -#include "engine/OSCEngineReceiver.hpp" -#endif -#ifdef HAVE_SOUP -#include "engine/HTTPEngineReceiver.hpp" -#endif #ifdef WITH_BINDINGS #include "bindings/ingen_bindings.hpp" #endif @@ -52,47 +46,68 @@ using namespace Ingen; SharedPtr engine; void -catch_int(int) +ingen_interrupt(int) { - signal(SIGINT, catch_int); - signal(SIGTERM, catch_int); - - cout << "[Main] Ingen interrupted." << endl; + cout << "ingen: Interrupted" << endl; engine->quit(); } +void +ingen_abort(const char* msg) +{ + cerr << "ingen: Error: " << msg << endl; + ingen_destroy_world(); + exit(1); +} + int main(int argc, char** argv) { + Raul::Configuration conf("A realtime modular audio processor.", + "Ingen is a flexible modular system that be used in various ways.\n" + "The engine can run as a stand-alone server controlled via a network protocol\n" + "(e.g. OSC), or internal to another process (e.g. the GUI). The GUI, or other\n" + "clients, can communicate with the engine via any supported protocol, or host the\n" + "engine in the same process. Many clients can connect to an engine at once.\n\n" + "Examples:\n" + " ingen -e # Run an engine, listen for OSC\n" + " ingen -g # Run a GUI, connect via OSC\n" + " ingen -eg # Run an engine and a GUI in one process\n" + " ingen -egl patch.ingen.ttl # Run an engine and a GUI and load a patch"); + + conf.add("client-port", 'C', "Client OSC port", Atom::INT, Atom()) + .add("connect", 'c', "Connect to engine URI", Atom::STRING, "osc.udp://localhost:16180") + .add("engine", 'e', "Run (JACK) engine", Atom::BOOL, false) + .add("engine-port", 'E', "Engine listen port", Atom::INT, 16180) + .add("gui", 'g', "Launch the GTK graphical interface", Atom::BOOL, false) + .add("help", 'h', "Print this help message", Atom::BOOL, false) + .add("jack-client", 'n', "JACK client name", Atom::STRING, "ingen") + .add("jack-server", 's', "JACK server name", Atom::STRING, "default") + .add("load", 'l', "Load patch", Atom::STRING, Atom()) + .add("parallelism", 'p', "Number of concurrent process threads", Atom::INT, 1) + .add("path", 'L', "Target path for loaded patch", Atom::STRING, Atom()) + .add("run", 'r', "Run script", Atom::STRING, Atom()); + // Parse command line options - gengetopt_args_info args; - if (cmdline_parser (argc, argv, &args) != 0) - return 1; + try { + conf.parse(argc, argv); + } catch (std::exception& e) { + cout << "ingen: " << e.what() << endl; + return EXIT_FAILURE; + } + // Verify option sanity if (argc <= 1) { - cmdline_parser_print_help(); - cerr << endl << "*** Ingen requires at least one command line parameter" << endl; - cerr << "*** Just want a graphical application? Try 'ingen -eg'" << endl; - return 1; - } else if (args.connect_given && args.engine_flag) { - cerr << "\n*** Nonsense arguments, can't both run a local engine " - << "and connect to a remote one." << endl - << "*** Run separate instances if that is what you want" << endl; - return 1; + conf.print_usage("ingen", cout); + return EXIT_FAILURE; + } else if (conf.option("help").get_bool()) { + conf.print_usage("ingen", cout); + return EXIT_SUCCESS; } // Set bundle path from executable location so resources/modules can be found Shared::set_bundle_path_from_code((void*)&main); - SharedPtr engine_module; - SharedPtr engine_http_module; - SharedPtr engine_osc_module; - SharedPtr engine_queued_module; - SharedPtr engine_jack_module; - SharedPtr client_module; - SharedPtr gui_module; - SharedPtr bindings_module; - SharedPtr engine_interface; Glib::thread_init(); @@ -100,7 +115,11 @@ main(int argc, char** argv) g_type_init(); #endif - Ingen::Shared::World* world = Ingen::Shared::get_world(); + Ingen::Shared::World* world = ingen_get_world(); + + world->argc = argc; + world->argv = argv; + world->conf = &conf; // Set up RDF namespaces world->rdf_world->add_prefix("dc", "http://purl.org/dc/elements/1.1/"); @@ -116,211 +135,113 @@ main(int argc, char** argv) world->rdf_world->add_prefix("xsd", "http://www.w3.org/2001/XMLSchema#"); // Run engine - if (args.engine_flag) { - engine_module = Ingen::Shared::load_module("ingen_engine"); - engine_jack_module = Ingen::Shared::load_module("ingen_engine_jack"); - engine_queued_module = Ingen::Shared::load_module("ingen_engine_queued"); - - if (!engine_queued_module) { - cerr << "ERROR: Unable to load (queued) engine interface module" << endl; - Ingen::Shared::destroy_world(); - return 1; - } - - if (engine_module) { - Engine* (*new_engine)(Ingen::Shared::World* world) = NULL; - if (engine_module->get_symbol("new_engine", (void*&)new_engine)) { - engine = SharedPtr(new_engine(world)); - world->local_engine = engine; - - // Load queued (direct in-process) engine interface - if (args.gui_given && engine_queued_module) { - Ingen::QueuedEngineInterface* (*new_interface)(Ingen::Engine& engine); - if (engine_queued_module->get_symbol("new_queued_interface", (void*&)new_interface)) { - SharedPtr interface(new_interface(*engine)); - world->local_engine->add_event_source(interface); - engine_interface = interface; - world->engine = engine_interface; - } - - // Load network engine interfaces - } else { - #ifdef HAVE_LIBLO - if ((engine_osc_module = Ingen::Shared::load_module("ingen_engine_osc"))) { - Ingen::OSCEngineReceiver* (*new_receiver)( - Ingen::Engine& engine, size_t queue_size, uint16_t port); - if (engine_osc_module->get_symbol("new_osc_receiver", (void*&)new_receiver)) { - static const size_t queue_size = 1024; // FIXME - SharedPtr receiver(new_receiver( - *engine, queue_size, args.engine_port_arg)); - world->local_engine->add_event_source(receiver); - } - } - #endif - #ifdef HAVE_SOUP - if ((engine_http_module = Ingen::Shared::load_module("ingen_engine_http"))) { - Ingen::HTTPEngineReceiver* (*new_receiver)( - Ingen::Engine& engine, uint16_t port); - if (engine_http_module->get_symbol("new_http_receiver", (void*&)new_receiver)) { - SharedPtr receiver(new_receiver( - *world->local_engine, args.engine_port_arg)); - world->local_engine->add_event_source(receiver); - } - } - #endif - } - } else { - engine_module.reset(); - } - } else { - cerr << "Unable to load engine module." << endl; + if (conf.option("engine").get_bool()) { + if (!world->load("ingen_engine")) + ingen_abort("Unable to load engine module"); + + if (!world->local_engine) + ingen_abort("Unable to create engine"); + + engine = world->local_engine; + engine_interface = world->engine; + + // Not loading a GUI, load network engine interfaces + if (!conf.option("gui").get_bool()) { + #ifdef HAVE_LIBLO + if (!world->load("ingen_osc")) + ingen_abort("Unable to load OSC module"); + #endif + #ifdef HAVE_SOUP + if (!world->load("ingen_http")) + ingen_abort("Unable to load HTTP module"); + #endif } } - // Load client library - if (args.load_given || args.gui_given) { - client_module = Ingen::Shared::load_module("ingen_client"); - if (!client_module) - cerr << "Unable to load client module." << endl; - } + // Load client library (required for patch loading and/or GUI) + if (conf.option("load").is_valid() || conf.option("gui").get_bool()) + if (!world->load("ingen_client")) + ingen_abort("Unable to load client module"); // If we don't have a local engine interface (for GUI), use network - if (client_module && ! engine_interface) { - SharedPtr (*new_remote_interface) - (Ingen::Shared::World*, const std::string&) = NULL; - - if (client_module->get_symbol("new_remote_interface", (void*&)new_remote_interface)) { - engine_interface = new_remote_interface(world, args.connect_arg); - } else { - cerr << "Unable to find symbol 'new_remote_interface' in " - "ingen_client module, aborting." << endl; - return -1; - } + if (!engine_interface) { + const char* const uri = conf.option("connect").get_string(); + if (!(engine_interface = world->interface(uri))) + ingen_abort((string("Unable to create interface to `") + uri + "'").c_str()); } // Activate the engine, if we have one if (engine) { - Ingen::JackAudioDriver* (*new_driver)( - Ingen::Engine& engine, - const std::string server_name, - const std::string client_name, - void* jack_client) = NULL; - if (engine_jack_module->get_symbol("new_jack_audio_driver", (void*&)new_driver)) { - engine->set_driver(Shared::PortType::AUDIO, SharedPtr(new_driver( - *engine, "default", args.engine_name_arg, NULL))); - } else { - cerr << Glib::Module::get_last_error() << endl; - } + if (!world->load("ingen_jack")) + ingen_abort("Unable to load jack module"); - engine->activate(args.parallelism_arg); + engine->activate(); } world->engine = engine_interface; - void (*gui_run)() = NULL; - - // Load GUI - bool run_gui = false; - if (args.gui_given) { - gui_module = Ingen::Shared::load_module("ingen_gui"); - if (gui_module) { - void (*init)(int, char**, Ingen::Shared::World*); - - bool found = gui_module->get_symbol("init", (void*&)init); - found = found && gui_module->get_symbol("run", (void*&)gui_run); - if (found) { - run_gui = true; - init(argc, argv, world); - } else { - cerr << "Unable to find hooks in GUI module, GUI not loaded." << endl; - } - } else { - cerr << "Unable to load GUI module." << endl; - } - } - // Load a patch - if (args.load_given && engine_interface) { + if (conf.option("load").is_valid() && engine_interface) { boost::optional data_path = Path("/"); boost::optional parent; boost::optional symbol; + const Raul::Atom& path_option = conf.option("path"); - if (args.path_given) { - const Glib::ustring path = args.path_arg; - if (Path::is_valid(path)) { - const Path p(path); + if (path_option.is_valid()) { + if (Path::is_valid(path_option.get_string())) { + const Path p(path_option.get_string()); if (!p.is_root()) { parent = p.parent(); - const string s = p.name(); - if (Symbol::is_valid(s)) - symbol = s; + symbol = p.name(); } } else { - cerr << "Invalid path given: '" << path << endl; + cerr << "Invalid path given: '" << path_option << endl; } } - bool found = false; - if (!world->serialisation_module) - world->serialisation_module = Ingen::Shared::load_module("ingen_serialisation"); - - Serialisation::Parser* (*new_parser)() = NULL; - - if (world->serialisation_module) - found = world->serialisation_module->get_symbol("new_parser", (void*&)new_parser); - - if (world->serialisation_module && found) { - SharedPtr parser(new_parser()); + if (!world->load("ingen_serialisation")) + ingen_abort("Unable to load serialisation module"); + if (world->parser) { // Assumption: Containing ':' means URI, otherwise filename - string uri = args.load_arg; + string uri = conf.option("load").get_string(); if (uri.find(':') == string::npos) { - if (Glib::path_is_absolute(args.load_arg)) - uri = Glib::filename_to_uri(args.load_arg); + if (Glib::path_is_absolute(uri)) + uri = Glib::filename_to_uri(uri); else uri = Glib::filename_to_uri(Glib::build_filename( - Glib::get_current_dir(), args.load_arg)); + Glib::get_current_dir(), uri)); } engine_interface->load_plugins(); - parser->parse_document(world, engine_interface.get(), uri, data_path, parent, symbol); + world->parser->parse_document( + world, engine_interface.get(), uri, data_path, parent, symbol); } else { - cerr << "Unable to load serialisation module, aborting." << endl; - return -1; + ingen_abort("Unable to create parser"); } } - // Run GUI (if applicable) - if (run_gui) - gui_run(); + // Load GUI + if (conf.option("gui").get_bool()) + if (!world->load("ingen_gui")) + ingen_abort("Unable to load GUI module"); // Run a script - if (args.run_given) { + if (conf.option("run").is_valid()) { #ifdef WITH_BINDINGS - bool (*run_script)(Ingen::Shared::World*, const char*) = NULL; - SharedPtr bindings_module = Ingen::Shared::load_module("ingen_bindings"); - if (bindings_module) { - bindings_module->make_resident(); - - bool found = bindings_module->get_symbol("run", (void*&)(run_script)); - if (found) { - setenv("PYTHONPATH", "../../bindings", 1); - run_script(world, args.run_arg); - } else { - cerr << "FAILED: " << Glib::Module::get_last_error() << endl; - } - } else { - cerr << Glib::Module::get_last_error() << endl; - } + if (!world->load("ingen_bindings")) + ingen_abort("Unable to load bindings module"); + + world->run("application/x-python", conf.option("run").get_string()); #else cerr << "This build of ingen does not support scripting." << endl; #endif // Listen to OSC and run main loop - } else if (engine && !run_gui) { - signal(SIGINT, catch_int); - signal(SIGTERM, catch_int); + } else if (engine && !conf.option("gui").get_bool()) { + signal(SIGINT, ingen_interrupt); + signal(SIGTERM, ingen_interrupt); engine->main(); // Block here } @@ -330,13 +251,7 @@ main(int argc, char** argv) engine.reset(); } - engine_interface.reset(); - client_module.reset(); - world->serialisation_module.reset(); - gui_module.reset(); - engine_module.reset(); - - Ingen::Shared::destroy_world(); + ingen_destroy_world(); return 0; } diff --git a/src/ingen/wscript b/src/ingen/wscript index 61c69bcd..839b789b 100644 --- a/src/ingen/wscript +++ b/src/ingen/wscript @@ -4,7 +4,7 @@ import autowaf def build(bld): obj = bld.new_task_gen(features='cxx cc cprogram') obj.target = 'ingen' - obj.source = 'main.cpp cmdline.c' + obj.source = 'main.cpp' obj.includes = ['..', '../..', '../common'] obj.defines = 'VERSION="' + bld.env['INGEN_VERSION'] + '"' obj.uselib_local = 'libingen_module libingen_shared' -- cgit v1.2.1