summaryrefslogtreecommitdiff
path: root/apps/dolmetschctl.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-10-12 06:47:36 +0200
committerChristian Pointner <equinox@spreadspace.org>2015-10-12 06:47:36 +0200
commit9e00c3ac52f5c289d87a017df8c25fb2d874f254 (patch)
tree59f5a655b7136cc4593cf9d932096bb01bd7beba /apps/dolmetschctl.c
parentosc requests get now acked (diff)
added command line parser
midi and osc are now optional
Diffstat (limited to 'apps/dolmetschctl.c')
-rw-r--r--apps/dolmetschctl.c110
1 files changed, 103 insertions, 7 deletions
diff --git a/apps/dolmetschctl.c b/apps/dolmetschctl.c
index b998042..fd63e99 100644
--- a/apps/dolmetschctl.c
+++ b/apps/dolmetschctl.c
@@ -23,8 +23,13 @@
#include "config.h"
#include <stdio.h>
+#include <unistd.h>
+#include <ctype.h>
#include <error.h>
+#include <lo/lo.h>
+#include <alsa/asoundlib.h>
+
#include "mixer.h"
#include "midi.h"
#include "osc.h"
@@ -40,11 +45,26 @@ void print_version()
#else
printf("%s\n", VERSION_STRING_1);
#endif
+
+ printf("linked against alsa-lib Version %s\n", snd_asoundlib_version());
+ char verstr[32];
+ lo_version(verstr, sizeof(verstr), 0, 0, 0, 0, 0, 0, 0);
+ printf("linked against liblo Version %s\n", verstr);
}
-void print_string(void* str)
+void print_usage()
{
- printf("%s\n", (char*)str);
+ printf("\ndolmetschctl <options>\n");
+ printf(" -h print this and exit\n");
+ printf(" -v print version information and exit\n");
+ printf(" -x <name> the name of the mixer, dolmetschctl will look for\n");
+ printf(" language files inside '%s/<name>/'\n", ETCDIR);
+ printf(" -d <dev> the mixer MIDI device name to use, i.e. hw:2,0,0\n");
+ printf(" (use `amidi -l` to list all available devices)'\n");
+ printf(" -m <dev> the MIDI control device name to use, this can be omitted to\n");
+ printf(" only wait for OSC messages'\n");
+ printf(" -o <port> the UDP port to listen on for OSC messages, this can be omitted\n");
+ printf(" to only use the control MIDI interface'\n");
}
int main_loop(mixer_t* x, midi_t* m, osc_t* o)
@@ -59,11 +79,11 @@ int main_loop(mixer_t* x, midi_t* m, osc_t* o)
int midi_npfds_offset = mixer_npfds_offset + mixer_npfds;
int midi_npfds = midi_get_poll_fd_count(m);
- assert(midi_npfds > 0);
+ assert(midi_npfds >= 0);
int osc_npfds_offset = midi_npfds_offset + midi_npfds;
int osc_npfds = osc_get_poll_fd_count(o);
- assert(osc_npfds > 0);
+ assert(osc_npfds >= 0);
int npfds = midi_npfds + osc_npfds + mixer_npfds;
struct pollfd *pfds = alloca(npfds * sizeof(struct pollfd));
@@ -106,16 +126,92 @@ int main_loop(mixer_t* x, midi_t* m, osc_t* o)
int main(int argc, char* argv[])
{
+ int helpflag = 0;
+ int versionflag = 0;
+ char* mixer_name = NULL;
+ char* mixer_dev = NULL;
+ char* midi_dev = NULL;
+ char* osc_port = NULL;
+
+ int c;
+ opterr = 0;
+ while ((c = getopt (argc, argv, "vhx:d:m:o:")) != -1) {
+ switch (c) {
+ case 'h':
+ helpflag = 1;
+ break;
+ case 'v':
+ versionflag = 1;
+ break;
+ case 'x':
+ mixer_name = optarg;
+ break;
+ case 'd':
+ mixer_dev = optarg;
+ break;
+ case 'm':
+ midi_dev = optarg;
+ break;
+ case 'o':
+ osc_port = optarg;
+ break;
+ case '?':
+ if (optopt == 'x')
+ error(0, 0, "Option -%c requires an argument.\n", optopt);
+ else if (optopt == 'd')
+ error(0, 0, "Option -%c requires an argument.\n", optopt);
+ else if (optopt == 'm')
+ error(0, 0, "Option -%c requires an argument.\n", optopt);
+ else if (optopt == 'o')
+ error(0, 0, "Option -%c requires an argument.\n", optopt);
+ else if (isprint (optopt))
+ error(0, 0, "Unknown option `-%c'.\n", optopt);
+ else
+ error(0, 0, "Unknown option character `\\x%x'.\n", optopt);
+ return -1;
+ default:
+ return -1;
+ }
+ }
+
+ if(helpflag) {
+ print_usage();
+ return 0;
+ }
+
+ if(versionflag) {
+ print_version();
+ return 0;
+ }
+
+ if(!mixer_name){
+ error(0, 0, "mixer name must be set");
+ print_usage();
+ return -1;
+ }
+
+ if(!mixer_dev){
+ error(0, 0, "mixer device name must be set");
+ print_usage();
+ return -1;
+ }
+
+ if(!midi_dev && !osc_port) {
+ error(0, 0, "either midi or osc (or both) must be specified");
+ print_usage();
+ return -1;
+ }
+
mixer_t x;
- if(mixer_init(&x, "qu24", "hw:2,0,0"))
+ if(mixer_init(&x, mixer_name, mixer_dev))
return -1;
midi_t m;
- if(midi_init(&m, "hw:3,0,0"))
+ if(midi_init(&m, midi_dev))
return -1;
osc_t o;
- if(osc_init(&o, "1200"))
+ if(osc_init(&o, osc_port))
return -1;
int ret = main_loop(&x, &m, &o);