ref: 8f824ed84aea2dbcf0617770a3dc28dfb7ee60f7
parent: d9225e3b6919e1ce7c62a76ca19a5f33438cb7fe
author: cancel <cancel@cancel.fm>
date: Sat Dec 8 18:45:30 EST 2018
Add osc server param
--- a/osc_out.c
+++ b/osc_out.c
@@ -10,7 +10,8 @@
struct sockaddr_in addr;
};
-Oosc_udp_create_error oosc_dev_create_udp(Oosc_dev** out_ptr, U16 port) {
+Oosc_udp_create_error oosc_dev_create_udp(Oosc_dev** out_ptr,
+ char const* dest_addr, U16 port) {
int udpfd = socket(AF_INET, SOCK_DGRAM, 0);
if (udpfd < 0) {
fprintf(stderr, "Failed to open UDP socket, error number: %d\n", errno);
@@ -19,7 +20,7 @@
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = inet_addr("127.0.0.1");
+ addr.sin_addr.s_addr = inet_addr(dest_addr);
addr.sin_port = htons((U16)port);
Oosc_dev* dev = malloc(sizeof(Oosc_dev));
dev->fd = udpfd;
--- a/osc_out.h
+++ b/osc_out.h
@@ -7,7 +7,8 @@
Oosc_udp_create_error_couldnt_open_socket = 1,
} Oosc_udp_create_error;
-Oosc_udp_create_error oosc_dev_create_udp(Oosc_dev** out_dev_ptr, U16 port);
+Oosc_udp_create_error oosc_dev_create_udp(Oosc_dev** out_dev_ptr,
+ char const* dest_addr, U16 port);
void oosc_dev_destroy(Oosc_dev* dev);
// raw UDP datagram
void oosc_send_datagram(Oosc_dev* dev, char const* data, Usz size);
--- a/tui_main.c
+++ b/tui_main.c
@@ -25,6 +25,10 @@
" -h or --help Print this message and exit.\n"
"\n"
"OSC options:\n"
+ " --osc-server <address>\n"
+ " IP address to send OSC messages to.\n"
+ " Default: 127.0.0.1\n"
+ "\n"
" --osc-port <number>\n"
" UDP Port to send OSC messages to.\n"
" Default: none\n"
@@ -575,12 +579,13 @@
}
}
-bool app_set_osc_udp_port(App_state* a, U16 port) {
+bool app_set_osc_udp(App_state* a, char const* dest_addr, U16 port) {
if (a->oosc_dev) {
oosc_dev_destroy(a->oosc_dev);
a->oosc_dev = NULL;
}
- Oosc_udp_create_error err = oosc_dev_create_udp(&a->oosc_dev, port);
+ Oosc_udp_create_error err =
+ oosc_dev_create_udp(&a->oosc_dev, dest_addr, port);
if (err) {
return false;
}
@@ -604,11 +609,11 @@
break;
case Midi_mode_type_osc_bidule: {
I32 ints[3];
- ints[0] = (0x9 << 4) | em->channel; // status
+ ints[0] = (0x9 << 4) | em->channel; // status
ints[1] = 12 * em->octave + em->note; // note number
// ints[1] = 12 * 4 + em->note; // note number
- ints[2] = em->velocity; // velocity
- ints[2] = 127; // velocity
+ ints[2] = em->velocity; // velocity
+ // ints[2] = 127; // velocity
oosc_send_int32s(oosc_dev, midi_mode->osc_bidule.path, ints,
ORCA_ARRAY_COUNTOF(ints));
} break;
@@ -840,6 +845,7 @@
enum {
Argopt_margins = UCHAR_MAX + 1,
+ Argopt_osc_server,
Argopt_osc_port,
Argopt_osc_midi_bidule,
};
@@ -848,6 +854,7 @@
static struct option tui_options[] = {
{"margins", required_argument, 0, Argopt_margins},
{"help", no_argument, 0, 'h'},
+ {"osc-server", required_argument, 0, Argopt_osc_server},
{"osc-port", required_argument, 0, Argopt_osc_port},
{"osc-midi-bidule", required_argument, 0, Argopt_osc_midi_bidule},
{NULL, 0, NULL, 0}};
@@ -854,6 +861,7 @@
char* input_file = NULL;
int margin_thickness = 2;
U16 osc_port = 0;
+ char const* osc_ip_send_addr = "127.0.0.1";
Midi_mode midi_mode;
midi_mode_init(&midi_mode);
for (;;) {
@@ -874,6 +882,9 @@
return 1;
}
} break;
+ case Argopt_osc_server: {
+ osc_ip_send_addr = optarg;
+ } break;
case Argopt_osc_port: {
int osc_port0 = atoi(optarg);
if (osc_port0 <= 0) {
@@ -911,7 +922,7 @@
app_init(&app_state);
if (osc_port != 0) {
- if (!app_set_osc_udp_port(&app_state, osc_port)) {
+ if (!app_set_osc_udp(&app_state, osc_ip_send_addr, osc_port)) {
fprintf(stderr, "Failed to open OSC UDP port %d\n", (int)osc_port);
exit(1);
}