2005-01-26 13:52:24 +00:00
|
|
|
;; -*- mode: lisp -*-
|
|
|
|
;;
|
|
|
|
;; Examples of how to send OSC messages. ..
|
|
|
|
;;
|
|
|
|
;; Copyright (C) 2004 FoAM vzw
|
|
|
|
;;
|
|
|
|
;; Authors
|
|
|
|
;; - nik gaffney <nik@f0.am>
|
|
|
|
;;
|
|
|
|
;;;;; ;; ; ; ;; ; ;
|
|
|
|
|
|
|
|
;;;;;::::: : : : ; ;; ; ; ; ; ; ;
|
|
|
|
;;
|
|
|
|
;; Commentry
|
|
|
|
;;
|
2006-02-10 23:38:40 +00:00
|
|
|
;; These examples are currently sbcl specific, but should be easily ported to
|
|
|
|
;; work with trivial-sockets, acl-compat or something similar. They should be
|
2005-08-11 09:02:31 +00:00
|
|
|
;; able to explain enough to get you started. ..
|
2005-01-26 13:52:24 +00:00
|
|
|
;;
|
|
|
|
;; eg. listen on port 6667 for incoming msgs
|
|
|
|
;;
|
|
|
|
;; (osc-listen 6667)
|
|
|
|
;;
|
|
|
|
;; eg. listen on port 6667 and send to 10.0.89:6668
|
|
|
|
;; note the ip# is formatted as a vector
|
|
|
|
;;
|
|
|
|
;; (osc-reflector 6667 #(10 0 0 89) 6668)
|
|
|
|
;;
|
|
|
|
;;;;;:::;;: ; ; ;::: ; ;; ;; ; ;; ;
|
|
|
|
|
|
|
|
(require :sb-bsd-sockets)
|
2005-02-10 13:32:51 +00:00
|
|
|
(use-package :osc)
|
2005-03-14 14:05:05 +00:00
|
|
|
(use-package :sb-bsd-sockets)
|
2005-01-26 15:19:43 +00:00
|
|
|
|
2005-01-26 13:52:24 +00:00
|
|
|
|
2005-03-14 14:05:05 +00:00
|
|
|
(defun osc-listen (port)
|
|
|
|
"a basic test function which attempts to decode an osc message a given port."
|
2005-03-07 10:09:57 +00:00
|
|
|
(let ((s (make-udp-socket))
|
2005-01-26 13:52:24 +00:00
|
|
|
(buffer (make-sequence '(vector (unsigned-byte 8)) 1024)))
|
2005-03-07 10:09:57 +00:00
|
|
|
(socket-bind s #(0 0 0 0) port)
|
2005-01-26 13:52:24 +00:00
|
|
|
(format t "listening on localhost port ~A~%~%" port)
|
|
|
|
(unwind-protect
|
|
|
|
(loop do
|
2005-03-14 14:05:05 +00:00
|
|
|
(socket-receive s buffer nil)
|
|
|
|
(format t "receiveded -=> ~S~%" (osc:decode-bundle buffer)))
|
2005-01-26 13:52:24 +00:00
|
|
|
(when s (socket-close s)))))
|
|
|
|
|
|
|
|
|
|
|
|
(defun osc-reflector (listen-port send-ip send-port)
|
|
|
|
"reflector.. . listens on a given port and sends out on another
|
|
|
|
note ip#s need to be in the format #(127 0 0 1) for now.. ."
|
2005-03-07 10:09:57 +00:00
|
|
|
(let ((in (make-udp-socket))
|
|
|
|
(out (make-udp-socket))
|
2005-01-26 13:52:24 +00:00
|
|
|
(buffer (make-sequence '(vector (unsigned-byte 8)) 512)))
|
2005-03-07 10:09:57 +00:00
|
|
|
(socket-bind in #(0 0 0 0) listen-port)
|
2005-01-26 13:52:24 +00:00
|
|
|
(socket-connect out send-ip send-port)
|
|
|
|
(let ((stream
|
|
|
|
(socket-make-stream
|
|
|
|
out :input t :output t
|
|
|
|
:element-type '(unsigned-byte 8) :buffering :full)))
|
|
|
|
(unwind-protect
|
|
|
|
(loop do
|
2005-03-14 14:05:05 +00:00
|
|
|
(socket-receive in buffer nil)
|
|
|
|
(let ((oscuff (osc:decode-bundle buffer)))
|
2005-01-26 13:52:24 +00:00
|
|
|
(format t "glonked -=> message with ~S~% arg(s)" (length oscuff))
|
2005-08-11 09:02:31 +00:00
|
|
|
(write-stream-t1 stream oscuff)))
|
2005-01-26 13:52:24 +00:00
|
|
|
(when in (socket-close in))
|
2005-02-10 13:32:51 +00:00
|
|
|
(when out (socket-close out))))))
|
2005-01-26 13:52:24 +00:00
|
|
|
|
|
|
|
|
2005-03-07 10:09:57 +00:00
|
|
|
(defun make-udp-socket()
|
|
|
|
(make-instance 'inet-socket :type :datagram :protocol :udp))
|
|
|
|
|
2005-08-11 09:02:31 +00:00
|
|
|
(defun write-stream-t1 (stream osc-message)
|
2005-02-10 13:32:51 +00:00
|
|
|
"writes a given message to a stream. keep in mind that when using a buffered
|
|
|
|
stream any funtion writing to the stream should call (finish-output stream)
|
|
|
|
after it sends the mesages,. ."
|
|
|
|
(write-sequence
|
|
|
|
(osc:encode-message "/bzzp" "got" "it" )
|
|
|
|
stream)
|
2005-01-26 13:52:24 +00:00
|
|
|
(finish-output stream))
|
|
|
|
|
2005-02-10 13:32:51 +00:00
|
|
|
(defmacro osc-write-to-stream (stream &body args)
|
|
|
|
`(progn (write-sequence (osc:encode-message ,@args) ,stream)
|
|
|
|
(finish-output ,stream)))
|
|
|
|
|
2005-03-07 10:09:57 +00:00
|
|
|
;end
|