atroscine

darcs-hash:20050811090231-2648a-b62b40c5f0df7e8f5231240a1d3698146582da42.gz
This commit is contained in:
nik gaffney 2005-08-11 17:02:31 +08:00
parent 814298e0dc
commit 9bcc4ffcc2
4 changed files with 24 additions and 22 deletions

View file

@ -22,7 +22,7 @@ or via asdf-install.. .
limitations
- doesnt send nested bundles or timetags later than 'now'
- will most likely crash if the input is malformed
- will raise an exception if the input is malformed
- doesnt do any pattern matching on addresses
- sbcl/cmucl specific float en/decoding
- only supports the type(tag)s specified in the OSC spec
@ -34,11 +34,11 @@ things to do
- portable en/decoding of floats -=> ieee754 tests
- doubles and other defacto typetags
- correct en/decoding of timetags
- asdf-installable
changes
2005-03-16
- packaged as an asdf installable lump
2005-03-11
- bundle and blob en/de- coding
2005-03-05

View file

@ -13,8 +13,10 @@
;;
;; Commentry
;;
;; These examples are currently sbcl specific (ports welcome!)
;; but should still be able to explain enough to get started. ..
;; These examples are currently sbcl specific [as is the float code],
;; but should be easily modifyable to work with trivial-sockets, or
;; something similar for portablity. these examples should still be
;; able to explain enough to get you started. ..
;;
;; eg. listen on port 6667 for incoming msgs
;;
@ -62,7 +64,7 @@
(socket-receive in buffer nil)
(let ((oscuff (osc:decode-bundle buffer)))
(format t "glonked -=> message with ~S~% arg(s)" (length oscuff))
(write-stream-t1 oscuff stream)))
(write-stream-t1 stream oscuff)))
(when in (socket-close in))
(when out (socket-close out))))))
@ -70,7 +72,7 @@
(defun make-udp-socket()
(make-instance 'inet-socket :type :datagram :protocol :udp))
(defun write-stream-t1 (osc-message stream)
(defun write-stream-t1 (stream osc-message)
"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,. ."

View file

@ -7,5 +7,5 @@
:author "nik gaffney <nik@fo.am>"
:licence "LLGPL"
:description "The Open Sound Control protocol, aka OSC"
:components ((:file "osc"))
)
:version "0.1"
:components ((:file "osc")))

View file

@ -28,8 +28,9 @@
;; http://www.cnmat.berkeley.edu/OpenSoundControl/
;;
;; - doesnt send nested bundles or timetags later than 'now'
;; - will most likely crash if the input is malformed
;; - malformed input -> exception
;; - int32 en/de-coding based on code (c) Walter C. Pelissero
;; - unknown types are sent as 'blobs' which may or may not be an issue
;;
;; see the README file for more details...
;;
@ -90,7 +91,8 @@
i => #(105) => int32
f => #(102) => float
s => #(115) => string
b => #(98) => blob"
b => #(98) => blob
and considers non int/float/string data to be a blob."
(let ((lump (make-array 0 :adjustable t
:fill-pointer t
@ -104,10 +106,9 @@
(integer (write-to-vector #\i))
(float (write-to-vector #\f))
(simple-string (write-to-vector #\s))
(simple-vector (write-to-vector #\b))
(t (error "can only encode ints, floats or strings"))))
(t (write-to-vector #\b)))))
(cat lump
(pad (padding-length (length lump)))))))
(pad (padding-length (length lump))))))
(defun encode-data (data)
"encodes data in a format suitable for an OSC message"
@ -119,8 +120,7 @@
(integer (enc encode-int32))
(float (enc encode-float32))
(simple-string (enc encode-string))
(simple-vector (enc encode-blob))
(t (error "wrong type. turn back"))))
(t (enc encode-blob))))
lump)))
@ -197,11 +197,11 @@
result)
(setf acc (subseq acc pointer))))
((eq x (char-code #\b))
(let ((size (decode-int32 (subseq acc 0 4))))
(let ((end (padded-length (+ 4 size))))
(push (decode-blob (subseq acc 0 end))
result)
(setf acc (subseq acc end)))))
(let* ((size (decode-int32 (subseq acc 0 4)))
(end (padded-length (+ 4 size))))
(push (decode-blob (subseq acc 0 end))
result)
(setf acc (subseq acc end))))
(t (error "unrecognised typetag"))))
tags)
(nreverse result))))
@ -323,7 +323,7 @@
(+ s (- 4 (mod s 4))))
(defun string-padding (string)
"returns the padding required for a given osc string"
q "returns the padding required for a given osc string"
(declare (type simple-string string))
(pad (- 4 (mod (length string) 4))))