annotate osc/sv-osc-send.c @ 151:152619d379e0

* Add a measurement mode tool -- no functionality yet
author Chris Cannam
date Wed, 13 Jun 2007 12:00:01 +0000
parents 76cc2c424268
children
rev   line source
Chris@69 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@69 2
Chris@69 3 #include <stdlib.h>
Chris@69 4 #include <stdio.h>
Chris@69 5 #include <string.h>
Chris@69 6 #include <ctype.h>
Chris@69 7 #include <lo/lo.h>
Chris@69 8
Chris@69 9 void
Chris@69 10 usage(char *program_name)
Chris@69 11 {
Chris@69 12 char *base_name = strrchr(program_name, '/');
Chris@69 13
Chris@69 14 if (base_name && *(base_name + 1) != 0) {
Chris@69 15 base_name += 1;
Chris@69 16 } else {
Chris@69 17 base_name = program_name;
Chris@69 18 }
Chris@69 19
Chris@69 20 fprintf(stderr, "\nusage: %s <OSC URL> [<values>]\n\n", program_name);
Chris@69 21 fprintf(stderr, "example OSC URLs:\n\n"
Chris@69 22 " osc.udp://localhost:19383/path/test 1.0 4.2\n"
Chris@69 23 " osc.udp://my.host.org:10886/3/13/load file\n\n");
Chris@69 24 fprintf(stderr, "numeric arguments will be treated as OSC 'f' floating point types.\n\n");
Chris@69 25 exit(1);
Chris@69 26 }
Chris@69 27
Chris@69 28 int main(int argc, char *argv[])
Chris@69 29 {
Chris@69 30 lo_address a;
Chris@69 31 char *url, *host, *port, *path;
Chris@69 32 lo_message message;
Chris@69 33 unsigned int i;
Chris@69 34
Chris@69 35 if (argc < 2) {
Chris@69 36 usage(argv[0]);
Chris@69 37 /* does not return */
Chris@69 38 }
Chris@69 39 url = argv[1];
Chris@69 40
Chris@69 41 host = lo_url_get_hostname(url);
Chris@69 42 port = lo_url_get_port(url);
Chris@69 43 path = lo_url_get_path(url);
Chris@69 44 a = lo_address_new(host, port);
Chris@69 45
Chris@69 46 message = lo_message_new();
Chris@69 47
Chris@69 48 for (i = 0; i + 2 < argc; ++i) {
Chris@69 49
Chris@69 50 int index = i + 2;
Chris@69 51 char *param;
Chris@69 52
Chris@69 53 param = argv[index];
Chris@69 54 if (!isdigit(param[0])) {
Chris@69 55 lo_message_add_string(message, argv[index]);
Chris@69 56 } else {
Chris@69 57 lo_message_add_float(message, atof(argv[index]));
Chris@69 58 }
Chris@69 59 }
Chris@69 60
Chris@69 61 lo_send_message(a, path, message);
Chris@69 62
Chris@69 63 if (lo_address_errno(a)) {
Chris@69 64 printf("liblo error: %s\n", lo_address_errstr(a));
Chris@69 65 }
Chris@69 66
Chris@69 67 free(host);
Chris@69 68 free(port);
Chris@69 69 free(path);
Chris@69 70
Chris@69 71 return 0;
Chris@69 72 }
Chris@69 73