diff options
Diffstat (limited to 'src/ingen')
-rw-r--r-- | src/ingen/Makefile.am | 30 | ||||
-rw-r--r-- | src/ingen/cmdline.c | 665 | ||||
-rw-r--r-- | src/ingen/cmdline.ggo | 36 | ||||
-rw-r--r-- | src/ingen/cmdline.h | 200 | ||||
-rwxr-xr-x | src/ingen/ingen.dbg | 5 | ||||
-rw-r--r-- | src/ingen/ingen.desktop.in | 9 | ||||
-rwxr-xr-x | src/ingen/ingen.dev | 5 | ||||
-rw-r--r-- | src/ingen/ingen.grind | 5 | ||||
-rw-r--r-- | src/ingen/main.cpp | 259 | ||||
-rw-r--r-- | src/ingen/wscript | 11 |
10 files changed, 1225 insertions, 0 deletions
diff --git a/src/ingen/Makefile.am b/src/ingen/Makefile.am new file mode 100644 index 00000000..c48a47a2 --- /dev/null +++ b/src/ingen/Makefile.am @@ -0,0 +1,30 @@ +AM_CXXFLAGS = \ + -DINGEN_MODULE_DIR=\"$(libdir)/ingen\" \ + @GTHREAD_CFLAGS@ \ + @GLIBMM_CFLAGS@ \ + @REDLANDMM_CFLAGS@ \ + @RAUL_CFLAGS@ \ + @SLV2_CFLAGS@ \ + @INGEN_CFLAGS@ + +MAINTAINERCLEANFILES = Makefile.in + +desktopfilesdir = $(datadir)/applications +dist_desktopfiles_DATA = ingen.desktop + +bin_PROGRAMS = ingen +ingen_LDADD = \ + ../../libs/module/libingen_module.la \ + ../../libs/shared/libingen_shared.la \ + @SLV2_LIBS@ \ + @REDLANDMM_LIBS@ \ + @RAUL_LIBS@ \ + @GTHREAD_LIBS@ \ + @GLIBMM_LIBS@ + +ingen_DEPENDENCIES = ../../libs/module/libingen_module.la + +ingen_SOURCES = \ + main.cpp \ + cmdline.h \ + cmdline.c diff --git a/src/ingen/cmdline.c b/src/ingen/cmdline.c new file mode 100644 index 00000000..ea48135c --- /dev/null +++ b/src/ingen/cmdline.c @@ -0,0 +1,665 @@ +/* + 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 <stdio.h> +#include <stdlib.h> +#include <string.h> + +#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", + " -e, --engine Run (JACK) engine (default=off)", + " -E, --engine-port=INT Engine OSC port (default=`16180')", + " -c, --connect=STRING Connect to existing engine at OSC URI \n (default=`osc.udp://localhost:16180')", + " -g, --gui Launch the GTK graphical interface (default=off)", + " -C, --client-port=INT Client OSC port", + " -l, --load=STRING Load patch", + " -L, --path=STRING Target path for loaded patch", + " -r, --run=STRING Run script", + " -p, --parallelism=INT Number of concurrent process threads (default=`1')", + 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->engine_given = 0 ; + args_info->engine_port_given = 0 ; + args_info->connect_given = 0 ; + args_info->gui_given = 0 ; + args_info->client_port_given = 0 ; + args_info->load_given = 0 ; + args_info->path_given = 0 ; + args_info->run_given = 0 ; + args_info->parallelism_given = 0 ; +} + +static +void clear_args (struct gengetopt_args_info *args_info) +{ + args_info->engine_flag = 0; + args_info->engine_port_arg = 16180; + args_info->engine_port_orig = NULL; + args_info->connect_arg = gengetopt_strdup ("osc.udp://localhost:16180"); + args_info->connect_orig = NULL; + args_info->gui_flag = 0; + args_info->client_port_orig = NULL; + args_info->load_arg = NULL; + args_info->load_orig = NULL; + args_info->path_arg = NULL; + args_info->path_orig = NULL; + args_info->run_arg = NULL; + args_info->run_orig = NULL; + args_info->parallelism_arg = 1; + args_info->parallelism_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->engine_help = gengetopt_args_info_help[2] ; + args_info->engine_port_help = gengetopt_args_info_help[3] ; + args_info->connect_help = gengetopt_args_info_help[4] ; + args_info->gui_help = gengetopt_args_info_help[5] ; + args_info->client_port_help = gengetopt_args_info_help[6] ; + args_info->load_help = gengetopt_args_info_help[7] ; + args_info->path_help = gengetopt_args_info_help[8] ; + args_info->run_help = gengetopt_args_info_help[9] ; + args_info->parallelism_help = gengetopt_args_info_help[10] ; + +} + +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->engine_port_orig)); + free_string_field (&(args_info->connect_arg)); + free_string_field (&(args_info->connect_orig)); + free_string_field (&(args_info->client_port_orig)); + free_string_field (&(args_info->load_arg)); + free_string_field (&(args_info->load_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)); + free_string_field (&(args_info->parallelism_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->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->connect_given) + write_into_file(outfile, "connect", args_info->connect_orig, 0); + if (args_info->gui_given) + write_into_file(outfile, "gui", 0, 0 ); + if (args_info->client_port_given) + write_into_file(outfile, "client-port", args_info->client_port_orig, 0); + if (args_info->load_given) + write_into_file(outfile, "load", args_info->load_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); + if (args_info->parallelism_given) + write_into_file(outfile, "parallelism", args_info->parallelism_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' }, + { "engine", 0, NULL, 'e' }, + { "engine-port", 1, NULL, 'E' }, + { "connect", 1, NULL, 'c' }, + { "gui", 0, NULL, 'g' }, + { "client-port", 1, NULL, 'C' }, + { "load", 1, NULL, 'l' }, + { "path", 1, NULL, 'L' }, + { "run", 1, NULL, 'r' }, + { "parallelism", 1, NULL, 'p' }, + { NULL, 0, NULL, 0 } + }; + + c = getopt_long (argc, argv, "hVeE:c:gC:l:L:r:p:", 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 '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 OSC 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 'c': /* Connect to existing engine at OSC 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 '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 '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 '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 '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 '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 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 new file mode 100644 index 00000000..994e6ff9 --- /dev/null +++ b/src/ingen/cmdline.ggo @@ -0,0 +1,36 @@ +# 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 "engine" e "Run (JACK) engine" flag off +option "engine-port" E "Engine OSC port" int no default="16180" +option "connect" c "Connect to existing engine at OSC URI" string no default="osc.udp://localhost:16180" +option "gui" g "Launch the GTK graphical interface" flag off +option "client-port" C "Client OSC port" int no +option "load" l "Load patch" string no +option "path" L "Target path for loaded patch" string no +option "run" r "Run script" string no +option "parallelism" p "Number of concurrent process threads" int no default="1" + diff --git a/src/ingen/cmdline.h b/src/ingen/cmdline.h new file mode 100644 index 00000000..80358089 --- /dev/null +++ b/src/ingen/cmdline.h @@ -0,0 +1,200 @@ +/** @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 <stdio.h> /* 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 engine_flag; /**< @brief Run (JACK) engine (default=off). */ + const char *engine_help; /**< @brief Run (JACK) engine help description. */ + int engine_port_arg; /**< @brief Engine OSC port (default='16180'). */ + char * engine_port_orig; /**< @brief Engine OSC port original value given at command line. */ + const char *engine_port_help; /**< @brief Engine OSC port help description. */ + char * connect_arg; /**< @brief Connect to existing engine at OSC URI (default='osc.udp://localhost:16180'). */ + char * connect_orig; /**< @brief Connect to existing engine at OSC URI original value given at command line. */ + const char *connect_help; /**< @brief Connect to existing engine at OSC URI 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. */ + 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 * 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. */ + 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. */ + 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. */ + + unsigned int help_given ; /**< @brief Whether help was given. */ + unsigned int version_given ; /**< @brief Whether version was given. */ + unsigned int engine_given ; /**< @brief Whether engine was given. */ + unsigned int engine_port_given ; /**< @brief Whether engine-port was given. */ + unsigned int connect_given ; /**< @brief Whether connect was given. */ + unsigned int gui_given ; /**< @brief Whether gui was given. */ + unsigned int client_port_given ; /**< @brief Whether client-port was given. */ + unsigned int load_given ; /**< @brief Whether load was given. */ + unsigned int path_given ; /**< @brief Whether path was given. */ + unsigned int run_given ; /**< @brief Whether run was given. */ + unsigned int parallelism_given ; /**< @brief Whether parallelism 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/ingen.dbg b/src/ingen/ingen.dbg new file mode 100755 index 00000000..412c89bc --- /dev/null +++ b/src/ingen/ingen.dbg @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +export INGEN_MODULE_PATH="`pwd`/../../libs/engine/.libs:`pwd`/../../libs/serialisation/.libs:`pwd`/../../libs/gui/.libs:`pwd`/../../libs/client/.libs:`pwd`/../../bindings/.libs" +export INGEN_GLADE_PATH="`pwd`/../../libs/gui/ingen_gui.glade" +libtool --mode=execute gdb --args ./ingen $@ diff --git a/src/ingen/ingen.desktop.in b/src/ingen/ingen.desktop.in new file mode 100644 index 00000000..6bd00e05 --- /dev/null +++ b/src/ingen/ingen.desktop.in @@ -0,0 +1,9 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Ingen +Comment=Create synthesizers and effects processors in a modular environment +Exec=ingen -g +Terminal=false +Icon=ingen-icon.svg +Type=Application +Categories=Application;AudioVideo;Sound;Audio diff --git a/src/ingen/ingen.dev b/src/ingen/ingen.dev new file mode 100755 index 00000000..023eba7e --- /dev/null +++ b/src/ingen/ingen.dev @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +export INGEN_MODULE_PATH="`pwd`/../../libs/engine/.libs:`pwd`/../../libs/serialisation/.libs:`pwd`/../../libs/gui/.libs:`pwd`/../../libs/client/.libs:`pwd`/../../bindings/.libs" +export INGEN_GLADE_PATH="`pwd`/../../libs/gui/ingen_gui.glade" +./ingen $@ diff --git a/src/ingen/ingen.grind b/src/ingen/ingen.grind new file mode 100644 index 00000000..9e597d44 --- /dev/null +++ b/src/ingen/ingen.grind @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +export INGEN_MODULE_PATH="`pwd`/../../libs/engine/.libs:`pwd`/../../libs/serialisation/.libs:`pwd`/../../libs/gui/.libs:`pwd`/../../libs/client/.libs:`pwd`/../../bindings/.libs" +export INGEN_GLADE_PATH="`pwd`/../../libs/gui/ingen_gui.glade" +libtool --mode=execute valgrind ./ingen $@ diff --git a/src/ingen/main.cpp b/src/ingen/main.cpp new file mode 100644 index 00000000..c8adf207 --- /dev/null +++ b/src/ingen/main.cpp @@ -0,0 +1,259 @@ +/* This file is part of Ingen. + * Copyright (C) 2007 Dave Robillard <http://drobilla.net> + * + * 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 CONFIG_H_PATH +#include <iostream> +#include <string> +#include <signal.h> +#include <dlfcn.h> +#include <boost/optional.hpp> +#include <glibmm/convert.h> +#include <glibmm/miscutils.h> +#include <glibmm/spawn.h> +#include <glibmm/thread.h> +#include <raul/Path.hpp> +#include <raul/SharedPtr.hpp> +#include <redlandmm/World.hpp> +#include "module/global.hpp" +#include "module/Module.hpp" +#include "module/World.hpp" +#include "engine/Engine.hpp" +#include "engine/QueuedEngineInterface.hpp" +#include "serialisation/Parser.hpp" +#include "cmdline.h" + +#ifdef WITH_BINDINGS +#include "bindings/ingen_bindings.hpp" +#endif + + +using namespace std; +using namespace Ingen; + + +SharedPtr<Engine> 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) { + cmdline_parser_print_help(); + cerr << endl << "*** Ingen requires at least one command line parameter" << endl; + cerr << "*** Just want to use a graphical app? 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; + } + + SharedPtr<Glib::Module> engine_module; + SharedPtr<Glib::Module> client_module; + SharedPtr<Glib::Module> gui_module; + SharedPtr<Glib::Module> bindings_module; + + SharedPtr<Shared::EngineInterface> engine_interface; + + Glib::thread_init(); +#if HAVE_SOUP + g_type_init(); +#endif + + Ingen::Shared::World* world = Ingen::Shared::get_world(); + + /* Set up RDF world */ + world->rdf_world->add_prefix("xsd", "http://www.w3.org/2001/XMLSchema#"); + world->rdf_world->add_prefix("ingen", "http://drobilla.net/ns/ingen#"); + world->rdf_world->add_prefix("ingenuity", "http://drobilla.net/ns/ingenuity#"); + world->rdf_world->add_prefix("lv2", "http://lv2plug.in/ns/lv2core#"); + world->rdf_world->add_prefix("lv2var", "http://lv2plug.in/ns/ext/instance-var#"); + world->rdf_world->add_prefix("lv2_midi", "http://lv2plug.in/ns/ext/midi"); + world->rdf_world->add_prefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#"); + world->rdf_world->add_prefix("doap", "http://usefulinc.com/ns/doap#"); + world->rdf_world->add_prefix("dc", "http://purl.org/dc/elements/1.1/"); + + /* Run engine */ + if (args.engine_flag) { + engine_module = Ingen::Shared::load_module("ingen_engine"); + if (engine_module) { + Engine* (*new_engine)(Ingen::Shared::World* world) = NULL; + if (engine_module->get_symbol("new_engine", (void*&)new_engine)) { + engine = SharedPtr<Engine>(new_engine(world)); + world->local_engine = engine; + /* Load queued (direct in-process) engine interface */ + if (args.gui_given) { + engine_interface = engine->new_queued_interface(); + world->engine = engine_interface; + } else { + engine->start_osc_driver(args.engine_port_arg); + engine->start_http_driver(args.engine_port_arg); + } + } else { + engine_module.reset(); + } + } else { + cerr << "Unable to load engine module." << endl; + } + } + + /* 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; + } + + /* If we don't have a local engine interface (for GUI), use network */ + if (client_module && ! engine_interface) { + SharedPtr<Shared::EngineInterface> (*new_remote_interface)(const std::string&) = NULL; + + if (client_module->get_symbol("new_remote_interface", (void*&)new_remote_interface)) { + engine_interface = new_remote_interface(args.connect_arg); + } else { + cerr << "Unable to find symbol 'new_remote_interface' in " + "ingen_client module, aborting." << endl; + return -1; + } + } + + /* Activate the engine, if we have one */ + if (engine) { + engine->start_jack_driver(); + engine->activate(args.parallelism_arg); + } + + world->engine = engine_interface; + + /* Load a patch */ + if (args.load_given && engine_interface) { + + Glib::ustring engine_base = "/"; + if (args.path_given) + engine_base = string(args.path_arg) + "/"; + + 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<Serialisation::Parser> parser(new_parser()); + + // Assumption: Containing ':' means URI, otherwise filename + string uri = args.load_arg; + if (uri.find(':') == string::npos) { + if (Glib::path_is_absolute(args.load_arg)) + uri = Glib::filename_to_uri(args.load_arg); + else + uri = Glib::filename_to_uri(Glib::build_filename( + Glib::get_current_dir(), args.load_arg)); + } + + + engine_interface->load_plugins(); + parser->parse_document(world, engine_interface.get(), uri, engine_base, uri); + + } 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**, Ingen::Shared::World*); + bool found = gui_module->get_symbol("run", (void*&)run); + + if (found) { + ran_gui = true; + run(argc, argv, world); + } else { + cerr << "Unable to find GUI module, GUI not loaded." << endl; + } + } + + /* Run a script */ + if (args.run_given) { +#ifdef WITH_BINDINGS + bool (*run_script)(Ingen::Shared::World*, const char*) = NULL; + SharedPtr<Glib::Module> bindings_module = Ingen::Shared::load_module("ingen_bindings"); + if (!bindings_module) + cerr << Glib::Module::get_last_error() << endl; + + bindings_module->make_resident(); + + bool found = bindings_module->get_symbol("run", (void*&)(run_script)); + if (found) { + cerr << "WORLD: " << world << endl; + cerr << "ENGINE: " << world->engine << endl; + setenv("PYTHONPATH", "../../bindings", 1); + run_script(world, args.run_arg); + } else { + cerr << "FAILED: " << Glib::Module::get_last_error() << endl; + } +#else + cerr << "This build of ingen does not support scripting." << endl; +#endif + + /* Listen to OSC and do our own main thing. */ + } else if (engine && !ran_gui) { + signal(SIGINT, catch_int); + signal(SIGTERM, catch_int); + engine->main(); + } + + cout << "Exiting." << endl; + + if (engine) { + engine->deactivate(); + engine.reset(); + } + + engine_interface.reset(); + client_module.reset(); + world->serialisation_module.reset(); + gui_module.reset(); + engine_module.reset(); + + Ingen::Shared::destroy_world(); + + return 0; +} + diff --git a/src/ingen/wscript b/src/ingen/wscript new file mode 100644 index 00000000..d2e42c51 --- /dev/null +++ b/src/ingen/wscript @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +def build(bld): + obj = bld.create_obj('cpp', 'program') + obj.target = 'ingen' + obj.source = 'main.cpp cmdline.c' + obj.includes = ['.', '../../common', '../..', '../../libs'] + obj.defines = 'VERSION=\\\"' + bld.env()['INGEN_VERSION'] + '\\\"' + obj.uselib = 'GTHREAD GLIBMM REDLANDMM RAUL SLV2 INGEN LIBLO' + obj.uselib_local = 'libingen_module libingen_shared' + |