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