summaryrefslogtreecommitdiffstats
path: root/src/progs/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/progs/server')
-rw-r--r--src/progs/server/Makefile.am43
-rw-r--r--src/progs/server/cmdline.c150
-rw-r--r--src/progs/server/cmdline.ggo7
-rw-r--r--src/progs/server/cmdline.h45
-rw-r--r--src/progs/server/main.cpp153
5 files changed, 398 insertions, 0 deletions
diff --git a/src/progs/server/Makefile.am b/src/progs/server/Makefile.am
new file mode 100644
index 00000000..9ba20719
--- /dev/null
+++ b/src/progs/server/Makefile.am
@@ -0,0 +1,43 @@
+AM_CXXFLAGS = @JACK_CFLAGS@ @LOSC_CFLAGS@ @ALSA_CFLAGS@ @LASH_CFLAGS@ @SLV2_CFLAGS@ -I$(top_srcdir)/src/common -I$(top_srcdir)/src/libs/engine -I$(top_srcdir)/src/libs/engine/events -fno-exceptions -fno-rtti
+
+MAINTAINERCLEANFILES = Makefile.in
+
+#
+# Stand-alone engine
+#
+if BUILD_ENGINE
+
+bin_PROGRAMS = ingen
+om_DEPENDENCIES = ../../libs/engine/libingen.la
+om_LDADD = @JACK_LIBS@ @LOSC_LIBS@ @ALSA_LIBS@ @LASH_LIBS@ @SLV2_LIBS@ -lrt ../../libs/engine/libingen.la
+
+om_SOURCES = \
+ main.cpp \
+ cmdline.h \
+ cmdline.c
+
+endif # BUILD_ENGINE
+
+
+##
+## Jack internal client
+##
+#if BUILD_IN_PROCESS_ENGINE
+#
+#
+## FIXME: broken
+#
+#
+## FIXME: Figure out how to get this properly
+#omdir = $(prefix)/lib/jack
+#
+#om_la_CFLAGS = -fPIC
+#om_LTLIBRARIES = om.la
+#om_la_LDFLAGS = -module -avoid-version @JACK_LIBS@ @LOSC_LIBS@ @ALSA_LIBS@ @LASH_LIBS@ @SLV2_LIBS@
+#om_la_SOURCES = OmInProcess.cpp
+#
+#endif # BUILD_IN_PROCESS_ENGINE
+
+
+
+
diff --git a/src/progs/server/cmdline.c b/src/progs/server/cmdline.c
new file mode 100644
index 00000000..6b7ddf6a
--- /dev/null
+++ b/src/progs/server/cmdline.c
@@ -0,0 +1,150 @@
+/*
+ File autogenerated by gengetopt version 2.10
+ generated with the following command:
+ gengetopt
+
+ 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.
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* If we use autoconf. */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "getopt.h"
+
+#include "cmdline.h"
+
+void
+cmdline_parser_print_version (void)
+{
+ printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
+}
+
+void
+cmdline_parser_print_help (void)
+{
+ cmdline_parser_print_version ();
+ printf("\n"
+ "Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE);
+ printf(" -h --help Print help and exit\n");
+ printf(" -V --version Print version and exit\n");
+ printf(" -pSTRING --port=STRING OSC port to listen on (default='16180')\n");
+ printf(" -i --in-jackd Run engine as in-process JACK client (default=off)\n");
+}
+
+
+static char *gengetopt_strdup (const char *s);
+
+/* gengetopt_strdup() */
+/* strdup.c replacement of strdup, which is not standard */
+char *
+gengetopt_strdup (const char *s)
+{
+ char *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)
+{
+ int c; /* Character of the parsed option. */
+ int missing_required_options = 0;
+
+ args_info->help_given = 0 ;
+ args_info->version_given = 0 ;
+ args_info->port_given = 0 ;
+ args_info->in_jackd_given = 0 ;
+#define clear_args() { \
+ args_info->port_arg = gengetopt_strdup("16180") ;\
+ args_info->in_jackd_flag = 0;\
+}
+
+ clear_args();
+
+ optarg = 0;
+ optind = 1;
+ opterr = 1;
+ optopt = '?';
+
+ while (1)
+ {
+ int option_index = 0;
+ char *stop_char;
+
+ static struct option long_options[] = {
+ { "help", 0, NULL, 'h' },
+ { "version", 0, NULL, 'V' },
+ { "port", 1, NULL, 'p' },
+ { "in-jackd", 0, NULL, 'i' },
+ { NULL, 0, NULL, 0 }
+ };
+
+ stop_char = 0;
+ c = getopt_long (argc, argv, "hVp:i", long_options, &option_index);
+
+ if (c == -1) break; /* Exit from `while (1)' loop. */
+
+ switch (c)
+ {
+ case 'h': /* Print help and exit. */
+ clear_args ();
+ cmdline_parser_print_help ();
+ exit (EXIT_SUCCESS);
+
+ case 'V': /* Print version and exit. */
+ clear_args ();
+ cmdline_parser_print_version ();
+ exit (EXIT_SUCCESS);
+
+ case 'p': /* OSC port to listen on. */
+ if (args_info->port_given)
+ {
+ fprintf (stderr, "%s: `--port' (`-p') option given more than once\n", CMDLINE_PARSER_PACKAGE);
+ clear_args ();
+ exit (EXIT_FAILURE);
+ }
+ args_info->port_given = 1;
+ args_info->port_arg = gengetopt_strdup (optarg);
+ break;
+
+ case 'i': /* Run engine as in-process JACK client. */
+ if (args_info->in_jackd_given)
+ {
+ fprintf (stderr, "%s: `--in-jackd' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE);
+ clear_args ();
+ exit (EXIT_FAILURE);
+ }
+ args_info->in_jackd_given = 1;
+ args_info->in_jackd_flag = !(args_info->in_jackd_flag);
+ break;
+
+
+ case 0: /* Long option with no short option */
+
+ case '?': /* Invalid option. */
+ /* `getopt_long' already printed an error message. */
+ exit (EXIT_FAILURE);
+
+ default: /* bug: option not considered. */
+ fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c);
+ abort ();
+ } /* switch */
+ } /* while */
+
+
+ if ( missing_required_options )
+ exit (EXIT_FAILURE);
+
+ return 0;
+}
diff --git a/src/progs/server/cmdline.ggo b/src/progs/server/cmdline.ggo
new file mode 100644
index 00000000..8c006ca7
--- /dev/null
+++ b/src/progs/server/cmdline.ggo
@@ -0,0 +1,7 @@
+# Process this file with gengetopt -u to generate the necessary code (in cmdline.h, cmdline.c)
+
+package "Om - An OSC controlled realtime modular synthesizer"
+
+option "port" p "OSC port to listen on" string default="16180" no
+option "in-jackd" i "Run engine as in-process JACK client" flag off
+
diff --git a/src/progs/server/cmdline.h b/src/progs/server/cmdline.h
new file mode 100644
index 00000000..fe36a969
--- /dev/null
+++ b/src/progs/server/cmdline.h
@@ -0,0 +1,45 @@
+/* cmdline.h */
+
+/* File autogenerated by gengetopt version 2.10 */
+
+#ifndef CMDLINE_H
+#define CMDLINE_H
+
+/* If we use autoconf. */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#ifndef CMDLINE_PARSER_PACKAGE
+#define CMDLINE_PARSER_PACKAGE "Om - An OSC controlled realtime modular synthesizer"
+#endif
+
+#ifndef CMDLINE_PARSER_VERSION
+#define CMDLINE_PARSER_VERSION VERSION
+#endif
+
+struct gengetopt_args_info
+{
+ char * port_arg; /* OSC port to listen on (default='16180'). */
+ int in_jackd_flag; /* Run engine as in-process JACK client (default=off). */
+
+ int help_given ; /* Whether help was given. */
+ int version_given ; /* Whether version was given. */
+ int port_given ; /* Whether port was given. */
+ int in_jackd_given ; /* Whether in-jackd was given. */
+
+} ;
+
+int cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info);
+
+void cmdline_parser_print_help(void);
+void cmdline_parser_print_version(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* CMDLINE_H */
diff --git a/src/progs/server/main.cpp b/src/progs/server/main.cpp
new file mode 100644
index 00000000..e1fe9d6a
--- /dev/null
+++ b/src/progs/server/main.cpp
@@ -0,0 +1,153 @@
+/* This file is part of Om. Copyright (C) 2006 Dave Robillard.
+ *
+ * Om 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.
+ *
+ * Om 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 <iostream>
+#include <cstddef>
+#include <signal.h>
+#include "config.h"
+#include "util.h"
+#include "cmdline.h"
+#include "Om.h"
+#include "OmApp.h"
+#ifdef HAVE_LASH
+#include "LashDriver.h"
+#endif
+#ifdef BUILD_IN_PROCESS_ENGINE
+#include <jack/jack.h>
+#include <jack/intclient.h>
+#endif
+
+using std::cout; using std::endl; using std::cerr;
+
+
+void
+catch_int(int)
+{
+ signal(SIGINT, catch_int);
+ signal(SIGTERM, catch_int);
+
+ std::cout << "[Main] Om interrupted." << std::endl;
+ Om::om->quit();
+}
+
+
+#ifdef BUILD_IN_PROCESS_ENGINE
+
+jack_client_t* jack_client;
+jack_intclient_t jack_intclient;
+
+
+void
+unload_in_process_engine(int)
+{
+ jack_status_t status;
+ int ret = EXIT_SUCCESS;
+
+ cout << "Unloading...";
+ status = jack_internal_client_unload(jack_client, jack_intclient);
+ if (status & JackFailure) {
+ cout << "failed" << endl;
+ ret = EXIT_FAILURE;
+ } else {
+ cout << "done" << endl;
+ }
+ jack_client_close(jack_client);
+ exit(ret);
+}
+
+
+int
+load_in_process_engine(const char* port)
+{
+ int ret = EXIT_SUCCESS;
+
+ jack_status_t status;
+
+ if ((jack_client = jack_client_open("om_load", JackNoStartServer,
+ &status)) != NULL) {
+ jack_intclient =
+ jack_internal_client_load(jack_client, "Om",
+ (jack_options_t)(JackLoadName|JackLoadInit),
+ &status, "om", port);
+ if (status == 0) {
+ cout << "Engine loaded" << endl;
+ signal(SIGINT, unload_in_process_engine);
+ signal(SIGTERM, unload_in_process_engine);
+
+ while (1) {
+ sleep(1);
+ }
+ } else if (status & JackFailure) {
+ cerr << "Could not load om.so" << endl;
+ ret = EXIT_FAILURE;
+ }
+
+ jack_client_close(jack_client);
+ } else {
+ cerr << "jack_client_open failed" << endl;
+ ret = EXIT_FAILURE;
+ }
+}
+
+#endif // BUILD_IN_PROCESS_ENGINE
+
+
+int
+main(int argc, char** argv)
+{
+#ifdef HAVE_LASH
+ lash_args_t* lash_args = lash_extract_args(&argc, &argv);
+#endif
+
+ int ret = EXIT_SUCCESS;
+
+ /* Parse command line options */
+ gengetopt_args_info args_info;
+ if (cmdline_parser (argc, argv, &args_info) != 0)
+ return EXIT_FAILURE;
+
+
+ if (args_info.in_jackd_flag) {
+#ifdef BUILD_IN_PROCESS_ENGINE
+ ret = load_in_process_engine(args_info.port_arg);
+#else
+ cerr << "In-process Jack client support not enabled in this build." << endl;
+ ret = EXIT_FAILURE;
+#endif // JACK_IN_PROCESS_ENGINE
+ } else {
+ signal(SIGINT, catch_int);
+ signal(SIGTERM, catch_int);
+
+ Om::set_denormal_flags();
+
+ Om::om = new Om::OmApp(args_info.port_arg);
+
+#ifdef HAVE_LASH
+ Om::lash_driver = new Om::LashDriver(Om::om, lash_args);
+#endif
+
+ Om::om->main();
+
+#ifdef HAVE_LASH
+ delete Om::lash_driver;
+#endif
+
+ delete Om::om;
+ }
+
+ return ret;
+}
+