recognosce

added openmcl float support and a few minor cleanups

darcs-hash:20051129111126-2648a-1f3055c480c24f4352e87e40d966b01a4aa1921e.gz
This commit is contained in:
nik gaffney 2005-11-29 19:11:26 +08:00
parent 1a1abf68bd
commit d8ffcab7b3
4 changed files with 108 additions and 57 deletions

View file

@ -2,13 +2,55 @@ Preamble to the Gnu Lesser General Public License
Copyright (c) 2000 Franz Incorporated, Berkeley, CA 94704
The concept of the GNU Lesser General Public License version 2.1 ("LGPL") has been adopted to govern the use and distribution of above-mentioned application. However, the LGPL uses terminology that is more appropriate for a program written in C than one written in Lisp. Nevertheless, the LGPL can still be applied to a Lisp program if certain clarifications are made. This document details those clarifications. Accordingly, the license for the open-source Lisp applications consists of this document plus the LGPL. Wherever there is a conflict between this document and the LGPL, this document takes precedence over the LGPL.
The concept of the GNU Lesser General Public License version 2.1 ("LGPL") has
been adopted to govern the use and distribution of above-mentioned
application. However, the LGPL uses terminology that is more appropriate for a
program written in C than one written in Lisp. Nevertheless, the LGPL can still
be applied to a Lisp program if certain clarifications are made. This document
details those clarifications. Accordingly, the license for the open-source Lisp
applications consists of this document plus the LGPL. Wherever there is a
conflict between this document and the LGPL, this document takes precedence over
the LGPL.
A "Library" in Lisp is a collection of Lisp functions, data and foreign modules. The form of the Library can be Lisp source code (for processing by an interpreter) or object code (usually the result of compilation of source code or built with some other mechanisms). Foreign modules are object code in a form that can be linked into a Lisp executable. When we speak of functions we do so in the most general way to include, in addition, methods and unnamed functions. Lisp "data" is also a general term that includes the data structures resulting from defining Lisp classes. A Lisp application may include the same set of Lisp objects as does a Library, but this does not mean that the application is necessarily a "work based on the Library" it contains.
A "Library" in Lisp is a collection of Lisp functions, data and foreign
modules. The form of the Library can be Lisp source code (for processing by an
interpreter) or object code (usually the result of compilation of source code or
built with some other mechanisms). Foreign modules are object code in a form
that can be linked into a Lisp executable. When we speak of functions we do so
in the most general way to include, in addition, methods and unnamed
functions. Lisp "data" is also a general term that includes the data structures
resulting from defining Lisp classes. A Lisp application may include the same
set of Lisp objects as does a Library, but this does not mean that the
application is necessarily a "work based on the Library" it contains.
The Library consists of everything in the distribution file set before any modifications are made to the files. If any of the functions or classes in the Library are redefined in other files, then those redefinitions ARE considered a work based on the Library. If additional methods are added to generic functions in the Library, those additional methods are NOT considered a work based on the Library. If Library classes are subclassed, these subclasses are NOT considered a work based on the Library. If the Library is modified to explicitly call other functions that are neither part of Lisp itself nor an available add-on module to Lisp, then the functions called by the modified Library ARE considered a work based on the Library. The goal is to ensure that the Library will compile and run without getting undefined function errors.
The Library consists of everything in the distribution file set before any
modifications are made to the files. If any of the functions or classes in the
Library are redefined in other files, then those redefinitions ARE considered a
work based on the Library. If additional methods are added to generic functions
in the Library, those additional methods are NOT considered a work based on the
Library. If Library classes are subclassed, these subclasses are NOT considered
a work based on the Library. If the Library is modified to explicitly call other
functions that are neither part of Lisp itself nor an available add-on module to
Lisp, then the functions called by the modified Library ARE considered a work
based on the Library. The goal is to ensure that the Library will compile and
run without getting undefined function errors.
It is permitted to add proprietary source code to the Library, but it must be done in a way such that the Library will still run without that proprietary code present. Section 5 of the LGPL distinguishes between the case of a library being dynamically linked at runtime and one being statically linked at build time. Section 5 of the LGPL states that the former results in an executable that is a "work that uses the Library." Section 5 of the LGPL states that the latter results in one that is a "derivative of the Library", which is therefore covered by the LGPL. Since Lisp only offers one choice, which is to link the Library into an executable at build time, we declare that, for the purpose applying the LGPL to the Library, an executable that results from linking a "work that uses the Library" with the Library is considered a "work that uses the Library" and is therefore NOT covered by the LGPL.
It is permitted to add proprietary source code to the Library, but it must be
done in a way such that the Library will still run without that proprietary code
present. Section 5 of the LGPL distinguishes between the case of a library being
dynamically linked at runtime and one being statically linked at build
time. Section 5 of the LGPL states that the former results in an executable that
is a "work that uses the Library." Section 5 of the LGPL states that the latter
results in one that is a "derivative of the Library", which is therefore covered
by the LGPL. Since Lisp only offers one choice, which is to link the Library
into an executable at build time, we declare that, for the purpose applying the
LGPL to the Library, an executable that results from linking a "work that uses
the Library" with the Library is considered a "work that uses the Library" and
is therefore NOT covered by the LGPL.
Because of this declaration, section 6 of LGPL is not applicable to the Library. However, in connection with each distribution of this executable, you must also deliver, in accordance with the terms and conditions of the LGPL, the source code of Library (or your derivative thereof) that is incorporated into this executable.
Because of this declaration, section 6 of LGPL is not applicable to the
Library. However, in connection with each distribution of this executable, you
must also deliver, in accordance with the terms and conditions of the LGPL, the
source code of Library (or your derivative thereof) that is incorporated into
this executable.

View file

@ -1,4 +1,5 @@
Open Sound Control
This is a common-lisp implementation of the Open Sound Control
@ -25,7 +26,7 @@ limitations
- doesnt send nested bundles or timetags later than 'now'
- will raise an exception if the input is malformed
- doesnt do any pattern matching on addresses
- sbcl/cmucl specific float en/decoding
- sbcl/cmucl/openmcl specific float en/decoding
- only supports the type(tag)s specified in the OSC spec
things to do in :osc
@ -41,6 +42,9 @@ things to do in :osc-ex[tensions|tras]
changes
2005-11-29
- version 0.2
- openmcl float en/decoding
2005-08-12
- corrections from Matthew Kennedy <mkennedy@gentoo.org>
2005-08-11

View file

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

103
osc.lisp
View file

@ -1,41 +1,42 @@
;; -*- mode: lisp -*-
;;
;; an implementation of the OSC (Open Sound Control) protocol
;;
;; copyright (C) 2004 FoAM vzw.
;;
;; You are granted the rights to distribute and use this software
;; under the terms of the Lisp Lesser GNU Public License, known
;; as the LLGPL. The LLGPL consists of a preamble and the LGPL.
;; Where these conflict, the preamble takes precedence. The LLGPL
;; is available online at http://opensource.franz.com/preamble.html
;; and is distributed with this code (see: LICENCE and LGPL files)
;;
;; authors
;;
;; nik gaffney <nik@f0.am>
;;
;; requirements
;;
;; dependent on sbcl or cmucl for float encoding, other suggestions welcome.
;;
;; commentary
;;
;; this is a partial implementation of the OSC protocol which is used
;; for communication mostly amongst music programs and their attatched
;; musicians. eg. sc3, max/pd, reaktor/traktorska etc+. more details
;; of the protocol can be found at the open sound control pages -=>
;; http://www.cnmat.berkeley.edu/OpenSoundControl/
;;
;; - doesnt send nested bundles or timetags later than 'now'
;; - 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...
;;
;; known BUGS
;; - only unknown for now.. .
;;; -*- mode: lisp -*-
;;;
;;; an implementation of the OSC (Open Sound Control) protocol
;;;
;;; copyright (C) 2004 FoAM vzw.
;;;
;;; You are granted the rights to distribute and use this software
;;; under the terms of the Lisp Lesser GNU Public License, known
;;; as the LLGPL. The LLGPL consists of a preamble and the LGPL.
;;; Where these conflict, the preamble takes precedence. The LLGPL
;;; is available online at http://opensource.franz.com/preamble.html
;;; and is distributed with this code (see: LICENCE and LGPL files)
;;;
;;; authors
;;;
;;; nik gaffney <nik@f0.am>
;;;
;;; requirements
;;;
;;; dependent on sbcl, cmucl or openmcl for float encoding, other suggestions
;;; welcome.
;;;
;;; commentary
;;;
;;; this is a partial implementation of the OSC protocol which is used
;;; for communication mostly amongst music programs and their attatched
;;; musicians. eg. sc3, max/pd, reaktor/traktorska etc+. more details
;;; of the protocol can be found at the open sound control pages -=>
;;; http://www.cnmat.berkeley.edu/OpenSoundControl/
;;;
;;; - doesnt send nested bundles or timetags later than 'now'
;;; - 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...
;;;
;;; known BUGS
;;; - only unknown for now.. .
(defpackage :osc
@ -54,7 +55,7 @@
;;
;; eNcoding OSC messages
;;
;;; ;; ;; ; ; ;; ; ; ; ;
;;;; ;; ;; ; ; ;; ; ; ; ;
(defun encode-bundle (data)
@ -95,8 +96,7 @@
and considers non int/float/string data to be a blob."
(let ((lump (make-array 0 :adjustable t
:fill-pointer t
:element-type 'character)))
:fill-pointer t)))
(macrolet ((write-to-vector (char)
`(vector-push-extend
(char-code ,char) lump)))
@ -107,8 +107,8 @@
(float (write-to-vector #\f))
(simple-string (write-to-vector #\s))
(t (write-to-vector #\b)))))
(cat lump
(pad (padding-length (length lump))))))
(cat lump
(pad (padding-length (length lump))))))
(defun encode-data (data)
"encodes data in a format suitable for an OSC message"
@ -207,7 +207,7 @@
(nreverse result))))
;;; ; ;; ;
;;;;;; ;; ;; ; ; ; ; ; ;; ;
;;
;; timetags
;;
@ -244,20 +244,25 @@
;;
;;; ;; ; ; ;
;; floats are encoded using implementation specific 'internals' which is not
;; particulaly portable, but 'works for now'.
(defun encode-float32 (f)
"encode an ieee754 float as a 4 byte vector. currently sbcl/cmucl specifc"
#+sbcl (encode-int32 (sb-kernel:single-float-bits f))
#+cmucl (encode-int32 (kernel:single-float-bits f))
#-(or sbcl cmucl) (error "cant encode floats using this implementation"))
#+openmcl (encode-int32 (CCL::SINGLE-FLOAT-BITS f))
#-(or sbcl cmucl openmcl) (error "cant encode floats using this implementation"))
(defun decode-float32 (s)
"ieee754 float from a vector of 4 bytes in network byte order"
#+sbcl (sb-kernel:make-single-float (decode-int32 s))
#+cmucl (kernel:make-single-float (decode-int32 s))
#-(or sbcl cmucl) (error "cant decode floats using this implementation"))
#+openmcl (CCL::HOST-SINGLE-FLOAT-FROM-UNSIGNED-BYTE-32 (decode-int32 s))
#-(or sbcl cmucl openmcl) (error "cant decode floats using this implementation"))
(defun decode-int32 (s)
"4 byte > 32 bit int > two's compliment (in network byte order)"
"4 byte -> 32 bit int -> two's compliment (in network byte order)"
(let ((i (+ (ash (elt s 0) 24)
(ash (elt s 1) 16)
(ash (elt s 2) 8)
@ -267,7 +272,7 @@
i)))
(defun encode-int32 (i)
"convert integer into a sequence of 4 bytes in network byte order."
"convert an integer into a sequence of 4 bytes in network byte order."
(declare (type integer i))
(let ((buf (make-sequence
'(vector (unsigned-byte 8)) 4)))
@ -325,7 +330,7 @@
(defun string-padding (string)
"returns the padding required for a given osc string"
(declare (type simple-string string))
(pad (- 4 (mod (length string) 4))))
(pad (padding-length (length string))))
(defun pad (n)
"make a sequence of the required number of #\Nul characters"