[CM] Receiving OSC
Kjetil S. Matheussen
k.s.matheussen at notam02.no
Thu Oct 23 09:33:02 PDT 2008
On Thu, 23 Oct 2008, Kjetil S. Matheussen wrote:
>
> I'm no expert in OSC, but I think using a C library, such as
> liblo would be easier to use in Snd than OscPack,
> which is a C++ library.
>
> Here's an example client:
> http://liblo.svn.sourceforge.net/viewvc/liblo/trunk/examples/example_client.c?revision=121&view=markup
>
> Using eval-c, the example (up to the first "send" command only
> and without the "blob"), can be written like this:
>
> (eval-c-add-int-type "int32_t")
> (eval-c "-llo"
> "#include <lo/lo.h>"
> (proto->public
> "lo_address lo_address_new(const char *host, const char *port);
> int lo_send_message (lo_address targ, const char *path, lo_message msg);
> lo_message lo_message_new (void);
> void lo_message_free (lo_message m);
> void lo_message_add_int32 (lo_message m, int32_t a);
> void lo_message_add_float (lo_message m, float a);
> void lo_message_add_string (lo_message m, const char *a);"))
>
> (define t (lo_address_new #f "7770"))
>
> (define message (lo_message_new))
>
> (lo_message_add_float message 0.12345678)
> (lo_message_add_float message 23.0)
>
> (define result (lo_send_message t "/foo/bar" message))
>
A convenient function:
(define (osc_send host port path . args)
(define address (lo_address_new host (if (string? port)
port
(number->string port))))
(define message (lo_message_new))
(for-each (lambda (arg)
(cond ((and (number? arg)
(integer? arg))
(lo_message_add_int32 message arg)))
((number? arg)
(lo_message_add_float message arg))
((string? arg)
(lo_message_add_string message arg))
(else (error "unkown arg" arg))))
args)
(let ((res (lo_send_message address path message)))
(lo_message_free message)
res))
(osc_send t #f 7770 "/foo/bar" 5.2 9.4 "hello" 9234/234)
;; ( #f means local host )
More information about the Cmdist
mailing list