Skip to content
Permalink
Browse files

Add raw UDP datagram ';' operator

  • Loading branch information...
cancel committed Jan 19, 2019
1 parent 5c09a12 commit ea71fc06eb53136d6b9bdbd13e09bbcc135430c6
Showing with 63 additions and 1 deletion.
  1. +10 −0 bank.h
  2. +1 −1 osc_out.c
  3. +11 −0 osc_out.h
  4. +27 −0 sim.c
  5. +14 −0 tui_main.c
10 bank.h
@@ -4,6 +4,7 @@
typedef enum {
Oevent_type_midi,
Oevent_type_osc_ints,
Oevent_type_udp_string,
} Oevent_types;

typedef struct {
@@ -28,10 +29,19 @@ typedef struct {
U8 numbers[Oevent_osc_int_count];
} Oevent_osc_ints;

enum { Oevent_udp_string_count = 16 };

typedef struct {
U8 oevent_type;
U8 count;
char chars[Oevent_udp_string_count];
} Oevent_udp_string;

typedef union {
Oevent_any any;
Oevent_midi midi;
Oevent_osc_ints osc_ints;
Oevent_udp_string udp_string;
} Oevent;

typedef struct {
@@ -91,7 +91,7 @@ void oosc_dev_destroy(Oosc_dev* dev) {
free(dev);
}

static void oosc_send_datagram(Oosc_dev* dev, char const* data, Usz size) {
void oosc_send_datagram(Oosc_dev* dev, char const* data, Usz size) {
ssize_t res = sendto(dev->fd, data, size, 0, dev->chosen->ai_addr,
dev->chosen->ai_addrlen);
if (res < 0) {
@@ -12,9 +12,20 @@ Oosc_udp_create_error oosc_dev_create_udp(Oosc_dev** out_ptr,
char const* dest_addr,
char const* dest_port);
void oosc_dev_destroy(Oosc_dev* dev);

// Send a raw UDP datagram.
void oosc_send_datagram(Oosc_dev* dev, char const* data, Usz size);

// Send a list/array of 32-bit integers in OSC format to the specified "osc
// address" (a path like /foo) as a UDP datagram.
void oosc_send_int32s(Oosc_dev* dev, char const* osc_address, I32 const* vals,
Usz count);

// Susnote is for handling MIDI note sustains -- each MIDI on event should be
// matched with a MIDI note-off event. The duration/sustain length of a MIDI
// note is specified when it is first triggered, so the orca VM itself is not
// responsible for sending the note-off event. We keep a list of currently 'on'
// notes so that they can have a matching 'off' sent at the correct time.
typedef struct {
float remaining;
U16 chan_note;
27 sim.c
@@ -224,6 +224,7 @@ Usz usz_clamp(Usz val, Usz min, Usz max) {
_('#', comment) \
_('*', bang) \
_(':', midi) \
_(';', udp) \
_('=', osc)

#define ALPHA_OPERATORS(_) \
@@ -369,6 +370,32 @@ BEGIN_OPERATOR(midi)
oe->bar_divisor = (U8)(index_of(length_g) + 1);
END_OPERATOR

BEGIN_OPERATOR(udp)
Usz n = width - x - 1;
if (n > 16)
n = 16;
Glyph const* restrict gline = gbuffer + y * width + x + 1;
Mark* restrict mline = mbuffer + y * width + x + 1;
Glyph cpy[Oevent_udp_string_count];
Usz i;
for (i = 0; i < n; ++i) {
Glyph g = gline[i];
if (g == '.')
break;
cpy[i] = g;
mline[i] |= Mark_flag_lock;
}
n = i;
STOP_IF_NOT_BANGED;
Oevent_udp_string* oe =
(Oevent_udp_string*)oevent_list_alloc_item(extra_params->oevent_list);
oe->oevent_type = (U8)Oevent_type_udp_string;
oe->count = (U8)n;
for (i = 0; i < n; ++i) {
oe->chars[i] = cpy[i];
}
END_OPERATOR

BEGIN_OPERATOR(osc)
PORT(0, 1, IN | PARAM);
PORT(0, 2, IN | PARAM);
@@ -102,6 +102,7 @@ static Glyph_class glyph_class_of(Glyph glyph) {
return Glyph_class_movement;
case '!':
case ':':
case ';':
case '=':
return Glyph_class_lowercase;
case '*':
@@ -587,6 +588,13 @@ void draw_oevent_list(WINDOW* win, Oevent_list const* oevent_list) {
wprintw(win, " %d", eo->numbers[i]);
}
} break;
case Oevent_type_udp_string: {
Oevent_udp_string const* eo = &ev->udp_string;
wprintw(win, "UDP\tcount %d\t", (int)eo->count);
for (Usz j = 0; j < (Usz)eo->count; ++j) {
waddch(win, (chtype)eo->chars[j]);
}
} break;
}
}
}
@@ -968,6 +976,12 @@ void send_output_events(Oosc_dev* oosc_dev, Midi_mode const* midi_mode, Usz bpm,
}
oosc_send_int32s(oosc_dev, path_buff, ints, nnum);
} break;
case Oevent_type_udp_string: {
if (!oosc_dev)
continue;
Oevent_udp_string const* eo = &e->udp_string;
oosc_send_datagram(oosc_dev, eo->chars, eo->count);
} break;
}
}

0 comments on commit ea71fc0

Please sign in to comment.
You can’t perform that action at this time.