Skip to content

Commit

Permalink
Added outlets for hostname and port of incoming messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
malloch committed Jun 7, 2012
1 parent 4c081c4 commit 748eff6
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 25 deletions.
18 changes: 16 additions & 2 deletions oscmulticast.c
Expand Up @@ -31,6 +31,8 @@ typedef struct _oscmulticast
{
t_object ob;
void *outlet1;
void *outlet2;
void *outlet3;
char *iface;
char *group;
char port[10];
Expand Down Expand Up @@ -101,10 +103,14 @@ void *oscmulticast_new(t_symbol *s, int argc, t_atom *argv)

#ifdef MAXMSP
if (x = object_alloc(oscmulticast_class)) {
x->outlet1 = outlet_new((t_object *)x, 0);
x->outlet3 = listout((t_object *)x);
x->outlet2 = listout((t_object *)x);
x->outlet1 = listout((t_object *)x);
#else
if (x = (t_oscmulticast *) pd_new(oscmulticast_class)) {
x->outlet1 = outlet_new(&x->ob, gensym("list"));
x->outlet2 = outlet_new(&x->ob, gensym("list"));
x->outlet3 = outlet_new(&x->ob, gensym("list"));
#endif

x->group = NULL;
Expand Down Expand Up @@ -309,7 +315,7 @@ void oscmulticast_poll(t_oscmulticast *x)
// *********************************************************
// -(OSC handler)-------------------------------------------
int oscmulticast_handler(const char *path, const char *types, lo_arg ** argv,
int argc, void *data, void *user_data)
int argc, lo_message msg, void *user_data)
{
t_oscmulticast *x = (t_oscmulticast *)user_data;
int i, j;
Expand All @@ -322,6 +328,14 @@ int oscmulticast_handler(const char *path, const char *types, lo_arg ** argv,
return 0;
}

lo_address address = lo_message_get_source(msg);
if (address) {
maxpd_atom_set_int(x->buffer, atoi(lo_address_get_port(address)));
outlet_anything(x->outlet3, gensym("int"), 1, x->buffer);
maxpd_atom_set_string(x->buffer, lo_address_get_hostname(address));
outlet_anything(x->outlet2, gensym("symbol"), 1, x->buffer);
}

if (argc > MAXSIZE) {
post("Truncating received message to 256 elements!");
argc = MAXSIZE;
Expand Down
12 changes: 8 additions & 4 deletions oscmulticast.help.pd
Expand Up @@ -2,7 +2,6 @@
#X obj 39 194 oscmulticast @group 224.0.1.3 @port 7570;
#X msg 39 165 /somedata \$1;
#X floatatom 39 137 5 0 0 0 - - -;
#X obj 39 224 print;
#X text 13 13 oscmulticast;
#X text 13 34 Sends and receives Open Sound Control over multicast
IP.;
Expand All @@ -15,8 +14,13 @@ with the message "interface";
#X msg 24 317 interface en0;
#X msg 116 317 interface lo0;
#X text 240 398 Joseph Malloch 2011;
#X connect 0 0 3 0;
#X obj 39 224 print msg;
#X obj 276 224 print port;
#X obj 157 225 print host;
#X connect 0 0 11 0;
#X connect 0 1 13 0;
#X connect 0 2 12 0;
#X connect 1 0 0 0;
#X connect 2 0 1 0;
#X connect 9 0 7 0;
#X connect 10 0 7 0;
#X connect 8 0 6 0;
#X connect 9 0 6 0;
125 changes: 106 additions & 19 deletions oscmulticast.maxhelp
Expand Up @@ -25,6 +25,59 @@
"enablevscroll" : 1,
"devicewidth" : 0.0,
"boxes" : [ {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-9",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 330.0, 225.0, 127.0, 20.0 ],
"text" : "print oscmulticast:port"
}

}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-15",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 330.0, 255.0, 147.0, 18.0 ],
"presentation_rect" : [ 348.0, 255.0, 0.0, 0.0 ]
}

}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-13",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 180.0, 225.0, 129.0, 20.0 ],
"text" : "print oscmulticast:host"
}

}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-14",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 180.0, 255.0, 147.0, 18.0 ]
}

}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
Expand All @@ -33,8 +86,7 @@
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 135.0, 345.0, 76.0, 18.0 ],
"presentation_rect" : [ 136.0, 344.0, 0.0, 0.0 ],
"patching_rect" : [ 120.0, 345.0, 76.0, 18.0 ],
"text" : "interface lo0"
}

Expand All @@ -48,7 +100,7 @@
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 45.0, 345.0, 80.0, 18.0 ],
"patching_rect" : [ 30.0, 345.0, 80.0, 18.0 ],
"text" : "interface en0"
}

Expand All @@ -62,8 +114,7 @@
"maxclass" : "comment",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 45.0, 300.0, 235.0, 34.0 ],
"presentation_rect" : [ 49.0, 298.0, 0.0, 0.0 ],
"patching_rect" : [ 30.0, 300.0, 235.0, 34.0 ],
"text" : "The network interface can be set with an argument or a message."
}

Expand All @@ -76,9 +127,9 @@
"linecount" : 2,
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 45.0, 375.0, 189.0, 34.0 ],
"numoutlets" : 3,
"outlettype" : [ "list", "list", "list" ],
"patching_rect" : [ 30.0, 375.0, 189.0, 34.0 ],
"text" : "oscmulticast @group 224.0.1.3 @port 7570 @interface lo0"
}

Expand All @@ -91,8 +142,8 @@
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 195.0, 225.0, 103.0, 20.0 ],
"text" : "print oscmulticast"
"patching_rect" : [ 30.0, 225.0, 129.0, 20.0 ],
"text" : "print oscmulticast:msg"
}

}
Expand All @@ -105,7 +156,7 @@
"maxclass" : "comment",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 315.0, 135.0, 150.0, 48.0 ],
"patching_rect" : [ 300.0, 105.0, 150.0, 48.0 ],
"text" : "This objects requires the group and port attributes to be set."
}

Expand All @@ -119,7 +170,7 @@
"numinlets" : 1,
"numoutlets" : 2,
"outlettype" : [ "float", "bang" ],
"patching_rect" : [ 45.0, 120.0, 50.0, 20.0 ]
"patching_rect" : [ 30.0, 120.0, 50.0, 20.0 ]
}

}
Expand All @@ -132,7 +183,7 @@
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 45.0, 225.0, 147.0, 18.0 ]
"patching_rect" : [ 30.0, 255.0, 147.0, 18.0 ]
}

}
Expand All @@ -145,7 +196,7 @@
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 45.0, 150.0, 123.0, 18.0 ],
"patching_rect" : [ 30.0, 150.0, 123.0, 18.0 ],
"text" : "/send_some_data $1"
}

Expand All @@ -157,9 +208,9 @@
"id" : "obj-1",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 45.0, 180.0, 242.0, 20.0 ],
"numoutlets" : 3,
"outlettype" : [ "list", "list", "list" ],
"patching_rect" : [ 30.0, 180.0, 319.0, 20.0 ],
"text" : "oscmulticast @group 224.0.1.3 @port 7570"
}

Expand Down Expand Up @@ -236,10 +287,37 @@
}
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-13", 0 ],
"hidden" : 0,
"midpoints" : [ ],
"source" : [ "obj-1", 1 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-14", 1 ],
"hidden" : 0,
"midpoints" : [ 189.5, 212.0, 317.5, 212.0 ],
"source" : [ "obj-1", 1 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-15", 1 ],
"hidden" : 0,
"midpoints" : [ 339.5, 212.0, 467.5, 212.0 ],
"source" : [ "obj-1", 2 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-3", 0 ],
"hidden" : 0,
"midpoints" : [ 54.5, 212.0, 204.5, 212.0 ],
"midpoints" : [ ],
"source" : [ "obj-1", 0 ]
}

Expand All @@ -248,10 +326,19 @@
"patchline" : {
"destination" : [ "obj-6", 1 ],
"hidden" : 0,
"midpoints" : [ 54.5, 212.0, 182.5, 212.0 ],
"midpoints" : [ 39.5, 212.0, 167.5, 212.0 ],
"source" : [ "obj-1", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-9", 0 ],
"hidden" : 0,
"midpoints" : [ ],
"source" : [ "obj-1", 2 ]
}

}
, {
"patchline" : {
Expand Down

0 comments on commit 748eff6

Please sign in to comment.