Mercurial > hg > plosc
changeset 2:6c1ba6bf9f96
Added osc_split_address/3 to analyse address into host and port.
author | samer |
---|---|
date | Tue, 31 Jan 2012 15:53:45 +0000 |
parents | 16c621d40b68 |
children | 44e4b80bdf97 |
files | c/plosc.c prolog/plosc.pl |
diffstat | 2 files changed, 29 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/c/plosc.c Tue Jan 31 10:34:46 2012 +0000 +++ b/c/plosc.c Tue Jan 31 15:53:45 2012 +0000 @@ -55,6 +55,7 @@ install_t install(); foreign_t mk_address( term_t host, term_t port, term_t addr); +foreign_t split_address( term_t addr, term_t host, term_t port); foreign_t is_address( term_t addr); foreign_t send_osc_now( term_t addr, term_t msg, term_t args); foreign_t send_osc_at( term_t addr, term_t msg, term_t args, term_t time); @@ -120,13 +121,14 @@ } install_t install() { - PL_register_foreign("osc_now", 2, (void *)now, 0); - PL_register_foreign("time_to_ts", 3, (void *)time_to_ts, 0); - PL_register_foreign("time_from_ts", 3, (void *)time_from_ts, 0); - PL_register_foreign("osc_mk_address", 3, (void *)mk_address, 0); - PL_register_foreign("osc_is_address", 1, (void *)is_address, 0); - PL_register_foreign("osc_send_now", 3, (void *)send_osc_now, 0); - PL_register_foreign("osc_send_at", 4, (void *)send_osc_at, 0); + PL_register_foreign("osc_now", 2, (void *)now, 0); + PL_register_foreign("time_to_ts", 3, (void *)time_to_ts, 0); + PL_register_foreign("time_from_ts", 3, (void *)time_from_ts, 0); + PL_register_foreign("osc_mk_address", 3, (void *)mk_address, 0); + PL_register_foreign("osc_split_address",3, (void *)split_address, 0); + PL_register_foreign("osc_is_address", 1, (void *)is_address, 0); + PL_register_foreign("osc_send_now", 3, (void *)send_osc_now, 0); + PL_register_foreign("osc_send_at", 4, (void *)send_osc_at, 0); PL_register_foreign("osc_send_from_at", 5, (void *)send_osc_from_at, 0); PL_register_foreign("osc_mk_server", 2, (void *)mk_server, 0); PL_register_foreign("osc_start_server", 1, (void *)start_server, 0); @@ -401,6 +403,17 @@ } } +foreign_t split_address(term_t addr, term_t host, term_t port) { + lo_address a; + const char *h, *p; + + return get_addr(addr,&a) + && (h=lo_address_get_hostname(a))!=NULL + && (p=lo_address_get_port(a))!=NULL + && PL_unify_atom_chars(host,h) + && PL_unify_integer(port,atoi(p)); +} + foreign_t now(term_t sec, term_t frac) { lo_timetag ts; int64_t s, f;
--- a/prolog/plosc.pl Tue Jan 31 10:34:46 2012 +0000 +++ b/prolog/plosc.pl Tue Jan 31 15:53:45 2012 +0000 @@ -7,6 +7,7 @@ osc_now/2 % -Seconds:int, -Fraction:int , osc_now/1 % -TS:osc_timestamp , osc_mk_address/3 % +Host:atom, +Port:nonneg, -Ref:osc_addr + , osc_split_address/3 % +Ref:osc_addr, -Host:atom, -Port:nonneg , osc_is_address/1 % +Ref , osc_send/3 % +Ref, +Path:atom, +Args:list(osc_arg) , osc_send/4 % +Ref, +Path:atom, +Args:list(osc_arg), +Time:float @@ -42,6 +43,14 @@ % @param Port is the port number of the OSC receiver % @param Ref is an atom representing the address +%% osc_split_address(+Ref:osc_addr,-Host:atom, -Port:nonneg) is det. +% +% Deconstruct a BLOB atom representing an OSC destination. +% +% @param Ref is an atom representing the OSC address +% @param Host is the IP address of the OSC receiver +% @param Port is the port number of the OSC receiver + %% osc_is_address(+Ref) is semidet. % % Succeeds if Ref is an OSC address created by osc_mk_address/3