summaryrefslogtreecommitdiff
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
parentosc requests get now acked (diff)
added command line parser
midi and osc are now optional
-rw-r--r--apps/dolmetschctl.c110
-rw-r--r--apps/midi.c23
-rw-r--r--apps/mixer.c2
-rw-r--r--apps/osc.c23
4 files changed, 140 insertions, 18 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);
diff --git a/apps/midi.c b/apps/midi.c
index fa5739b..6ef5775 100644
--- a/apps/midi.c
+++ b/apps/midi.c
@@ -45,10 +45,12 @@ int midi_init(midi_t* m, const char* device)
slist_init(&(m->done_data_), free);
- int ret = snd_rawmidi_open(&(m->input_), &(m->output_), device, SND_RAWMIDI_NONBLOCK);
- if(ret < 0) {
- error(0, 0, "MIDI: cannot open port '%s': %s", device, snd_strerror(ret));
- return ret;
+ if(device) {
+ int ret = snd_rawmidi_open(&(m->input_), &(m->output_), device, SND_RAWMIDI_NONBLOCK);
+ if(ret < 0) {
+ error(0, 0, "MIDI: cannot open port '%s': %s", device, snd_strerror(ret));
+ return ret;
+ }
}
return 0;
@@ -58,6 +60,9 @@ int midi_get_poll_fd_count(midi_t* m)
{
assert(m);
+ if(!m->input_ || !m->output_)
+ return 0;
+
m->in_pfds_cnt_ = snd_rawmidi_poll_descriptors_count(m->input_);
assert(m->in_pfds_cnt_ > 0);
m->out_pfds_cnt_ = snd_rawmidi_poll_descriptors_count(m->output_);
@@ -68,7 +73,10 @@ int midi_get_poll_fd_count(midi_t* m)
int midi_get_poll_fds(midi_t* m, struct pollfd *pfds, int npfds)
{
- assert(m && pfds && npfds);
+ assert(m);
+
+ if(!m->input_ || !m->output_)
+ return 0;
snd_rawmidi_poll_descriptors(m->input_, pfds, m->in_pfds_cnt_);
snd_rawmidi_poll_descriptors(m->output_, &(pfds[m->in_pfds_cnt_]), npfds - m->in_pfds_cnt_);
@@ -216,7 +224,10 @@ static int midi_handle_out_revents(midi_t* m, struct pollfd *pfds, int npfds)
int midi_handle_revents(midi_t* m, struct pollfd *pfds, int npfds, mixer_t* x)
{
- assert(m && x && pfds);
+ assert(m);
+
+ if(!m->input_ || !m->output_)
+ return 0;
int ret = midi_handle_in_revents(m, pfds, m->in_pfds_cnt_, x);
if(ret)
diff --git a/apps/mixer.c b/apps/mixer.c
index 026a43e..54df1b4 100644
--- a/apps/mixer.c
+++ b/apps/mixer.c
@@ -194,7 +194,7 @@ int mixer_switch_lang(mixer_t* x, const char* lang, void (*done_cb)(void*), void
return 0;
}
}
- error(0, 0, "requested language '%s' not found ... ignoring switch", lang);
+ error(0, 0, "requested language '%s' not found ... ignoring request", lang);
return 0;
}
diff --git a/apps/osc.c b/apps/osc.c
index 9172625..656d400 100644
--- a/apps/osc.c
+++ b/apps/osc.c
@@ -87,6 +87,12 @@ int osc_init(osc_t* o, const char* port)
{
assert(o != NULL);
+ o->server_ = NULL;
+ slist_init(&(o->done_data_), free_osc_done_data);
+
+ if(!port)
+ return 0;
+
o->server_ = lo_server_new(port, print_error);
if(!o->server_)
return -1;
@@ -94,20 +100,26 @@ int osc_init(osc_t* o, const char* port)
if(!lo_server_add_method(o->server_, "/lang/switch", "s", lang_handler, (void*)o))
return -1;
- slist_init(&(o->done_data_), free_osc_done_data);
-
return 0;
}
int osc_get_poll_fd_count(osc_t* o)
{
+ assert(o);
+
+ if(!o->server_)
+ return 0;
+
return 1;
}
int osc_get_poll_fds(osc_t* o, struct pollfd *pfds, int npfds)
{
- assert(o && pfds && npfds == 1);
+ assert(o);
+
+ if(!o->server_)
+ return 0;
pfds[0].fd = lo_server_get_socket_fd(o->server_);
pfds[0].events = POLLIN;
@@ -118,7 +130,10 @@ int osc_get_poll_fds(osc_t* o, struct pollfd *pfds, int npfds)
int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds, mixer_t* x)
{
- assert(o && pfds && npfds == 1);
+ assert(o);
+
+ if(!o->server_)
+ return 0;
if(pfds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) {
error(0, 0, "OSC: got POLLERR, POLLHUP or POLLNVAL");