id
int64 0
45.1k
| file_name
stringlengths 4
68
| file_path
stringlengths 14
193
| content
stringlengths 32
9.62M
| size
int64 32
9.62M
| language
stringclasses 1
value | extension
stringclasses 6
values | total_lines
int64 1
136k
| avg_line_length
float64 3
903k
| max_line_length
int64 3
4.51M
| alphanum_fraction
float64 0
1
| repo_name
stringclasses 779
values | repo_stars
int64 0
882
| repo_forks
int64 0
108
| repo_open_issues
int64 0
90
| repo_license
stringclasses 8
values | repo_extraction_date
stringclasses 146
values | sha
stringlengths 64
64
| __index_level_0__
int64 0
45.1k
| exdup_ids_cmlisp_stkv2
sequencelengths 1
47
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
852 | sound-analysis.lisp | cac-t-u-s_om-sharp/src/packages/sound/sound/sound-analysis.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
(in-package :om)
(defmethod* sound-rms ((s internal-sound))
:icon 'sound-normalize
:indoc '("a sound")
:doc "Returns the linear Root-Mean-Square (RMS) value of <s>."
(when (check-valid-sound-buffer s)
(with-audio-buffer (input-buffer s)
(let* ((ptr (oa::om-pointer-ptr input-buffer))
(type (smpl-type s))
(nch (n-channels s))
(size (n-samples s)))
(let ((summed-square-signal
(loop for i from 0 to (1- size) sum
(loop for n from 0 to (1- nch)
sum (fli:dereference (fli:dereference ptr :index n :type :pointer) :index i :type type)
into sample-sum
finally (return (let ((mean-value (/ sample-sum nch)))
(* mean-value mean-value)))))))
(sqrt (/ summed-square-signal size)))
))))
(defmethod* sound-transients ((s internal-sound)
&key (method :rms) (threshold 0.2)
(window-size 512) (step 256)
(time-threshold 0.0) (output :ms))
:icon 'sound-transients
:initvals '(nil :rms 0.2 512 256 0.01 :ms)
:menuins '((1 (("RMS" :rms)
("Mean" :mean)
("Peak" :peak)))
(6 (("seconds" :sec)
("milliseconds" :ms))))
:indoc '("a sound"
"a detection method"
"a threshold for transient detection"
"detection window size (samples)"
"step between two windows (samples)"
"minimal time (sec) between transients"
"output times format (seconds or milliseconds)")
:doc "Finds and return transients/attacks detected in <s>.
Every <step> samples, a widow of <window-size> samples is analyzed by the selected <method>.
If the value is higher that <threshold> as compared to the previous window, the time is added to the returned list of transients.
<output> can be in seconds (float precision) or milliseconds (rounded).
"
(let ((transient-times ()))
(unless step (setf step window-size))
(with-audio-buffer (input-buffer s)
(if (null (oa::om-pointer-ptr input-buffer))
(om-beep-msg "Error: null sound buffer")
(let* ((ptr (oa::om-pointer-ptr input-buffer))
(type (smpl-type s))
(nch (n-channels s))
(size (n-samples s))
(sr (sample-rate s))
(previous-window-value 0.0)
(indx 0))
(loop while (< indx size) do
(let* ((real-size (min (- size indx) window-size))
(window-value
(cond
((equal method :rms)
(let ((summed-square-window
(loop for i from 0 to (1- real-size) sum
(loop for n from 0 to (1- nch)
sum (fli:dereference (fli:dereference ptr :index n :type :pointer) :index (+ indx i) :type type)
into sample-sum
finally (return (let ((mean-value (/ sample-sum nch)))
(* mean-value mean-value)))))))
(sqrt (/ summed-square-window real-size))))
((equal method :mean)
(/
(loop for i from 0 to (1- real-size) sum
(loop for n from 0 to (1- nch)
sum (fli:dereference (fli:dereference ptr :index n :type :pointer) :index (+ indx i) :type type)
into sample-sum
finally (return (/ sample-sum nch))))
real-size))
((equal method :peak)
(loop for i from 0 to (1- real-size) maximize
(loop for n from 0 to (1- nch)
sum (fli:dereference (fli:dereference ptr :index n :type :pointer) :index (+ indx i) :type type)
into sample-sum
finally (return (/ sample-sum nch)))))
(t (om-beep-msg "Error unknown method: ~A" method)
0.0))
))
(when (> (- window-value previous-window-value) threshold)
(let ((time (samples->sec indx sr)))
(when (or (null transient-times)
(> (- time (car transient-times)) time-threshold))
(push time transient-times))))
(setq previous-window-value window-value)
(incf indx real-size)))
)))
(reverse
(if (equal output :ms)
(sec->ms transient-times)
transient-times))))
| 5,843 | Common Lisp | .lisp | 111 | 35.783784 | 141 | 0.461902 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | cf4aeb5097710d1f2dfa60109638e45dff349e5b953759041ae145428e4f0897 | 852 | [
-1
] |
853 | audio-tools.lisp | cac-t-u-s_om-sharp/src/packages/sound/sound/audio-tools.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
(in-package :om)
(defmethod* adsr (amp1 amp2 a d s r &optional (decimals 3))
:icon 'sound-fade
:indoc '("max amplitude" "sustained amplitude" "attack time" "decay time" "sustain time" "release time" "BPF precision")
:initvals '(1 0.8 0.2 0.1 0.5 0.2 3)
:doc "Generates an ADSR BPF (Attack-Decay-Sustain-Release)
If either <amp2> or <d> is NIL, generates a simple envelope with attack and release time (no decay).
"
(if (and amp2 d)
(make-instance 'BPF
:x-points (list 0 a (+ a d) (+ a d s) (+ a d s r))
:y-points (list 0 amp1 amp2 amp2 0)
:decimals decimals)
(make-instance 'BPF
:x-points(list 0 a (+ a s) (+ a s r))
:y-points (list 0 amp1 amp1 0)
:decimals decimals)))
;;;========================
;;; CONVERSIONS
;;;========================
;;; fromerly lintodb ;;;
(defun lin-to-dB (x)
(let ((y (if (= 0.0 x) 0.00000001 x)))
(* (log y 10) 20)))
(defun db-to-lin (x)
(expt 10.0 (/ x 20.0)))
;;; DB / LIN
(defmethod* dB->lin ((x t))
:icon 'conversion
:indoc '("a value or list of values in dB")
:initvals '(-20)
:doc "Converts <x> from dB to linear value."
(cond ((numberp x) (db-to-lin x))
((listp x) (mapcar #'(lambda (y) (dB->lin y)) x))
(t (error "illegal arg ~a" x))))
(defmethod* lin->dB ((x t))
:icon 'conversion
:indoc '("a value or list of values")
:initvals '(0.1)
:doc "Converts <x> from linear to dB."
(cond((numberp x) (lin-to-db x))
((listp x) (mapcar #'lin->dB x))
(t (error "illegal arg ~a" x))))
;;; SAMPLES / SECONDS
(defmethod* sec->ms ((n number))
:icon 'conversion
:initvals '(0)
:indoc '("seconds")
:numouts 1
:doc "Converts <n> (seconds / floats) to milliseconds (intergers)."
(round (* n 1000)))
(defmethod* sec->ms ((n list)) (mapcar #'(lambda (s) (sec->ms s)) n))
(defmethod* ms->sec ((n number))
:icon 'conversion
:initvals '(0)
:indoc '("milliseconds")
:numouts 1
:doc "Converts <n> (milliseconds / integers) to seconds (floats)."
(/ n 1000.0))
(defmethod* ms->sec ((n list)) (mapcar #'(lambda (s) (ms->sec s)) n))
;;; SEC or MS / SECONDS
(defmethod* to-sec ((n number))
:icon 'conversion
:initvals '(0)
:indoc '("seconds or milliseconds")
:numouts 1
:doc "If <n> is float, leave as it is, otherwise convert ms to seconds "
(if (floatp n) n (* n 0.001)))
(defmethod* to-sec ((n list)) (mapcar #'(lambda (s) (to-sec s)) n))
(defmethod* to-ms ((n number))
:icon 'conversion
:initvals '(0)
:indoc '("seconds or milliseconds")
:numouts 1
:doc "If <n> is integer, leave as it is, otherwise convert sec to ms"
(if (floatp n) (round (* n 1000)) n))
(defmethod* to-ms ((n list)) (mapcar #'(lambda (s) (to-ms s)) n))
;;; SAMPLES / SECONDS
(defmethod* samples->sec ((samples number) samplerate)
:icon 'conversion
:initvals '(0 nil)
:indoc '("number of samples" "sample rate (Hz)")
:numouts 1
:doc "Converts <samples> to a time (or duration) in seconds depending on <samplerate>.
If <samplerate> is NIL, the default sample rate is used to calculate the time."
(float (/ samples (or samplerate (get-pref-value :audio :samplerate)))))
(defmethod* samples->sec ((samples list) samplerate)
(mapcar #'(lambda (input) (samples->sec input samplerate)) samples))
(defmethod* sec->samples ((secs number) samplerate)
:icon 'conversion
:initvals '(0 nil)
:indoc '("duration (s)" "sample rate (Hz)")
:numouts 1
:doc "Converts <secs> to a number of samples depending on <samplerate>.
If <samplerate> is NIL, the default sample rate is used to calculate the samples."
(round (* secs (or samplerate (get-pref-value :audio :samplerate)))))
(defmethod* sec->samples ((secs list) (samplerate number))
(mapcar #'(lambda (input) (sec->samples input samplerate)) secs))
;;; SAMPLES / MILLISECONDS
(defmethod* samples->ms ((samples number) samplerate)
:icon 'conversion
:initvals '(0 nil)
:indoc '("number of samples" "sample rate (Hz)")
:numouts 1
:doc "Converts <samples> to a time (or duration) in milliseconds depending on <samplerate>.
If <samplerate> is NIL, the default sample rate is used to calculate the time."
(* (/ samples (or samplerate (get-pref-value :audio :samplerate))) 1000.0))
(defmethod* samples->ms ((samples list) samplerate)
(mapcar #'(lambda (input) (samples->ms input samplerate)) samples))
(defmethod* ms->samples ((ms number) samplerate)
:icon 'conversion
:initvals '(0 nil)
:indoc '("duration (ms)" "sample rate (Hz)")
:numouts 1
:doc "Converts <ms> to a number of samples depending on <samplerate>.
If <samplerate> is NIL, the default sample rate is used to calculate the samples."
(round (* ms (or samplerate (get-pref-value :audio :samplerate)) 0.001)))
(defmethod* ms->samples ((ms list) (samplerate number))
(mapcar #'(lambda (input) (ms->samples input samplerate)) ms))
;;;========================
;;; MISC. UTILS
;;;========================
(defun clip (val &optional (min 0.0) (max 1.0))
" If val is below min, return min,
if val is above max, return max,
otherwise return val.
"
(let ((from min) (to max))
(when (> min max) (setf from max) (setf to min))
(cond
((> val to) to)
((< val from) from)
(t val))))
| 6,051 | Common Lisp | .lisp | 147 | 37.646259 | 122 | 0.606784 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 415840ce33ba2fe1f79983eadf842588ba6082e6c69c6abedc6aa3917286d1a2 | 853 | [
-1
] |
854 | sound-processing.lisp | cac-t-u-s_om-sharp/src/packages/sound/sound/sound-processing.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File authors: D. Bouche, J. Bresson
;============================================================================
(in-package :om)
;======================================================
;SND Process boxes
; THIS FILE USES LISPWORKS-SPECIFIC TOOLS FOR MEMORY ALLOCATION AND RELEASE
;======================================================
; D. Bouche 2013
;======================================================
(defmethod* sound-resample ((s internal-sound) sample-rate &optional (resample-method 0))
:icon 'sound-resample
:initvals '(nil 44100 0)
:menuins '((2 (("Best Quality" 0)
("Medium Quality" 1)
("Fastest" 2)
("Zero-Order Hold" 3)
("Linear" 4))))
:indoc '("a sound or sound-data buffer" "new sample rate in Hz" "resampling method")
:doc "Resamples a sound <s>."
(when (check-valid-sound-buffer s)
(if (and
(= (mod sample-rate 1) 0)
(> (/ sample-rate (sample-rate s) 1.0) (/ 1.0 256))
(< (/ sample-rate (sample-rate s) 1.0) 256))
(let* ((buffer (oa::om-pointer-ptr (buffer s)))
(size (n-samples s))
(nch (n-channels s))
(sr (sample-rate s))
(ratio (coerce (/ sample-rate sr) 'double-float))
(out-size (round (* ratio size)))
(interleaved-in (om-alloc-memory (* size nch) :type (smpl-type s) :clear t))
(interleaved-out (om-alloc-memory (* out-size nch) :type (smpl-type s) :clear t))
(final-buffer (make-audio-buffer nch out-size (smpl-type s)))
s2)
(interleave-buffer buffer interleaved-in size nch)
;;; USE LIBSAMPLERATE
;;; (resample-method values correspond to libsamplerate options)
(multiple-value-bind (success newsize-or-error)
(lsr::resample-audio-buffer interleaved-in size nch interleaved-out out-size ratio resample-method)
(if success
(progn
(split-buffer interleaved-out final-buffer out-size nch)
(setq s2 (make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr final-buffer :nch nch)
:n-samples newsize-or-error
:n-channels nch
:sample-rate sample-rate
:smpl-type (smpl-type s))))
(progn
(om-beep-msg (format nil "Resample failed to resample and returned this error : ~A. Output is the original input." newsize-or-error ))
(setq s2 s))))
(om-free-memory interleaved-in)
(om-free-memory interleaved-out)
s2)
(progn
(om-beep-msg "The sample-rate supplied is invalid. It must be an integer, and the output-sr/input-sr ratio must be inside [1/256, 256] range. Output is the original input.")
s))))
(defmethod* sound-normalize ((s internal-sound) &key (level 0) (method :peak))
:icon 'sound-normalize
:initvals '(nil 0 :peak)
:menuins '((2 (("Peak" :peak)
("RMS" :rms)
("Peak RMS / Hard limiting" :peak-rms))))
:indoc '("a sound" "a normalization level" "a normalization method")
:doc "Normalizes a sound <s>.
<level> is the targetted level of normalized samples. If negative, it is considered as a dB value. Not used with 'Peak RMS' method.
<method> is the normalization method used."
(when (check-valid-sound-buffer s)
(with-audio-buffer (input-buffer s)
(let* ((ptr (oa::om-pointer-ptr input-buffer))
(type (smpl-type s))
(nch (n-channels s))
(size (n-samples s))
(normalize-level (if (plusp level) level (db->lin level)))
(final-buffer (make-audio-buffer nch size type)))
(cond
((equal method :peak)
(let ((peak 0.0)
(x 0.0))
(dotimes (i size)
(dotimes (n nch)
(setq x (abs (fli:dereference (fli:dereference ptr :index n :type :pointer) :index i :type type)))
(if (> x peak) (setf peak x))))
(when (> peak 0)
(let ((gain (/ normalize-level peak)))
(dotimes (i size)
(dotimes (n nch)
(setf (fli:dereference (fli:dereference final-buffer :index n :type :pointer) :index i :type type)
(* gain (fli:dereference (fli:dereference ptr :index n :type :pointer) :index i :type type)))))
))))
((equal method :rms)
(let* ((summed-square-signal
(loop for i from 0 to (1- size) sum
(loop for n from 0 to (1- nch)
sum (fli:dereference (fli:dereference ptr :index n :type :pointer) :index i :type type)
into sample-sum
finally (return (let ((mean-value (/ sample-sum nch)))
(* mean-value mean-value))))))
(gain (sqrt (/ (* size normalize-level normalize-level) summed-square-signal))))
(dotimes (i size)
(dotimes (n nch)
(setf (fli:dereference (fli:dereference final-buffer :index n :type :pointer) :index i :type type)
(* gain (fli:dereference (fli:dereference ptr :index n :type :pointer) :index i :type type)))))
))
((equal method :peak-rms) ;; remove this one? (is this working?)
(let ((peak-rms 0.0)
(tampon (list))
(indx 0)
(rms 0.0)
(tampon-size 100)
(x 0.0))
(loop while (< indx size) do
(dotimes (i tampon-size)
(dotimes (n nch)
(push (fli:dereference (fli:dereference ptr :index n :type :pointer) :index indx :type type) tampon))
(incf indx))
(when tampon
(setq tampon (mapcar #'(lambda (x) (* x x)) tampon))
(setq rms (sqrt (/ (reduce #'+ tampon) tampon-size)))
(if (> rms peak-rms) (setf peak-rms rms))
(setf tampon nil)))
(dotimes (i size)
(dotimes (n nch)
(setq x (/ (fli:dereference (fli:dereference ptr :index n :type :pointer) :index i :type type) peak-rms))
(setf (fli:dereference (fli:dereference final-buffer :index n :type :pointer) :index i :type type)
(cond ((< x -1) -1.0)
((> x 1) 1.0)
(t x)))))
))
(t (om-beep-msg "Error unsupported normalization method: ~A" method)))
(make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr final-buffer :nch nch)
:n-samples size
:n-channels nch
:sample-rate (sample-rate s)
:smpl-type type)
))))
(defmethod* sound-silence ((dur float) &optional (channels 1) sample-rate)
:icon 'sound-silence
:initvals (list 1.0 1 nil)
:indoc '("duration (float or integer)" "number of channels" "sample rate (Hz)")
:doc "Generates a silence of duration = <dur>.
<dur> is considered to be in seconds if a float number is given (e.g. 20.0) or in milliseconds if integer (e.g. 20)\.
<channels> is the number of channel of generated audio sound.
<sample-rate> is the output sample rate in Hz. If NIL, the sample rate is used from the 'Audio' preferences."
(let* ((sr (or sample-rate (get-pref-value :audio :samplerate)))
(nsmpl (round (* dur sr)))
(ch (if (< channels 1) 1 channels)))
(make-instance 'internal-sound
:buffer (make-om-sound-buffer-GC :ptr (make-audio-buffer ch nsmpl :float) :nch ch)
:n-samples nsmpl
:n-channels ch
:sample-rate sr
:smpl-type :float)))
(defmethod* sound-silence ((dur integer) &optional (channels 1) sample-rate)
(let* ((sr (or sample-rate (get-pref-value :audio :samplerate)))
(nsmpl (round (* dur (/ sr 1000.0))))
(ch (if (< channels 1) 1 channels)))
(make-instance 'internal-sound
:buffer (make-om-sound-buffer-GC :ptr (make-audio-buffer ch nsmpl :float) :nch ch)
:n-samples nsmpl
:n-channels ch
:sample-rate sr
:smpl-type :float)))
(defmethod* sound-fade ((s internal-sound) (in float) (out float))
:icon 'sound-fade
:initvals '(nil 0.1 0.1)
:indoc '("a internal-sound" "fade in duration" "fade out duration")
:doc "Generates a fade-in and/or fade-out effect on <s>.
<in> and <out> can be in seconds (floats, e.g. 0.3) or milliseconds (integer, e.g. 300)."
(when (check-valid-sound-buffer s)
(let* ((nch (n-channels s))
(sr (sample-rate s))
(size (n-samples s))
(size2 (* size nch))
(fade-in-frames (round (* in sr nch)))
(fade-in-factor (/ 1.0 fade-in-frames))
(fade-out-frames (round (* out sr nch)))
(fade-out-frames-start (- size2 (round (* out sr nch))))
(fade-out-factor (- (/ 1.0 fade-out-frames)))
(b1 (om-alloc-memory size2 :type (smpl-type s) :clear t))
(b2 (om-alloc-memory size2 :type (smpl-type s) :clear t))
(out-buffer (make-audio-buffer nch size (smpl-type s)))
s2)
(interleave-buffer (oa::om-pointer-ptr (buffer s)) b1 size nch)
(dotimes (i size2)
(setf (fli:dereference b2 :index i)
(cond ((< i fade-in-frames)
(* fade-in-factor i (fli:dereference b1 :index i)))
((> i fade-out-frames-start)
(* (1+ (* fade-out-factor (- i (- size2 fade-out-frames)))) (fli:dereference b1 :index i)))
(t (fli:dereference b1 :index i)))))
(setq s2 (make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr (split-buffer b2 out-buffer size nch) :nch nch)
:n-samples size
:n-channels nch
:sample-rate sr
:smpl-type (smpl-type s)))
(om-free-memory b2)
(om-free-memory b1)
s2)))
(defmethod* sound-fade ((s internal-sound) (in integer) (out integer))
(sound-fade s (ms->sec in) (ms->sec out)))
(defmethod* sound-loop ((s internal-sound) n)
:icon 'sound-loop
:initvals '(nil 3)
:indoc '("a sound" "a number")
:doc "Generates a <n>-times repetition of <s>."
(when (check-valid-sound-buffer s)
(let* ((nch (n-channels s))
(size (n-samples s))
(final-buffer (make-audio-buffer nch (* n size) (smpl-type s))))
(dotimes (i (* n size))
(dotimes (n nch)
(setf (fli:dereference (fli:dereference final-buffer :index n :type :pointer) :index i :type (smpl-type s))
(fli:dereference (fli:dereference (oa::om-pointer-ptr (buffer s)) :index n :type :pointer) :index (mod i size) :type :float))))
(make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr final-buffer :nch nch)
:n-samples (* n size)
:n-channels nch
:sample-rate (sample-rate s)
:smpl-type (smpl-type s)))))
(defmethod* sound-cut ((s internal-sound) (beg float) (end float))
:icon 'sound-cut
:initvals '(nil 0.0 1.0)
:indoc '("a sound" "begin time" "end time")
:doc "Cuts and returns an extract between <beg> and <end> in <s>.
<beg> and <end> can be in seconds (floats, e.g. 0.3) or milliseconds (integer, e.g. 300)."
(when (check-valid-sound-buffer s)
(let* ((init-buffer (oa::om-pointer-ptr (buffer s)))
(type (smpl-type s))
(nch (n-channels s))
(sr (sample-rate s))
(size (round (* (- end beg) sr)))
(start (round (* beg sr)))
(final-buffer (make-audio-buffer nch size type)))
(dotimes (i size)
(dotimes (n nch)
(setf (fli:dereference (fli:dereference final-buffer :index n :type :pointer) :index i :type type)
(fli:dereference (fli:dereference init-buffer :index n :type :pointer) :index (+ start i) :type type))))
(make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr final-buffer :nch nch)
:n-samples size
:n-channels nch
:sample-rate sr
:smpl-type type))))
(defmethod* sound-cut ((s internal-sound) (beg integer) (end integer))
(sound-cut s (ms->sec beg) (ms->sec end)))
(defmethod* sound-gain ((s internal-sound) gain &optional (in 1) (out 1))
:icon 'sound-normalize
:initvals '(nil 1.0 1 1)
:indoc '("a sound" "a gain value" "fade in duration" "fade out duration")
:doc "Adds gain effect (volume) on <s>.
<gain> is a multiplicative factor to the sound sample values.
<in> and <out> determine fade-in / fade-out periods for the gain effect.
They can be in seconds (floats, e.g. 0.3) or milliseconds (integer, e.g. 300)."
(when (check-valid-sound-buffer s)
(let* ((ptr (oa::om-pointer-ptr (buffer s)))
(nch (n-channels s))
(sr (sample-rate s))
(size (n-samples s))
(type (smpl-type s))
(in (if (integerp in) (* in 0.001) in))
(out (if (integerp out) (* out 0.001) out))
(fade-in-frames (round (* in sr)))
(fade-in-factor (/ (1- gain) fade-in-frames))
(fade-out-frames (round (* out sr)))
(fade-out-factor (/ (- 1 gain) fade-out-frames))
(fade-out-frame-start (- size fade-out-frames))
(final-buffer (make-audio-buffer nch size type)))
(dotimes (i size)
(dotimes (n nch)
(setf (fli:dereference (fli:dereference final-buffer :index n :type :pointer) :index i :type type)
(* (cond ((< i fade-in-frames) (1+ (* fade-in-factor i)))
((>= i fade-out-frame-start) (+ gain (* fade-out-factor (- i (- size fade-out-frames)))))
(t gain))
(fli:dereference (fli:dereference ptr :index n :type :pointer) :index i :type type)))))
(make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr final-buffer :nch nch)
:n-samples size
:n-channels nch
:sample-rate sr
:smpl-type type))))
; compatibility
(defmethod sound-vol ((s internal-sound) gain &optional (in 1) (out 1))
(sound-gain s gain in out))
(defmethod* sound-mono-to-stereo ((s internal-sound) &optional (pan 0))
:icon 'sound-mono-to-stereo
:initvals '(nil 0)
:indoc '("a sound" "a panoramic value between -100 and 100")
:doc "Convers a mono sound to stereo (with possible pan).
<pan> is a panoramic value between -100 (Left channel) and 100 (Right channel)."
(when (check-valid-sound-buffer s)
(if (= (n-channels s) 1)
(let* ((ptr (oa::om-pointer-ptr (buffer s)))
(type (smpl-type s))
(size (n-samples s))
(nch (n-channels s))
(final-buffer (make-audio-buffer 2 size type))
(pan (/ pan 100.0))
(Lgain (if (<= pan 0) 1 (- 1 pan)))
(Rgain (if (>= pan 0) 1 (+ 1 pan)))
(x 0.0))
(dotimes (i size)
(setf x (fli:dereference (fli:dereference ptr :index 0 :type :pointer) :index i :type type))
(setf (fli:dereference (fli:dereference final-buffer :index 0 :type :pointer) :type type :index i) (* Lgain x)
(fli:dereference (fli:dereference final-buffer :index 1 :type :pointer) :type type :index i) (* Rgain x)))
(make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr final-buffer :nch nch)
:n-samples size
:n-channels 2
:sample-rate (sample-rate s)
:smpl-type type))
(progn
(om-beep-msg
(format nil "Error: sound-mono-to-stereo requires mono sound input (numchannels=~D). Output is the original input."
(n-channels s)))
s))
))
(defmethod* sound-to-mono ((s internal-sound))
:icon 'sound-to-mono
:initvals '(nil)
:indoc '("a sound")
:doc "Merges all channels of <s> into a single-channel (mono) a sound."
(when (check-valid-sound-buffer s)
(let* ((ptr (oa::om-pointer-ptr (buffer s)))
(type (smpl-type s))
(final-buffer (make-audio-buffer 1 (n-samples s) type))
(nch (n-channels s)))
(dotimes (i (n-samples s))
(setf (fli:dereference (fli:dereference final-buffer :index 0 :type :pointer) :index i :type type)
(/ (loop for c from 0 to (1- nch)
sum (fli:dereference (fli:dereference ptr :index c :type :pointer) :index i :type type))
(float nch))
))
(make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr final-buffer :nch 1)
:n-samples (n-samples s)
:n-channels 1
:sample-rate (sample-rate s)
:smpl-type type))
))
(defmethod* sound-stereo-pan ((s internal-sound) left right)
:icon 'sound-stereo-pan
:initvals '(nil -100 100)
:indoc '("a sound" "a left channel pan value" "a right channel pan value")
:doc "Pan a stereo sound.
<left> is a panoramic value for the left channel between -100 (full left) and 100 (full right).
<right> is a panoramic value for the right channel between -100 (full left) and 100 (full right)."
(when (check-valid-sound-buffer s)
(if (= (n-channels s) 2)
(let* ((ptr (oa::om-pointer-ptr (buffer s)))
(type (smpl-type s))
(nch (n-channels s))
(size (n-samples s))
(left (cond ((< left -100) 100) ((> left 100) -100) (t (- left))))
(right (cond ((< right -100) -100) ((> right 100) 100) (t right)))
(leftRgain (- 0.5 (* (/ 1.0 200) left)))
(leftLgain (+ 0.5 (* (/ 1.0 200) left)))
(rightRgain (+ 0.5 (* (/ 1.0 200) right)))
(rightLgain (- 0.5 (* (/ 1.0 200) right)))
(xl 0.0) (xr 0.0)
(final-buffer (make-audio-buffer nch size type)))
(dotimes (i size)
(setf xl (fli:dereference (fli:dereference ptr :index 0 :type :pointer) :index i :type type)
xr (fli:dereference (fli:dereference ptr :index 1 :type :pointer) :index i :type type))
(setf (fli:dereference (fli:dereference final-buffer :index 0 :type :pointer) :index i :type type) (+ (* leftLgain xl) (* rightLgain xr))
(fli:dereference (fli:dereference final-buffer :index 1 :type :pointer) :index i :type type) (+ (* leftRgain xl) (* rightRgain xr))))
(make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr final-buffer :nch nch)
:n-samples size
:n-channels nch
:sample-rate (sample-rate s)
:smpl-type type))
(progn
(om-beep-msg "Error: Trying to pan a sound with ~A channels. Needs 2. Output is the original input." (n-channels s))
s))
))
(defmethod* sound-mix ((s1 internal-sound) (s2 internal-sound) &key (s1-offset 0) (s2-offset 0) (method 0))
:icon 'sound-mix
:initvals '(nil nil 0)
:menuins '((4 (("Sum" 0)
("Sum / Average" 1)
("Sum / Hard Limiting" 2))))
:indoc '("an internal-sound" "an internal-sound" "a mixing method")
:doc "Generates a mix of <s1> and <s2>.
<s1-offset> and <s2-offset> are temporal offsets in seconds (float) or milliseconds (int)."
(when (and (check-valid-sound-buffer s1)
(check-valid-sound-buffer s2))
(if (and (= (n-channels s1) (n-channels s2))
(= (sample-rate s1) (sample-rate s2)))
(let* ((ptr1 (oa::om-pointer-ptr (buffer s1)))
(type1 (smpl-type s1))
(ptr2 (oa::om-pointer-ptr (buffer s2)))
(type2 (smpl-type s2))
(nch (n-channels s1))
(size1 (n-samples s1))
(size2 (n-samples s2))
(offset1 (round (* (if (integerp s1-offset) (* s1-offset 0.001) s1-offset) (sample-rate s1))))
(offset2 (round (* (if (integerp s2-offset) (* s2-offset 0.001) s2-offset) (sample-rate s2))))
(final-size (max (+ size1 offset1) (+ size2 offset2)))
(final-buffer (make-audio-buffer nch final-size type1))
(res 0.0))
(cond ((= method 0)
(dotimes (i final-size)
(dotimes (n nch)
(setf (fli:dereference (fli:dereference final-buffer :index n :type :pointer) :index i :type type1)
(+ (if (< i offset1) 0.0
(if (< i (+ offset1 size1))
(fli:dereference (fli:dereference ptr1 :index n :type :pointer) :index (- i offset1) :type type1)
0.0))
(if (< i offset2) 0.0
(if (< i (+ offset2 size2))
(fli:dereference (fli:dereference ptr2 :index n :type :pointer) :index (- i offset2) :type type2)
0.0))
))
)))
((= method 1)
(dotimes (i final-size)
(dotimes (n nch)
(setf (fli:dereference (fli:dereference final-buffer :index n :type :pointer) :index i :type type1)
(/
(+ (if (< i offset1) 0.0
(if (< i (+ offset1 size1))
(fli:dereference (fli:dereference ptr1 :index n :type :pointer) :index (- i offset1) :type type1)
0.0))
(if (< i offset2) 0.0
(if (< i (+ offset2 size2))
(fli:dereference (fli:dereference ptr2 :index n :type :pointer) :index (- i offset2) :type type2)
0.0))
)
2)))))
((= method 2)
(dotimes (i final-size)
(dotimes (n nch)
(setf res
(+ (if (< i offset1) 0.0
(if (< i (+ offset1 size1))
(fli:dereference (fli:dereference ptr1 :index n :type :pointer) :index (- i offset1) :type type1)
0.0))
(if (< i offset2) 0.0
(if (< i (+ offset2 size2))
(fli:dereference (fli:dereference ptr2 :index n :type :pointer) :index (- i offset2) :type type2)
0.0))
))
(setf (fli:dereference (fli:dereference final-buffer :index n :type :pointer) :index i :type type1)
(cond ((< res -1) -1.0)
((> res 1) 1.0)
(t res)))))))
(make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr final-buffer :nch nch)
:n-samples final-size
:n-channels nch
:sample-rate (sample-rate s1)
:smpl-type type1))
(progn
(om-beep-msg "Error: Trying to mix sounds with different number of channels or different sample rate. Output is the input 1.")
s1))))
(defmethod* sound-merge ((sound-list list))
:icon 'sound-mix
:initvals '(nil)
:indoc '("a list of sounds")
:doc "Merges the sounds in <sound-list> into a single multi-channel sound."
(when (not (member nil (mapcar #'check-valid-sound-buffer sound-list)))
(let* ((sounds (mapcar 'get-sound sound-list))
(type (smpl-type (car sounds)))
(sr (sample-rate (car sounds)))
;;; actually we should check if all sounds have same type and sample-rate
(n-samples-out (apply 'max (mapcar 'n-samples sounds)))
(n-channels-out (apply '+ (mapcar 'n-channels sounds)))
(final-buffer (make-audio-buffer n-channels-out n-samples-out type))
(c 0))
(loop for snd in sounds do
(with-audio-buffer (b snd)
(dotimes (srcchan (n-channels snd))
(let ((bptr (oa::om-pointer-ptr b)))
(dotimes (i (n-samples snd))
;(print (list b c srcchan i))
(setf (fli:dereference (fli:dereference final-buffer :index c :type :pointer) :type type :index i)
(fli:dereference (fli:dereference bptr :index srcchan :type :pointer) :type type :index i)))
(setf c (1+ c))))
))
(make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr final-buffer :nch n-channels-out)
:n-samples n-samples-out
:n-channels n-channels-out
:sample-rate sr
:smpl-type type)
)))
(defmethod* sound-split ((s internal-sound))
:icon 'sound-mix
:initvals '(nil)
:indoc '("a (multichannel) sounds")
:doc "Outputs a list of mono sounds from the channels of <s>."
(when (check-valid-sound-buffer s)
(let ((type (smpl-type s)))
(with-audio-buffer (b s)
(let ((bptr (oa::om-pointer-ptr b)))
(loop for c from 0 to (1- (n-channels s)) collect
(let ((new-buffer (make-audio-buffer 1 (n-samples s) type)))
(dotimes (i (n-samples snd))
(setf (fli:dereference (fli:dereference new-buffer :index 0 :type :pointer) :type type :index i)
(fli:dereference (fli:dereference bptr :index c :type :pointer) :type type :index i)))
(make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr new-buffer :nch 1)
:n-samples (n-samples s)
:n-channels 1
:sample-rate (sample-rate s)
:smpl-type type)
)))
))))
(defmethod* sound-seq ((s1 internal-sound) (s2 internal-sound) &optional (crossfade 0))
:icon 'sound-seq
:initvals '(nil nil 0)
:indoc '("a sound" "a sound" "cross-fading duration (ms)")
:doc "Concatenates <s1> and <s2>.
<crossfade> (duration in seconds/flots or milliseconds/int) determines a fade-in/fade out overlapping between the sounds."
(when (and (check-valid-sound-buffer s1)
(check-valid-sound-buffer s2))
(if (and (= (n-channels s1) (n-channels s2))
(= (sample-rate s1) (sample-rate s2)))
(let* ((ptr1 (oa::om-pointer-ptr (buffer s1)))
(type1 (smpl-type s1))
(ptr2 (oa::om-pointer-ptr (buffer s2)))
(type2 (smpl-type s2))
(nch (n-channels s1))
(sr (sample-rate s1))
(size1 (n-samples s1))
(size2 (n-samples s2))
(cf (if (integerp crossfade) (* crossfade 0.001) crossfade))
(smp-cross (round (* cf sr)))
(factor1 (- (/ 1.0 (max 1 smp-cross))))
(factor2 (/ 1.0 (max 1 smp-cross)))
(final-size (- (+ size1 size2) smp-cross))
(final-buffer (make-audio-buffer nch final-size type1)))
(dotimes (i final-size)
(dotimes (n nch)
(setf (fli:dereference (fli:dereference final-buffer :index n :type :pointer) :index i :type type1)
(cond ((< i (- size1 smp-cross))
(fli:dereference (fli:dereference ptr1 :index n :type :pointer) :index i :type type1))
((and (>= i (- size1 smp-cross)) (< i size1))
(+ (* (1+ (* factor1 (- i (- size1 smp-cross))))
(fli:dereference (fli:dereference ptr1 :index n :type :pointer) :index i :type type1))
(* factor2 (- i (- size1 smp-cross))
(fli:dereference (fli:dereference ptr2 :index n :type :pointer) :index (+ smp-cross (- i size1)) :type type2))))
((>= i size1)
(fli:dereference (fli:dereference ptr2 :index n :type :pointer) :index (+ smp-cross (- i size1)) :type type2))))))
(make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr final-buffer :nch nch)
:n-samples final-size
:n-channels nch
:sample-rate (sample-rate s1)
:smpl-type type1))
(progn
(om-beep-msg "Error: Trying to sequence incompatible audio buffers: s1: ~Dch - sr=~DHz / s2: ~Dch - sr=~DHz. Output is input 1."
(n-channels s1) (sample-rate s1) (n-channels s2) (sample-rate s2))
s1))))
(defmethod* sound-reverse ((s internal-sound))
:icon 'sound-reverse
:indoc '("a sound")
:doc "Reverses the sound."
(when (check-valid-sound-buffer s)
(let* ((ptr (oa::om-pointer-ptr (buffer s)))
(type (smpl-type s))
(nch (n-channels s))
(size (n-samples s))
(final-buffer (make-audio-buffer nch size type)))
(dotimes (i size)
(dotimes (n nch)
(setf (fli:dereference (fli:dereference final-buffer :index n :type :pointer) :index i :type type)
(fli:dereference (fli:dereference ptr :index n :type :pointer) :index (- size i) :type type))))
(make-instance 'sound
:buffer (make-om-sound-buffer-GC :ptr final-buffer :nch nch)
:n-samples size
:n-channels nch
:sample-rate (sample-rate s)
:smpl-type type))
))
| 31,494 | Common Lisp | .lisp | 590 | 39.094915 | 181 | 0.514897 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 74f63c1f6415695f8a07fdc0a06a0e3d6ba97712790430fd1f38026f57552439 | 854 | [
-1
] |
855 | file-access.lisp | cac-t-u-s_om-sharp/src/packages/sound/audio-api/file-access.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
;;==================================
;;; AUDIO FILE ACCESS TOOLS (R/W)
;;==================================
(in-package :cl-user)
;;; genertal package for low-level audio features
(defpackage :audio-io
(:use cl-user common-lisp))
(in-package :audio-io)
(export '(
om-get-sound-info
om-get-audio-buffer
om-free-audio-buffer
om-save-buffer-in-file
) :audio-io)
;;==================================
;;; FILE I/O
;;==================================
;;;Convert path
(defun convert-filename-encoding (path) (namestring path))
; doesn't work ? when is it used ?
; #+cocoa (external-format::decode-external-string (external-format::encode-lisp-string (namestring path) :utf-8) :latin-1)
; #-cocoa (namestring path))
; RETURNS: format n-channels sample-rate sample-size size
(defun om-get-sound-info (path)
(juce::juce-get-sound-info (convert-filename-encoding path)))
; RETURNS: buffer format n-channels sample-rate sample-size size skip
(defun om-get-audio-buffer (path &optional (type :float) (interleaved nil))
(juce::juce-get-sound-buffer (convert-filename-encoding path) type))
(defun om-free-audio-buffer (buffer nch)
(when nch (dotimes (c nch) (fli::free-foreign-object (fli:dereference buffer :type :pointer :index c))))
(fli::free-foreign-object buffer))
;;; audio buffer NOT interleaved
(defun om-save-buffer-in-file (buffer filename size nch sr resolution format)
(juce::juce-save-sound-in-file buffer filename size nch sr resolution format))
#|
;;; USE LIBSNDFILE API
;;; interleave-util code
;(itl-buffer
; (if (> nch 1)
; (fli:allocate-foreign-object :type :float :nelems (* nsmp nch))
; (cffi::mem-aref (oa::om-pointer-ptr (buffer sound)) :pointer 0)))
;(when (> nch 1)
; (interleave-buffer (oa::om-pointer-ptr (buffer sound)) itl-buffer nsmp nch))
;(when (> nch 1) (om-free-memory itl-buffer))
;;; Acquire sound infos
(defun om-get-sound-info (path)
;; RETURNS format n-channels sample-rate sample-size size skip
(sf::sndfile-get-sound-info (convert-filename-encoding path))
)
;; RETURNS buffer format n-channels sample-rate sample-size size skip
(defun om-get-sound-buffer (path &optional (type :float) (interleaved nil))
(when (probe-file path)
(if interleaved
(sf::sndfile-get-sound-buffer (convert-filename-encoding path) type)
(multiple-value-bind (buffer format n-channels sample-rate sample-size size skip)
(sf::sndfile-get-sound-buffer (convert-filename-encoding path) type)
(if (= 1 n-channels)
(let ((buffer2 (fli::allocate-foreign-object :type :pointer)))
(setf (fli:dereference buffer2) buffer)
(values buffer2 format n-channels sample-rate sample-size size skip))
(unwind-protect
(let ((buffer2 (fli::allocate-foreign-object
:type :pointer :nelems n-channels
:initial-contents (loop for c from 0 to (1- n-channels) collect
(fli::allocate-foreign-object
:type type
:nelems size)))))
(dotimes (i size)
(dotimes (c n-channels)
;;; apparently FLI:DEREFERENCE iS MUCH FASTER THAN CFFI:MEM-AREF
(setf (fli:dereference (fli:dereference buffer2 :type :pointer :index c) :type type :index i)
(fli:dereference buffer :type type :index (+ c (* n-channels i))))
;(setf (cffi::mem-aref (cffi::mem-aref buffer2 :pointer c) type i)
; (cffi::mem-aref buffer type (+ c (* n-channels i))))
))
(values buffer2 format n-channels sample-rate sample-size size skip))
(cffi::foreign-free buffer)))))))
(defun om-save-buffer-in-file (buffer filename size nch sr resolution format)
(let ((interleaved (fli:allocate-foreign-object :type :float :nelems (* (n-samples self) (n-channels self)) :fill 0)))
(dotimes (smp size)
(dotimes (ch nch)
(setf (cffi::mem-aref interleaved :float (+ (* smp channels) ch))
(cffi::mem-aref (cffi::mem-aref buffer :pointer ch) :float smp))))
(unwind-protect
(sf::sndfile-save-sound-in-file buffer filename size nch sr resolution format)
(fli::free-foreign-object interleaved))
))
|#
| 5,236 | Common Lisp | .lisp | 102 | 43.754902 | 124 | 0.587659 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 1057be27161d340077ae5f2f92f1fa8cde90e630ea3b7a033e8f7d2573ad5d66 | 855 | [
-1
] |
856 | load-audio-api.lisp | cac-t-u-s_om-sharp/src/packages/sound/audio-api/load-audio-api.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
;;===========================================================================
; AUDIO API
;;===========================================================================
(in-package :cl-user)
(compile&load (decode-local-path "libsamplerate/libsamplerate"))
(compile&load (decode-local-path "omaudiolib/omaudiolib"))
(compile&load (decode-local-path "file-access"))
(push :audio *features*)
(defun load-audio-libs ()
(om-fi::om-load-foreign-library
"omaudiolib"
`((:macosx ,(om-fi::om-foreign-library-pathname "omaudiolib.dylib"))
(:windows ,(om-fi::om-foreign-library-pathname "omaudiolib.dll"))
(:linux ,(om-fi::om-foreign-library-pathname "omaudiolib.so"))))
; (om-fi::om-load-foreign-library
; "LIBSNDFILE"
; `((:macosx ,(om-fi::om-foreign-library-pathname "libsndfile.dylib"))
; (:unix (:default "libsndfile"))
; (:windows (:or ,(om-fi::om-foreign-library-pathname "libsndfile-1.dll")
; (:default "libsndfile-1")))
; (t (:default "libsndfile"))))
(om-fi::om-load-foreign-library
"libsamplerate"
`((:macosx ,(om-fi::om-foreign-library-pathname "libsamplerate.dylib"))
(:unix (:default "libsamplerate"))
(:windows (:or ,(om-fi::om-foreign-library-pathname "libsamplerate-0.dll")
(:default "libsamplerate")))
(t (:default "libsamplerate"))))
)
(om-fi::add-foreign-loader 'load-audio-libs)
| 2,134 | Common Lisp | .lisp | 44 | 45.840909 | 79 | 0.542389 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 01264867b13274d3a5aa6cf3858ec082bcdf65fddc89bebb8eb015bf93924174 | 856 | [
-1
] |
857 | libsndfile-api.lisp | cac-t-u-s_om-sharp/src/packages/sound/audio-api/libsndfile/libsndfile-api.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
(in-package :sf)
(defconstant formatAiff 0)
(defconstant formatWave 1)
(defconstant formatAifc 2)
(defconstant formatWAVint 0)
(defconstant formatWAVfloat 1)
(defconstant formatAIFFint 2)
(defconstant formatAIFFfloat 3)
(defun decode-format (sndfile-format)
(let* ((format_list (map 'list #'digit-char-p (prin1-to-string (write-to-string sndfile-format :base 16))))
(ff (cond ((or (null (cadr format_list)) (null (cadddr (cddr format_list)))) nil)
((and (= 1 (cadr format_list)) (< (cadddr (cddr format_list)) 6)) 0)
((and (= 1 (cadr format_list)) (>= (cadddr (cddr format_list)) 6)) 1)
((and (= 2 (cadr format_list)) (< (cadddr (cddr format_list)) 6)) 2)
((and (= 2 (cadr format_list)) (>= (cadddr (cddr format_list)) 6)) 3)
(t 0)))
(ss (cond ((null (cadddr (cddr format_list))) nil)
((= 1 (cadddr (cddr format_list))) 8)
((= 2 (cadddr (cddr format_list))) 16)
((= 3 (cadddr (cddr format_list))) 24)
((= 4 (cadddr (cddr format_list))) 32)
((= 5 (cadddr (cddr format_list))) 8)
((= 6 (cadddr (cddr format_list))) 32)
(t 0)))
(name (case ff
(0 "Wav(int)")
(1 "Wav(float)")
(2 "AIFF(int)")
(3 "AIFF(float)")
(otherwise "Unknown")
)))
(values ff ss name)))
;(cadddr (cddr (map 'list #'digit-char-p (prin1-to-string (write-to-string SF_FORMAT_WAV :base 16)))))
;(write-to-string 255 :base 16)
;(logior (ash sf::sf_format_aiff 1) (ash b 8) c)
;;; READ
(defun sndfile-get-sound-info (path)
"Returns info about the soudn file (not the actual data)."
(cffi:with-foreign-object (sfinfo '(:struct |libsndfile|::sf_info))
(setf (cffi:foreign-slot-value sfinfo '(:struct |libsndfile|::sf_info) 'sf::format) 0) ; Initialize the slots
(let* ((sndfile-handle (sf::sf_open path sf::SFM_READ sfinfo))
(size-ptr (cffi:foreign-slot-pointer sfinfo '(:struct |libsndfile|::sf_info) 'sf::frames))
(size (fli::dereference size-ptr :type :int :index #+powerpc 1 #-powerpc 0))
(channels-ptr (cffi:foreign-slot-pointer sfinfo '(:struct |libsndfile|::sf_info) 'sf::channels))
(channels (fli::dereference channels-ptr :type :int :index #+powerpc 1 #-powerpc 0))
(sr-ptr (cffi:foreign-slot-pointer sfinfo '(:struct |libsndfile|::sf_info) 'sf::samplerate))
(sr (fli::dereference sr-ptr :type :int :index #+powerpc 1 #-powerpc 0))
(format-ptr (cffi:foreign-slot-pointer sfinfo '(:struct |libsndfile|::sf_info) 'sf::format))
(format (fli::dereference format-ptr :type :int :index #+powerpc 1 #-powerpc 0))
(skip (cffi:foreign-slot-value sfinfo '(:struct |libsndfile|::sf_info) 'sf::seekable)))
(multiple-value-bind (ff ss nn)
(decode-format format)
;;;Detection format and Sample size : cf http://www.mega-nerd.com/libsndfile/api.html#open
(sf::sf_close sndfile-handle) ; should return 0 on successful closure.
(values nn channels sr ss size skip)))))
(defun sndfile-get-sound-buffer (path &optional (datatype :float))
"Returns a sound data buffer + info. The soudn buffer must be freed."
(cffi:with-foreign-object (sfinfo '(:struct |libsndfile|::sf_info))
(setf (cffi:foreign-slot-value sfinfo '(:struct |libsndfile|::sf_info) 'sf::format) 0) ; Initialize the slots
(let* ((sndfile-handle (sf::sf_open path sf::SFM_READ sfinfo))
(size-ptr (cffi:foreign-slot-pointer sfinfo '(:struct |libsndfile|::sf_info) 'sf::frames))
(size (fli::dereference size-ptr :type :int :index #+powerpc 1 #-powerpc 0))
(channels-ptr (cffi:foreign-slot-pointer sfinfo '(:struct |libsndfile|::sf_info) 'sf::channels))
(channels (fli::dereference channels-ptr :type :int :index #+powerpc 1 #-powerpc 0))
(sr-ptr (cffi:foreign-slot-pointer sfinfo '(:struct |libsndfile|::sf_info) 'sf::samplerate))
(sr (fli::dereference sr-ptr :type :int :index #+powerpc 1 #-powerpc 0))
(format-ptr (cffi:foreign-slot-pointer sfinfo '(:struct |libsndfile|::sf_info) 'sf::format))
(format (fli::dereference format-ptr :type :int :index #+powerpc 1 #-powerpc 0))
(skip (cffi:foreign-slot-value sfinfo '(:struct |libsndfile|::sf_info) 'sf::seekable))
(buffer-size (* size channels))
(buffer (fli:allocate-foreign-object :type datatype :nelems buffer-size :fill 0))
(frames-read
(ignore-errors
(case datatype
(:double (sf::sf-readf-double sndfile-handle buffer buffer-size))
(:float (sf::sf-readf-float sndfile-handle buffer buffer-size))
(:int (sf::sf-readf-int sndfile-handle buffer buffer-size))
(:short (sf::sf-readf-short sndfile-handle buffer buffer-size))
(otherwise (print (concatenate 'string "Warning: unsupported datatype for reading audio data: " (string datatype))))))))
(multiple-value-bind (ff ss nn)
(decode-format format)
(sf::sf_close sndfile-handle) ; should return 0 on successful closure.
(values buffer nn channels sr ss size skip)))))
;; WRITE
(defun sndfile-save-sound-in-file (buffer filename size nch sr resolution format &optional (datatype :float))
(let* ((res (case resolution
(8 sf::sf_format_pcm_s8)
(16 sf::sf_format_pcm_16)
(24 sf::sf_format_pcm_24)
(32 sf::sf_format_pcm_32)
(otherwise sf::sf_format_pcm_16)))
(format (logior (case format
(:aiff sf::sf_format_aiff)
(:wav sf::sf_format_wav)
(:ogg sf::sf_format_ogg)
(:flac sf::sf_format_flac)
(otherwise sf::sf_format_aiff))
res)))
(cffi:with-foreign-object (sfinfo '(:struct |libsndfile|::sf_info))
(setf (cffi:foreign-slot-value sfinfo '(:struct |libsndfile|::sf_info) 'sf::samplerate) sr)
(setf (cffi:foreign-slot-value sfinfo '(:struct |libsndfile|::sf_info) 'sf::channels) nch)
(setf (cffi:foreign-slot-value sfinfo '(:struct |libsndfile|::sf_info) 'sf::format) format)
(let ((sndfile-handle-out (sf::sf_open filename sf::SFM_WRITE sfinfo)))
;(datatype (fli::pointer-element-type buffer)) ;; not reliable all the time :(
(if (cffi::null-pointer-p sndfile-handle-out)
(print (format nil "error initializing pointer to write ~A. Probably no write access in ~A."
filename (make-pathname :directory (or (pathname-directory filename) '(:absolute)))))
(case datatype
(:float (sf::sf-write-float sndfile-handle-out buffer (* nch size)))
(:int (sf::sf-write-int sndfile-handle-out buffer (* nch size)))
(:short (sf::sf-write-short sndfile-handle-out buffer (* nch size)))
(otherwise (print (concatenate 'string "Warning: unsupported datatype for writing audio data: " (string datatype)))))
)
(sf::sf_close sndfile-handle-out)
)))
(probe-file filename))
| 8,133 | Common Lisp | .lisp | 130 | 52.061538 | 136 | 0.5835 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 1675afa4e52682e33ceb937e0a67f1b9adb3d483f9b6227f1d7a0609b4f717fa | 857 | [
-1
] |
858 | libsndfile.lisp | cac-t-u-s_om-sharp/src/packages/sound/audio-api/libsndfile/libsndfile.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
(in-package :cl-user)
(defpackage "libsndfile"
(:nicknames "SF")
(:use common-lisp cffi))
(in-package :sf)
(pushnew :libsndfile *features*)
;(defctype :long-long :pointer)
(defconstant SF_FORMAT_WAV #x010000)
(defconstant SF_FORMAT_AIFF #x020000)
(defconstant SF_FORMAT_AU #x030000)
(defconstant SF_FORMAT_RAW #x040000)
(defconstant SF_FORMAT_PAF #x050000)
(defconstant SF_FORMAT_SVX #x060000)
(defconstant SF_FORMAT_NIST #x070000)
(defconstant SF_FORMAT_VOC #x080000)
(defconstant SF_FORMAT_IRCAM #x0A0000)
(defconstant SF_FORMAT_W64 #x0B0000)
(defconstant SF_FORMAT_MAT4 #x0C0000)
(defconstant SF_FORMAT_MAT5 #x0D0000)
(defconstant SF_FORMAT_PVF #x0E0000)
(defconstant SF_FORMAT_XI #x0F0000)
(defconstant SF_FORMAT_HTK #x100000)
(defconstant SF_FORMAT_SDS #x110000)
(defconstant SF_FORMAT_AVR #x120000)
(defconstant SF_FORMAT_WAVEX #x130000)
(defconstant SF_FORMAT_SD2 #x160000)
(defconstant SF_FORMAT_FLAC #x170000)
(defconstant SF_FORMAT_CAF #x180000)
(defconstant SF_FORMAT_OGG #x200000)
(defconstant SF_FORMAT_PCM_S8 #x0001)
(defconstant SF_FORMAT_PCM_16 #x0002)
(defconstant SF_FORMAT_PCM_24 #x0003)
(defconstant SF_FORMAT_PCM_32 #x0004)
(defconstant SF_FORMAT_PCM_U8 #x0005)
(defconstant SF_FORMAT_FLOAT #x0006)
(defconstant SF_FORMAT_DOUBLE #x0007)
(defconstant SF_FORMAT_ULAW #x0010)
(defconstant SF_FORMAT_ALAW #x0011)
(defconstant SF_FORMAT_IMA_ADPCM #x0012)
(defconstant SF_FORMAT_MS_ADPCM #x0013)
(defconstant SF_FORMAT_GSM610 #x0020)
(defconstant SF_FORMAT_VOX_ADPCM #x0021)
(defconstant SF_FORMAT_G721_32 #x0030)
(defconstant SF_FORMAT_G723_24 #x0031)
(defconstant SF_FORMAT_G723_40 #x0032)
(defconstant SF_FORMAT_DWVW_12 #x0040)
(defconstant SF_FORMAT_DWVW_16 #x0041)
(defconstant SF_FORMAT_DWVW_24 #x0042)
(defconstant SF_FORMAT_DWVW_N #x0043)
(defconstant SF_FORMAT_DPCM_8 #x0050)
(defconstant SF_FORMAT_DPCM_16 #x0051)
(defconstant SF_FORMAT_VORBIS #x0060)
(defconstant SF_ENDIAN_FILE #x00000000)
(defconstant SF_ENDIAN_LITTLE #x10000000)
(defconstant SF_ENDIAN_BIG #x20000000)
(defconstant SF_ENDIAN_CPU #x30000000)
(defconstant SF_FORMAT_SUBMASK #x0000FFFF)
(defconstant SF_FORMAT_TYPEMASK #x0FFF0000)
(defconstant SF_FORMAT_ENDMASK #x30000000)
(defconstant SFC_GET_LIB_VERSION #x1000)
(defconstant SFC_GET_LOG_INFO #x1001)
(defconstant SFC_GET_NORM_DOUBLE #x1010)
(defconstant SFC_GET_NORM_FLOAT #x1011)
(defconstant SFC_SET_NORM_DOUBLE #x1012)
(defconstant SFC_SET_NORM_FLOAT #x1013)
(defconstant SFC_SET_SCALE_FLOAT_INT_READ #x1014)
(defconstant SFC_GET_SIMPLE_FORMAT_COUNT #x1020)
(defconstant SFC_GET_SIMPLE_FORMAT #x1021)
(defconstant SFC_GET_FORMAT_INFO #x1028)
(defconstant SFC_GET_FORMAT_MAJOR_COUNT #x1030)
(defconstant SFC_GET_FORMAT_MAJOR #x1031)
(defconstant SFC_GET_FORMAT_SUBTYPE_COUNT #x1032)
(defconstant SFC_GET_FORMAT_SUBTYPE #x1033)
(defconstant SFC_CALC_SIGNAL_MAX #x1040)
(defconstant SFC_CALC_NORM_SIGNAL_MAX #x1041)
(defconstant SFC_CALC_MAX_ALL_CHANNELS #x1042)
(defconstant SFC_CALC_NORM_MAX_ALL_CHANNELS #x1043)
(defconstant SFC_GET_SIGNAL_MAX #x1044)
(defconstant SFC_GET_MAX_ALL_CHANNELS #x1045)
(defconstant SFC_SET_ADD_PEAK_CHUNK #x1050)
(defconstant SFC_UPDATE_HEADER_NOW #x1060)
(defconstant SFC_SET_UPDATE_HEADER_AUTO #x1061)
(defconstant SFC_FILE_TRUNCATE #x1080)
(defconstant SFC_SET_RAW_START_OFFSET #x1090)
(defconstant SFC_SET_DITHER_ON_WRITE #x10A0)
(defconstant SFC_SET_DITHER_ON_READ #x10A1)
(defconstant SFC_GET_DITHER_INFO_COUNT #x10A2)
(defconstant SFC_GET_DITHER_INFO #x10A3)
(defconstant SFC_GET_EMBED_FILE_INFO #x10B0)
(defconstant SFC_SET_CLIPPING #x10C0)
(defconstant SFC_GET_CLIPPING #x10C1)
(defconstant SFC_GET_INSTRUMENT #x10D0)
(defconstant SFC_SET_INSTRUMENT #x10D1)
(defconstant SFC_GET_LOOP_INFO #x10E0)
(defconstant SFC_GET_BROADCAST_INFO #x10F0)
(defconstant SFC_SET_BROADCAST_INFO #x10F1)
(defconstant SFC_TEST_IEEE_FLOAT_REPLACE #x6001)
(defconstant SFC_SET_ADD_DITHER_ON_WRITE #x1070)
(defconstant SFC_SET_ADD_DITHER_ON_READ #x1071)
(defconstant SF_STR_TITLE #x01)
(defconstant SF_STR_COPYRIGHT #x02)
(defconstant SF_STR_SOFTWARE #x03)
(defconstant SF_STR_ARTIST #x04)
(defconstant SF_STR_COMMENT #x05)
(defconstant SF_STR_DATE #x06)
(defconstant SF_FALSE 0)
(defconstant SF_TRUE 1)
(defconstant SFM_READ #x10)
(defconstant SFM_WRITE #x20)
(defconstant SFM_RDWR #x30)
(defconstant SF_ERR_NO_ERROR 0)
(defconstant SF_ERR_UNRECOGNISED_FORMAT 1)
(defconstant SF_ERR_SYSTEM 2)
(defconstant SF_ERR_MALFORMED_FILE 3)
(defconstant SF_ERR_UNSUPPORTED_ENCODING 4)
(defconstant SF_COUNT_MAX #x7FFFFFFFFFFFFFFF)
(defcstruct SF_INFO
(frames :double)
(samplerate :int)
(channels :int)
(format :int)
(sections :int)
(seekable :int))
(defcstruct SF_FORMAT_INFO
(format :int)
(name :string)
(extension :string))
(defconstant SFD_DEFAULT_LEVEL 0)
(defconstant SFD_CUSTOM_LEVEL #x40000000)
(defconstant SFD_NO_DITHER 500)
(defconstant SFD_WHITE 501)
(defconstant SFD_TRIANGULAR_PDF 502)
(defcstruct SF_DITHER_INFO
(type :int)
(level :double)
(name :string))
(defcstruct SF_EMBED_FILE_INFO
(offset :double)
(length :double))
(defconstant SF_LOOP_NONE 800)
(defconstant SF_LOOP_FORWARD 0)
(defconstant SF_LOOP_BACKWARD 0)
(defconstant SF_LOOP_ALTERNATING 0)
(defcstruct SF_INSTRUMENT
(gain :int)
(basenote :char)
(detune :char)
(velocity_lo :char)
(velocity_hi :char)
(key_lo :char)
(key_hi :char)
(loop_count :int)
(loops :pointer))
(defcstruct SF_INSTRUMENT_loops
(mode :int)
(start :unsigned-int)
(end :unsigned-int)
(count :unsigned-int))
(defcstruct SF_LOOP_INFO
(time_sig_num :short)
(time_sig_den :short)
(loop_mode :int)
(num_beats :int)
(bpm :float)
(root_key :int)
(future :pointer))
(defcstruct SF_BROADCAST_INFO
(description :pointer)
(originator :pointer)
(originator_reference :pointer)
(origination_date :pointer)
(origination_time :pointer)
(time_reference_low :int)
(time_reference_high :int)
(version :short)
(umid :pointer)
(reserved :pointer)
(coding_history_size :unsigned-int)
(coding_history :pointer))
(defcstruct SF_VIRTUAL_IO
(get_filelen :pointer)
(seek :pointer)
(read :pointer)
(write :pointer)
(tell :pointer))
(defcfun ("sf_open" sf_open) :pointer
(path :string)
(mode :int)
(sfinfo :pointer))
(defcfun ("sf_open_fd" sf_open_fd) :pointer
(fd :int)
(mode :int)
(sfinfo :pointer)
(close_desc :int))
(defcfun ("sf_open_virtual" sf_open_virtual) :pointer
(sfvirtual :pointer)
(mode :int)
(sfinfo :pointer)
(user_data :pointer))
(defcfun ("sf_close" sf_close) :int
(sndfile :pointer))
(defcfun ("sf_error" sf_error) :int
(sndfile :pointer))
(defcfun ("sf_strerror" sf_strerror) :string
(sndfile :pointer))
(defcfun ("sf_error_number" sf_error_number) :string
(errnum :int))
(defcfun ("sf_perror" sf_perror) :int
(sndfile :pointer))
(defcfun ("sf_error_str" sf_error_str) :int
(sndfile :pointer)
(str :string)
(len :pointer))
(defcfun ("sf_command" sf_command) :int
(sndfile :pointer)
(command :int)
(data :pointer)
(datasize :int))
(defcfun ("sf_format_check" sf_format_check) :int
(info :pointer))
(defcfun ("sf_seek" sf_seek) :double
(sndfile :pointer)
(frames :long-long)
(whence :int))
(defcfun ("sf_set_string" sf_set_string) :int
(sndfile :pointer)
(str_type :int)
(str :string))
(defcfun ("sf_get_string" sf_get_string) :string
(sndfile :pointer)
(str_type :int))
(defcfun ("sf_write_sync" sf_write_sync) :void
(sndfile :pointer))
;;;============
(defcfun (sf-readf-float "sf_readf_float") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-read-float "sf_read_float") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-writef-float "sf_writef_float") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-write-float "sf_write_float") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-readf-int "sf_readf_int") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-read-int "sf_read_int") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-writef-int "sf_writef_int") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-write-int "sf_write_int") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-readf-short "sf_readf_short") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-read-short "sf_read_short") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-writef-short "sf_writef_short") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-write-short "sf_write_short") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
;;; test double ?
(defcfun (sf-readf-double "sf_readf_double") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-read-double "sf_read_double") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-writef-double "sf_writef_double") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
(defcfun (sf-write-double "sf_write_double") :long-long
(sndfile :pointer)
(ptr :pointer)
(frames :long-long))
;#-linux
;(fli:define-foreign-function (sf-readf-float "sf_readf_float")
; ((sndfile :pointer)
; (ptr :pointer)
; (frames :long-long))
; :result-type :long-long)
| 11,713 | Common Lisp | .lisp | 319 | 30.131661 | 78 | 0.632405 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 052a5b035196726da2bd0d226df9d26f1bca65ad7918a39271b23a864c17b786 | 858 | [
-1
] |
859 | libsamplerate.lisp | cac-t-u-s_om-sharp/src/packages/sound/audio-api/libsamplerate/libsamplerate.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: D. Bouche
;============================================================================
(in-package :cl-user)
(defpackage "LibSampleRate"
(:nicknames "LSR")
(:use common-lisp cffi))
(in-package :lsr)
(pushnew :libsamplerate *features*)
(defparameter SRC_SINC_BEST_QUALITY 0)
(defparameter SRC_SINC_MEDIUM_QUALITY 1)
(defparameter SRC_SINC_FASTEST 2)
(defparameter SRC_ZERO_ORDER_HOLD 3)
(defparameter SRC_LINEAR 4)
(defcstruct SRC_DATA
(data_in :pointer)
(data_out :pointer)
(input_frames :long)
(output_frames :long)
(input_frames_used :long)
(output_frames_gen :long)
(end_of_input :int)
(src_ratio :double))
(defcstruct SRC_CB_DATA
(frames :long)
(data_in :pointer))
(defcfun (src-simple "src_simple") :int
(src-data :pointer)
(converter-type :int)
(channels :int))
(defcfun (src-strerror "src_strerror") :string
(error :int))
(defun resample-audio-buffer (in-buffer in-size n-channels out-buffer out-size ratio method)
(cffi:with-foreign-object (lsrdata '(:struct lsr::src_data))
(setf (cffi:foreign-slot-value lsrdata '(:struct lsr::src_data) 'lsr::data_in) in-buffer)
(setf (cffi:foreign-slot-value lsrdata '(:struct lsr::src_data) 'lsr::input_frames) in-size)
(setf (cffi:foreign-slot-value lsrdata '(:struct lsr::src_data) 'lsr::data_out) out-buffer)
(setf (cffi:foreign-slot-value lsrdata '(:struct lsr::src_data) 'lsr::output_frames) out-size)
(setf (cffi:foreign-slot-value lsrdata '(:struct lsr::src_data) 'lsr::src_ratio) ratio)
(let ((res (lsr::src-simple lsrdata method n-channels)))
(if (= res 0)
(values T (cffi:foreign-slot-value lsrdata '(:struct lsr::src_data) 'lsr::output_frames_gen))
(values NIL (lsr::src-strerror res))))))
| 2,397 | Common Lisp | .lisp | 54 | 41.574074 | 103 | 0.625269 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | fdb1ce39ee2bd986e572b87ce534b6263a77cd8ac0056eb9be39770cdf0b0187 | 859 | [
-1
] |
860 | omaudiolib.lisp | cac-t-u-s_om-sharp/src/packages/sound/audio-api/omaudiolib/omaudiolib.lisp | ;============================================================================
; omaudiolib: Lisp bindings
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
(in-package :cl-user)
(defpackage :juce)
(push :omaudiolib *features*)
(in-package :juce)
(cffi:defcfun ("versionString" versionString) :string)
;;;==============================================
;; PLAYER
;;;==============================================
(cffi:defcfun ("openAudioManager" openAudioManager) :pointer)
(cffi:defcfun ("closeAudioManager" closeAudioManager) :void (player :pointer))
(cffi:defcfun ("getDevicesTypeCount" getDevicesTypeCount) :int (player :pointer))
(cffi:defcfun ("getDeviceTypeName" getDeviceTypeName) :string (player :pointer) (type :int))
(cffi:defcfun ("setDeviceType" setDeviceType) :void (player :pointer) (type :string))
(cffi:defcfun ("getCurrentDeviceType" getCurrentDeviceType) :string (player :pointer))
(cffi:defcfun ("getInputDevicesCountForType" getInputDevicesCountForType) :int (player :pointer) (type :int))
(cffi:defcfun ("getOutputDevicesCountForType" getOutputDevicesCountForType) :int (player :pointer) (type :int))
(cffi:defcfun ("getNthInputDeviceName" getNthInputDeviceName) :string (player :pointer) (type :int) (n :int))
(cffi:defcfun ("getNthOutputDeviceName" getNthOutputDeviceName) :string (player :pointer) (type :int) (n :int))
(cffi:defcfun ("getCurrentDeviceName" getCurrentDeviceName) :string (player :pointer))
(cffi:defcfun ("setInputDevice" setInputDevice) :int (player :pointer) (n :int))
(cffi:defcfun ("setOutputDevice" setOutputDevice) :int (player :pointer) (n :int))
(cffi:defcfun ("initializeAudioChannels" initializeAudioChannels) :void (player :pointer) (in-channels :int) (out-channels :int))
(cffi:defcfun ("getInputChannelsCount" GetInputChannelsCount) :int (player :pointer))
(cffi:defcfun ("getOutputChannelsCount" GetOutputChannelsCount) :int (player :pointer))
(cffi:defcfun ("setOutputChannelsMapping" setOutputChannelsMapping) :int (player :pointer) (n :int) (map :pointer))
(cffi:defcfun ("getAvailableSampleRatesCount" getAvailableSampleRatesCount) :int (player :pointer))
(cffi:defcfun ("getNthAvailableSampleRate" getNthAvailableSampleRate) :int (player :pointer) (n :int))
(cffi:defcfun ("getCurrentSampleRate" getCurrentSampleRate) :int (player :pointer))
(cffi:defcfun ("setSampleRate" setSampleRate) :int (player :pointer) (sr :int))
(cffi:defcfun ("getAvailableBufferSizesCount" getAvailableBufferSizesCount) :int (player :pointer))
(cffi:defcfun ("getNthAvailableBufferSize" getNthAvailableBufferSize) :int (player :pointer) (n :int))
(cffi:defcfun ("getCurrentBufferSize" getCurrentBufferSize) :int (player :pointer))
(cffi:defcfun ("getDefaultBufferSize" getDefaultBufferSize) :int (player :pointer))
(cffi:defcfun ("setBufferSize" setBufferSize) :int (player :pointer) (size :int))
;;; SCAN UTILITIES (INDEPENDENT ON THE CURRENT SETUP)
(defun get-audio-drivers (audiomanager)
(let ((n-types (juce::getDevicesTypeCount audiomanager)))
(loop for type from 0 to (1- n-types) collect
(juce::getDeviceTypeName audiomanager type))))
(defun audio-driver-output-devices (audiomanager driver)
(let ((type-num (position driver (get-audio-drivers audiomanager) :test 'string-equal)))
(if type-num
(loop for n from 0 to (1- (juce::getOutputDevicesCountForType audiomanager type-num))
collect (juce::getNthOutputDeviceName audiomanager type-num n))
(error "Audio driver ~S not found." driver))))
(defun audio-driver-input-devices (audiomanager driver)
(let ((type-num (position driver (get-audio-drivers audiomanager) :test 'string-equal)))
(if type-num
(loop for n from 0 to (1- (juce::getInputDevicesCountForType audiomanager type-num))
collect (juce::getNthInputDeviceName audiomanager type-num n))
(error "Audio driver ~S not found." driver))))
(defun setoutputchannels (player activechannelslist)
(let* ((l (length activechannelslist))
(map (cffi:foreign-alloc :int :count l :initial-contents (mapcar '1- activechannelslist))))
(unwind-protect
(setoutputchannelsmapping player l map)
(cffi-sys:foreign-free map))))
(defun getinputchannelslist (player)
(or (loop for i from 1 to (juce::GetInputChannelsCount player) collect i) '(0)))
(defun getoutputchannelslist (player)
(or (loop for i from 1 to (juce::GetOutputChannelsCount player) collect i) '(0)))
(defun getsamplerates (player)
(loop for i from 0 to (1- (juce::getavailablesampleratescount player))
collect (juce::getnthavailablesamplerate player i)))
(defun getbuffersizes (player)
(loop for i from 0 to (1- (juce::getavailablebuffersizescount player))
collect (juce::getnthavailablebuffersize player i)))
;;;==============================================
;; BUFFER
;;;==============================================
(cffi:defcfun ("makeAudioSourceFromBuffer" makeAudioSourceFromBuffer)
:pointer
(buffer :pointer)
(channels :int)
(size :int)
(sr :int))
(cffi:defcfun ("makeAudioSourceFromFile" makeAudioSourceFromFile) :pointer (file :string))
(cffi:defcfun ("freeAudioSource" freeAudioSource) :void (source :pointer))
(cffi:defcfun ("startAudioSource" startAudioSource) :void (player :pointer) (source :pointer))
(cffi:defcfun ("pauseAudioSource" pauseAudioSource) :void (player :pointer) (source :pointer))
(cffi:defcfun ("stopAudioSource" stopAudioSource) :void (player :pointer) (source :pointer))
(cffi:defcfun ("setAudioSourcePos" setAudioSourcePos) :void (source :pointer) (pos :long-long))
(cffi:defcfun ("getAudioSourcePos" getAudioSourcePos) :long-long (source :pointer))
(cffi:defcfun ("getAudioSourceGain" getAudioSourceGain) :float (source :pointer))
(cffi:defcfun ("setAudioSourceGain" setAudioSourceGain) :void (source :pointer) (gain :float))
;;;==============================================
;; FILE I/O
;;;==============================================
(cffi:defcfun ("makeAudioFileReader" makeAudioFileReader) :pointer (file :string))
(cffi:defcfun ("freeAudioFileReader" freeAudioFileReader) :void (handler :pointer))
(cffi:defcfun ("getAudioFileNumChannels" getAudioFileNumChannels) :int (handler :pointer))
(cffi:defcfun ("getAudioFileNumSamples" getAudioFileNumSamples) :long-long (handler :pointer))
(cffi:defcfun ("getAudioFileSampleRate" getAudioFileSampleRate) :double (handler :pointer))
(cffi:defcfun ("getAudioFileSampleSize" getAudioFileSampleSize) :int (handler :pointer))
(cffi:defcfun ("getAudioFileFloatFormat" getAudioFileFloatFormat) :boolean (handler :pointer))
(cffi:defcfun ("getAudioFileFormat" getAudioFileFormat) :string (handler :pointer))
(cffi:defcfun ("getAudioFileSamples" getAudioFileSamples)
:boolean
(handler :pointer)
(buffer :pointer)
(startp :long-long)
(nsamples :int))
(cffi:defcfun ("makeAudioFileWriter" makeAudioFileWriter) :pointer (file :string) (format :int))
(cffi:defcfun ("freeAudioFileWriter" freeAudioFileWriter) :void (handler :pointer))
(cffi:defcfun ("writeSamplesToAudioFile" writeSamplesToAudioFile)
:boolean
(handler :pointer) (buffer :pointer)
(nch :int) (size :long-long) (sr :double) (resolution :int))
(defun juce-get-sound-info (path)
(let ((fileptr (juce::makeAudioFileReader path)))
(if (fli:null-pointer-p fileptr)
(error "Error reading file: ~A" path)
(unwind-protect
(let ((channels (juce::getAudioFileNumChannels fileptr))
(size (juce::getAudioFileNumSamples fileptr))
(sr (round (juce::getAudioFileSampleRate fileptr)))
(ss (juce::getAudioFileSampleSize fileptr))
(floats (juce::getAudioFileFloatFormat fileptr))
(format (juce::getAudioFileFormat fileptr)))
(values format channels sr ss size floats))
(juce::freeAudioFileReader fileptr)))))
(defun juce-get-sound-buffer (path &optional (datatype :float))
(let ((fileptr (juce::makeAudioFileReader path)))
(if (fli:null-pointer-p fileptr)
(error "Error reading file: ~A" path)
(unwind-protect
(let ((channels (juce::getAudioFileNumChannels fileptr))
(size (juce::getAudioFileNumSamples fileptr))
(sr (round (juce::getAudioFileSampleRate fileptr)))
(ss (juce::getAudioFileSampleSize fileptr))
(floats (juce::getAudioFileFloatFormat fileptr))
(format (juce::getAudioFileFormat fileptr)))
(let ((buffer (fli:allocate-foreign-object
:type :pointer :nelems channels
:initial-contents (loop for c from 0 to (1- channels) collect
(fli::allocate-foreign-object
:type datatype
:nelems size)))))
(juce::getAudioFileSamples fileptr buffer 0 size)
(values buffer format channels sr ss size floats)))
(juce::freeAudioFileReader fileptr)))))
;;; format = :aiff, wav, :ogg, :flac ...
(defun juce-save-sound-in-file (buffer filename size nch sr resolution format &optional (datatype :float))
(let* ((format_code (case format
(:wav 0)
(:aiff 1)
(otherwise 0)))
(fileptr (juce::makeAudioFileWriter filename format_code)))
(unwind-protect
(juce::writeSamplesToAudioFile fileptr buffer nch size (coerce sr 'double-float) resolution)
(juce::freeAudioFileWriter fileptr))))
| 10,130 | Common Lisp | .lisp | 165 | 55.533333 | 129 | 0.677543 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | b725a978d8c6d5ed628625e9488ccfd4cfff898deee0915f00c3f2786cd0f45c | 860 | [
-1
] |
861 | buffer-player.lisp | cac-t-u-s_om-sharp/src/packages/sound/player/buffer-player.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: D. Bouche
;============================================================================
(in-package :om)
(declaim (optimize (speed 3) (safety 0) (debug 1)))
(defstruct (buffer-player
(:conc-name bp-))
(pointer nil)
;(volume-effect nil)
(buffer nil)
(size 0)
(channels 2)
(sample-rate 44100)
(state :stop)
(:documentation ""))
(defun make-player-from-buffer (buffer size channels sample-rate)
(let ((bp (make-buffer-player :buffer buffer
:size size
:channels channels
:sample-rate sample-rate))
(ptr (juce::makeAudioSourceFromBuffer buffer channels size sample-rate)))
(setf (bp-pointer bp) ptr)
bp))
(defun free-buffer-player (bp)
(audio-io::om-free-audio-buffer (bp-buffer bp) (bp-channels bp))
(juce::freeAudioSource (bp-pointer bp)))
(defmethod set-buffer-player-volume ((self buffer-player) volume)
(print (list "TODO: set volume" volume)))
(defvar *default-audio-type* :float)
(defun make-player-from-file (path &optional (buffered nil))
(if (not buffered)
(make-buffer-player :pointer (juce::makeAudioSourceFromFile path))
(progn
(multiple-value-bind (buffer format channels sr ss size)
(audio-io::om-get-audio-buffer path *default-audio-type* nil)
(declare (ignore format ss))
(make-player-from-buffer buffer size channels sr)))))
(defmethod start-buffer-player ((self buffer-player) &key (start-frame 0))
(when (eq (bp-state self) :stop)
(jump-to-frame self start-frame)
(setf (bp-state self) :play)
(juce::startAudioSource *juce-player* (bp-pointer self))))
(defmethod pause-buffer-player ((self buffer-player))
(when (eq (bp-state self) :play)
(setf (bp-state self) :pause)
(juce::pauseAudioSource *juce-player* (bp-pointer self))))
(defmethod continue-buffer-player ((self buffer-player))
(when (eq (bp-state self) :pause)
(setf (bp-state self) :play)
(juce::startAudioSource *juce-player* (bp-pointer self))))
(defmethod stop-buffer-player ((self buffer-player))
(when (not (eq (bp-state self) :stop))
(setf (bp-state self) :stop)
(juce::stopAudioSource *juce-player* (bp-pointer self))))
(defmethod jump-to-frame ((self buffer-player) frame)
(juce::setAudioSourcePos (bp-pointer self) frame)
(when (eq (bp-state self) :play)
(juce::startAudioSource *juce-player* (bp-pointer self))))
(defmethod jump-to-time ((self buffer-player) time)
(jump-to-frame
self
(min
(max 0 (round (* time (/ (bp-sample-rate self) 1000.0))))
(bp-size self))))
(defmethod buffer-player-set-gain ((self buffer-player) gain)
(juce::setAudioSourceGain (bp-pointer self) gain))
| 3,394 | Common Lisp | .lisp | 77 | 39.441558 | 81 | 0.621097 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | cefb4936930603a27015c9279b583345a69278ddc9cf4d9787d0b8c4ce6fd8d8 | 861 | [
-1
] |
862 | juce-player.lisp | cac-t-u-s_om-sharp/src/packages/sound/player/juce-player.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
(in-package :om)
(defvar *juce-player* nil)
(add-preference-module :audio "Audio")
(add-preference-section :audio "Driver")
(add-preference :audio :driver "Type" nil nil nil 'set-audio-driver) ;; will be set at player startup
(add-preference :audio :output "Output" nil nil nil 'set-audio-device) ;; will be set at player startup
(add-preference-section :audio "Settings")
(add-preference :audio :out-channels "Output Channels" '(2) 2 nil 'set-audio-settings)
(add-preference :audio :samplerate "Sample Rate" '(44100) 44100 nil 'set-audio-settings)
(add-preference :audio :buffersize "Buffer Size" '(256 512 1024) 512 nil 'set-audio-settings)
(add-preference :audio :channels-config "Buffer channel-routing" :list nil
'("format : out-for-ch1 out-for-ch2 ..."
"NIL/- = mute channel"
"Channels beyond the list will be routed to their direct output."
"This will NOT apply on sounds that are accessed from file.")
'set-audio-settings)
(defun set-audio-driver ()
(let* ((device-types (juce::get-audio-drivers *juce-player*))
(default-driver (car (remove nil device-types))))
;;; update the preference fields with the current drivers
(add-preference :audio :driver "Type" device-types default-driver nil 'set-audio-driver)
(unless (and (get-pref-value :audio :driver)
(find (get-pref-value :audio :driver) device-types :test 'string-equal))
(when (get-pref-value :audio :driver)
(om-beep-msg "Audio driver: ~S not found. Restoring default." (get-pref-value :audio :driver)))
(put-default-value (get-pref :audio :driver)))
(let ((selected-device-type (get-pref-value :audio :driver))
(current-device-type (juce::getCurrentDeviceType *juce-player*)))
(if selected-device-type
(progn
(unless (string-equal selected-device-type current-device-type)
(om-print (format nil "Setting audio driver: \"~A\"" (get-pref-value :audio :driver)) "AUDIO")
(juce::setDeviceType *juce-player* (get-pref-value :audio :driver)))
(set-audio-device))
(om-beep-msg "AUDIO: ERROR! Could not find any audio driver.")))))
(defun set-audio-device ()
(let ((out-devices (juce::audio-driver-output-devices *juce-player* (get-pref-value :audio :driver))))
;;; update the preference fields
(add-preference :audio :output "Output device" out-devices (car out-devices) nil 'set-audio-device)
(unless (and (get-pref-value :audio :output)
(find (get-pref-value :audio :output) out-devices :test 'string-equal))
(when (get-pref-value :audio :output)
(om-beep-msg "Audio output device: ~S not found. restoring default." (get-pref-value :audio :output)))
(put-default-value (get-pref :audio :output)))
(let ((selected-device (get-pref-value :audio :output))
(current-device (juce::getCurrentDeviceName *juce-player*)))
(if selected-device
(unless (string-equal selected-device current-device)
(om-print (format nil "Setting audio device \"~A\"" (get-pref-value :audio :output)) "AUDIO")
(let ((pos (position selected-device out-devices :test 'string-equal)))
(assert pos)
(juce::setOutputDevice *juce-player* pos))
(set-audio-settings))
(om-beep-msg "AUDIO: ERROR! Could not find any audio device.")))))
(defun set-audio-settings ()
(let ((device-supported-out-channels (juce::getoutputchannelslist *juce-player*))
(device-supported-sample-rates (juce::getsamplerates *juce-player*))
(device-supported-buffer-sizes (juce::getbuffersizes *juce-player*)))
;;; update the preference fields
(add-preference :audio :out-channels "Output Channels" device-supported-out-channels 2
nil 'set-audio-settings)
(add-preference :audio :samplerate "Sample Rate" device-supported-sample-rates 44100
nil 'set-audio-settings)
(add-preference :audio :buffersize "Buffer Size" device-supported-buffer-sizes 512
nil 'set-audio-settings)
;;; check for conformity of current settings
;;; reset defaults if needed
(unless (find (get-pref-value :audio :out-channels) device-supported-out-channels :test '=)
(put-default-value (get-pref :audio :out-channels)))
(juce::initializeaudiochannels *juce-player* 0 (get-pref-value :audio :out-channels))
(configure-audio-channels)
(unless (find (get-pref-value :audio :samplerate) device-supported-sample-rates :test '=)
(put-default-value (get-pref :audio :samplerate)))
(juce::setsamplerate *juce-player* (get-pref-value :audio :samplerate))
(unless (find (get-pref-value :audio :buffersize) device-supported-buffer-sizes :test '=)
(put-default-value (get-pref :audio :buffersize)))
(juce::setbuffersize *juce-player* (get-pref-value :audio :buffersize))
(update-preference-window-item :audio :out-channels)
(update-preference-window-item :audio :samplerate)
(update-preference-window-item :audio :buffersize)
(om-print (format nil "[out] ~s, ~D out channels / ~D. ~D Hz."
(juce::getcurrentdevicename *juce-player*)
(get-pref-value :audio :out-channels)
(juce::getoutputchannelscount *juce-player*)
(juce::getcurrentsamplerate *juce-player*))
"AUDIO")
))
; (juce::getCurrentDeviceType *juce-player*)
; (juce::audio-driver-output-devices *juce-player* "Windows Audio")
;;; when this function si called the preferences are set to their default or saved values
(defun open-juce-player ()
(setq *juce-player* (juce::openAudioManager))
(set-audio-driver))
(defun close-juce-player ()
(juce::closeAudioManager *juce-player*)
(setf *juce-player* nil))
;;; CONVENTION:
;;; (nth n list) = target for channel n in the sounds :
;;; c >= 1 : play on channel c
;;; c = 0 : play on its original channel
;;; c = -1 : mute
(defun configure-audio-channels ()
(let ((list (get-pref-value :audio :channels-config)))
(om-print (format nil "routing channels:") "AUDIO")
(unless list (om-print "[reset]" "AUDIO"))
(let* ((available-channels (juce::getoutputchannelslist *juce-player*))
(checked-list
(loop for to in list
for from = 1 then (+ from 1) collect
(cond
((or (null to) (not (integerp to)))
(om-print (format nil "~D => off" from) "AUDIO")
-1) ;; don't play this channel
((and (find to available-channels :test '=)
(<= to (get-pref-value :audio :out-channels)))
(om-print (format nil "~D => ~D" from to) "AUDIO")
to) ;; ok
(t ;;; 'to' channel not available
(let ((to2 (if (and (find from available-channels :test '=)
(<= from (get-pref-value :audio :out-channels)))
from -1) ;; keep on same channel ('from') if available or mute
))
(om-print-format
"~D => ERROR: channel ~D not available/enabled => ~A"
(list from to (if (minusp to2) "off" to2))
"AUDIO")
to2)
)))))
(juce::setoutputchannels *juce-player* checked-list))))
; INIT AND EXIT CALLS:
(add-om-init-fun 'open-juce-player)
(add-om-exit-action 'close-juce-player)
| 8,467 | Common Lisp | .lisp | 146 | 48.486301 | 111 | 0.607549 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 8f50a77a8643259b61b706918efec695795177892e2fd1a084ee95f78fb1b453 | 862 | [
-1
] |
863 | load.lisp | cac-t-u-s_om-sharp/src/player/load.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
(in-package :om)
(mapc #'(lambda (filename)
(cl-user::compile&load (cl-user::decode-local-path filename)))
'(
"scheduler/load-scheduling-system"
"scheduler/clock"
"play/timed-object"
"play/general-player"
"play/box-player"
"play/editor-player"
"data/object-with-action"
"data/time-sequence"
"data/timeline-editor"
"data/data-track"
"data/data-track-editor"
))
(omNG-make-package
"Data"
:container-pack (get-subpackage *om-package-tree* "Visual Language")
:classes '(data-track))
| 1,384 | Common Lisp | .lisp | 34 | 34.852941 | 78 | 0.508996 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 5678655a3ac1652c1f6c47f0c60239fe9c3e76c03b0492b6e581de461ee327c8 | 863 | [
-1
] |
864 | time-sequence.lisp | cac-t-u-s_om-sharp/src/player/data/time-sequence.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;=========================================================================
; Author: J. Garcia, J. Bresson
;=========================================================================
(in-package :om)
;;;========================================
;;; TIME SEQUENCE
;;; an object made of a set of timed items
;;; the timed items can actually have no time
;;; TIME-SEQUENCE handles this using hidden, interpolated 'internal-time'
;;;========================================
;;; Objects in a time-sequence should be subclasses of timed-item
;;; OR provide the same accessors
(defclass timed-item ()
((item-internal-time :initform nil :accessor item-internal-time :initarg :item-internal-time)
(item-type :initform nil :accessor item-type :initarg :item-type)
))
(defmethod item-get-time ((self timed-item)) (error "timed-item subclass should provide an item-get-time accessor"))
(defmethod item-set-time ((self timed-item) time) (error "timed-item subclass should provide an item-set-time accessor"))
(defmethod item-get-internal-time ((self timed-item)) (item-internal-time self))
(defmethod item-set-internal-time ((self timed-item) time) (setf (item-internal-time self) time))
(defmethod item-get-type ((self timed-item)) (item-type self))
(defmethod item-set-type ((self timed-item) type) (setf (item-type self) type))
(defmethod items-merged-p ((i1 timed-item) (i2 timed-item)) (equal i1 i2))
(defmethod items-distance ((i1 timed-item) (i2 timed-item))
(if (and (item-get-time i2) (item-get-time i1))
(abs (- (item-get-time i2) (item-get-time i1)))
1))
;;; time-sequence does not deal with durations but this can be useful, e.g to determine the end
(defmethod item-get-duration ((self t)) 0)
(defmethod item-set-duration ((self t) dur) nil)
(defmethod item-end-time ((self timed-item)) (+ (item-get-internal-time self) (item-get-duration self)))
;;; e.g. for get-obj-dur
(defun item-real-time (timed-item) (or (item-get-time timed-item) (item-get-internal-time timed-item)))
;TODO:
; - MOVE gesture time in editor
; - Interpolate output values if interpol is on ?
(defclass time-sequence (timed-object)
((time-types :initform nil :accessor time-types)
(duration :initform 0 :accessor duration :initarg :duration)
(interpol :initform nil :accessor interpol :initarg :interpol)))
(defmethod initialize-instance :after ((self time-sequence) &rest args)
(setf (interpol self)
(make-number-or-nil :number (or (and (number-? (interpol self))
(number-number (interpol self)))
50)
:t-or-nil (number-? (interpol self))))
self)
(defmethod om-init-instance :after ((self time-sequence) &optional initargs)
(time-sequence-update-internal-times self)
(time-sequence-update-obj-dur self) ;;; is this necessary ?
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;to be redefined by subclasses of TIME-SEQUENCE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmethod time-sequence-get-timed-item-list ((self time-sequence)) nil)
(defmethod time-sequence-set-timed-item-list ((self time-sequence) items)
(time-sequence-update-obj-dur self))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;CAN be redefined by subclasses of TIME-SEQUENCE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmethod time-sequence-get-times ((self time-sequence))
(loop for item in (time-sequence-get-timed-item-list self)
collect (item-get-time item)))
(defmethod time-sequence-set-times ((self time-sequence) times)
(loop for point in (time-sequence-get-timed-item-list self)
for time in times do (item-set-time point time))
(time-sequence-update-internal-times self))
(defmethod time-sequence-get-internal-times ((self time-sequence))
(loop for point in (time-sequence-get-timed-item-list self)
collect (item-get-internal-time point)))
;;; when there is no items insiode...
(defmethod time-sequence-default-duration ((self time-sequence)) 0)
(defmethod time-sequence-make-timed-item-at ((self time-sequence) at)
(let ((ti (make-instance 'timed-item)))
(item-set-time ti at)
ti))
;;; REDEFINE THIS METHOD IF NEEDED
; but should not called directly
; => USE time-sequence-insert-timed-item-and-update
(defmethod time-sequence-insert-timed-item ((self time-sequence) item &optional position)
"Insert a timed-item into the item-list at pos position"
(let* ((list (time-sequence-get-timed-item-list self))
(p (or position (length list))))
(time-sequence-set-timed-item-list
self
(append (and list (first-n list p))
(list item)
(nthcdr p list)))
))
; USE THIS METHOD TO UPDATE THE TIME PROPERTIES WHEN ADDING A POINT
(defmethod time-sequence-insert-timed-item-and-update ((self time-sequence) item &optional position)
(let ((pos (or position (find-position-at-time self (item-get-time item)))))
(clean-master-points-type self)
(time-sequence-insert-timed-item self item pos)
(time-sequence-update-internal-times self)
pos))
(defmethod time-sequence-remove-timed-item ((self time-sequence)
item
&optional (update-internal-times t))
(time-sequence-set-timed-item-list
self
(remove item (time-sequence-get-timed-item-list self)))
(when update-internal-times
(time-sequence-update-internal-times self)))
(defmethod time-sequence-remove-nth-timed-item ((self time-sequence)
pos &optional
(update-internal-times t))
(time-sequence-set-timed-item-list
self
(remove-nth pos (time-sequence-get-timed-item-list self)))
(when update-internal-times
(time-sequence-update-internal-times self)))
(defmethod time-sequence-reverse ((self time-sequence))
(let* ((t0 (get-first-time self))
(times (time-sequence-get-times self))
(durations (reverse (x->dx (remove nil times))))
reversed-times)
(time-sequence-set-timed-item-list self
(reverse (time-sequence-get-timed-item-list self)))
(setf reversed-times
(loop for item in times collect
(if item
(let ((val t0))
(setf t0 (+ t0 (or (pop durations) 0)))
val)
item)))
(time-sequence-set-times self reversed-times)
self))
;;;======================================
;;; UTILS (internal)
;;;======================================
(defmethod get-nth-point ((self time-sequence) n)
(nth n (time-sequence-get-timed-item-list self)))
(defmethod get-first-time ((self time-sequence))
(if (time-sequence-get-timed-item-list self)
(item-get-internal-time (nth 0 (time-sequence-get-timed-item-list self)))
0))
(defmethod get-obj-dur ((self time-sequence))
(duration self))
(defmethod time-sequence-update-obj-dur ((self time-sequence))
(setf (duration self)
(if (remove nil (time-sequence-get-timed-item-list self))
(loop for frame in (time-sequence-get-timed-item-list self)
maximize (+ (item-real-time frame) (item-get-duration frame)))
(time-sequence-default-duration self))
))
(defmethod set-internal-times ((self time-sequence) internal-times)
(loop for point in (time-sequence-get-timed-item-list self)
for time in internal-times
do (item-set-internal-time point time)))
(defmethod update-time-types-from-tpoint-list ((self time-sequence))
(setf (time-types self)
(loop for item in (time-sequence-get-timed-item-list self)
collect (item-get-type item))))
(defmethod update-tpoint-list-from-time-types ((self time-sequence))
(set-tpoint-list-time-types self (time-types self)))
(defmethod set-tpoint-list-time-types ((self time-sequence) types)
(loop for point in (time-sequence-get-timed-item-list self)
for type in types do
(item-set-type point type)))
(defmethod get-active-interpol-time ((self time-sequence) time)
(let* ((interpol-time (number-number (interpol self)))
(delta (- time (get-first-time self)))
(rest (mod delta interpol-time))
(mod (floor (/ delta interpol-time))))
(if (< mod 0)
(get-first-time self)
(+ (* (if (= 0 rest) mod (1+ mod)) interpol-time) (get-first-time self)))
))
(defmethod get-points-from-indices ((self time-sequence) indices)
(let ((point-list (time-sequence-get-timed-item-list self)))
(if (find T indices)
point-list
(loop for n in indices collect (nth n point-list)))))
(defmethod get-indices-from-points ((self time-sequence) points)
(let ((point-list (time-sequence-get-timed-item-list self)))
(remove nil (loop for p in points
collect (position p point-list)))))
(defmethod filter-points-for-obj ((self time-sequence) points)
(loop for p in points
when (member p (time-sequence-get-timed-item-list self))
collect p))
(defmethod point-exists-at-time ((self time-sequence) time)
(loop for point in (time-sequence-get-timed-item-list self)
when (and ;; (not (= (floor (item-get-internal-time point)) 0))
;; (= (floor (item-get-internal-time (print point))) (floor time))
(= (item-get-internal-time point) time))
return point))
(defmethod get-point-at-time ((self time-sequence) time)
(let ((pos (find-position-at-time self time)))
(nth pos (time-sequence-get-timed-item-list self))))
; Last active position
(defmethod find-active-position-at-time ((self time-sequence) time)
(or
(position time (time-sequence-get-timed-item-list self)
:key 'item-get-internal-time :test '>= :from-end t)
0))
; Position in the element list.
; If in between two elements, returns the position of the last one
(defmethod find-position-at-time ((self time-sequence) time)
(or
(position time (time-sequence-get-timed-item-list self)
:key 'item-get-internal-time :test '<=)
(length (time-sequence-get-timed-item-list self))))
(defmethod time-sequence-make-interpolated-timed-item-at ((self time-sequence) time)
(time-sequence-make-timed-item-at self time))
(defmethod time-sequence-get-active-timed-item-at ((self time-sequence) time)
(if (number-? (interpol self))
(let ((interpol-time (get-active-interpol-time self time)))
(time-sequence-make-interpolated-timed-item-at self interpol-time))
(let ((pos (find-active-position-at-time self time)))
(nth pos (time-sequence-get-timed-item-list self)))))
; Successive points sets of which the first and last times are known.
; (If possible avoid copy of the points...)
#|
(defun get-time-segments (points)
(let ((rep (list (list (om-copy (car points))))))
(loop for pt in (cdr points) do
(push (om-copy pt) (car rep))
(when (item-get-time pt)
(setf (car rep) (reverse (car rep)))
(push (list (om-copy pt)) rep)))
(if (= 1 (length (car rep))) ;; last point had a time
(setf rep (cdr rep))
(setf (car rep) (reverse (car rep))))
(reverse rep)))
|#
(defun get-time-segments (points)
(let ((rep (list (list (car points)))))
(loop for pt in (cdr points) do
(push pt (car rep))
(when (item-get-time pt)
(setf (car rep) (reverse (car rep)))
(push (list pt) rep)))
(if (= 1 (length (car rep))) ;; last point had a time
(setf rep (cdr rep))
(setf (car rep) (reverse (car rep))))
(reverse rep)))
(defun calc-constant-time-intermediate-values (begin end n)
(if (= begin end)
(make-list n :initial-element begin)
(arithm-ser begin end (/ (- end begin) (1- (float n))))))
(defun calc-constant-speed-intermediate-values (seg)
(let* ((distances (loop for i from 0 to (- (length seg) 2) collect
(items-distance (nth i seg) (nth (1+ i) seg))))
(total-length (reduce '+ distances :initial-value 0))
(ratios (mapcar
#'(lambda (l)
(if (zerop total-length) 1 (/ l total-length)))
distances)))
(om-round (om+ (om* (dx->x 0 ratios)
(- (item-get-time (last-elem seg))
(item-get-time (car seg))))
(item-get-time (car seg))))
))
; todo:
; - clean and avoid calls to om-copy
; - simplify when all points have a time !!
(defmethod time-sequence-update-internal-times ((self time-sequence)
&optional
(interpol-mode :constant-speed)
(duration 10000)
(modif-time nil))
;Create a list of times for all timed points even if they are nil.
;It can do with constant time or constant speed interpolations
;(interpol-mod = :constant-speed or :constant-time)
;If the time of the first point is not specified, use 0.
;If the time of the last point is not specified, use <duration>
;or the length of the previous timed segment.
;; reset the internal times
(set-internal-times self (copy-list (time-sequence-get-times self)))
(let ((points (time-sequence-get-timed-item-list self)))
(when points
(let ((tmp-points
(if (= 1 (length points))
;;the list contains only one point then return0 or the existing time
;(let ((pt (om-copy (car points))))
; (item-set-time pt (or (item-get-time (car points)) 0))
; (list pt))
(list (or (item-get-time (car points)) 0))
;;the list contains more than one point
(let ((seg-list (get-time-segments points)))
;; first and time is NIL
(unless (item-get-time (car (car seg-list)))
(item-set-time (car (car seg-list)) 0.0))
;; last time is NIL
(unless (item-get-time (last-elem (last-elem seg-list)))
;;; only 1 segment : arbirary end time at 'duration'
(if (= 1 (length seg-list))
(item-set-time (last-elem (last-elem seg-list))
(+ (item-get-time (car (last-elem seg-list))) duration))
;; set the same duration as the previous segment
(let ((prev-segment (car (last seg-list 2))))
(item-set-time (last-elem (last-elem seg-list))
(+ (item-get-time (car (last-elem seg-list)))
(- (item-get-time (last-elem prev-segment))
(item-get-time (car prev-segment))))))))
(cons (item-get-time (car (car seg-list))) ;; we ensured it has a time...
(loop for seg in seg-list append
(let ((timestamps (if (equal interpol-mode :constant-time)
;;; constant duration between points
(calc-constant-time-intermediate-values
(item-get-time (car seg))
(item-get-time (last-elem seg))
(length seg))
;;; constant speed between points
(calc-constant-speed-intermediate-values seg)
)))
(cdr timestamps))))
))))
;;; set the new list of times as internal times
(set-internal-times self tmp-points)
)))
(update-time-types self))
(defmethod time-sequence-reorder-timed-item-list ((self time-sequence))
(let ((points (time-sequence-get-timed-item-list self)))
(when points
(clean-master-points-type self)
;; order point list
(time-sequence-set-timed-item-list self (sort points '< :key 'item-get-internal-time))
(time-sequence-update-internal-times self))))
(defmethod get-all-master-points-positions ((self time-sequence))
(om-all-positions :master (time-types self)))
(defmethod get-all-master-points ((self time-sequence))
(loop for p in (time-sequence-get-timed-item-list self)
when (equal (item-get-type p) :master)
collect p))
(defmethod get-all-master-points-times ((self time-sequence))
(loop for point in (get-all-master-points self)
collect
(item-get-internal-time point)))
(defmethod set-all-points-as-master ((self time-sequence))
(loop for point in (time-sequence-get-timed-item-list self)
do (item-set-type point :master))
(update-time-types-from-tpoint-list self))
(defmethod get-first-and-last-time ((self time-sequence))
(let ((points (time-sequence-get-timed-item-list self)))
(when points
(if (> (length points) 1)
(list (item-get-internal-time (car points)) (item-get-internal-time (last-elem points)))
(list (item-get-internal-time (car points)))))))
(defmethod clean-master-points-type ((self time-sequence))
(let ((points (time-sequence-get-timed-item-list self)))
(when points
;; remove-first and last master-points
(when (> (length points) 0)
(item-set-type (car points) (item-get-time (car points))))
(when (> (length points) 1)
(item-set-type (last-elem points) (item-get-time (last-elem points))))))
(update-time-types-from-tpoint-list self))
(defmethod update-time-types ((self time-sequence))
(let ((points (time-sequence-get-timed-item-list self)))
(loop for point in points
do
(unless (eql (item-get-type point) :master)
(item-set-type point (item-get-time point))))
(when (> (length points) 0)
(item-set-type (car points) :master))
(when (> (length points) 1)
(item-set-type (last-elem points) :master))
(update-time-types-from-tpoint-list self)
))
(defmethod temporal-translate-all ((self time-sequence) dt)
(loop for point in (time-sequence-get-timed-item-list self) do
(item-set-time point (+ (item-get-time point) dt))))
(defmethod temporal-translate-points ((self time-sequence) points dt)
;; if only one point and master then translate as master point
(if (and (eql (length points) 1) (eql (item-get-type (car points)) :master))
(time-stretch-from-master-point self (car points) dt)
;; otherwise translate normally if possible
(when (possible-time-translation self points dt)
(loop for point in points do
(item-set-time point (max 0 (+ (item-get-internal-time point) dt))))))
(time-sequence-update-internal-times self))
(defmethod possible-time-translation ((self time-sequence) points dt)
(when points
(setf points (sort points '< :key 'item-get-internal-time))
(let ((timed-items (time-sequence-get-timed-item-list self)))
(if (eql (length timed-items) 1)
t
(let ((point-before (find (item-get-internal-time (car points)) timed-items
:key 'item-get-internal-time :test '> :from-end t))
(point-after (find (item-get-internal-time (car (last points))) timed-items
:key 'item-get-internal-time :test '<)))
(and (or (null point-before)
(> (+ (item-get-internal-time (car points)) dt) (item-get-internal-time point-before)))
(or (null point-after)
(< (+ (item-get-internal-time (car (last points))) dt) (item-get-internal-time point-after)))
)
)))))
(defmethod possible-time-translation-from-indices ((self time-sequence) indices dt)
(let ((all-times (time-sequence-get-internal-times self)))
(and indices
(or (eql (length all-times) 1)
(let ((min-ind (car indices))
(max-ind (car (last indices)))
(prev-t 0)
(post-t (get-obj-dur self)))
(when (> min-ind 0)
(setf prev-t (nth (1- min-ind) all-times)))
(when (< max-ind (1- (length all-times)))
(setf post-t (nth (1+ max-ind) all-times)))
(and (< (+ dt (nth max-ind all-times)) post-t)
(> (+ (nth min-ind all-times) dt) prev-t)))))
))
(defmethod temporal-translate-points-from-indices ((self time-sequence) indices dt)
;; if only one point and master then translate as master point
(if (and (eql (length indices) 1) (eql (nth (car indices) (time-types self)) :master))
(time-stretch-from-master-point self (car indices) dt)
;; otherwise translate normally if possible
(when (possible-time-translation self indices dt)
(loop for point_index in indices do
(item-set-time (nth point_index (time-sequence-get-timed-item-list self))
(max 0 (+ (nth point_index (time-sequence-get-internal-times self)) dt))))))
(time-sequence-update-internal-times self))
;;; return T if the right-move is ok
(defmethod move-the-right-side ((self time-sequence) master-point dt)
(let* ((points (time-sequence-get-timed-item-list self))
(times (time-sequence-get-internal-times self))
(master-time (item-get-internal-time master-point))
(new-t (max 0 (+ dt master-time)))
(master-pos (find-position-at-time self master-time))
(all-master-pos (get-all-master-points-positions self))
(pos-in-masters (position master-pos all-master-pos))
(next-master-pos (nth (1+ pos-in-masters) all-master-pos))
(next-master-time (nth next-master-pos times))
(next-master-ratio (if (= master-time next-master-time) 0 ;;; in principle we want to avoid this
(/ (- new-t next-master-time) (- master-time next-master-time)))))
;;; process all points between the two adjacent master-poinyts
(loop for idx = (1- next-master-pos) then (- idx 1)
while (> idx master-pos)
do
(let ((p (nth idx points)))
(when (item-get-time p)
(let ((new-p-time (round (+ (* next-master-ratio (- (nth idx times) master-time)) new-t)))
(next-p-time (nth (1+ idx) times)))
(when (< new-p-time next-p-time)
(item-set-time p new-p-time))
)
)))
(< (round new-t) (nth (1+ master-pos) times))
))
;;; return T if the left-move is ok
(defmethod move-the-left-side ((self time-sequence) master-point dt)
(let* ((points (time-sequence-get-timed-item-list self))
(times (time-sequence-get-internal-times self))
(master-time (item-get-internal-time master-point))
(new-t (max 0 (+ dt master-time)))
(master-pos (find-position-at-time self master-time))
(all-master-pos (get-all-master-points-positions self))
(pos-in-masters (position master-pos all-master-pos))
(prev-master-pos (nth (1- pos-in-masters) all-master-pos))
(prev-master-time (nth prev-master-pos times))
(prev-master-ratio (/ (- new-t prev-master-time) (- master-time prev-master-time))))
;;; process all points between the two adjacent master-poinyts
(loop for idx from (1+ prev-master-pos) to (1- master-pos)
do
(let ((p (nth idx points)))
(when (item-get-time p)
(let ((new-p-time (round (+ (* prev-master-ratio (- (nth idx times) prev-master-time)) prev-master-time)))
(prev-p-time (nth (1- idx) times)))
(when (> new-p-time prev-p-time)
(item-set-time p new-p-time))
)
)))
(> (round new-t) (nth (1- master-pos) times))
))
(defmethod time-stretch-from-master-point ((self time-sequence) master-point dt)
(let* ((points (time-sequence-get-timed-item-list self))
(master-time (item-get-internal-time master-point))
(new-t (max 0 (+ dt master-time)))
(pos (find-position-at-time self master-time))
(all-master-pos (get-all-master-points-positions self))
(pos-index-in-masters (position pos all-master-pos))
(master-point-before (find master-point points
:test #'(lambda (p1 p2)
(and (equal (item-get-type p2) :master)
(> (item-get-internal-time p1) (item-get-internal-time p2))))
:from-end t))
(master-point-after (find master-point points
:test #'(lambda (p1 p2)
(and (equal (item-get-type p2) :master)
(< (item-get-internal-time p1) (item-get-internal-time p2)))))))
(when (and pos-index-in-masters
(or (eql (length points) 1)
(and (or (null master-point-before)
(> (round new-t) (item-get-internal-time master-point-before)))
(or (null master-point-after)
(< (round new-t) (item-get-internal-time master-point-after))))))
;;=> The move is OK wrt. other master-points
(cond ((> dt 0) ;;; MOVE-RIGHT
;;; check right-compression first
(let ((do-it (or (null master-point-after)
(move-the-right-side self master-point dt))))
(when do-it
(item-set-time master-point (round new-t))
(when master-point-before
(move-the-left-side self master-point dt)))
))
((< dt 0) ;;; MOVE LEFT
;;; check left-compression first
(let ((do-it (or (null master-point-before)
(move-the-left-side self master-point dt))))
(when do-it
(item-set-time master-point (round new-t))
(when master-point-after
(move-the-right-side self master-point dt)))
))
(t nil))
)))
;;;=========================================
;;; TIME MARKERS METHODS
;;;=========================================
(defmethod get-time-markers ((self time-sequence))
(cons 0 (get-all-master-points-times self)))
(defmethod get-elements-for-marker ((self time-sequence) marker)
(list (point-exists-at-time self marker)))
;;; jb: not sure it is ever needed to redefine it
(defmethod translate-elements-from-time-marker ((self time-sequence) elems dt)
(when (not (member nil elems))
(temporal-translate-points self elems dt)))
;;;=========================================
;;; LENGTH AND SPEED METHODS
;;;=========================================
(defmethod give-speed-profile ((self time-sequence))
;; Compute speed profile (all speeds bewteen points) for the curve.
;; When div by zero should occur and infite speed it replace with -1.
;; Returns nil if no points
(let ((points (time-sequence-get-timed-item-list self))
(times (time-sequence-get-internal-times self)))
(if (not points)
nil
(loop for i from 0 to (1- (1- (length points)))
collect
(let* ((p1 (nth i points))
(t1 (nth i times))
(p2 (nth (1+ i) points))
(t2 (nth (1+ i) times))
(dist (items-distance p1 p2))
(dur (- t2 t1)))
(if (= dur 0) -1 (/ dist dur)))))))
(defmethod give-length-profile ((self time-sequence))
;; Give length profile (all segment legnthes) for the curve.
;; Returns nil if no points.
(let ((points (time-sequence-get-timed-item-list self)))
(if (not points)
nil
(loop for i from 0 to (1- (1- (length points)))
collect
(let* ((p1 (nth i points))
(p2 (nth (1+ i) points)))
(items-distance p1 p2))))))
(defmethod give-length ((self time-sequence))
;; Give the length of the curve.
;; Returns 0 if no points
(if (not (time-sequence-get-timed-item-list self))
0
(reduce '+ (give-length-profile self))))
(defmethod give-normalized-cumulative-length-profile ((self time-sequence))
;; Give length profile cumulated and normalized between 0 and 1.
;; Returns nil if no or 1 points.
(let ((pl (time-sequence-get-timed-item-list self)))
(when (>= (length pl) 1)
(let ((length-profile (give-length-profile self)))
(when length-profile
(let ((length (reduce '+ length-profile))
(val (dx->x 0 length-profile)))
(if (zerop length) (list 0)
(om/ val length))))))))
| 29,763 | Common Lisp | .lisp | 580 | 41.377586 | 121 | 0.586567 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 99ea9e67022c4e344a38dea6f4c45c57677a49d4ba3a478a7244a50808e163dc | 864 | [
-1
] |
865 | object-with-action.lisp | cac-t-u-s_om-sharp/src/player/data/object-with-action.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
(in-package :om)
;THIS simple class combines methods needed for BPFs and Time-Sequences
(defclass object-with-action ()
((action :initform nil :accessor action :initarg :action) ;;; user (interface) specification
(action-fun :initform nil :accessor action-fun) ;; actual (hidden lambda fun)
))
; ((:type name def-val) ...)
(defmethod arguments-for-action ((fun t)) nil)
(defmethod argument-values-for-action ((fun t))
(loop for arg in (arguments-for-action fun)
collect (nth 2 arg)))
(defmethod set-action ((self object-with-action) action)
(cond ((functionp action)
(setf (action-fun self) action)
(setf (action self) :internal-lambda))
((ompatch-p action)
(compile-patch action)
(setf (action-fun self) (intern-om (compiled-fun-name action))
(action self) action))
((consp action)
(setf (action-fun self) #'(lambda (x) (apply (car action) (cons x (cdr action))))
(action self) action))
((and (symbolp action) (fboundp action))
(set-action self (cons action (argument-values-for-action action))))
((equal action :internal-lambda)
(setf (action self) action)
;;; here we can do nothing more but hope there is a good lambda in action-fun
(unless (functionp (action-fun self)) (om-beep-msg "Problem with internal lambda: NEED TO RELOAD THE ACTION !!")))
((null action)
(setf (action-fun self) nil
(action self) nil))
(action (om-beep-msg "Unrecognized action: ~A" action))))
(defmethod om-init-instance :around ((self object-with-action) &optional initargs)
(let* ((object (call-next-method))
(action (or (find-value-in-kv-list initargs :action)
(slot-value object 'action))))
(set-action object action)
object))
| 2,605 | Common Lisp | .lisp | 52 | 44.25 | 123 | 0.586085 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | cdb65a790ab7face849b6d925cf8c1045be33b2b9df4c73c0372adbdd1c9cd34 | 865 | [
-1
] |
866 | data-track-editor.lisp | cac-t-u-s_om-sharp/src/player/data/data-track-editor.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
(in-package :om)
;;;======================================
;;; EDITOR
;;;======================================
(defclass data-track-editor (OMEditor play-editor-mixin undoable-editor-mixin multi-display-editor-mixin)
((timeline-editor :accessor timeline-editor :initform nil)
(record-process :accessor record-process :initform nil)))
;;; compatibility (editors in libraries inheriting from data-stream-editor)
(defclass* data-stream-editor (data-track-editor) ())
(defmethod object-default-edition-params ((self data-track))
'((:display-mode :blocks)
(:grid t)
(:x1 0) (:x2 nil)
(:y1 0) (:y2 100)))
(defclass data-track-panel (x-cursor-graduated-view y-graduated-view OMEditorView om-tt-view)
((stream-id :accessor stream-id :initform 0 :initarg :stream-id)
(left-view :accessor left-view :initform nil :initarg :left-view))
(:default-initargs
:input-model (om-input-model :touch-pan t)))
(defmethod editor-view-class ((self data-track-editor)) 'data-track-panel)
(defmethod object-has-editor ((self internal-data-track)) t)
(defmethod get-editor-class ((self internal-data-track)) 'data-track-editor)
(defmethod get-obj-to-play ((self data-track-editor)) (object-value self))
(defmethod get-object-slots-for-undo ((self internal-data-track)) '(frames))
(defmethod alllow-insert-point-from-timeline ((self data-track-editor)) nil)
;;; from play-editor-mixin
(defmethod cursor-panes ((self data-track-editor))
;(append (get-g-component self :data-panel-list)
(cons (active-panel self)
(and (timeline-editor self)
(cursor-panes (timeline-editor self)))))
(defmethod active-panel ((editor data-track-editor))
(let ((n (or (and (multi-display-p editor)
(position (object-value editor) (multi-obj-list editor)))
0)))
(nth n (get-g-component editor :data-panel-list))))
(defmethod editor-window-init-size ((self data-track-editor)) (om-make-point 650 200))
(defmethod frame-display-modes-for-object ((self data-track-editor) (object t)) '(:blocks :bubbles))
(defmethod make-editor-controls ((editor data-track-editor))
(let ((object (object-value editor)))
(when (> (length (frame-display-modes-for-object editor object)) 1)
(om-make-di 'om-popup-list :size (omp 80 24) :font (om-def-font :gui)
:items (frame-display-modes-for-object editor object)
:di-action #'(lambda (item)
(editor-set-edit-param editor :display-mode (om-get-selected-item item))
(mapc 'om-invalidate-view (get-g-component editor :data-panel-list)))
:value (editor-get-edit-param editor :display-mode)
))))
(defmethod editor-with-timeline ((self data-track-editor)) t)
(defun make-timeline-check-box (editor)
(om-make-di 'om-check-box :text "timeline" :size (omp 65 24) :font (om-def-font :gui)
:checked-p (editor-get-edit-param editor :show-timeline)
:enabled (timeline-editor editor)
:di-action #'(lambda (item)
(let ((timeline-ed (timeline-editor editor)))
(editor-set-edit-param editor :show-timeline (om-checked-p item))
(clear-timeline timeline-ed)
(when (om-checked-p item) (make-timeline-view timeline-ed))
(om-update-layout (main-view editor))))
))
(defun make-control-bar (editor)
(let ((mousepostext (om-make-graphic-object 'om-item-text :size (omp 60 16))))
(set-g-component editor :mousepos-txt mousepostext)
(om-make-layout
'om-row-layout
:ratios '(1 100 1 1 1 1 1)
:subviews (list mousepostext
nil
(make-time-monitor editor)
(make-play-button editor :enable t)
(make-repeat-button editor :enable t)
(make-pause-button editor :enable t)
(make-stop-button editor :enable t)
(when (can-record editor)
(make-rec-button editor :enable t
:record-fun #'(lambda (on)
(if on (editor-record-on editor)
(editor-record-off editor)))
))
))))
(defmethod init-editor ((editor data-track-editor))
(call-next-method)
(when (editor-with-timeline editor)
(setf (timeline-editor editor)
(make-instance 'timeline-editor
:object (object editor)
:container-editor editor))
))
(defmethod editor-close ((editor data-track-editor))
(when (can-record editor)
(editor-record-off editor))
(call-next-method))
;;; stop record after box eval
(defmethod editor-update-play-state ((editor data-track-editor) object)
(call-next-method)
(when (can-record editor)
(editor-record-off editor)))
;;; sets the editor slightly longer that the actual object length
(defmethod editor-view-after-init-space ((self t)) 1000)
;;; the small view at the left of the timeline should be sized according to the editor's layout
(defmethod make-timeline-left-item ((self data-track-editor) id)
(om-make-view 'om-view :size (omp 28 15)))
(defmethod make-left-panel-for-object ((editor data-track-editor) (object t) view)
(let ((ruler (om-make-view 'y-ruler-view
:size (omp 30 nil)
:related-views (list view)
:bg-color (om-def-color :white)
:y1 (editor-get-edit-param editor :y1)
:y2 (editor-get-edit-param editor :y2))))
ruler))
(defmethod reinit-y-ranges-from-ruler ((editor data-track-editor) ruler)
(set-ruler-range ruler
(get-default-edit-param (object editor) :y1)
(get-default-edit-param (object editor) :y2)))
(defmethod data-track-get-x-ruler-vmin ((self data-track-editor)) 0)
;;; voice editor has a different ruler
(defmethod make-time-ruler ((editor data-track-editor) dur)
(let ((vmin (data-track-get-x-ruler-vmin editor)))
(om-make-view 'time-ruler
:related-views (get-g-component editor :data-panel-list)
:size (omp nil 20)
:bg-color (om-def-color :white)
:vmin vmin
:x1 (or (editor-get-edit-param editor :x1) vmin)
:x2 (or (editor-get-edit-param editor :x2) dur))))
(defmethod editor-scroll-v ((self data-track-editor)) nil)
(defmethod make-editor-window-contents ((editor data-track-editor))
(let* ((data-track (object-value editor))
(object-s (if (multi-display-p editor)
(multi-obj-list editor)
(list data-track)))
(n-objs (length object-s))
(max-dur (loop for obj in object-s maximize (or (get-obj-dur obj) 0)))
(ed-dur (if (zerop max-dur)
10000
(+ max-dur (editor-view-after-init-space data-track)))))
(set-g-component editor :data-panel-list
(loop for d-s in object-s
for i = 0 then (+ i 1) collect
(let* ((view (om-make-view (editor-view-class editor) :stream-id i
:editor editor
:size (omp 50 nil)
:direct-draw t
:bg-color (om-def-color :white)
;; internal vertical scroller
:scrollbars (editor-scroll-v editor)
))
(ruler (make-left-panel-for-object editor d-s view)))
(setf (left-view view) ruler)
view)))
(set-g-component editor :x-ruler (make-time-ruler editor ed-dur))
(set-g-component editor :main-panel (car (get-g-component editor :data-panel-list)))
(when (timeline-editor editor)
(set-g-component (timeline-editor editor) :main-panel (om-make-layout 'om-row-layout))
(when (editor-get-edit-param editor :show-timeline)
(make-timeline-view (timeline-editor editor))))
(om-make-layout
'om-column-layout
:ratios '(96 2 2)
:subviews (list
;;; first group with the 'main' editor:
(om-make-layout
'om-simple-layout
;;; if this is a multi-object editor with 3+ objects, add vertical scroller
:scrollbars (if (> (length (get-g-component editor :data-panel-list)) 2) :v nil)
:subviews
(list
(om-make-layout
'om-grid-layout
:delta 0
:ratios `((nil 100)
,(append '(0.01)
(make-list n-objs :initial-element (/ 0.98 n-objs))
'(0.01)))
:subviews
(append (list nil (make-control-bar editor))
(loop for view in (get-g-component editor :data-panel-list)
append (list (left-view view) view))
(list nil (get-g-component editor :x-ruler)))
)
))
;;; the timeline editor:
(when (timeline-editor editor)
(get-g-component (timeline-editor editor) :main-panel))
;;; the bottom control bar:
(om-make-layout 'om-row-layout
:size (omp nil 40)
:subviews (list (make-editor-controls editor) nil
(and (editor-with-timeline editor)
(make-timeline-check-box editor))))
))
))
(defmethod om-view-scrolled ((self data-track-panel) pos)
(om-set-scroll-position (left-view self) (omp 0 (cadr pos))))
;===== MultiDisplay API
(defmethod enable-multi-display ((editor data-track-editor) obj-list)
(call-next-method)
(when (container-editor editor)
(om-substitute-subviews
(main-view (container-editor editor))
(main-view editor)
(setf (main-view editor)
(make-editor-window-contents editor)))
(init-editor-window editor)
))
(defmethod disable-multi-display ((editor data-track-editor))
(call-next-method)
(when (container-editor editor)
(om-substitute-subviews
(main-view (container-editor editor))
(main-view editor)
(setf (main-view editor)
(make-editor-window-contents editor)))
(init-editor-window editor)
))
;======================
(defmethod init-editor-window ((editor data-track-editor))
(call-next-method)
(when (get-g-component editor :x-ruler)
(update-views-from-ruler (get-g-component editor :x-ruler)))
(let ((y1 (editor-get-edit-param editor :y1))
(y2 (editor-get-edit-param editor :y2)))
(when (and y1 y2) ;; some editors don't, e.g. chord-seq editor
(loop for view in (get-g-component editor :data-panel-list)
do (setf (y1 view) y1
(y2 view) y2)
(set-shift-and-factor view)))))
(defmethod update-to-editor ((editor data-track-editor) (from ombox))
(let* ((data-track (object-value editor)))
(when data-track
(let ((new-max-dur (if (zerop (get-obj-dur data-track))
10000
(+ (get-obj-dur data-track) (editor-view-after-init-space data-track)))))
(when (get-g-component editor :x-ruler)
(setf (vmax (get-g-component editor :x-ruler)) new-max-dur)
(set-ruler-range
(get-g-component editor :x-ruler)
(v1 (get-g-component editor :x-ruler))
new-max-dur))
(mapc 'om-invalidate-view (get-g-component editor :data-panel-list))
(when (and (timeline-editor editor)
(editor-get-edit-param editor :show-timeline))
(update-to-editor (timeline-editor editor) editor))
(call-next-method)
))))
(defmethod update-to-editor ((editor data-track-editor) (from t))
(call-next-method)
(mapc 'om-invalidate-view (get-g-component editor :data-panel-list)))
(defmethod editor-invalidate-views ((self data-track-editor))
(call-next-method)
(mapc 'om-invalidate-view (get-g-component self :data-panel-list))
(when (timeline-editor self)
(editor-invalidate-views (timeline-editor self))))
;;; todo : factorize this in different editors..
(defmethod editor-delete-contents-from-timeline ((self data-track-editor) timeline-id sel)
(let ((data-track (object-value self)))
(mapcar #'(lambda (point) (time-sequence-remove-timed-item data-track point)) sel)
(time-sequence-update-internal-times data-track))
(editor-invalidate-views self)
(report-modifications self))
;;; called when resetting the x-rulers
(defmethod play-editor-get-ruler-views ((self data-track-editor))
(get-g-component self :x-ruler))
;;;===========================================
;;; FRAMES DRAW & SELECTION
;;;===========================================
;;; attributes are no intrinsec data of the frame
;;; they should calculated depending on the frame data and according to a given mode of display
(defmethod get-frame-graphic-duration ((self data-frame))
(if (zerop (item-get-duration self)) 200 (item-get-duration self)))
(defmethod get-frame-color ((self data-frame))
(or (getf (attributes self) :color)
(setf (getf (attributes self) :color) (om-random-color 0.4))))
;; random !
;; compare values to y-range
(defmethod get-frame-posy ((self data-frame))
(or (getf (attributes self) :posy)
(setf (getf (attributes self) :posy) (om-random 30 90))))
;; arbitrary !
(defmethod get-frame-sizey ((self data-frame))
(max 10 (* 1.2 (data-size self))))
(defmethod finalize-data-frame ((f data-frame) &rest args) nil)
;; returns (x y w h)
(defmethod get-frame-area ((frame data-frame) editor)
(let ((panel (active-panel editor))
(sizey (get-frame-sizey frame))
(posy (get-frame-posy frame)))
(case (editor-get-edit-param editor :display-mode)
(:bubbles (values
(x-to-pix panel (item-get-internal-time frame))
(y-to-pix panel (+ posy (/ sizey 2)))
(- (dy-to-dpix panel sizey))
(- (dy-to-dpix panel sizey))
))
(otherwise (values (x-to-pix panel (item-get-internal-time frame))
(y-to-pix panel posy)
(max 3 (dx-to-dpix panel (get-frame-graphic-duration frame)))
(max 3 (- (dy-to-dpix panel sizey))) ;; !! downwards
)))))
(defmethod draw ((frame data-frame) x y w h selected) nil)
(defmethod draw-data-frame ((frame data-frame) editor i &optional (active t))
(multiple-value-bind (x y w h)
(get-frame-area frame editor)
(om-with-fg-color (get-frame-color frame)
(or (draw frame x y w h (and active (find i (selection editor))))
(case (editor-get-edit-param editor :display-mode)
(:bubbles
;(om-draw-rect x y w h :fill nil)
(let ((r (abs (min w h))))
(om-draw-circle (+ x (round r 2))
(+ y (round r 2))
(round r 2) :fill t)
(when (and active (find i (selection editor)))
(om-draw-circle (+ x (round r 2))
(+ y (round r 2))
(round r 2) :fill t
:color (om-make-color .5 .5 .5 .5)))
))
(otherwise
(om-draw-rect x y w h :fill t)
(when (and active (find i (selection editor)))
(om-draw-rect x y w h :fill t
:color (om-make-color .5 .5 .5 .5))))
))
)))
(defmethod frame-at-pos ((editor data-track-editor) position)
(let ((frames (data-track-get-frames (object-value editor))))
(when frames
(position-if #'(lambda (f)
(multiple-value-bind (x y w h)
(get-frame-area f editor)
(om-point-in-rect-p position x y w h)))
frames))))
(defmethod frames-in-area ((editor data-track-editor) p1 p2)
(loop for f in (data-track-get-frames (object-value editor))
for i = 0 then (1+ i)
when (multiple-value-bind (x y w h)
(get-frame-area f editor)
(rect-intersection
(om-point-x p1) (om-point-y p1) (om-point-x p2) (om-point-y p2)
x y (+ x w) (+ y h)))
collect i))
;;;=======================
;;; EDITOR FUNCTIONS
;;;=======================
(defmethod draw-background ((editor data-track-editor) (view data-track-panel)) nil)
(defmethod om-draw-contents ((self data-track-panel))
(let* ((editor (editor self))
(stream (if (multi-display-p editor)
(nth (stream-id self) (multi-obj-list editor))
(object-value editor)))
(active (if (multi-display-p editor)
(equal self (active-panel editor))
t)))
(when active (draw-background editor self))
(when (editor-get-edit-param editor :grid)
(om-with-fg-color (om-def-color :light-gray)
(om-with-line '(2 2)
(draw-grid-from-ruler self (get-g-component editor :x-ruler)))))
(when stream
(om-with-fg-color (om-def-color :dark-gray)
(loop for frame in (data-track-get-frames stream)
for i = 0 then (1+ i) do
(draw-data-frame frame editor i active)))
)))
(defmethod om-draw-contents :after ((self data-track-panel))
(when (and (multi-display-p (editor self))
(equal self (active-panel (editor self))))
(om-draw-rect 0 0 (w self) (h self) :fill nil
:line 4 :color (om-make-color .8 .4 .4))
))
(defmethod position-display ((editor data-track-editor) pos-pix)
(when (active-panel editor)
(let* ((time (round (pix-to-x (active-panel editor) (om-point-x pos-pix)))))
(om-set-text (get-g-component editor :mousepos-txt) (format nil "~Dms" time)))))
(defmethod move-editor-selection ((self data-track-editor) &key (dx 0) (dy 0))
(declare (ignore dy)) ;; in a basic data-frame -- subclasses can do it !
(loop for fp in (selection self) do
(let ((frame (nth fp (data-track-get-frames (object-value self)))))
(item-set-time frame (max 0 (round (+ (item-get-time frame) dx))))
)))
(defmethod resize-editor-selection ((self data-track-editor) &key (dx 0) (dy 0))
(declare (ignore dy)) ;; in a basic data-frame -- subclasses can do it !
(loop for fp in (selection self) do
(let ((frame (nth fp (data-track-get-frames (object-value self)))))
(item-set-duration frame (max 0 (round (+ (item-get-duration frame) dx))))
))
(time-sequence-update-obj-dur (object-value self)))
(defmethod delete-editor-selection ((self data-track-editor))
(loop for pos in (sort (selection self) '>) do
(time-sequence-remove-nth-timed-item (object-value self) pos)))
;;; sort the frames and reset the selection indices correctly
(defmethod editor-sort-frames ((self data-track-editor))
(let* ((stream (object-value self))
(selected-objects (loop for pos in (selection self) collect
(nth pos (data-track-get-frames stream)))))
(time-sequence-reorder-timed-item-list stream)
(setf (selection self)
(loop for selected in selected-objects
collect (position selected (data-track-get-frames stream))))))
(defmethod resizable-frame ((self data-frame)) nil)
(defmethod update-view-from-ruler ((self x-ruler-view) (view data-track-panel))
(call-next-method)
(editor-set-edit-param (editor view) :x1 (x1 self))
(editor-set-edit-param (editor view) :x2 (x2 self)))
(defmethod update-view-from-ruler ((self y-ruler-view) (view data-track-panel))
(call-next-method)
(editor-set-edit-param (editor view) :y1 (y1 self))
(editor-set-edit-param (editor view) :y2 (y2 self)))
(defmethod om-view-mouse-motion-handler ((self data-track-panel) position)
(let ((editor (editor self)))
(when (object-value editor)
;;; show the mouse position on screen
(position-display editor position)
(unless (or (equal (editor-play-state editor) :play)
(and (multi-display-p editor) (not (equal self (active-panel editor)))))
(om-hide-tooltip self)
(let ((frames (data-track-get-frames (object-value editor)))
(fp (frame-at-pos editor position)))
(when fp
(let ((frame (nth fp frames)))
(if (om-command-key-p)
;;; show tooltip for the frame under the mouse cursor
(om-show-tooltip self (data-frame-text-description frame)
(omp (- (om-point-x position) 60) 20)
0)
;;; show reisize cursor if by the end of a resizable-frame
(when (resizable-frame frame)
(let ((mouse-x (om-point-x position))
(frame-end-time-x (time-to-pixel self (item-end-time frame))))
(if (and (<= mouse-x frame-end-time-x) (>= mouse-x (- frame-end-time-x 5)))
(om-set-view-cursor self (om-get-cursor :h-size))
(om-set-view-cursor self nil)))
))))
)))))
(defmethod om-view-click-handler :around ((self data-track-panel) position)
(let ((editor (editor self)))
(when (and (container-editor editor)
(not (equal self (active-panel editor))))
(set-current-nth (container-editor editor) (stream-id self)))
(call-next-method)
))
(defmethod om-view-click-handler ((self data-track-panel) position)
(let* ((editor (editor self))
(object (object-value editor)))
(set-paste-position position self)
(unless (handle-selection-extent self position) ;; => play-editor-mixin handles cursor etc.
(when object
(let ((p0 position)
(selection (frame-at-pos editor position)))
(set-selection editor selection)
(update-timeline-editor editor)
(om-invalidate-view self)
(cond
((and (null selection) (om-add-key-down)
(not (locked object)))
(store-current-state-for-undo editor)
(let ((frame (time-sequence-make-timed-item-at object (pixel-to-time self (om-point-x p0)))))
(finalize-data-frame frame :posy (pix-to-y self (om-point-y p0)))
(with-schedulable-object object
(time-sequence-insert-timed-item-and-update object frame))
(report-modifications editor)
(update-timeline-editor editor)
(om-invalidate-view self)))
((and selection (not (locked object)))
(let* ((selected-frame (nth selection (data-track-get-frames object)))
(selected-frame-end-t (time-to-pixel self (item-end-time selected-frame))))
(store-current-state-for-undo editor)
;;; resize the selected frame ?
(if (and (resizable-frame selected-frame)
(<= (om-point-x position) selected-frame-end-t) (>= (om-point-x position) (- selected-frame-end-t 5)))
(om-init-temp-graphics-motion
self position nil
:motion #'(lambda (view pos)
(declare (ignore view))
(let ((dx (dpix-to-dx self (- (om-point-x pos) (om-point-x p0)))))
(when (> (- (om-point-x pos) (x-to-pix self (item-get-time selected-frame))) 10)
(resize-editor-selection editor :dx (round dx))
(setf p0 pos)
(om-invalidate-view self))))
:release #'(lambda (view pos)
(declare (ignore view pos))
(notify-scheduler object)
(report-modifications editor)
(om-invalidate-view self))
:min-move 4)
;;; move the selection
(om-init-temp-graphics-motion
self position nil
:motion #'(lambda (view pos)
(declare (ignore view))
(let ((dx (dpix-to-dx self (- (om-point-x pos) (om-point-x p0))))
(dy (- (dpix-to-dy self (- (om-point-y pos) (om-point-y p0))))))
(move-editor-selection editor :dx dx :dy dy)
(setf p0 pos)
(position-display editor pos)
(update-timeline-editor editor)
(om-invalidate-view self)
))
:release #'(lambda (view pos)
(declare (ignore view pos))
(let ((selected-frames (posn-match (data-track-get-frames object) (selection editor))))
(with-schedulable-object (object-value editor)
(editor-sort-frames editor)
(move-editor-selection editor :dy :round)
(time-sequence-reorder-timed-item-list object))
(update-timeline-editor editor)
;;; reset the selection:
(set-selection editor
(loop for f in selected-frames collect
(position f (data-track-get-frames object))))
)
(report-modifications editor)
(om-invalidate-view self))
:min-move 4)
))
)
(t
;; no selection: start selection lasso
(om-init-temp-graphics-motion
self position
(om-make-graphic-object 'selection-rectangle :position position :size (om-make-point 4 4))
:min-move 10
:release #'(lambda (view position)
(declare (ignore view))
(setf (selection editor) (frames-in-area editor p0 position))
(update-timeline-editor editor)
(om-invalidate-view self))
)
))
)))))
(defmethod editor-key-action ((editor data-track-editor) key)
(let* ((panel (active-panel editor))
(stream (object-value editor)))
(case key
(:om-key-delete
(when (and (selection editor) (not (locked stream)))
(store-current-state-for-undo editor)
(with-schedulable-object (object-value editor)
(delete-editor-selection editor))
(setf (selection editor) nil)
(om-invalidate-view panel)
(update-timeline-editor editor)
;; (time-sequence-update-obj-dur stream) ; why not ?
(report-modifications editor)))
(:om-key-esc
;; maybe not needed ? we already have the db-click on ruler for that...
;; (reinit-x-ranges editor)
)
(:om-key-left
(when (and (selection editor) (not (locked stream)))
(store-current-state-for-undo editor)
(with-schedulable-object
(object-value editor)
(move-editor-selection
editor
:dx (- (get-units (get-g-component editor :x-ruler)
(if (om-shift-key-p) 100 10))))
(editor-sort-frames editor)
(time-sequence-update-internal-times stream))
(om-invalidate-view panel)
(update-timeline-editor editor)
(report-modifications editor)
))
(:om-key-right
(when (and (selection editor) (not (locked stream)))
(store-current-state-for-undo editor)
(with-schedulable-object
(object-value editor)
(move-editor-selection
editor
:dx (get-units (get-g-component editor :x-ruler)
(if (om-shift-key-p) 100 10)))
(editor-sort-frames editor)
(time-sequence-update-internal-times stream))
(om-invalidate-view panel)
(update-timeline-editor editor)
(report-modifications editor)))
(:om-key-tab
(setf (selection editor)
(if (selection editor)
(list (next-element-in-editor editor (car (selection editor))))
(list (first-element-in-editor editor))))
(editor-invalidate-views editor))
(otherwise (call-next-method))
)))
;;; in data-strea-editor the selection is an index to elements in the frame sequence
;;; this is not necessarilythe case of editor subclasses
(defmethod first-element-in-editor ((editor data-track-editor))
(and (data-track-get-frames (object-value editor)) 0))
(defmethod next-element-in-editor ((editor data-track-editor) (element number))
(let ((seq (object-value editor)))
(and (data-track-get-frames seq)
(mod (1+ element) (length (data-track-get-frames seq))))))
(defmethod next-element-in-editor ((editor data-track-editor) (element t)) nil)
(defmethod select-all-command ((self data-track-editor))
#'(lambda ()
(set-selection
self
(loop for i from 0 to (1- (length (data-track-get-frames (object-value self))))
collect i))
(update-timeline-editor self)
(editor-invalidate-views self)
))
(defmethod copy-command ((self data-track-editor))
(when (selection self)
#'(lambda ()
(set-om-clipboard
(mapcar #'om-copy
(posn-match (data-track-get-frames (object-value self)) (selection self)))))))
(defmethod cut-command ((self data-track-editor))
(when (and (selection self) (not (locked (object-value self))))
#'(lambda ()
(set-om-clipboard
(mapcar #'om-copy
(posn-match (data-track-get-frames (object-value self)) (selection self))))
(store-current-state-for-undo self)
(with-schedulable-object (object-value self)
(delete-editor-selection self))
(setf (selection self) nil)
(om-invalidate-view (active-panel self))
(update-timeline-editor self)
(report-modifications self))
))
(defmethod paste-command ((self data-track-editor))
(when (get-om-clipboard)
#'(lambda ()
(let ((data-track (object-value self))
(frames (mapcar
#'om-copy
(sort
(remove-if-not #'(lambda (element)
(subtypep (type-of element) 'data-frame))
(get-om-clipboard))
#'< :key #'item-get-time)))
(view (active-panel self)))
(if frames
(let* ((t0 (item-get-time (car frames)))
(paste-pos (get-paste-position view))
(p0 (if paste-pos
(pixel-to-time view (om-point-x paste-pos))
(+ t0 200))))
(loop for f in frames do
(item-set-time f (+ p0 (- (item-get-time f) t0))))
(set-paste-position (omp (time-to-pixel view (+ p0 200))
(if paste-pos (om-point-y paste-pos) 0))
view)
(store-current-state-for-undo self)
(with-schedulable-object
data-track
(loop for f in frames do
(time-sequence-insert-timed-item-and-update data-track f)))
(report-modifications self)
(editor-invalidate-views self)
t)
)))))
;;;==================================
;;; TURN PAGES / FOLLOW PLAY POSITION
;;;==================================
(defmethod play-editor-callback ((editor data-track-editor) time)
(call-next-method)
(let ((panel (get-g-component editor :main-panel))
(x-ruler (get-g-component editor :x-ruler)))
(when (and panel x-ruler)
(let ((x-range (round (- (x2 panel) (x1 panel)))))
(cond ((> time (x2 panel))
(set-ruler-range x-ruler (+ (v1 x-ruler) x-range) (+ (v2 x-ruler) x-range)))
((< time (x1 panel))
(set-ruler-range x-ruler time (+ time x-range)))
(t nil))))
))
;;;=========================
;;; TOUCH GESTURES
;;;=========================
(defmethod om-view-pan-handler ((self data-track-panel) position dx dy)
(let ((fact 10))
(move-rulers self :dx (* fact dx) :dy (* fact dy))))
(defmethod om-view-zoom-handler ((self data-track-panel) position zoom)
(zoom-rulers self :dx (- 1 zoom) :dy 0 :center position))
(defmethod move-rulers ((self data-track-panel) &key (dx 0) (dy 0))
(declare (ignore dy)) ;; no y-ruler
(shift-time-ruler (get-g-component (editor self) :x-ruler) dx))
;;; no y-ruler : zoom just in x
(defmethod zoom-rulers ((panel data-track-panel) &key (dx 0.1) (dy 0.1) center)
(declare (ignore dy)) ;; no y-ruler
(let ((x-ruler (get-g-component (editor panel) :x-ruler)))
(when (and x-ruler (ruler-zoom-? x-ruler))
(zoom-time-ruler x-ruler dx center panel))))
;;;======================================
;;; RECORD
;;;======================================
(defmethod can-record ((self data-track-editor)) t)
(defmethod editor-record-on ((self data-track-editor))
(let ((object (get-obj-to-play self))
(port (get-pref-value :osc :in-port))
(host nil))
(setf (record-process self)
(om-start-udp-server port host
#'(lambda (msg)
(when (equal :play (editor-play-state self))
(let ((time-ms (player-get-object-time (player self) object)))
(time-sequence-insert-timed-item-and-update
object
(make-instance 'osc-bundle :onset time-ms
:messages (process-osc-bundle (osc-decode msg) nil)))
(report-modifications self)
(update-timeline-editor self)
(editor-invalidate-views self))))
nil self))
(when (record-process self)
(om-print (format nil "Start OSC receive server on ~A ~D" host port) "DATA-TRACK")
(record-process self))))
(defmethod editor-record-off ((self data-track-editor))
(when (record-process self)
(om-print (format nil "Stop ~A" (om-process-name (record-process self))) "DATA-TRACK")
(om-stop-udp-server (record-process self))))
(defmethod notify-udp-server-stopped ((self data-track-editor) server)
(editor-record-off self))
(defmethod editor-record-on :around ((self data-track-editor))
(setf (pushed (rec-button self)) t)
(editor-invalidate-views self)
(call-next-method)
t)
(defmethod editor-record-off :around ((self data-track-editor))
(setf (pushed (rec-button self)) nil)
(editor-invalidate-views self)
(call-next-method)
t)
| 37,369 | Common Lisp | .lisp | 742 | 37.369272 | 125 | 0.54653 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 99924c424a809b5ab0e3379fb1c847b40dab8d9dd969895a74d4d234040bfee7 | 866 | [
-1
] |
867 | data-track.lisp | cac-t-u-s_om-sharp/src/player/data/data-track.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
(in-package :om)
;;;======================================
;;; DIFFERENT KIND OF DATA (FRAMES/BUNDLES)
;;;======================================
(defclass* data-frame (timed-item timed-object)
((attributes :accessor attributes :initarg :attributes :initform nil :documentation "some additional attributes for drawing etc.")))
;;; COMPAT: REPLACE THE CALLS WITH ONSET
(defmethod date ((self data-frame)) (onset self))
(defmethod (setf date) (time (self data-frame)) (setf (onset self) time))
;;; TIME-SEQUENCE API
(defmethod item-get-time ((self data-frame)) (date self))
(defmethod item-set-time ((self data-frame) time)
(setf (date self) time)
(item-set-internal-time self time))
(defmethod data-size ((self data-frame)) 1)
(defmethod data-frame-text-description ((self data-frame)) '("DATA FRAME"))
(defmethod get-frame-action ((self data-frame))
#'(lambda () nil))
(defmethod get-obj-dur ((self data-frame)) (item-get-duration self))
;;; SIMPLEST DATA FRAME
(defclass* action-bundle (data-frame)
((onset :accessor onset :initarg :onset :initform 0 :documentation "date/time of the object")
(actions :accessor actions :initarg :actions :initform nil :documentation "list of functions or lambdas"))
(:documentation "A container for a set of actions to be performed at a given time in a DATA-TRACK."))
(defmethod get-frame-action ((self action-bundle))
#'(lambda () (mapcar 'funcall (list! (actions self)))))
(defun make-action-bundle (date actions)
(make-instance 'action-bundle
:date date
:actions (list! actions)))
;;;======================================
;;; INTERNAL CLASS
;;;======================================
(defclass internal-data-track (named-object time-sequence schedulable-object)
((default-frame-type :accessor default-frame-type :initarg :default-frame-type :initform 'action-bundle)
(frames :initform nil :documentation "a list of timed data chunks")
(locked :initform nil :accessor locked)
))
;; redefine for other slots
(defmethod data-track-frames-slot ((self internal-data-track)) 'frames)
(defmethod frames ((self internal-data-track)) (slot-value self (data-track-frames-slot self)))
(defmethod (setf frames) (frames (self internal-data-track)) (setf (slot-value self (data-track-frames-slot self)) frames))
(defmethod data-track-get-frames ((self internal-data-track)) (frames self))
(defmethod data-track-set-frames ((self internal-data-track) frames)
(setf (frames self) frames)
(time-sequence-update-internal-times self)
(time-sequence-update-obj-dur self))
;;; TIME-SEQUENCE API (called by timeline editor etc.)
(defmethod time-sequence-get-timed-item-list ((self internal-data-track))
(data-track-get-frames self))
(defmethod time-sequence-set-timed-item-list ((self internal-data-track) list)
(data-track-set-frames self list))
(defmethod time-sequence-make-timed-item-at ((self internal-data-track) at)
(make-instance (default-frame-type self) :onset at))
(defmethod lock-edit ((self internal-data-track))
(setf (locked self) t))
(defmethod unlock-edit ((self internal-data-track))
(setf (locked self) nil))
;;;======================================
;;; MAIN CLASS
;;;======================================
;;; redefines the slots as :initargs
(defclass* data-track (internal-data-track named-object time-sequence schedulable-object)
((frames :initarg :frames :initform nil :documentation "a list of timed data chunks"))
(:documentation "A container and editor to organize and play data in time.
<frames> can be a list of any sub-type of DATA-FRAME, such as: ACTION-BUNDLE, OSC-BUNDLE, SDIFFRAME, MIDIEVENT/MIDI-NOTE.
<self> can be a symbol designating one of these types to create an empty DATA-TRACK of this type.
"))
;;; For backward-compatibility (patches)
(defclass* data-stream (data-track) ())
(defmethod update-reference ((ref (eql 'data-stream))) 'data-track)
;;; called after initialize-instance in OM-context
(defmethod om-init-instance ((self data-track) &optional initargs)
(let ((frames (find-value-in-kv-list initargs :frames)))
(when frames
(setf (default-frame-type self) (type-of (car frames)))
;;; => makes copies of the frames if provided as initargs
(setf (frames self) (om-copy (frames self))))
(setf (frames self) (sort (remove nil (frames self)) '< :key 'item-get-time))
(mapc #'(lambda (f) (setf (attributes f) nil)) frames))
(call-next-method))
(defmethod objFromObjs ((model symbol) (target data-track))
(if (subtypep model 'data-frame)
(make-instance (type-of target) :default-frame-type model)
(om-beep-msg "Unrecognized DATA-FRAME type: ~A" model)))
(defmethod display-modes-for-object ((self data-track))
'(:mini-view :text :hidden))
(defmethod draw-mini-view ((self data-track) (box t) x y w h &optional time)
(let* ((mid-y (+ y (/ h 2)))
(range 3)
(h 8)
(base (- mid-y (* h (round range 2))))
pos-y-list max-y min-y)
(setf pos-y-list (loop for frame in (data-track-get-frames self)
for posy = (- (get-frame-posy frame))
when (or (not max-y) (> posy max-y)) do (setf max-y posy)
when (or (not min-y) (< posy min-y)) do (setf min-y posy)
collect posy))
(om-with-fg-color (om-make-color-alpha (om-def-color :dark-blue) 0.5)
(om-draw-line x mid-y (+ x w) mid-y :style '(1 3))
(when pos-y-list
(let ((y-range (- max-y min-y)))
(multiple-value-bind (fx ox)
(conversion-factor-and-offset 0 (get-obj-dur self) (- w h) x)
(loop for frame in (data-track-get-frames self)
for posy in pos-y-list
do
(om-draw-rect (+ ox (* fx (or (date frame) 0)))
(if (zerop y-range)
(- mid-y h)
(+ base (* h (round (* range (/ (- posy min-y) y-range))))))
h h
:fill t)
)
))))))
;;;======================================
;;; OBJECT PROPERTIES
;;;======================================
(defmethod play-obj? ((self internal-data-track)) t)
(defmethod get-action-list-for-play ((object internal-data-track) interval &optional parent)
(mapcar
#'(lambda (frame)
(list (date frame)
#'(lambda () (funcall (get-frame-action frame)))))
(remove-if #'(lambda (date) (not (in-interval date interval :exclude-high-bound t)))
(data-track-get-frames object)
:key #'onset)))
;;;======================================
;;; OMMETHOD FOR PATCHES
;;;======================================
(defmethod* add-frame-in-data-track ((self internal-data-track) frame)
(time-sequence-insert-timed-item-and-update self frame)
frame)
(defmethod* add-frame-in-data-track ((self t) frame)
(om-beep-msg "ERROR: ~A is not a valid DATA-TRACK" self))
;;; when editing in mode "box" => allows updating editor
(defmethod* add-frame-in-data-track ((self omboxeditcall) frame)
(time-sequence-insert-timed-item-and-update (get-box-value self) frame)
(update-after-eval self)
frame)
(defmethod* clear-data-track ((self internal-data-track))
(data-track-set-frames self nil))
(defmethod* clear-data-track ((self t))
(om-beep-msg "ERROR: ~A is not a valid DATA-TRACK" self))
;;; when editing in mode "box" => allows updating editor
(defmethod* clear-data-track ((self omboxeditcall))
(clear-data-track (get-box-value self))
(update-after-eval self))
| 8,407 | Common Lisp | .lisp | 162 | 46.425926 | 134 | 0.614239 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 4b78369a0aa7bd72d9c9d590a9905e0d09a7a566d72b9b9f6a907579ea15d4c4 | 867 | [
-1
] |
868 | editor-player.lisp | cac-t-u-s_om-sharp/src/player/play/editor-player.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
(in-package :om)
;;;=================================
;;; AN EDITOR ASSOCIATED WITH A PLAYER
;;;=================================
(defclass play-editor-mixin ()
((player :initform nil :accessor player)
(loop-play :initform nil :accessor loop-play)
(play-interval :initform nil :accessor play-interval)
(end-callback :initform nil :accessor end-callback)
(play-button :initform nil :accessor play-button)
(pause-button :initform nil :accessor pause-button)
(stop-button :initform nil :accessor stop-button)
(time-monitor :initform nil :accessor time-monitor)
(rec-button :initform nil :accessor rec-button)
(repeat-button :initform nil :accessor repeat-button)
(next-button :initform nil :accessor next-button)
(prev-button :initform nil :accessor prev-button)
(metronome :initform nil :initarg :metronome :accessor metronome) ;; a metronome object is defined in the score package
))
(defmethod editor-make-player ((self play-editor-mixin))
(make-player :reactive-player
:run-callback 'play-editor-callback
:stop-callback 'stop-editor-callback))
(defmethod initialize-instance :after ((self play-editor-mixin) &rest initargs)
(setf (player self) (editor-make-player self)))
(defmethod editor-close ((self play-editor-mixin))
(editor-stop self)
(call-next-method))
;;; TO BE OVERRIDEN BY SUBCLASSES
(defmethod cursor-panes ((self play-editor-mixin)) nil)
;;;=====================================
;;; LOOP:
;;;=====================================
(defmethod update-play-state ((object t) (box OMBoxEditCall))
(when (editor box)
(editor-update-play-state (editor box) object)))
(defmethod update-after-eval :after ((self OMBoxEditCall))
(update-play-state (car (value self)) self))
(defmethod editor-update-play-state (editor object) nil)
(defmethod editor-update-play-state ((editor play-editor-mixin) (object schedulable-object))
(call-next-method)
(player-set-object-loop (player editor) object (loop-play editor)))
;;;=====================================
;;; HELPERS TO SEND DATA TO THE PLAYER:
;;;=====================================
(defmethod get-player-engine ((self play-editor-mixin)) nil)
(defmethod get-obj-to-play ((self play-editor-mixin)) nil)
(defmethod get-play-duration ((self play-editor-mixin))
(+ (get-obj-dur (get-obj-to-play self)) 100)) ;;; = 0 if obj = NIL
(defmethod play-selection-first ((self t)) t)
(defmethod additional-player-params ((self t)) nil)
;;; return the views to update
(defmethod play-editor-get-ruler-views ((self play-editor-mixin)) nil)
(defmethod default-editor-min-x-range ((self play-editor-mixin)) 1000)
(defmethod default-editor-x-range ((self play-editor-mixin))
(let ((play-obj (get-obj-to-play self)))
(list 0
(+ (or (get-obj-dur play-obj) 0) (default-editor-min-x-range self)))))
(defmethod reinit-x-ranges ((self play-editor-mixin))
(let ((def-range (default-editor-x-range self)))
(mapcar #'(lambda (ruler-view)
(set-ruler-range ruler-view (car def-range) (cadr def-range)))
(list! (play-editor-get-ruler-views self)))
))
(defmethod reinit-x-ranges-from-ruler ((self play-editor-mixin) ruler)
(reinit-x-ranges self))
;;;=====================================
;;; INTERVAL
;;;=====================================
(defmethod play-editor-default-interval ((self t)) '(0 0))
(defmethod get-interval-to-play ((self play-editor-mixin))
(when (and (play-selection-first self)
(play-interval self)
(get-obj-to-play self))
(if (= (car (play-interval self)) (cadr (play-interval self)))
(when (plusp (car (play-interval self)))
(list (car (play-interval self)) most-positive-fixnum ))
(play-interval self))))
(defmethod start-interval-selection ((self play-editor-mixin) view pos)
(let ((t1 (round (pix-to-x view (om-point-x pos)))))
(om-init-temp-graphics-motion
view pos nil
:motion #'(lambda (view p2)
(let ((t2 (round (pixel-to-time view (om-point-x p2)))))
(editor-set-interval self (list (min t1 t2) (max t1 t2)))))
:release #'(lambda (view pos)
(declare (ignore view pos))
(om-invalidate-view (window self)))
:min-move 10)))
(defmethod change-interval-begin ((self play-editor-mixin) view pos)
(om-init-temp-graphics-motion
view pos nil
:motion #'(lambda (view p)
(let ((t1 (round (pixel-to-time view (om-point-x p)))))
(editor-set-interval self (list t1 (cadr (play-interval self))))))
:release #'(lambda (view pos)
(declare (ignore view pos))
(editor-set-interval self (list (apply 'min (play-interval self))
(apply 'max (play-interval self))))
(om-invalidate-view (window self)))
:min-move 4))
(defmethod change-interval-end ((self play-editor-mixin) view pos)
(om-init-temp-graphics-motion
view pos nil
:motion #'(lambda (view p)
(let ((t2 (round (pixel-to-time view (om-point-x p)))))
(editor-set-interval self (list (car (play-interval self)) t2))))
:release #'(lambda (view pos)
(declare (ignore view pos))
(editor-set-interval self (list (apply 'min (play-interval self))
(apply 'max (play-interval self))))
(when (is-looping (get-obj-to-play self))
(notify-scheduler (get-obj-to-play self)))
(om-invalidate-view (window self)))
:min-move 4))
(defmethod editor-fix-interval ((self play-editor-mixin) interval &key (high-bound nil))
(list (if (car interval) (max 0 (car interval)) 0)
(if high-bound
(min (get-obj-dur (get-obj-to-play self)) (cadr interval))
(cadr interval))))
(defmethod editor-set-interval ((self t) interval) nil)
(defmethod update-cursor-pane-intervals ((self play-editor-mixin))
(let ((inter (play-interval self)))
(when inter
(mapcar #'(lambda (p)
(setf (cursor-interval p) inter)
(om-invalidate-view p))
(cursor-panes self)))))
(defmethod editor-set-interval ((self play-editor-mixin) interval)
(let ((inter (editor-fix-interval self interval)))
(setf (play-interval self) inter)
(set-object-interval (get-obj-to-play self) inter)
(update-cursor-pane-intervals self)
))
(defmethod set-cursor-time ((self play-editor-mixin) time)
(mapcar #'(lambda (pane) (update-cursor pane time)) (cursor-panes self))
(editor-invalidate-views self))
;;;=================================
;;; PLAYER CALLS
;;;=================================
(defmethod play-obj? ((self t)) nil)
(defmethod editor-play-state ((self play-editor-mixin))
(player-get-object-state (player self) (get-obj-to-play self)))
(defmethod start-box-callback ((self t)) nil)
(defmethod play-box-callback ((self t) time) nil)
(defmethod stop-box-callback ((self t)) nil)
(defmethod start-editor-callback ((self t)) nil)
(defmethod start-editor-callback ((self play-editor-mixin))
(when (pause-button self) (button-unselect (pause-button self)))
(when (play-button self) (button-select (play-button self)))
(mapcar #'start-cursor (cursor-panes self))
(when (object self) (start-box-callback (object self))))
(defmethod play-editor-callback ((self play-editor-mixin) time)
(set-time-display self time)
(mapcar #'(lambda (view) (when view (update-cursor view time))) (cursor-panes self))
(when (object self) (play-box-callback (object self) time)))
(defmethod stop-editor-callback ((self t)) nil)
(defmethod stop-editor-callback ((self play-editor-mixin))
(when (play-button self) (button-unselect (play-button self)))
(when (pause-button self) (button-unselect (pause-button self)))
(mapcar 'stop-cursor (remove nil (cursor-panes self)))
(when (object self) (stop-box-callback (object self))))
;;; never used..
(defmethod editor-callback-fun ((self play-editor-mixin))
#'(lambda (editor time)
(handler-bind ((error #'(lambda (e)
(print e)
(om-kill-process (callback-process (player self)))
(abort e))))
(play-editor-callback editor time))))
(defmethod editor-play ((self play-editor-mixin))
(let ((object (get-obj-to-play self)))
(when (play-obj? object)
(start-editor-callback self)
(if (equal (player-get-object-state (player self) object) :pause)
(progn
(player-continue-object (player self) object)
(when (metronome self)
(player-continue-object (player self) (metronome self))))
(let ((interval (get-interval-to-play self)))
(when (metronome self)
(player-play-object (player self) (metronome self) nil :interval interval))
(player-set-object-loop (player self) object (loop-play self))
(player-play-object (player self) object self :interval interval)
(player-start (player self) :start-t (or (car interval) 0) :end-t (cadr interval)))
))))
(defmethod editor-pause ((self play-editor-mixin))
(when (play-button self) (button-unselect (play-button self)))
(when (pause-button self) (button-select (pause-button self)))
(when (metronome self)
(player-pause-object (player self) (metronome self)))
(player-pause-object (player self) (get-obj-to-play self)))
;;; this is called sometimes to reset by security..
(defmethod editor-stop ((self t)) nil)
(defmethod editor-stop ((self play-editor-mixin))
(stop-editor-callback self)
(when (not (equal :stop (player-get-object-state (player self) (get-obj-to-play self))))
(player-stop-object (player self) (get-obj-to-play self)))
(when (and (metronome self)
(not (equal :stop (player-get-object-state (player self) (metronome self)))))
(player-stop-object (player self) (metronome self)))
(let ((start-time (or (car (play-interval self)) (car (play-editor-default-interval self)))))
(set-time-display self start-time)
(mapcar #'(lambda (view) (update-cursor view start-time)) (cursor-panes self)))
)
(defmethod editor-play/stop ((self play-editor-mixin))
(if (not (eq (player-get-object-state (player self) (get-obj-to-play self)) :stop))
(editor-stop self)
(editor-play self)))
(defmethod editor-play/pause ((self play-editor-mixin))
(if (not (eq (player-get-object-state (player self) (get-obj-to-play self)) :play))
(editor-play self)
(editor-pause self)))
;;; FUNCTIONS TO DEFINE BY THE EDITORS
(defmethod editor-next-step ((self play-editor-mixin)) nil)
(defmethod editor-previous-step ((self play-editor-mixin)) nil)
(defmethod editor-set-loop ((self play-editor-mixin) t-or-nil)
(setf (loop-play self) t-or-nil)
(player-set-object-loop (player self) (get-obj-to-play self) t-or-nil))
(defmethod editor-reset-interval ((self play-editor-mixin))
(editor-set-interval self (play-editor-default-interval self))
(mapcar 'reset-cursor (cursor-panes self)))
(defmethod editor-reset-cursor ((self play-editor-mixin))
(mapcar 'stop-cursor (cursor-panes self)))
(defmethod editor-key-action :around ((self play-editor-mixin) key)
(case key
(#\Space (editor-play/pause self) t)
(#\p (editor-play/pause self) t)
(#\s (editor-stop self) t)
(:om-key-esc
(when (eq (player-get-object-state (player self) (get-obj-to-play self)) :stop)
(if (equal '(0 0) (play-interval self))
(call-next-method) ;; if the interval is already reset: check if there is another 'escape' to do
(editor-reset-interval self)))
(editor-stop self)
(call-next-method)
t)
(otherwise (call-next-method))
))
;;;===================================
; VIEW WITH CURSOR
;;;===================================
(defclass x-cursor-graduated-view (x-graduated-view om-transient-drawing-view)
((cursor-mode :initform :normal :accessor cursor-mode :initarg :cursor-mode) ;; :normal ou :interval
(cursor-interval :initform '(0 0) :accessor cursor-interval)
(cursor-interval-fill-color :accessor cursor-interval-fill-color :initarg :cursor-interval-fill-color
:initform (om-make-color-alpha (om-def-color :gray) 0.2))
(cursor-interval-lines-color :accessor cursor-interval-lines-color :initarg :cursor-interval-lines-color
:initform (om-make-color 0.4 0.2 0.2))
(cursor-pos :initform 0 :accessor cursor-pos))
(:default-initargs :fit-size-to-children nil))
(defmethod time-to-pixel ((self x-cursor-graduated-view) time)
(x-to-pix self time))
;++++++++++++++++++++++++++++++++
; RULES FOR THE CURSOR:
; - Set cursot at a position = click on the view
; - Move cursor = click and drag on it
; - Set a new interval/start point = double-click on the view
; - Change existing interval : click and drag on begin or end
; - Reset cursor = escape
; - Reset interval = 2nd escape
;++++++++++++++++++++++++++++++++
(defmethod draw-cursor-line ((self x-cursor-graduated-view) position size)
(om-draw-line (om-point-x position) (om-point-y position)
(om-point-x position)
(+ (om-point-y position) (om-point-y size))
:color (om-make-color 0.8 0.5 0.5)))
(defmethod drag-move-cursor ((self x-cursor-graduated-view) position)
(om-init-temp-graphics-motion
self position nil
:motion #'(lambda (view p)
(declare (ignore view))
(let ((t1 (round (pix-to-x self (om-point-x p)))))
(set-cursor-time (editor self) t1)))
:release #'(lambda (view pos)
(declare (ignore view pos))
(om-invalidate-view (window (editor self))))
:min-move 4))
(defmethod start-cursor ((self x-cursor-graduated-view))
(om-stop-transient-drawing self)
(om-start-transient-drawing
self #'draw-cursor-line
(omp (time-to-pixel self (or (car (cursor-interval self)) 0)) 0)
(omp 2 (h self))))
(defmethod stop-cursor ((self x-cursor-graduated-view))
(om-stop-transient-drawing self)
(om-invalidate-view self))
(defmethod reset-cursor ((self x-cursor-graduated-view))
(update-cursor self 0))
(defmethod om-view-resized :after ((self x-cursor-graduated-view) size)
(om-update-transient-drawing
self
:x (time-to-pixel self (cursor-pos self))
:h (om-point-y size)))
(defmethod update-cursor ((self x-cursor-graduated-view) time &optional y1 y2)
(unless (= (cursor-pos self) time)
(setf (cursor-pos self) time))
(unless ;; return nil if there was nothing to draw!
(om-update-transient-drawing self :x (time-to-pixel self (cursor-pos self)))
;;; restart and try again
(start-cursor self)
(om-update-transient-drawing self :x (time-to-pixel self (cursor-pos self)))
))
(defmethod update-view-from-ruler ((self x-ruler-view) (view x-cursor-graduated-view))
(om-update-transient-drawing view :x (time-to-pixel view (cursor-pos view)))
(call-next-method))
(defmethod pixel-to-time ((self x-cursor-graduated-view) x)
(round (pix-to-x self x)))
(defmethod om-draw-contents :after ((self x-cursor-graduated-view))
(when (and (play-obj? (get-obj-to-play (editor (om-view-window self))))
(cursor-interval self))
(let ((t1 (car (cursor-interval self)))
(t2 (cadr (cursor-interval self))))
(unless (= t1 t2 0)
(let ((i1 (time-to-pixel self (car (cursor-interval self))))
(i2 (time-to-pixel self (cadr (cursor-interval self)))))
(om-with-fg-color (cursor-interval-lines-color self)
(om-with-line '(3 3)
(om-with-line-size 1
(om-draw-line i1 0 i1 (h self))
(om-draw-line i2 0 i2 (h self)))))
(om-draw-rect i1 0 (- i2 i1) (h self) :fill t :color (cursor-interval-fill-color self))
(unless t ;(equal (editor-play-state (editor self)) :play)
;; => never do that, when play is stopped
(draw-cursor-line self
(omp (time-to-pixel self (cursor-pos self)) 0)
(omp 4 (h self)))
)
)))))
;;; return T if detected/did something
(defmethod handle-selection-extent ((self x-cursor-graduated-view) position)
(when (cursor-interval self)
(let ((tpl-editor (editor (om-view-window self)))
(bx (time-to-pixel self (car (cursor-interval self))))
(ex (time-to-pixel self (cadr (cursor-interval self)))))
(cond ((om-point-in-line-p position (omp ex 0) (omp ex (h self)) 4)
(change-interval-end tpl-editor self position)
t)
((om-point-in-line-p position (omp bx 0) (omp bx (h self)) 4)
(change-interval-begin tpl-editor self position)
t)
(t
;(set-cursor-time tpl-editor (pixel-to-time self (om-point-x position)))
;(start-interval-selection tpl-editor self position)
nil
)))))
(defmethod om-view-click-handler ((self x-cursor-graduated-view) position)
(handle-selection-extent self position))
(defmethod om-transient-drawing-item-clicked ((self x-cursor-graduated-view) clicked-pos-in-view)
(drag-move-cursor self clicked-pos-in-view))
(defmethod om-view-doubleclick-handler ((self x-cursor-graduated-view) position)
(let ((time (max 0 (pixel-to-time self (om-point-x position))))
(tpl-editor (editor self)) ;; we assume it is an OMEditorView...
)
(editor-set-interval tpl-editor (list time time))
(set-cursor-time tpl-editor time)
(editor-stop tpl-editor)
(call-next-method)))
(defmethod override-interval-interaction ((self x-cursor-graduated-view) position) nil)
(defmethod om-view-mouse-motion-handler :around ((self x-cursor-graduated-view) position)
(if (and (cursor-interval self)
(let ((bx (time-to-pixel self (car (cursor-interval self))))
(ex (time-to-pixel self (cadr (cursor-interval self)))))
(or (om-point-in-line-p position (omp bx 0) (omp bx (h self)) 4)
(om-point-in-line-p position (omp ex 0) (omp ex (h self)) 4)))
(not (override-interval-interaction self position)))
(om-set-view-cursor self (om-get-cursor :h-size))
(progn
(om-set-view-cursor self (om-view-cursor self))
(call-next-method))))
;;;=================================
;;; STANDARDIZED PLAY CONTROLS
;;;=================================
;;; inserts teh button in a view, so it can be in a simple layout
(defun make-button-view (button)
(om-make-view 'om-view
:size (om-view-size button)
:subviews (list button)))
(defmethod make-play-button ((editor play-editor-mixin) &key size enable)
(make-button-view
(setf (play-button editor)
(om-make-graphic-object 'om-icon-button :size (or size (omp 16 16))
:icon :icon-play-black
:icon-pushed :icon-play-green
:icon-disabled :icon-play-gray
:lock-push t :enabled enable
:pushed (equal (player-get-object-state (player editor) (get-obj-to-play editor)) :play)
:action #'(lambda (b)
(declare (ignore b))
(editor-play editor))))))
(defmethod make-pause-button ((editor play-editor-mixin) &key size enable)
(make-button-view
(setf (pause-button editor)
(om-make-graphic-object 'om-icon-button :size (or size (omp 16 16))
:icon :icon-pause-black :icon-pushed :icon-pause-orange :icon-disabled :icon-pause-gray
:lock-push t :enabled enable
:pushed (equal (player-get-object-state (player editor) (get-obj-to-play editor)) :pause)
:action #'(lambda (b)
(declare (ignore b))
(editor-pause editor))))))
(defmethod make-stop-button ((editor play-editor-mixin) &key size enable)
(make-button-view
(setf (stop-button editor)
(om-make-graphic-object 'om-icon-button :size (or size (omp 16 16))
:icon :icon-stop-black :icon-pushed :icon-stop-orange :icon-disabled :icon-stop-gray
:lock-push nil :enabled enable
:action #'(lambda (b)
(declare (ignore b))
(when (pause-button editor) (button-unselect (pause-button editor)))
(when (play-button editor) (button-unselect (play-button editor)))
(editor-stop editor))))))
(defmethod make-previous-button ((editor play-editor-mixin) &key size enable)
(make-button-view
(setf (prev-button editor)
(om-make-graphic-object 'om-icon-button :size (or size (omp 16 16))
:icon :icon-previous-black :icon-pushed :icon-previous-white :icon-disabled :icon-previous-gray
:lock-push nil :enabled enable
:action #'(lambda (b)
(declare (ignore b))
(editor-previous-step editor))))))
(defmethod make-next-button ((editor play-editor-mixin) &key size enable)
(make-button-view
(setf (next-button editor)
(om-make-graphic-object 'om-icon-button :size (or size (omp 16 16))
:icon :icon-next-black :icon-pushed :icon-next-white :icon-disabled :icon-next-gray
:lock-push nil :enabled enable
:action #'(lambda (b)
(declare (ignore b))
(editor-next-step editor))))))
(defmethod make-rec-button ((editor play-editor-mixin) &key size enable record-fun)
(make-button-view
(setf (rec-button editor)
(om-make-graphic-object 'om-icon-button :size (or size (omp 16 16))
:icon :icon-record-black :icon-pushed :icon-record-red :icon-disabled :icon-record-gray
:lock-push t :enabled enable
:action (when record-fun
#'(lambda (b)
(funcall record-fun (pushed b)))
)))))
(defmethod make-repeat-button ((editor play-editor-mixin) &key size enable)
(make-button-view
(setf (repeat-button editor)
(om-make-graphic-object 'om-icon-button :size (or size (omp 16 16))
:icon :icon-repeat-black :icon-pushed :icon-repeat-blue :icon-disabled :icon-repeat-gray
:lock-push t :enabled enable
:pushed (loop-play editor)
:action #'(lambda (b)
(editor-set-loop editor (pushed b)))))))
(defun time-display (time_ms &optional format)
(multiple-value-bind (time_s ms)
(floor (round time_ms) 1000)
(multiple-value-bind (time_m s)
(floor time_s 60)
(multiple-value-bind (h m)
(floor time_m 60)
(list h m s ms)
(if format
(format nil "~2,'0dh~2,'0dm~2,'0ds~3,'0d" h m s ms)
(if (= h 0)
(format nil "~2,'0d:~2,'0d:~3,'0d" m s ms)
(format nil "~2,'0d:~2,'0d:~2,'0d:~3,'0d" h m s ms)))))))
(defmethod make-time-monitor ((editor play-editor-mixin) &key time color background font (h 20))
(setf (time-monitor editor)
(om-make-di 'om-simple-text :size (omp 76 h)
:text (if time (time-display time) "")
:font (or font (om-def-font :gui))
:bg-color background
:fg-color (or color (om-def-color :black)))))
(defmethod set-time-display ((self play-editor-mixin) time)
(when (time-monitor self)
(om-set-dialog-item-text (time-monitor self) (if time (time-display time) ""))))
(defmethod enable-play-controls ((self play-editor-mixin) t-or-nil)
(mapc
#'(lambda (b) (when b (setf (enabled b) t-or-nil) (om-invalidate-view b)))
(list (play-button self)
(pause-button self)
(stop-button self)
(rec-button self)
(repeat-button self)
(prev-button self)
(next-button self)))
(when (time-monitor self)
(set-time-display self (if t-or-nil 0 nil))))
;;;==========================
;;; A RULER WITH TIME GRADUATION + MOVING CURSOR
;;;==========================
(defclass time-ruler (x-ruler-view x-cursor-graduated-view)
((unit :accessor unit :initform :ms :initarg :unit)
(bottom-p :accessor bottom-p :initform t :initarg :bottom-p) ;bottom-p indicates if the arrow need to be on the top or the bottom (default is on the top)
(markers-p :accessor markers-p :initform t :initarg :markers-p) ;use or not markers
(markers-count-object-onset-p
:accessor markers-count-object-onset-p :initform t :initarg :markers-count-object-onset-p
:documentation "if T, markers will consider the objet onset for placement (e.g. in a sequencer)")
(snap-to-grid :accessor snap-to-grid :initform t :initarg :snap-to-grid)
(selected-time-markers :accessor selected-time-markers :initform nil))
(:default-initargs :vmin 0))
(defmethod start-cursor ((self time-ruler)) nil)
(defmethod pixel-to-time ((self time-ruler) x)
(round (pix-to-x self x)))
(defmethod unit-value-str ((self time-ruler) value &optional (unit-dur 0))
(if (equal (unit self) :ms) (call-next-method)
(if (> unit-dur 100) (format nil "~d" (round (/ value 1000.0)))
(format nil
(cond ((= unit-dur 100) "~1$")
((= unit-dur 10) "~2$")
((= unit-dur 1) "~3$")
(t "~0$"))
(/ value 1000.0)))))
(defmethod om-draw-contents ((self time-ruler))
;draw the markers
(when (markers-p self)
(loop for marker in (get-all-time-markers self)
do
(let ((pos (time-to-pixel self marker)))
(om-with-fg-color (om-make-color 0.9 0.7 0 (if (find marker (selected-time-markers self)) 1 0.45))
(om-draw-line pos 0 pos (h self))
(if (bottom-p self)
(om-draw-polygon (list (omp (- pos 4) 0)
(omp (- pos 4) (- (h self) 5))
(omp pos (h self))
(omp (+ pos 4) (- (h self) 5))
(omp (+ pos 4) 0) )
:fill t)
(om-draw-polygon (list (omp (- pos 4) (h self))
(omp (- pos 4) 5)
(omp pos 0)
(omp (+ pos 4) 5)
(omp (+ pos 4) (h self)))
:fill t)
)))))
;draw the play head
;(let ((pos (x-to-pix self (cursor-pos self))))
; (om-with-fg-color (om-make-color 1 1 1 0.5)
; (if (bottom-p self)
; (om-draw-polygon (list (omp (- pos 5) (- (h self) 5))
; (omp (+ pos 5) (- (h self) 5))
; (omp pos (h self)))
; :fill t)
; (om-draw-polygon (list (omp (- pos 5) 5)
; (omp (+ pos 5) 5)
; (omp pos 0))
; :fill t)))
; (call-next-method))
(call-next-method)
)
(defmethod draw-grid-from-ruler ((self om-view) (ruler time-ruler))
(when (markers-p ruler)
(loop for marker in (get-all-time-markers ruler)
do
(let ((pos (time-to-pixel ruler marker)))
(om-with-fg-color (om-make-color 0.9 0.7 0 (if (find marker (selected-time-markers ruler)) 1 0.45))
(om-draw-line pos 0 pos (h self))))))
(om-with-line '(2 2)
(call-next-method)))
;;;=================================
; SNAP TO GRID FUNCITONNALITIES
;;;=================================
(defmethod snap-time-to-grid ((ruler time-ruler) time &optional (snap-delta nil))
;returns a time value corresponding to the given time aligned on the grid with a delta (in ms) treshold.
;default treshold is a tenth of the grid
(let* ((unit-dur (get-units ruler))
(delta (if snap-delta (min snap-delta (/ unit-dur 2)) (/ unit-dur 8)))
(offset (mod time unit-dur)))
(if (> offset (- unit-dur delta))
(- (+ time unit-dur) offset)
(if (< offset delta)
(- time offset)
time))))
(defmethod snap-time-to-markers ((ruler time-ruler) time &optional (snap-delta nil) (source-time nil))
(let* ((unit-dur (get-units ruler))
(delta (if snap-delta (min snap-delta (/ unit-dur 2)) (/ unit-dur 8)))
(markers (get-all-time-markers ruler))
(pos nil)
(pre-marker nil)
(post-marker nil))
(when source-time
(let ((src-pos (position source-time markers)))
(when src-pos
(setf markers (remove-nth src-pos markers)))))
(setf pos (or (position time markers :test '<= ) (length markers)))
(when (> pos 0)
(setf pre-marker (nth (1- pos) markers)))
(when (< pos (1- (length markers)))
(setf post-marker (nth pos markers)))
(if (and pre-marker (< (- time pre-marker) delta))
pre-marker
(if (and post-marker (< (- post-marker time) delta))
post-marker
time))))
(defmethod snap-time-to-grid-and-markers ((ruler time-ruler) time &optional (snap-delta nil) (source-time nil))
(let* ((time-grid (snap-time-to-grid ruler time snap-delta))
(time-marker (snap-time-to-markers ruler time snap-delta source-time))
(d1 (if (equal time time-grid) most-positive-fixnum (abs (- time time-grid))))
(d2 (if (equal time time-marker) most-positive-fixnum (abs (- time time-marker)))))
(if (<= d2 d1) time-marker time-grid)))
;utilities to adapt dt for snap to grid functionnalities
(defmethod adapt-dt-for-grid ((ruler time-ruler) selected-point-time dt)
(let* ((newt (+ selected-point-time dt))
(newt-grid (snap-time-to-grid ruler newt nil))
(offset (- newt-grid newt)))
(+ dt offset)))
(defmethod adapt-dt-for-markers ((ruler time-ruler) selected-point-time dt)
(let* ((newt (+ selected-point-time dt))
(newt-grid (snap-time-to-markers ruler newt nil selected-point-time))
(offset (- newt-grid newt)))
(+ dt offset)))
(defmethod adapt-dt-for-grid-and-markers ((ruler time-ruler) selected-point-time dt &optional snap-delta)
(let* ((newt (+ selected-point-time dt))
(newt-grid (snap-time-to-grid-and-markers ruler newt snap-delta selected-point-time))
(offset (- newt-grid newt)))
(+ dt offset)))
;;; CALLED BY PAN/ZOOM GESTURES
(defmethod shift-time-ruler ((self time-ruler) dx)
(let ((dxx (* (/ dx (w self)) (- (v2 self) (v1 self)))))
(unless (or (and (plusp dxx) (vmin self) (= (vmin self) (v1 self)))
(and (minusp dxx) (vmax self) (= (vmax self) (v2 self))))
(set-ruler-range self
(if (vmin self) (max (vmin self) (- (v1 self) dxx)) (- (v1 self) dxx))
(if (vmax self) (min (vmax self) (- (v2 self) dxx)) (- (v2 self) dxx))))
))
(defmethod zoom-time-ruler ((self time-ruler) dx center view)
(let* ((position (or center (omp (* (w view) .5) (* (h view) .5))))
(x-pos (pix-to-x view (om-point-x position)))
(curr-w (- (x2 view) (x1 view)))
(new-w (round (* curr-w (1+ dx))))
(new-x1 (round (- x-pos (/ (* (- x-pos (x1 view)) new-w) curr-w)))))
(set-ruler-range self new-x1 (+ new-x1 new-w))
))
;;;=================================
;;; TIME MARKERS API
;;;=================================
;TO USE MARQUERS :
;1) Have a child class of timed-objects and overload the get-time-markers method
;2) Have a child class of x-graduated view and overload the following methods
(defmethod get-time-markers ((self t))
"returns the list of time markers in an object"
nil)
(defmethod get-elements-for-marker ((self timed-object) marker)
"returns a list of one or more elements in the object that correspond to the marker"
nil)
(defmethod translate-elements-from-time-marker ((self timed-object) elems dt)
"translates elements from a time marker with dt"
(declare (ignore elems))
(setf (onset self) (max 0 (+ (onset self) dt))))
(defmethod get-timed-objects-with-markers ((self x-graduated-view))
"returns a list of timed-object containing markers"
nil)
(defmethod select-elements-at-time ((self x-cursor-graduated-view) marker-time)
"selects the elements with same time than the marker-time"
nil)
;;; optional
(defmethod clear-editor-selection ((self OMEditor))
(set-selection self nil))
(defmethod get-editor-for-graduated-view ((self x-graduated-view))
"returns the editor handling the graduated view/selection and translation for timed-objects"
(editor self))
;;;=================================
;;; ACTIONS ands Utilities
;;;=================================
;;; after undo/redo
(defmethod update-after-state-change ((self play-editor-mixin))
(notify-scheduler (get-obj-to-play self))
(call-next-method))
(defmethod get-related-views-editors ((self time-ruler))
(remove-duplicates (remove nil (loop for rv in (related-views self) collect (get-editor-for-graduated-view rv)))))
(defmethod select-elements-from-marker ((self time-ruler) marker-time)
(loop for ed in (get-related-views-editors self) do
(clear-editor-selection ed))
(loop for rv in (related-views self) do
(select-elements-at-time rv marker-time)))
(defmethod get-onset ((self timed-object)) (onset self))
(defmethod get-onset ((self OMBox)) (get-box-onset self))
(defmethod get-all-time-markers ((self time-ruler))
(sort (remove nil (flat (loop for view in (related-views self)
collect
(loop for timed-obj in (get-timed-objects-with-markers view)
collect
(if (markers-count-object-onset-p self)
(om+ (get-time-markers timed-obj) (get-onset timed-obj))
(get-time-markers timed-obj))
)))) '<))
(defmethod find-marker-at-time ((self time-ruler) time)
;gets the first marker for each related views that is close of 5pix to the position of the mouse.
(let ((delta-t (dpix-to-dx self 5)))
(loop for marker-time in (get-all-time-markers self)
when (and (<= time (+ delta-t marker-time)) (>= time (- marker-time delta-t)))
return marker-time
)))
(defmethod get-schedulable-object ((self OMBox)) (get-obj-to-play self))
(defmethod get-schedulable-object ((self schedulable-object)) self)
(defmethod get-schedulable-object ((self t)) nil)
(defmethod translate-from-marker-action ((self time-ruler) marker position)
(let* ((ref-time (pix-to-x self (om-point-x position)))
(objs (remove nil (flat (loop for rv in (related-views self)
collect
(get-timed-objects-with-markers rv)))))
(obj-elem-list
(remove nil
(loop for obj in objs collect
(let ((matching-elements
(get-elements-for-marker
obj
(if (markers-count-object-onset-p self)
(om- marker (get-onset obj)) marker))))
(when matching-elements
(list obj matching-elements (get-schedulable-object obj)))))))
(move nil))
(om-init-temp-graphics-motion
self position nil
:min-move 4
:motion #'(lambda (view pos)
(let* ((tmp_time (pixel-to-time view (om-point-x pos)))
(dt (round (- tmp_time ref-time)))
(new-dt (if (snap-to-grid self) (adapt-dt-for-grid-and-markers self marker dt) dt)))
(unless (zerop new-dt)
(loop for item in obj-elem-list do
(let ((obj (car item))
(elem (cadr item)))
(translate-elements-from-time-marker obj elem new-dt)))
(loop for ed in (get-related-views-editors self)
do (update-to-editor ed self))
(setf (selected-time-markers self)
(replace-in-list (selected-time-markers self)
(+ marker new-dt)
(position marker (selected-time-markers self))))
(setf marker (+ marker new-dt))
(setf ref-time (+ ref-time new-dt))
(setf move t)
(mapcar 'om-invalidate-view (related-views self))
(om-invalidate-view self))))
:release #'(lambda (view pos)
(declare (ignore view pos))
(when move
(loop for item in obj-elem-list do
(notify-scheduler (nth 2 item))))
)
)))
;=========
; EVENTS
;=========
(defmethod om-view-click-handler ((self time-ruler) position)
(if (markers-p self)
(let* ((time (pix-to-x self (om-point-x position)))
(marker (find-marker-at-time self time)))
(if marker
(progn
(setf (selected-time-markers self) (list marker))
(select-elements-from-marker self marker)
(translate-from-marker-action self marker position))
(call-next-method)))
(call-next-method)))
(defmethod om-view-mouse-leave-handler ((self time-ruler))
(om-set-view-cursor self nil))
(defmethod om-view-mouse-motion-handler ((self time-ruler) pos)
(when (markers-p self)
(if (find-marker-at-time self (pix-to-x self (om-point-x pos)))
(om-set-view-cursor self nil)
(om-set-view-cursor self (om-view-cursor self)))))
| 39,762 | Common Lisp | .lisp | 772 | 41.778497 | 156 | 0.581576 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 7faf1faf736c74e8d5dfa87180c2eeaf3627bcbba0068fdc8f4e7868bb6aecbd | 868 | [
-1
] |
869 | box-player.lisp | cac-t-u-s_om-sharp/src/player/play/box-player.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson, D. Bouche
;============================================================================
(in-package :om)
;;;=================================
;;; GENERAL PLAYER: USED IN PATCH EDITORS
;;;=================================
(defvar *general-player* nil)
(defvar *play-boxes* nil)
(defun init-om-player ()
(setf *general-player*
(make-player :reactive-player
:run-callback 'play-editor-callback
:callback-tick 50
:stop-callback 'stop-editor-callback)))
;(register *general-player*)
(defun abort-om-player ()
(destroy-player *general-player*)
(setf *general-player* nil))
;(abort-om-player)
;(init-om-player)
(add-om-init-fun 'init-om-player)
(defmethod get-obj-to-play ((self ombox))
(play-obj-from-value (car (value self)) self))
(defmethod play-obj-from-value (val box) val)
;;; when the value of a box is another box...
(defmethod play-obj-from-value ((val ombox) box)
(unless (equal (car (value val)) box) ;;; can happen, with "MY-BOX" !
(play-obj-from-value (car (value val)) box)))
(defmethod play-box? ((self t)) nil)
(defmethod play-box? ((self OMBoxEditCall)) t)
(defmethod get-obj-dur ((self t)) 0)
(defmethod get-obj-dur ((self ombox))
(if (play-obj? (get-obj-to-play self))
(get-obj-dur (get-obj-to-play self))
0))
(defmethod additional-player-params ((self omboxeditcall))
(list :port (get-edit-param self :outport)
:approx (get-edit-param self :approx)))
(defmethod play-box-callback ((self OMBox) time)
(handler-bind ((error #'(lambda (e)
(print (format nil "~A" e))
;(om-kill-process (callback-process *general-player*))
(abort e))))
(let* ((frame (frame self)))
(set-box-play-time frame time) ; (- time (play-state box))))
(om-invalidate-view frame))
))
(defmethod start-box-callback ((self OMBox))
(setf (play-state self) t)
(when (frame self)
(om-invalidate-view (frame self))))
(defmethod stop-box-callback ((self OMBox))
(setf (play-state self) nil)
(when (frame self)
(set-box-play-time (frame self) 0)
(om-invalidate-view (frame self))))
;;; called from the system / user
(defun box-player-start (box)
(when box
(start-box-callback box)
(when (editor box) (start-editor-callback (editor box)))
))
(defun box-player-stop (box)
(when box
(stop-box-callback box)
(when (editor box) (stop-editor-callback (editor box)))
))
;;; called by the player
(defmethod play-editor-callback ((self OMBox) time)
(play-box-callback self time)
(when (editor self) (play-editor-callback (editor self) time)))
(defmethod stop-editor-callback ((self OMBox))
(box-player-stop self)
(when (editor self) (stop-editor-callback (editor self))))
;;; called from an action
(defmethod play-boxes ((boxlist list))
(let ((list2play (remove-if-not 'play-box? boxlist)))
(mapcar #'(lambda (box)
(when (play-obj? (get-obj-to-play box))
(player-play-object *general-player* (get-obj-to-play box) box)
(box-player-start box)
(push box *play-boxes*)
))
list2play)
(when *play-boxes*
(player-start *general-player*)
)))
(defmethod stop-boxes ((boxlist list))
(mapc #'(lambda (box)
(when (play-obj? (get-obj-to-play box))
(player-stop-object *general-player* (get-obj-to-play box))
;;; ABORT THE OBJECT !!
(box-player-stop box)
(setf *play-boxes* (remove box *play-boxes*))
))
boxlist)
(unless *play-boxes* (player-stop *general-player*)))
(defmethod play/stop-boxes ((boxlist list))
(let ((play-boxes (remove-if-not 'play-box? boxlist)))
(if (find-if 'play-state play-boxes)
;;; stop all
(mapc #'(lambda (box)
(player-stop-object *general-player* (get-obj-to-play box))
(box-player-stop box)
)
play-boxes)
;;; start all
(mapc #'(lambda (box)
(when (play-obj? (get-obj-to-play box))
(player-play-object *general-player* (get-obj-to-play box) box)
(box-player-start box))
)
play-boxes))))
(defmethod stop-all-boxes ()
(stop-boxes *play-boxes*))
| 5,094 | Common Lisp | .lisp | 127 | 33.551181 | 82 | 0.571805 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 972774f65a75521cb67dee6d5697aee07324ae34698d8412343612737c08bd7f | 869 | [
-1
] |
870 | general-player.lisp | cac-t-u-s_om-sharp/src/player/play/general-player.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: J. Bresson
;============================================================================
(in-package :om)
;;;=================================
;;; MAIN PLAYER
;;;=================================
;;; METHODS TO REDEFINE
(defgeneric make-player (id &key run-callback stop-callback callback-tick time-window))
(defmethod destroy-player (player) nil)
(defmethod player-set-time-interval (player from to))
(defmethod player-get-time (player) 0)
(defmethod player-get-state (player) t)
(defmethod player-get-object-state (player object) nil)
(defmethod player-idle-p (player) t)
(defmethod player-stop-object (player object) t)
(defmethod player-add-callback (player) t)
(defmethod player-remove-callback (player) t)
(defmethod player-reset (player) t)
(defmethod player-start (player &key start-t end-t) (declare (ignore start-t end-t)))
(defmethod player-stop (player))
(defmethod player-pause (player))
(defmethod player-continue (player))
(defmethod player-loop (player))
(defmethod player-start-record (player))
(defmethod player-stop-record (player))
;;; RETURN A LIST OF ACTIONS + TIME FOR AN OBJECT TO BE PLAYED
(defmethod get-action-list-for-play (object interval &optional parent) nil)
(defmethod player-play-object (engine object caller &key parent interval)
(declare (ignore parent interval))
(om-print (format nil "NO RENDERER FOR ~A" object)))
;(defmethod player-stop-object ((engine t) &optional objects) nil)
;;;=================================
;;; DEFAULT PLAYER
;;; (simple loop on a list of events)
;;; This player is actually not used anymore
;;;=================================
(defclass omplayer ()
((state :accessor state :initform :stop) ; :play :pause :stop :record
(loop-play :accessor loop-play :initform nil)
(start-time :accessor start-time :initform 0)
(stop-time :accessor stop-time :initform 0)
(play-interval :accessor play-interval :initform nil) ;;; check if this is necessary or if we can do everything with start-time and end-time....
(player-offset :accessor player-offset :initform 0)
(ref-clock-time :accessor ref-clock-time :initform 0)
;;; CALLBACKS
(callback-tick :initform 0.1 :accessor callback-tick :initarg :callback-tick)
(caller :initform nil :accessor caller :initarg :caller)
(callback-fun :initform nil :accessor callback-fun :initarg :callback-fun)
(callback-process :initform nil :accessor callback-process)
(stop-fun :initform nil :accessor stop-fun :initarg :stop-fun)
;;; SCHEDULING TASKS
(events :initform nil :accessor events :initarg :events)
(scheduling-process :initform nil :accessor scheduling-process)
(scheduler-tick :initform 0.01 :accessor scheduler-tick :initarg :scheduler-tick)
;;; OBJECTS
(play-list :initform nil :accessor play-list :initarg :play-list)
))
(defmethod sort-events ((self omplayer))
(setf (events self) (sort (events self) '< :key 'car)))
(defmethod schedule-task ((player omplayer) task at &optional (sort t))
(push (cons at task) (events player))
(when sort (sort-events player)))
(defmethod unschedule-all ((player omplayer))
(setf (events player) nil))
(defun get-my-play-list (engine play-list)
(mapcar 'cadr (remove-if-not #'(lambda (x) (equal x engine)) play-list :key 'car)))
(defmethod make-player ((id t) &key run-callback stop-callback (callback-tick 0.05) time-window)
(declare (ignore time-window))
(make-instance 'omplayer
:callback-fun run-callback
:callback-tick callback-tick
:stop-fun stop-callback))
(defun clock-time () (om-get-internal-time))
(defmethod player-get-time ((player omplayer))
(cond ((equal (state player) :play)
(+ (player-offset player) (start-time player) (- (clock-time) (ref-clock-time player))))
((equal (state player) :pause)
(+ (player-offset player) (start-time player)))
(t 0)))
(defmethod player-get-object-time ((player omplayer) object)
(player-get-time player))
(defmethod player-get-state ((player omplayer)) (state player))
(defmethod player-set-time-interval ((player omplayer) from to)
(setf (play-interval player) (list from to)))
(defmethod player-idle-p ((self omplayer))
(not (member (state self) '(:play :record))))
(defmethod player-schedule-tasks ((player omplayer) object tasklist)
(loop for task in tasklist do (schedule-task player (cadr task) (car task))))
;;; CALLED WHEN THE PLAYER HAS TO PLAY SEVERAL THINGS OR PREPARE THEM IN ADVANCE
(defmethod player-play-object ((player omplayer) obj caller &key parent interval)
(setf (caller player) caller)
(player-schedule-tasks player obj (get-action-list-for-play obj interval parent)))
(defmethod player-get-object-state ((player omplayer) object) (state player))
(defmethod player-stop-object ((player omplayer) object) (player-stop player))
(defmethod player-pause-object ((player omplayer) object) (player-pause player))
(defmethod player-continue-object ((player omplayer) object) (player-continue player))
(defmethod player-loop-object ((player omplayer) object) (player-loop player))
(defmethod player-set-object-loop ((player omplayer) object loop?)
(declare (ignore object))
(setf (loop-play player) loop?))
;;; CALLED TO START PLAYER
(defmethod player-start ((player omplayer) &key (start-t 0) (end-t 3600000))
(cond ((equal (state player) :play)
(setf (stop-time player) (max (stop-time player) (or end-t 0))))
(t
(when end-t (setf (stop-time player) end-t))
(when (callback-process player)
(om-kill-process (callback-process player)))
(when (scheduling-process player)
(om-kill-process (scheduling-process player)))
(setf (scheduling-process player)
(om-run-process "player scheduling"
#'(lambda ()
(loop
(loop while (and (events player) (>= (player-get-time player) (car (car (events player))))) do
(funcall (cdr (pop (events player)))))
(when (and (stop-time player) (> (player-get-time player) (stop-time player)))
(if (loop-play player) (player-loop player) (player-stop player)))
(sleep (scheduler-tick player))
))
:priority 80000000))
(when (callback-fun player)
(setf (callback-process player)
(om-run-process "player caller callback"
#'(lambda ()
(loop
(funcall (callback-fun player) (caller player) (player-get-time player))
(sleep (callback-tick player))
))
:priority 10)
))
(setf (state player) :play
(start-time player) start-t
(ref-clock-time player) (clock-time))
;(om-delayed-funcall stop-time #'player-stop player obj)
)
))
;;; CALLED TO PAUSE PLAYER
(defmethod player-pause ((player omplayer))
(when (equal (state player) :play)
(setf (start-time player) (player-get-time player)
(state player) :pause)
(om-stop-process (scheduling-process player))
(om-stop-process (callback-process player))
))
;;; CALLED TO CONTINUE PLAYER
(defmethod player-continue ((player omplayer))
(om-resume-process (scheduling-process player))
(om-resume-process (callback-process player))
(setf (ref-clock-time player) (clock-time)
(state player) :play))
;;; CALLED TO LOOP PLAYER
(defmethod player-loop ((player omplayer))
;(setf (stop-time player) (cadr (play-interval player)))
(setf (start-time player) (or (car (play-interval player)) 0)
(ref-clock-time player) (clock-time)))
;;; CALLED TO STOP PLAYER
(defmethod player-stop ((player omplayer))
(unschedule-all player)
(setf (play-list player) nil)
(when (and (stop-fun player) (caller player))
(funcall (stop-fun player) (caller player)))
(when (callback-process player)
(om-kill-process (callback-process player))
(setf (callback-process player) nil))
(setf (state player) :stop
(ref-clock-time player) (clock-time)
(start-time player) 0)
(when (scheduling-process player)
(om-kill-process (scheduling-process player))
(setf (scheduling-process player) nil))
)
;;; CALLED TO START RECORD WITH PLAYER
(defmethod player-start-record ((player omplayer))
(if (equal (state player) :stop)
(progn
(setf (state player) :record))
(om-beep)))
;;; CALLED TO STOP RECORD WITH PLAYER
(defmethod player-stop-record ((player omplayer))
(when (callback-process player)
(om-kill-process (callback-process player))
(setf (callback-process player) nil))
(setf (state player) :stop
(ref-clock-time player) (clock-time)
(start-time player) 0)
(when (scheduling-process player)
(om-kill-process (scheduling-process player))
(setf (scheduling-process player) nil)))
#|
;;; SPECIFIES SOMETHING TO BE PLAYED ATHER A GIVEN DELAY (<at>) PAST THE CALL TO PLAYER-START
;;; THE DEFAULT BEHAVIOUR IS TO SCHEDULE 'player-play-object' AT DELAY
(defmethod prepare-to-play ((engine t) (player omplayer) object at interval params)
(schedule-task player
#'(lambda ()
(player-play-object engine object :interval interval :params params))
at))
;;; PLAY (NOW)
;;; IF THE RENDERER RELIES ON THE PLAYER SCHEDULING, THIS IS THE ONLY METHOD TO IMPLEMENT
(defmethod player-play-object ((engine t) object &key interval params)
(declare (ignore interval))
;(print (format nil "~A : play ~A - ~A" engine object interval))
t)
;;; START (PLAY WHAT IS SCHEDULED)
(defmethod player-start ((engine t) &optional play-list)
;(print (format nil "~A : start" engine))
t)
;;; PAUSE (all)
(defmethod player-pause ((engine t) &optional play-list)
;(print (format nil "~A : pause" engine))
t)
;;; CONTINUE (all)
(defmethod player-continue ((engine t) &optional play-list)
;(print (format nil "~A : continue" engine))
t)
;;; STOP (all)
(defmethod player-stop ((engine t) &optional play-list)
;(print (format nil "~A : stop" engine))
t)
;;; SET LOOP (called before play)
(defmethod player-set-loop ((engine t) &optional start end)
;(print (format nil "~A : set loop" engine))
t)
;;; an engine must choose a strategy to reschedule it's contents on loops
(defmethod player-loop ((engine t) player &optional play-list)
;(print (format nil "~A : loop" engine))
t)
(defmethod player-record-start ((engine t))
;(print (format nil "~A : record" engine))
t)
;;; must return the recorded object
(defmethod player-record-stop ((engine t))
;(print (format nil "~A : record stop" engine))
nil)
|#
| 11,686 | Common Lisp | .lisp | 247 | 41.255061 | 148 | 0.64405 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | e5e0a8aa3349218941fb05038aabe6ba7242a4c166903a3b60fdc514485ff2cb | 870 | [
-1
] |
871 | timed-object.lisp | cac-t-u-s_om-sharp/src/player/play/timed-object.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File authors: J. Bresson, D. Bouche, J. Garcia
;============================================================================
; This class facillitates time manipulations in Sequencer and the use of time markers with time rulers.
(in-package :om)
(defclass timed-object ()
((onset :accessor onset :initform 0
:initarg :onset :initarg :date ;;; two possible initargs (for compatibility)
:documentation "date/time of the object")))
;;; redefine for subclasses
(defmethod get-obj-dur ((self timed-object)) 1)
(defmethod set-object-onset ((self timed-object) onset)
(setf (onset self) onset))
(defmethod set-object-onset ((self t) onset)
;(om-beep-msg "~A has no onset attribute !" (type-of self))
onset)
| 1,377 | Common Lisp | .lisp | 27 | 48.592593 | 103 | 0.571642 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | b6247c02b4356625d53f93e94a759927c22340051f7f69fae467cbaa7e55d29f | 871 | [
-1
] |
872 | schedulable-object.lisp | cac-t-u-s_om-sharp/src/player/scheduler/schedulable-object.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: D. Bouche
;============================================================================
;;===========================================================================
; Schedulable Object
;;===========================================================================
(declaim (optimize (speed 3) (safety 0) (debug 1)))
(in-package :om)
;;===========================================================================
;;;Schedulable-Object = Object to be played by a Dynamic-Scheduler
;;===========================================================================
;;;Structure
(defclass schedulable-object ()
((scheduler-settings :initform (list :autostop t) :accessor scheduler-settings :type (or null cons))
(scheduler-info :initform (list :state :stop :loop-count 0) :accessor scheduler-info :type (or null cons))
(scheduler-data :initform (list :plan-lock (mp:make-lock) :task-plan-lock (mp:make-lock)) :accessor scheduler-data :type (or null cons))
(player-info :initform nil :accessor player-info))
(:documentation "
SCHEDULABLE OBJECT: an object to be played through a SCHEDULER.
=======================================================================
Any subtype of schedulable-object is playable.
For a proper use, some methods have to be redefined:
1) The method (get-action-list-for-play ((self OBJECT-CLASS) time-interval)).
This method will ask the object what has to be played in [(car time-interval);(cadr time-interval)[.
The output has to be:
.((Date1 Function1 Data1) ... (DateN FunctionN DataN)) where DateN is the date in ms when FunctionN has to be called with DataN as a list of arguments (NIL if no arguments needed),
.NIL if nothing has to be played (no item to play found in time-interval).
2) The method (get-computation-list-for-play ((self OBJECT-CLASS) time-interval)).
This method will ask the object what has to be computed in [(car time-interval);(cadr time-interval)[.
The output has to be:
.((Date1 Deadline1 Function1 Data1) ... (DateN DeadlineN FunctionN DataN)) where DateN is the date in ms when FunctionN is allowed to be performed and Deadline1 is the date in ms when the result has to be produced,
.NIL if nothing has to be computed.
3) Every modification on the data used by the previous methods has to be wrapped in the macro (with-schedulable-object object &rest body).
If the use of a macro is not convenient, you can simple call (notify-scheduler object) each time you think rescheduling might be useful."))
;;===========================================================================
;; API
;;===========================================================================
;; TO REDEFINE FOR YOUR SUBCLASS
;; It should return a list of lists containing a date, a function and its arguments
(defmethod get-action-list-for-play ((self schedulable-object) time-interval &optional parent)
(append
(if (not (or (eq (state self) :play) (play-planned? self)))
(progn
(setf (play-planned? self) t)
(list
(list
(max 0 (car time-interval))
#'(lambda ()
(print (format nil "No redefinition of get-action-list-for-play found => starting ~A" self))
(player-play-object *scheduler* self nil
:interval (list (max 0 (car time-interval)) (cadr (interval self)))
:parent parent)
(setf (play-planned? self) nil))
nil)))
'())
(if (>= (cadr time-interval) (get-obj-dur self))
(list
(list
(get-obj-dur self)
#'(lambda ()
(player-stop-object *scheduler* self))
nil)))))
;;; some objects can call this instead of returning a list of action (e.g. sound, etc.)
;;; this will call the specific play/stop actions for these objects
(defmethod external-player-actions ((self schedulable-object) time-interval &optional parent)
(append
(if (not (or (eq (state self) :play) (play-planned? self)))
(progn
(setf (play-planned? self) t)
(list
(list
(max 0 (car time-interval))
#'(lambda ()
(player-play-object *scheduler* self nil
:interval (list (max 0 (car (interval self)))
(cadr (interval self)))
:parent parent)
(setf (play-planned? self) nil))
nil)))
'())
(when (and
(>= (cadr time-interval) (get-obj-dur self))
(not (is-looping self)))
(list
(list
(get-obj-dur self)
#'(lambda ()
(player-stop-object *scheduler* self))
nil)))))
;; TO REDEFINE FOR YOUR SUBCLASS
;; It should return a list of lists containing a date when a computation can start, its deadline, a function and its arguments
(defmethod get-computation-list-for-play ((self schedulable-object) &optional time-interval)
nil)
;; TO REDEFINE FOR YOUR SUBCLASS
;; It should return an absolute duration
(defmethod get-obj-dur ((self schedulable-object)) *positive-infinity*)
;; TO USE TO EDIT DATA SLOTS OF YOUR OBJECT USED BY GET-ACTION-LIST-FOR-PLAY
;; (if not used, concurrent play and edit of the object is not ensured to be safe)
(defmethod with-schedulable-object-depth ((self schedulable-object))
(or (getf (scheduler-data self) :macro-depth) 0))
(defmethod (setf with-schedulable-object-depth) (new-depth (self schedulable-object))
(setf (getf (scheduler-data self) :macro-depth) new-depth))
(defmacro with-schedulable-object (object &rest body)
`(let (res)
(incf (with-schedulable-object-depth ,object) 1)
(setq res (progn ,@body))
(decf (with-schedulable-object-depth ,object) 1)
(when (and (eq (state ,object) :play) (eq (with-schedulable-object-depth ,object) 0))
(setf (time-window ,object) (or (user-time-window ,object) *Lmin*))
(reschedule ,object *scheduler* (get-obj-time ,object)))
res))
;; ALTERNATIVE TO THE MACRO ABOVE
;; (notifies the scheduler of potentially needed replanning)
(defmethod notify-scheduler ((object schedulable-object))
(when (eq (state object) :play) ; (> (time-window object) *Lmin*)
(setf (time-window object) *Lmin*)
(reschedule object *scheduler* (get-obj-time object))))
;; TO SET IF THE OBJECT HAS TO AUTOMATICALLY STOP WHEN GET-OBJ-DUR IS REACHED BY THE SCHEDULER
;; (t by default, set to nil is useful for objects that are filled while being played)
(defmethod set-object-autostop ((self schedulable-object) t-or-nil)
(setf (autostop self) t-or-nil))
;; SET THE OBJECT TIME WHILE PLAYING
;; Sets the time and replans from this date
(defmethod set-object-current-time ((self schedulable-object) time)
(setf (ref-time self) (- (om-get-internal-time) time))
(if (eq (state self) :play)
(reschedule self *scheduler* time nil)))
(defmethod set-object-current-time ((self t) time) nil)
;; CALLBACK USED WHEN THE SYSTEM SWITCHES THE OBJECT TIME AUTOMATICALLY
;; Happens when the object loops.
(defmethod set-time-callback ((self schedulable-object) time) nil)
;; CALLBACK USED WHEN THE SYSTEM RESCHEDULES THE OBJECT
(defmethod reschedule-callback ((self schedulable-object) interval) nil)
;; SET THE OBJECT SCHEDULER TIME WINDOW
(defmethod set-object-time-window ((self schedulable-object) window)
(setf (user-time-window self) window)) ;(max window *Lmin*)
;; LOOP/UNLOOP AN OBJECT
;; The object will loop at the end of its interval of at its own end time
(defmethod set-object-loop ((self schedulable-object) loop)
(unless (equal (looper self) loop)
(setf (looper self) loop)
(notify-scheduler self)))
(defmethod is-looping ((self schedulable-object))
(looper self))
;; SET AN OBJECT'S INTERVAL
(defmethod set-object-interval ((self schedulable-object) interval)
(setf (interval self) (if (or (null (cadr interval))
(= (car interval) (cadr interval)))
(list (car interval) *positive-infinity*)
interval)))
(defmethod set-object-interval ((self t) interval) interval)
;; GET AN OBJECT'S STATE
(defmethod get-object-state ((self schedulable-object)) (state self))
(defmethod get-object-state ((self t)) nil)
;; AUGMENTED TRANSPORT
;; Automatically play/continue or pause object according to its current state
(defmethod player-play/pause-object ((self scheduler) (object schedulable-object) caller &key parent (at 0) interval params)
(declare (ignore at params parent))
(if (eq (state object) :pause)
(player-continue-object self object)
(if (eq (state object) :play)
(player-pause-object self object)
(player-play-object self object caller :interval interval))))
(defmethod player-play/pause-object ((self t) (object t) caller &key parent (at 0) interval params)
(declare (ignore self object caller parent at interval params))
nil)
;; AUGMENTED TRANSPORT
;; Automatically play or stop object according to its current state
(defmethod player-play/stop-object ((self scheduler) (object schedulable-object) caller &key parent (at 0) interval params)
(declare (ignore at params parent))
(if (or (not (state object)) (eq (state object) :stop))
(player-play-object self object caller :interval interval)
(player-stop-object self object))
;;; return play-state
(state object))
(defmethod player-play/stop-object ((self t) (object t) caller &key parent (at 0) interval params)
(declare (ignore self object caller parent at interval params))
nil)
(defmethod player-set-object-loop ((player scheduler) (object schedulable-object) loop?)
(declare (ignore player))
(set-object-loop object loop?))
;;===========================================================================
;; GETTERS & SETTERS
;;===========================================================================
(defmethod looper ((self schedulable-object))
(getf (scheduler-settings self) :looper))
(defmethod (setf looper) (t-or-nil (self schedulable-object))
(setf (getf (scheduler-settings self) :looper) t-or-nil))
(defmethod interval ((self schedulable-object))
(getf (scheduler-settings self) :interval))
(defmethod (setf interval) (new-interval (self schedulable-object))
(setf (getf (scheduler-settings self) :interval) new-interval))
(defmethod autostop ((self schedulable-object))
(getf (scheduler-settings self) :autostop))
(defmethod (setf autostop) (t-or-nil (self schedulable-object))
(setf (getf (scheduler-settings self) :autostop) t-or-nil))
(defmethod user-time-window ((self schedulable-object))
(getf (scheduler-settings self) :user-time-window))
(defmethod (setf user-time-window) (new-window (self schedulable-object))
(setf (getf (scheduler-settings self) :user-time-window) new-window))
(defmethod state ((self schedulable-object))
(getf (scheduler-info self) :state))
(defmethod (setf state) (new-state (self schedulable-object))
(setf (getf (scheduler-info self) :state) new-state))
(defmethod play-planned? ((self schedulable-object))
(getf (scheduler-info self) :play-planned?))
(defmethod (setf play-planned?) (t-or-nil (self schedulable-object))
(setf (getf (scheduler-info self) :play-planned?) t-or-nil))
(defmethod loop-count ((self schedulable-object))
(getf (scheduler-info self) :loop-count))
(defmethod (setf loop-count) (count (self schedulable-object))
(setf (getf (scheduler-info self) :loop-count) count))
(defmethod auto-adapt-time-window ((self schedulable-object))
(getf (scheduler-info self) :auto-adapt-time-window))
(defmethod (setf auto-adapt-time-window) (t-or-nil (self schedulable-object))
(setf (getf (scheduler-info self) :auto-adapt-time-window) t-or-nil))
(defmethod update-object-time-window ((self schedulable-object))
(if (and (auto-adapt-time-window self) (not (user-time-window self)))
(setf (time-window self) (min *Lmax* (* 2 (time-window self))))))
(defmethod destroy-data ((self schedulable-object))
(setf (scheduler-data self) (list :plan-lock (plan-lock self)
:task-plan-lock (task-plan-lock self)))
(setf (loop-count self) 0))
(defmethod children ((self schedulable-object))
(getf (scheduler-data self) :children))
(defmethod (setf children) (children (self schedulable-object))
(setf (getf (scheduler-data self) :children) children))
(defmethod time-window ((self schedulable-object))
(or (getf (scheduler-data self) :time-window) (user-time-window self) *Ldefault*))
(defmethod (setf time-window) (new-window (self schedulable-object))
(setf (getf (scheduler-data self) :time-window) new-window))
(defmethod ref-time ((self schedulable-object))
(or (getf (scheduler-data self) :ref-time) 0))
(defmethod (setf ref-time) (new-time (self schedulable-object))
(setf (getf (scheduler-data self) :ref-time) new-time))
(defmethod pause-time ((self schedulable-object))
(or (getf (scheduler-data self) :pause-time) 0))
(defmethod (setf pause-time) (new-time (self schedulable-object))
(setf (getf (scheduler-data self) :pause-time) new-time))
(defmethod current-local-time ((self schedulable-object))
(or (getf (scheduler-data self) :current-local-time) 0))
(defmethod (setf current-local-time) (new-time (self schedulable-object))
(setf (getf (scheduler-data self) :current-local-time) new-time))
(defmethod plan ((self schedulable-object))
(or (getf (scheduler-data self) :plan) (list)))
(defmethod (setf plan) (new-plan (self schedulable-object))
(setf (getf (scheduler-data self) :plan) new-plan))
(defmethod plan-lock ((self schedulable-object))
(getf (scheduler-data self) :plan-lock))
(defmethod (setf plan-lock) (new-lock (self schedulable-object))
(setf (getf (scheduler-data self) :plan-lock) new-lock))
(defmethod task-plan ((self schedulable-object))
(or (getf (scheduler-data self) :task-plan) (list)))
(defmethod (setf task-plan) (new-plan (self schedulable-object))
(setf (getf (scheduler-data self) :task-plan) new-plan))
(defmethod task-plan-lock ((self schedulable-object))
(getf (scheduler-data self) :task-plan-lock))
(defmethod (setf task-plan-lock) (new-lock (self schedulable-object))
(setf (getf (scheduler-data self) :task-plan-lock) new-lock))
(defmethod computation-plan ((self schedulable-object))
(or (getf (scheduler-data self) :computation-plan) (list)))
(defmethod (setf computation-plan) (new-plan (self schedulable-object))
(setf (getf (scheduler-data self) :computation-plan) new-plan))
(defmethod actionlist ((self schedulable-object))
(getf (scheduler-data self) :actionlist))
(defmethod (setf actionlist) (actionlist (self schedulable-object))
(setf (getf (scheduler-data self) :actionlist) actionlist))
(defmethod last-action-pos ((self schedulable-object))
(getf (scheduler-data self) :last-action-pos))
(defmethod (setf last-action-pos) (new-pos (self schedulable-object))
(setf (getf (scheduler-data self) :last-action-pos) new-pos))
;;===========================================================================
;; Plan related methods
;;===========================================================================
;; !! TIME-WINDOW must be adapted depending on the scheduling duration
;(t1 (om-get-internal-time)) ;;start date of scheduling operation
; t2 ;;end date of scheduling operation
; dt ;;duration of the scheduling operation
;; SCHEDULE : produces the next plan for an object
(defmethod schedule ((sched scheduler) (obj schedulable-object))
(let ((scheduling
#'(lambda ()
(let ((I (get-next-I obj))
bundles actlist)
;; Get actions as raw data
(om-with-timeout (timeout sched)
#'(lambda ()
(print (format nil "Schedule operation timed out (> ~As) : ~A stopped" (timeout sched) obj))
(stop-schedulable-object obj sched))
#'(lambda () (setq bundles (get-action-list-for-play obj (subseq I 0 2)))))
;; Wrap actions in the appropriate data structure
(setq actlist (loop for bundle in bundles
collect
(act-alloc :timestamp (car bundle)
:fun (cadr bundle)
:data (caddr bundle))))
;; Update the scheduler next action date (used in timer execution mode only)
(when (car actlist)
(setf (next-date sched) (min (next-date sched) (act-timestamp (car actlist)))))
;; Add new actions to the object plan
(mp:with-lock ((plan-lock obj))
(setf (plan obj)
(sort (append (plan obj)
(if (nth 2 I)
(if (eq (nth 2 I) :loop)
;; If the object has to loop, reset its time at the end
(append actlist
(list (act-alloc :timestamp (1- (cadr I))
:fun #'(lambda ()
(player-loop-object sched obj)
))))
;; If the object has to stop, stop the object at the end of interval
(append actlist
(list (act-alloc :timestamp (1- (cadr I))
:fun #'(lambda ()
(funcall (run-callback sched)
(get-caller obj sched)
(1- (cadr I)))
(player-stop-object sched obj)
)))))
;; If the object continues, keep scheduling
(append (list (act-alloc :timestamp (car I)
:fun #'(lambda ()
(schedule sched obj)
(interleave-tasks obj
(list (cadr I)
(+ (cadr I) (time-window obj)))))))
actlist)))
'< :key 'act-timestamp))
)))))
(if (scheduler-multi-thread sched)
(mp:process-send (process sched) scheduling)
(funcall scheduling))
))
;; move forward the intervals in the object.
;; returns the next interval to schedule
;; returns (t1 t2+1 :stop) when reaches the end (if looper is on, returns :loop and restarts from the beginning)
;; !!! get-obj-dur must be defined for the object (and > 0, otherwise will never start)
(defmethod get-next-I ((self schedulable-object))
(let* ((tmax (if (cadr (interval self))
(if (= (cadr (interval self)) *positive-infinity*)
(if (autostop self)
(get-obj-dur self)
*positive-infinity*)
(cadr (interval self)))
(if (autostop self)
(get-obj-dur self)
*positive-infinity*)))
(t1 (current-local-time self))
(t2 (min (+ t1 (time-window self)) (or tmax *positive-infinity*))))
(if (= t2 tmax) ;; the interval touches the end of the object/interval
(if (looper self)
(progn
(reset-I self)
(list t1 (1+ t2) :loop))
(list t1 (1+ t2) :stop))
(progn
(incf (current-local-time self) (time-window self))
(when (not (user-time-window self))
(setf (time-window self) (min *Lmax* (* 2 (time-window self)))))
(list t1 t2)))))
(defmethod reset-I ((self schedulable-object) &optional date)
(setf (current-local-time self) (or date (car (interval self)) 0)
(time-window self) (or (user-time-window self) *Lmin*)))
;; RESCHEDULING OF AN OBJECT
;; From <time> if provided, instantaneous otherwise
;; <preserve> keeps the plan before rescheduling date
(defmethod reschedule ((self schedulable-object) (sched scheduler) &optional time (preserve t))
(let ((switch-date (if time (+ time *Lmin*)
(get-obj-time self))))
(setf (play-planned? self) nil
(time-window self) (or (user-time-window self) *lmin*)
(current-local-time self) switch-date)
(let ((interval (list switch-date (+ switch-date (time-window self)))))
(reschedule-callback self interval)
(mp:with-lock ((plan-lock self))
(setf (plan self)
(when preserve
(subseq (plan self)
0 (position switch-date (plan self) :test '< :key 'act-timestamp)))))
(interleave-tasks self interval))
(schedule sched self)))
(defmethod interleave-tasks ((self schedulable-object) interval)
(mp:with-lock ((plan-lock self))
(setf (plan self)
(sort
(append (plan self)
(cast-computation-list
(get-computation-list-for-play
self
(list (or (car interval) 0) (or (cadr interval) (get-obj-dur self))))))
'< :key 'act-timestamp))))
(defun cast-computation-list (plan)
(loop for task in plan
collect
(let ((fun (nth 2 task))
(data (nth 3 task)))
(act-alloc :timestamp (nth 0 task)
:fun #'(lambda () (if data
(compute (apply fun data))
(compute (funcall fun))))
:marker t))))
(defmethod get-pre-computation-plan ((self schedulable-object) interval)
(loop for task in (sort (get-computation-list-for-play
self
(list (or (car interval) 0)
(or (cadr interval) (get-obj-dur self)))) '< :key 'cadr)
collect
(let ((fun (nth 2 task))
(data (nth 3 task)))
(act-alloc :timestamp (nth 0 task)
:fun #'(lambda () (if data
(apply fun data)
(funcall fun)))))))
;;===========================================================================
;;;Object informations & Scheduler redefinitions
;;===========================================================================
;; SETS THE ID OF AN OBJECT
;(defmethod set-schedulable-object-id ((self schedulable-object) (number integer))
; (loop for char across (number-to-string number) do
; (vector-push-extend char (identifier self)))
; (vector-push-extend #\. (identifier self)))
;; GET THE OBJECT TIME
(defmethod get-obj-time ((self schedulable-object) &key internal-time)
(cond ((eq (state self) :pause)
(pause-time self))
((eq (state self) :stop) 0)
(t (- (or internal-time (om-get-internal-time)) (ref-time self)))))
;; inlined version
(declaim (inline %get-obj-time))
(defun %get-obj-time (obj)
(cond ((eq (state obj) :pause)
(pause-time obj))
((eq (state obj) :stop) 0)
(t (- (om-get-internal-time) (ref-time obj)))))
;; GET THE TIMESTAMP OF AN OBJECT
(defmethod item-timestamp ((self schedulable-object))
0)
;; PLAY AN OBJECT
(defmethod play-item ((self schedulable-object) (sched scheduler) &key caller parent)
(declare (ignore parent))
(player-play-object sched self caller))
;;===========================================================================
;;;Player methods
;;===========================================================================
;; PLAYS AN OBJECT
;; internal-time can be used to fix the start reference time (for sync between multiple objects)
;; interval sets the playing interval of the object
;; caller is the object to receive graphic updates
(defmethod play-schedulable-object ((self schedulable-object) (sched scheduler)
&key internal-time interval parent caller)
(when (or (eq (state self) :stop)
(not (state self)))
(init-schedulable-object self :interval interval :parent parent)
(pre-schedule sched self)
(setf (ref-time self) (- (or internal-time (om-get-internal-time))
(or (car (interval self)) 0)
;(act-timestamp (car (plan self)))
))
;(pre-compute-plan self)
(register-object sched self caller)
(poke-scheduling-system)))
(defmethod init-schedulable-object ((self schedulable-object) &key interval parent)
(setf (interval self) interval
(plan self) nil
(current-local-time self) (or (car interval) 0)
(state self) :play)
(if parent
(push self (children parent))))
(defmethod pre-schedule ((self scheduler) (obj schedulable-object))
(schedule self obj)
(loop for act in
(get-pre-computation-plan obj (list (or (car (interval obj)) 0)
(+ (or (car (interval obj)) 0) (time-window obj))))
do
(if (< (act-timestamp act) 0)
(%play-action act)
(mp:with-lock ((plan-lock obj))
(push act (plan obj)))))
(mp:with-lock ((plan-lock obj))
(sort (plan obj) '< :key 'act-timestamp)))
(defmethod register-object ((self scheduler) object caller)
(mp:with-lock ((lock self))
(push (list object caller) (register self))))
(defmethod unregister-object ((self scheduler) object)
(mp:with-lock ((lock self))
(setf (register self) (remove object (register self) :key 'car))))
(defmethod pre-compute-plan ((self schedulable-object))
(mp:with-lock ((plan-lock self))
(loop while (and (plan self) (< (act-timestamp (car (plan self))) 0))
do
(om-ignore&print-error (%play-action (pop (plan self)))))))
(defmethod play-schedulable-object ((self t) (sched scheduler) &key internal-time interval parent caller)
(declare (ignore self sched internal-time interval parent caller))
nil)
;; PAUSES AN OBJECT
;; internal-time can be used to fix the pause reference time (for sync between multiple objects)
(defmethod pause-schedulable-object ((self schedulable-object) (sched scheduler) &key internal-time)
(when (eq (state self) :play)
(let ((internal-time (or internal-time (om-get-internal-time))))
(loop for child in (children self)
do
(player-pause-object sched child))
(setf (pause-time self) (get-obj-time self :internal-time internal-time)
(current-local-time self) (pause-time self)
(state self) :pause))))
(defmethod pause-schedulable-object ((self t) (sched scheduler) &key internal-time)
(declare (ignore self sched internal-time))
nil)
;; CONTINUES AN OBJECT
;; internal-time can be used to fix the start reference time (for sync between multiple objects)
(defmethod continue-schedulable-object ((self schedulable-object) (sched scheduler) &key internal-time)
(when (eq (state self) :pause)
(let ((internal-time (or internal-time (om-get-internal-time))))
(loop for child in (children self) do
(player-continue-object sched child))
(setf (ref-time self) (round (- internal-time (pause-time self))))
(setf (state self) :play)
(poke-scheduling-system))))
(defmethod continue-schedulable-object ((self t) (sched scheduler) &key internal-time)
(declare (ignore self sched internal-time))
nil)
;; STOPS AN OBJECT
(defmethod stop-schedulable-object ((self t) (sched scheduler))
(declare (ignore self sched))
nil)
(defmethod stop-schedulable-object ((self schedulable-object) (sched scheduler))
(let ((caller (get-caller self sched)))
(loop for child in (children self)
do
(player-stop-object sched child))
(unregister-object sched self)
(when caller (funcall (stop-callback sched) caller))
(abort-schedulable-object self)))
(defmethod abort-schedulable-object ((self schedulable-object))
(setf (state self) :stop
(current-local-time self) (or (car (interval self)) 0)
(play-planned? self) nil)
;(mp:with-lock ((plan-lock self)) (setf (plan self) nil))
(setf (plan self) nil)
(destroy-data self))
;;; LOOPS AN OBJECT
(defmethod loop-schedulable-object ((obj schedulable-object) (sched scheduler))
(let ((start-t (or (car (interval obj)) 0)))
(incf (loop-count obj))
(setf (ref-time obj) (- (om-get-internal-time) start-t)
(play-planned? obj) nil)
(setf (current-local-time obj) start-t)
(schedule sched obj)
(interleave-tasks obj
(list start-t
(+ start-t (time-window obj))))
(set-time-callback obj (or (car (interval obj)) 0))))
(defmethod get-caller ((self schedulable-object) (sched scheduler))
(cadr (find self (register sched) :key 'car)))
| 30,458 | Common Lisp | .lisp | 566 | 44.25265 | 214 | 0.5913 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | d3ad28ba0a5d951d0a847d49f7fb31519871534c5452fe370fea5aacbb8eab00 | 872 | [
-1
] |
873 | scheduler.lisp | cac-t-u-s_om-sharp/src/player/scheduler/scheduler.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: D. Bouche
;============================================================================
(in-package :om)
(defvar *scheduler* nil)
(defvar *Lmin* 10)
(defvar *Lmax* *positive-infinity*)
(defvar *Ldefault* 100)
(defstruct (scheduler
(:print-object
(lambda (s stream)
(print-unreadable-object (s stream :type t :identity t)
(princ `(:currently ,(scheduler-state s) :with :next :action :at ,(scheduler-next-date s)) stream)
))))
(state :idle :type symbol)
(process nil :type (or mp:process null))
(multi-thread t :type boolean) ; single or multi-thread architecture
(register nil :type list)
(lock (mp:make-lock :name "Scheduler register lock") :type mp:lock)
(alarm nil :type boolean)
(stop-callback nil)
(run-callback nil)
(next-date *positive-infinity*)
(timeout 1)
(:documentation "Component to produce plans (schedule) on demand for objects in the register."))
;===================================================================
; Getters & Setters
;===================================================================
(defmethod state ((self scheduler))
(scheduler-state self))
(defmethod (setf state) (new-state (self scheduler))
(setf (scheduler-state self) new-state))
(defmethod process ((self scheduler))
(scheduler-process self))
(defmethod (setf process) (process (self scheduler))
(setf (scheduler-process self) process))
;;;list of object and graphic-caller pairs
(defmethod register ((self scheduler))
(mp:with-lock ((lock self))
(scheduler-register self)))
(defmethod (setf register) (register (self scheduler))
(mp:with-lock ((lock self))
(setf (scheduler-register self) register)))
;;;register lock
(defmethod lock ((self scheduler))
(scheduler-lock self))
(defmethod (setf lock) (lock (self scheduler))
(setf (scheduler-lock self) lock))
;;;wake-up alarm when running timer rendering mode
(defmethod alarm ((self scheduler))
(scheduler-alarm self))
(defmethod (setf alarm) (t-or-nil (self scheduler))
(setf (scheduler-alarm self) t-or-nil))
;;;stop-callback method to redefine for graphic-callers
;;;called when an object stops
(defmethod stop-callback ((self scheduler))
(scheduler-stop-callback self))
(defmethod (setf stop-callback) (callback (self scheduler))
(setf (scheduler-stop-callback self) callback))
;;;run-callback method to redefine for graphic-callers
;;;called periodically when playing
(defmethod run-callback ((self scheduler))
(scheduler-run-callback self))
(defmethod (setf run-callback) (callback (self scheduler))
(setf (scheduler-run-callback self) callback))
;;;next wake up date, when running timer rendering mode
(defmethod next-date ((self scheduler))
(scheduler-next-date self))
(defmethod (setf next-date) (callback (self scheduler))
(setf (scheduler-next-date self) callback))
;;;maximum duration for a scheduling operation to perform
(defmethod timeout ((self scheduler))
(scheduler-timeout self))
(defmethod (setf timeout) (new-timeout (self scheduler))
(setf (scheduler-timeout self) new-timeout))
;=========================================================================
; API
;=========================================================================
(defun build-scheduler (&key run-callback stop-callback)
(let ((scheduler (make-scheduler :run-callback run-callback
:stop-callback stop-callback)))
(setf (process scheduler) (mp:process-run-function "scheduler-thread"
nil
'scheduler-function
scheduler))
scheduler))
(defmethod abort-scheduler ((self scheduler))
(if (mp:process-alive-p (process self))
(mp:process-kill (process self))))
; receives and processes scheduling requests
(defmethod scheduler-function ((self scheduler))
(mp:ensure-process-mailbox)
(loop
(setf (state self) :idle)
(let ((task (mp:mailbox-read (mp:process-mailbox (process self)) ;;; make sure (process self) is non-NIL.. ?
"Waiting for scheduling request")))
(setf (state self) :busy)
(om-ignore&print-error (funcall task)))))
(defmethod next-delay ((self scheduler))
(- (next-date self) (om-get-internal-time)))
(defmethod refresh-next-date ((self scheduler))
(setf (next-date self)
(loop for obj in (register self)
if (plan (car obj))
minimize
(act-timestamp (car (plan (car obj)))))))
(defmethod get-next-trigger ((self scheduler))
(let ((date *positive-infinity*)
(next (list nil *positive-infinity*)))
(if (register self)
(loop for object+caller in (register self)
do
(if (plan (car object+caller))
(setq date (act-timestamp (car (plan (car object+caller)))))
(setq date 0))
(if (< date (cadr next))
(setf (car next) (car object+caller)
(cadr next) date)))
(setq next (list nil *positive-infinity*)))
next))
(defmethod scheduler-idle-p ((self scheduler))
(not (find :play (mapcar #'state (mapcar #'car (register self))))))
(defun poke-scheduling-system ()
(setf (alarm *scheduler*) t)
(when (and *dispatcher* (process *dispatcher*) (mp:process-stopped-p (process *dispatcher*)))
(mp:process-unstop (process *dispatcher*)))
(when (and *graphics* (process *graphics*) (mp:process-stopped-p (process *graphics*)))
(mp:process-unstop (process *graphics*)))
)
| 6,303 | Common Lisp | .lisp | 140 | 39.3 | 115 | 0.605641 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 2135a911001e8c195cef12e52d648fa0fc78e8c9868166f0973d8d766bbf410b | 873 | [
-1
] |
874 | clock.lisp | cac-t-u-s_om-sharp/src/player/scheduler/clock.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: D. Bouche
;============================================================================
;;===========================================================================
; Clock: an object used just like a clock in musical sequences
;;===========================================================================
(in-package :om)
(defclass clock (schedulable-object timed-object)
((action :initform nil :initarg :action :accessor action :documentation "A function to call periodically")
(period :initform 1000 :initarg :period :accessor period :documentation "A time period in ms")
(duration :initform nil :initarg :duration :accessor duration :documentation "A duration in ms or nil if infinite")
(outval :initform nil :accessor outval :documentation "Slot to store the action's output")
(parentbox :initform nil :accessor parentbox :documentation "Slot to store the box to propagate the result")
(tick-n :initform 0 :accessor tick-n :documentation "Internal tick-n if no action is provided")))
(defmethod display-modes-for-object ((self clock))
'(:mini-view :text :hidden))
;;; Accessor redefinition so the action output is accessible
(defmethod action ((self clock))
(outval self))
(defmethod get-action ((self clock))
(or (slot-value self 'action) 'identity))
(defmethod set-period ((self clock) new-period)
(setf (period self) new-period))
(defmethod initialize-instance :after ((self clock) &rest initargs)
(set-object-time-window self (period self))
(set-object-loop self t)
self)
(defmethod get-action-list-for-play ((object clock) time-interval &optional parent)
(list
(list 0
#'(lambda ()
(setf (outval object) (funcall (get-action object)
(progn
(incf (tick-n object))
(1- (tick-n object)))))
(if (parentbox object)
(self-notify (parentbox object)))))))
(defmethod player-play-object ((self scheduler) (object clock) caller &key parent interval)
(declare (ignore parent interval))
(setf (parentbox object) caller)
(call-next-method))
(defmethod player-stop-object ((self scheduler) (object clock))
(setf (tick-n object) 0)
(call-next-method))
(defmethod get-obj-dur ((self clock)) (or (duration self) (period self)))
(defmethod get-obj-time ((self clock) &key internal-time)
(declare (ignore internal-time))
(if (duration self)
(call-next-method)
(mod (call-next-method) (period self))))
(defmethod draw-mini-view ((self clock) (box t) x y w h &optional time)
(multiple-value-bind (fx ox)
(conversion-factor-and-offset 0 (get-obj-dur self) w x)
(multiple-value-bind (fy oy)
(conversion-factor-and-offset h 0 (- h 20) (+ y 10))
(om-with-font (om-def-font :large-b)
(om-draw-string (+ ox (* fx 10))
(+ oy (* fy (+ (/ h 2) 10))) (format nil "~A ms Loop" (period self))))
(om-draw-dashed-line (+ ox (* fx x)) (+ oy (* fy (/ h 2)))
(+ ox (* fx (+ x 10000))) (+ oy (* fy (/ h 2)))))))
| 3,814 | Common Lisp | .lisp | 71 | 47.394366 | 118 | 0.573498 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | c46e3fdf779a46abf178238dc8f736312f082581d2be1f252f51b76b1ce59c7b | 874 | [
-1
] |
875 | thread-pool.lisp | cac-t-u-s_om-sharp/src/player/scheduler/thread-pool.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: S. Bell-Bell
;============================================================================
(in-package :om)
(defvar *threadpool* nil)
(defclass thread-pool ()
((taskqueue :initform (mp:make-mailbox) :accessor taskqueue)
(pending-taskqueue :initform (list) :accessor pending-taskqueue)
(workers :initform nil :initarg :workers :accessor workers)
(state :initform :stop :accessor state)))
;============================================
; API
;============================================
(defmethod build-thread-pool (nbthread)
(setq *threadpool* (make-instance 'thread-pool))
(setf (workers *threadpool*)
(loop for i from 1 to nbthread
collect
(mp:process-run-function (format nil "Thread-~A" i)
nil
'thread-function *threadpool*)))
*threadpool*)
(defmethod abort-thread-pool ((self thread-pool))
(loop for worker in (workers self)
do
(if (mp:process-alive-p worker)
(mp:process-kill worker)))
(setq *threadpool* nil))
(defmethod restart-thread-pool ((self thread-pool))
(abort-thread-pool self)
(build-thread-pool 8))
(defmethod task-number-left ((pool thread-pool))
(mp:mailbox-count (taskqueue pool)))
(defmethod engine-tasks-left ()
(task-number-left *threadpool*))
;=============================================
(defmethod thread-function ((self thread-pool))
(mp:ensure-process-mailbox)
(loop
(let ((task (mp:mailbox-read (taskqueue self))))
(if (not task)
(mp:process-wait-local "Waiting for request asleep" 'mp:mailbox-not-empty-p (taskqueue self))
(funcall task)))))
(defmethod poke-thread-pool ((pool thread-pool))
(mapcar 'mp:process-poke (workers pool)))
(defmethod add-worker ((self thread-pool) thread)
(push thread (workers self)))
(defmethod add-task ((self thread-pool) fun)
(mp:mailbox-send (taskqueue self) fun))
(defmethod add-multiple-tasks ((self thread-pool) tasklist)
(loop for task in tasklist
do
(add-task self task))
(poke-thread-pool self))
| 2,758 | Common Lisp | .lisp | 65 | 37.738462 | 102 | 0.574309 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 6e2e5169546a524a78c85a84c699d8370e95780ddab22537cdcc50ad1c683085 | 875 | [
-1
] |
876 | engine.lisp | cac-t-u-s_om-sharp/src/player/scheduler/engine.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: D. Bouche
;============================================================================
(in-package :om)
(defvar *engine* nil)
(defstruct (engine)
(state :idle :type symbol)
(process nil :type (or mp:process null))
(task-plan nil :type list)
;(alarm nil :type boolean)
(behavior :EDF :type symbol)
(:documentation "Component to perform non-zero time computations"))
;===================================================================
; Getters & Setters
;===================================================================
(defmethod state ((self engine))
(engine-state self))
(defmethod (setf state) (new-state (self engine))
(setf (engine-state self) new-state))
(defmethod process ((self engine))
(engine-process self))
(defmethod (setf process) (process (self engine))
(setf (engine-process self) process))
(defmethod task-plan ((self engine))
(engine-task-plan self))
(defmethod (setf task-plan) (plan (self engine))
(setf (engine-task-plan self) plan))
(defmethod behavior ((self engine))
(engine-behavior self))
(defmethod (setf behavior) (new (self engine))
(setf (engine-behavior self) new))
(defun build-engine ()
(let ((engine (make-engine)))
(setf (process engine) (mp:process-run-function "engine-thread"
nil
'engine-function
engine))
engine))
(defmacro compute (&rest body)
`(if (scheduler-multi-thread *scheduler*)
(progn
(mp:mailbox-send (taskqueue *engine*) (lambda () ,@body))
(poke-thread-pool *engine*))
(progn ,@body)))
(defmacro compute2 (obj clef time-type &body body)
`(let (res)
(if (eq ,time-type 'ms)
(setq res (mesure-time-in-body-milli-sec ,obj ,clef ,@body)))
; (if (eq ,time-type 'us)
; (setq res (mesure-time-in-body-micro-sec ,obj ,clef ,@body)))
; (if (eq ,time-type 'ns)
; (setq res (mesure-time-in-body-nano-sec ,obj ,clef ,@body)))
res))
(defmethod engine-function ((self engine))
(mp:ensure-process-mailbox)
(loop
(setf (state self) :idle)
;(setf (alarm self) nil)
(let ((task (mp:mailbox-read (mp:process-mailbox
(process self))
"Waiting for computation request")))
(when task
(setf (state self) :busy)
(om-ignore&print-error (funcall task))))))
; (loop while (and (task-plan self)
; (<= (act-timestamp (first (task-plan self))) (om-get-internal-time)))
; do
; (om-ignore&print-error
; (%play-action (pop (task-plan self)))))
; (if (task-plan self)
; (mp:process-wait-local-with-timeout "Sleeping" (max 0.001
; (/ (- (act-timestamp (first (task-plan self))) (om-get-internal-time))
; 1000.0)) 'alarm self)
; (mp:process-wait-with-timeout "Sleeping" 0.001))))
| 3,704 | Common Lisp | .lisp | 85 | 38.341176 | 130 | 0.528726 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 6b66a96c4bc5883e504e8a1b3e6e8b54abbb292025f51ed9ce231af7a0433ed6 | 876 | [
-1
] |
877 | graphics-callback.lisp | cac-t-u-s_om-sharp/src/player/scheduler/graphics-callback.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: D. Bouche
;============================================================================
(in-package :om)
(defvar *graphics* nil)
(defstruct (graphics-handler)
(state :stop :type symbol)
(process nil :type (or mp:process null))
(scheduler nil :type scheduler)
(precision 50 :type integer)
(:documentation "Component to send back timing informations to playing objects regitered in the corresponding scheduler."))
;===================================================================
; Getters & Setters
;===================================================================
(defmethod state ((self graphics-handler))
(graphics-handler-state self))
(defmethod (setf state) (new-state (self graphics-handler))
(setf (graphics-handler-state self) new-state))
(defmethod process ((self graphics-handler))
(graphics-handler-process self))
(defmethod (setf process) (process (self graphics-handler))
(setf (graphics-handler-process self) process))
(defmethod scheduler ((self graphics-handler))
(graphics-handler-scheduler self))
(defmethod (setf scheduler) (scheduler (self graphics-handler))
(setf (graphics-handler-scheduler self) scheduler))
(defmethod precision ((self graphics-handler))
(graphics-handler-precision self))
(defmethod (setf precision) (precision (self graphics-handler))
(setf (graphics-handler-precision self) precision))
;=================================================================================
; API
;=================================================================================
(defun build-graphics-handler (scheduler &key (precision 50))
(let ((graphics (make-graphics-handler :scheduler scheduler
:precision precision)))
(setf (process graphics) (mp:process-run-function "graphics-thread"
nil
'graphics-function
graphics))
graphics))
;==================================================================================
(defmethod graphics-function ((self graphics-handler))
(let ((sched (scheduler self)))
(loop
(when (scheduler-idle-p sched)
(mp:process-stop (process self) "Idle"))
(loop for object+caller in (register sched)
do
(when (and (run-callback sched)
(cadr object+caller)
(eq (player-get-object-state sched (car object+caller)) :play))
(om-ignore&print-error
(funcall (run-callback sched) (cadr object+caller) (%get-obj-time (car object+caller))))))
(om-process-wait (precision self)))))
| 3,352 | Common Lisp | .lisp | 66 | 44.166667 | 125 | 0.530076 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 421e8f42d2cce766f15412fb3ce605db05100fcea093749ae035babb9dd88c40 | 877 | [
-1
] |
878 | scheduling-system.lisp | cac-t-u-s_om-sharp/src/player/scheduler/scheduling-system.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: D. Bouche
;============================================================================
(in-package :om)
(defmethod make-player ((id (eql :reactive-player)) &key run-callback stop-callback (callback-tick 50) (time-window 5))
(declare (ignore time-window))
(let ((sched (or *scheduler* (setq *scheduler* (build-scheduler :run-callback run-callback
:stop-callback stop-callback)))))
(setq *dispatcher* (or *dispatcher* (build-dispatcher sched))
*graphics* (or *graphics* (build-graphics-handler sched :precision callback-tick))
*engine* (or *engine* (build-thread-pool 8));(or *engine* (build-engine))
)
*scheduler*))
(defmethod destroy-player ((self scheduler))
; (if (process *engine*)
; (mp:process-kill (process *engine*)))
(if (workers *engine*)
(abort-thread-pool *engine*))
(if (process *scheduler*)
(mp:process-kill (process *scheduler*)))
(if (process *dispatcher*)
(mp:process-kill (process *dispatcher*)))
(if (process *graphics*)
(mp:process-kill (process *graphics*)))
(setq *graphics* nil
*scheduler* nil
*engine* nil
*dispatcher* nil))
(defun restart-scheduling-system ()
(let ((runC (run-callback *scheduler*))
(stopC (stop-callback *scheduler*))
(precision (precision *graphics*)))
; (if (process *engine*)
; (mp:process-kill (process *engine*)))
; (if (process *scheduler*)
; (mp:process-kill (process *scheduler*)))
; (if (process *dispatcher*)
; (mp:process-kill (process *dispatcher*)))
; (if (process *graphics*)
; (mp:process-kill (process *graphics*)))
(destroy-player *scheduler*) t
(setq *graphics* nil
*scheduler* nil
*engine* nil
*dispatcher* nil)
(make-player :reactive-player
:run-callback runC
:stop-callback stopC
:callback-tick precision)))
;(progn (abort-om-player) (init-om-player))
;;===========================================================================
;;;Links to previous architecture
;;===========================================================================
(defmethod player-play-object ((self scheduler) (object schedulable-object) caller &key parent interval)
(play-schedulable-object object self :interval interval :caller caller :parent parent))
(defmethod player-stop-object ((self scheduler) (object schedulable-object))
(stop-schedulable-object object self))
(defmethod player-pause-object ((self scheduler) (object schedulable-object))
(pause-schedulable-object object self))
(defmethod player-continue-object ((self scheduler) (object schedulable-object))
(continue-schedulable-object object self))
(defmethod player-loop-object ((self scheduler) (object schedulable-object))
(loop-schedulable-object object self))
(defmethod player-get-object-state ((self scheduler) (object schedulable-object))
(or (state object) :stop))
(defmethod player-get-object-time ((self scheduler) (object schedulable-object))
(get-obj-time object))
;;===========================================================================
| 3,869 | Common Lisp | .lisp | 79 | 43.810127 | 119 | 0.58309 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 00a25ba57fbebe5567bdfa634874cb1dc90c33abca0c027133e26d1af407e58b | 878 | [
-1
] |
879 | load-scheduling-system.lisp | cac-t-u-s_om-sharp/src/player/scheduler/load-scheduling-system.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: D. Bouche
;============================================================================
(in-package :om)
(mapc #'(lambda (filename)
(compile&load (decode-local-path filename)))
'(
"action"
"scheduler"
"engine"
"thread-pool"
"dispatcher"
"graphics-callback"
"schedulable-object"
"scheduling-system"
))
| 1,042 | Common Lisp | .lisp | 27 | 34.259259 | 77 | 0.471866 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 1492b84b71440c6ba9bdcdaec3d3778370ac537a98ed2e23cb881427a0b23301 | 879 | [
-1
] |
880 | dispatcher.lisp | cac-t-u-s_om-sharp/src/player/scheduler/dispatcher.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: D. Bouche
;============================================================================
(in-package :om)
(defvar *dispatcher* nil)
(declaim (optimize (speed 3) (safety 0) (debug 1)))
;================================================================
; Dispatcher structure
;================================================================
(defstruct (dispatcher)
(state :stop :type symbol) ;Current state
(process nil :type (or mp:process null)) ;Reference to the main process
(precision 1 :type integer) ;Best possible time accuracy in dispatching actions (in ms)
(scheduler nil :type scheduler) ;Reference to the linked scheduler (to access object register etc.)
(:documentation "Component to dispatch actions from a scheduler register on due time."))
;===================================================================
; Getters & Setters
;===================================================================
(defmethod state ((self dispatcher))
(dispatcher-state self))
(defmethod (setf state) (new-state (self dispatcher))
(setf (dispatcher-state self) new-state))
(defmethod process ((self dispatcher))
(dispatcher-process self))
(defmethod (setf process) (process (self dispatcher))
(setf (dispatcher-process self) process))
(defmethod precision ((self dispatcher))
(dispatcher-precision self))
(defmethod (setf precision) (precision (self dispatcher))
(setf (dispatcher-precision self) precision))
(defmethod scheduler ((self dispatcher))
(dispatcher-scheduler self))
(defmethod (setf scheduler) (scheduler (self dispatcher))
(setf (dispatcher-scheduler self) scheduler))
;=================================================================================
; API
;=================================================================================
(defun build-dispatcher (scheduler &key (precision 1))
(let ((dispatcher (make-dispatcher :precision (max 1 (round precision))
:scheduler scheduler)))
(setf (process dispatcher) (mp:process-run-function "dispatcher-thread"
nil
'dispatch-actions-cycle
dispatcher))
dispatcher))
(defmethod abort-dispatcher ((self dispatcher))
(if (mp:process-alive-p (process self))
(mp:process-kill (process self))))
;====================================================================================
(declaim (inline play-object-action))
(defmethod play-object-action ((disp dispatcher) obj action)
(let ((sched (scheduler disp)))
(if (and (not (scheduler-multi-thread sched)) (act-marker action))
(progn
(pause-schedulable-object obj sched)
(%play-action action)
(reschedule obj sched nil nil)
(continue-schedulable-object obj sched))
(%play-action action))))
(defmethod dispatch-actions-cycle ((self dispatcher))
(let ((sched (scheduler self))
(tick (/ (precision self) 1000.0)))
(loop
;;;When idle, garbage collector + stop
(when (scheduler-idle-p sched)
(%clean-action-garbage)
(mp:process-stop (process self) "Idle"))
;;;Or look in the register who which objects need to play actions
(loop for object+caller in (register sched)
do
(mp:with-lock ((plan-lock (car object+caller)))
(loop while (and (plan (car object+caller))
(<= (act-timestamp (car (plan (car object+caller)))) (%get-obj-time (car object+caller))))
do
(om-ignore&print-error
(play-object-action self (car object+caller) (pop (plan (car object+caller))))))))
;;;And sleeps tick seconds (usually 0.001 s)
(mp:process-wait-with-timeout "Sleeping" tick))))
(defmethod dispatch-actions-with-timer ((self dispatcher))
(let ((sched (scheduler self))
(anticipation 10)
next-trigger)
(loop
(setq next-trigger (get-next-trigger sched))
(mp:process-wait-local-with-timeout "Sleeping"
(max 0.001 (/ (- (cadr next-trigger) (om-get-internal-time) anticipation) 1000.0))
'alarm sched)
(om-ignore&print-error
(if (car next-trigger)
(if (alarm sched)
(setf (alarm sched) nil)
(progn
(loop while (> (cadr next-trigger) (om-get-internal-time))
do
(mp:process-wait-with-timeout "Sleeping" 0.001))
(mp:with-lock ((plan-lock (car next-trigger)))
(%play-action (pop (plan (car next-trigger))))))))))))
;(progn (restart-scheduling-system) (init-om-player))
;(get-next-trigger *scheduler*) (plan (caar (register *scheduler*)))
;(register *scheduler*)
;(incf i) (refresh-next-date sched)
;(if (> (next-delay sched) 50)
; (loop for object+caller in (register sched)
; do
; (when (and
; (= 0 (mod i 50))
; (run-callback *graphics*)
; (cadr object+caller)
; (eq (player-get-object-state sched (car object+caller)) :play))
; (om-ignore&print-error
; (funcall (run-callback *graphics*) (cadr object+caller) (player-get-object-time sched (car object+caller)))))))
| 6,112 | Common Lisp | .lisp | 122 | 42.42623 | 130 | 0.536205 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 9699d0584f620a88684d6f46513d954ff0e5ea1d3e62e726e891149405be95ec | 880 | [
-1
] |
881 | action.lisp | cac-t-u-s_om-sharp/src/player/scheduler/action.lisp | ;============================================================================
; om#: visual programming language for computer-assisted music composition
;============================================================================
;
; This program is free software. For information on usage
; and redistribution, see the "LICENSE" file in this distribution.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
;============================================================================
; File author: D. Bouche
;============================================================================
;;===========================================================================
; Actions
;;===========================================================================
(declaim (optimize (speed 3) (safety 0) (debug 1)))
(in-package :om)
;;;This list is used to accumulate already trigerred actions
;;;It is intended to avoid automatic garbage collection while rendering objects
;;;Its efficiency should be investigated
(defvar *action-garbage* '())
;;===========================================================================
;;;Action
;;===========================================================================
;;;Structure
(defstruct (action
(:print-object
(lambda (a stream)
(print-unreadable-object (a stream :type t :identity t)
(princ `(:at ,(act-timestamp a) :. :data :=,(act-data a)) stream))))
(:conc-name act-))
(timestamp 0 :type integer)
(fun #'(lambda ()) :type function)
(data nil)
(marker nil :type boolean)
(:documentation "A structure to wrap timed function calls from a SCHEDULABLE-OBJECT."))
;;;Allocate and Free action methods using cache pool
(defun new-action-pool (size)
(let ((list (make-list size)))
(loop
for n on list do
(setf (car n) (make-action)))
list))
(let* ((cache-lock (mp:make-lock))
(cache-size 1024)
(cache-list '()))
(declare (type fixnum cache-size))
(mp:with-lock (cache-lock)
(setf cache-list (new-action-pool cache-size)))
(defun act-alloc (&key (timestamp 0) (fun #'(lambda ())) data marker)
(mp:with-lock (cache-lock)
(when (null cache-list)
(setf cache-list (new-action-pool cache-size)
cache-size (* 2 cache-size)))
(let ((act (pop cache-list)))
(setf (act-timestamp act) timestamp
(act-fun act) fun
(act-data act) (if (listp data) data (list data))
(act-marker act) marker)
act)))
(defmethod act-free ((self action))
(mp:with-lock (cache-lock)
(setf (act-timestamp self) 0
(act-fun self) #'(lambda ())
(act-data self) nil
(act-marker self) nil)
(push self cache-list)
nil)))
;;;Function to trigger actions (inlined)
(declaim (inline %play-action))
(defun %play-action (self)
(if (act-data self)
(apply (act-fun self) (act-data self))
(funcall (act-fun self)))
(push self *action-garbage*))
;;;Function to clean the garbage list (inlined)
(declaim (inline %clean-action-garbage))
(defun %clean-action-garbage ()
(loop while *action-garbage* do
(act-free (pop *action-garbage*)))
(gc-all))
| 3,395 | Common Lisp | .lisp | 83 | 36.072289 | 89 | 0.528342 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | a188a54498b531ec200d231a8459dbcf7ecbf06cd151239992cdddcba7dbf754 | 881 | [
-1
] |
882 | trivial-features-tests.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/trivial-features/trivial-features-tests.asd | ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; trivial-features-tests.asd --- ASDF definition.
;;;
;;; Copyright (C) 2007, Luis Oliveira <[email protected]>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
(eval-when (:load-toplevel :execute)
;; We need to load trivial-features this way before the the
;; defsystem form is read for the corner case when someone loads
;; trivial-features-tests before trivial-features since the system
;; definition's got a #+windows reader conditional that is supplied
;; by trivial-features.
(oos 'load-op 'trivial-features))
(defsystem trivial-features-tests
:description "Unit tests for TRIVIAL-FEATURES."
:defsystem-depends-on (cffi-grovel)
:depends-on (trivial-features rt cffi alexandria)
:components
((:module tests
:serial t
:components
((:file "package")
#-windows (:cffi-grovel-file "utsname")
#+windows (:file "sysinfo")
(:file "tests")))))
(defmethod perform ((o test-op) (c (eql (find-system 'trivial-features-tests))))
(let ((*package* (find-package 'trivial-features-tests)))
(funcall (find-symbol (symbol-name '#:do-tests)))))
| 2,205 | Common Lisp | .asd | 47 | 44.680851 | 80 | 0.733179 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 64a769cce13fdf48fd5521f6186aaa3e3daa7fb23bc8e015298ec800222f4ae1 | 882 | [
110067,
237504
] |
883 | trivial-features.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/trivial-features/trivial-features.asd | ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; trivial-features.asd --- ASDF system definition.
;;;
;;; Copyright (C) 2007, Luis Oliveira <[email protected]>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
#-(or sbcl clisp allegro openmcl mcl mkcl lispworks ecl cmu scl cormanlisp abcl xcl mocl)
(error "Sorry, your Lisp is not supported. Patches welcome.")
(defsystem trivial-features
:version "0.7"
:description "Ensures consistent *FEATURES* across multiple CLs."
:author "Luis Oliveira <[email protected]>"
:licence "MIT"
:components
((:module src
:serial t
:components
(#+allegro (:file "tf-allegro")
#+clisp (:file "tf-clisp")
#+cmu (:file "tf-cmucl")
#+cormanlisp (:file "tf-cormanlisp")
#+ecl (:file "tf-ecl")
#+lispworks (:file "tf-lispworks")
#+openmcl (:file "tf-openmcl")
#+mcl (:file "tf-mcl")
#+mkcl (:file "tf-mkcl")
#+sbcl (:file "tf-sbcl")
#+scl (:file "tf-scl")
#+abcl (:file "tf-abcl")
#+xcl (:file "tf-xcl")
#+mocl (:file "tf-mocl")
))))
(defmethod perform ((o test-op) (c (eql (find-system 'trivial-features))))
(operate 'load-op 'trivial-features-tests)
(operate 'test-op 'trivial-features-tests))
| 2,372 | Common Lisp | .asd | 54 | 41.055556 | 89 | 0.677322 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 1a0f064726cc0059f515e6662df68d46cfa8b2ec0c18eef8487c562102fb243e | 883 | [
-1
] |
884 | alexandria-tests.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/alexandria/alexandria-tests.asd | (defsystem alexandria-tests
:depends-on (:alexandria #+sbcl :sb-rt #-sbcl :rt)
:components ((:file "tests")))
(defmethod operation-done-p
((o test-op) (c (eql (find-system :alexandria-tests))))
nil)
(defmethod perform ((o test-op) (c (eql (find-system :alexandria-tests))))
(flet ((run-tests (&rest args)
(apply (intern (string '#:run-tests) '#:alexandria-tests) args)))
(run-tests :compiled nil)
(run-tests :compiled t))) | 455 | Common Lisp | .asd | 11 | 37.454545 | 76 | 0.654628 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | dd71f80bcb75f10d110ceff17d6a5030646d69cc9ba5fcaf608c388008f47be5 | 884 | [
219104
] |
885 | alexandria.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/alexandria/alexandria.asd | (in-package :asdf)
(defsystem :alexandria
:version "0.0.0"
:licence "Public Domain / 0-clause MIT"
:description "Alexandria is a collection of portable public domain utilities."
:long-description
"Alexandria is a project and a library.
As a project Alexandria's goal is to reduce duplication of effort and improve
portability of Common Lisp code according to its own idiosyncratic and rather
conservative aesthetic. What this actually means is open to debate, but each
project member has a veto on all project activities, so a degree of
conservativism is inevitable.
As a library Alexandria is one of the means by which the project strives for
its goals.
Alexandria is a collection of portable public domain utilities that meet
the following constraints:
* Utilities, not extensions: Alexandria will not contain conceptual
extensions to Common Lisp, instead limiting itself to tools and utilities
that fit well within the framework of standard ANSI Common Lisp.
Test-frameworks, system definitions, logging facilities, serialization
layers, etc. are all outside the scope of Alexandria as a library, though
well within the scope of Alexandria as a project.
* Conservative: Alexandria limits itself to what project members consider
conservative utilities. Alexandria does not and will not include anaphoric
constructs, loop-like binding macros, etc.
* Portable: Alexandria limits itself to portable parts of Common Lisp. Even
apparently conservative and useful functions remain outside the scope of
Alexandria if they cannot be implemented portably. Portability is here
defined as portable within a conforming implementation: implementation bugs
are not considered portability issues.
* Team player: Alexandria will not (initially, at least) subsume or provide
functionality for which good-quality special-purpose packages exist, like
split-sequence. Instead, third party packages such as that may be
\"blessed\"."
:components
((:static-file "LICENCE")
(:static-file "tests.lisp")
(:file "package")
(:file "definitions" :depends-on ("package"))
(:file "binding" :depends-on ("package"))
(:file "strings" :depends-on ("package"))
(:file "conditions" :depends-on ("package"))
(:file "hash-tables" :depends-on ("package"))
(:file "io" :depends-on ("package" "macros" "lists" "types"))
(:file "macros" :depends-on ("package" "strings" "symbols"))
(:file "control-flow" :depends-on ("package" "definitions" "macros"))
(:file "symbols" :depends-on ("package"))
(:file "functions" :depends-on ("package" "symbols" "macros"))
(:file "lists" :depends-on ("package" "functions"))
(:file "types" :depends-on ("package" "symbols" "lists"))
(:file "arrays" :depends-on ("package" "types"))
(:file "sequences" :depends-on ("package" "lists" "types"))
(:file "numbers" :depends-on ("package" "sequences"))
(:file "features" :depends-on ("package" "control-flow"))))
(defmethod operation-done-p ((o test-op) (c (eql (find-system :alexandria))))
nil)
(defmethod perform ((o test-op) (c (eql (find-system :alexandria))))
(operate 'load-op :alexandria-tests)
(operate 'test-op :alexandria-tests))
| 3,206 | Common Lisp | .asd | 59 | 51.152542 | 80 | 0.745061 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 1424b237428724f8bae0f1085f54d53ab79c0f6af0a511260e86740f583cccc3 | 885 | [
-1
] |
886 | cffi-grovel.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/cffi-grovel.asd | ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; cffi-grovel.asd --- ASDF system definition for cffi-grovel.
;;;
;;; Copyright (C) 2007, Luis Oliveira <[email protected]>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
;;;
(asdf:defsystem cffi-grovel
:description "The CFFI Groveller"
:author "Dan Knapp <[email protected]>"
:depends-on (cffi alexandria)
:licence "MIT"
:components
((:module grovel
:serial t
:components
((:file "package")
(:file "invoke")
(:static-file "common.h")
(:file "grovel")
(:file "asdf")))))
;; vim: ft=lisp et
| 1,653 | Common Lisp | .asd | 41 | 38.195122 | 70 | 0.72236 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | ae7815854b3a011f316787733f4ae820fee099a7d9c6ab982b06ee4dc58692f0 | 886 | [
64561
] |
887 | cffi-uffi-compat.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/cffi-uffi-compat.asd | ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; cffi-uffi-compat.asd --- ASDF system definition for CFFI-UFFI-COMPAT.
;;;
;;; Copyright (C) 2005-2006, James Bielman <[email protected]>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
;;;
(defpackage #:cffi-uffi-compat-system
(:use #:cl #:asdf))
(in-package #:cffi-uffi-compat-system)
(defsystem cffi-uffi-compat
:description "UFFI Compatibility Layer for CFFI"
:author "James Bielman <[email protected]>"
:components
((:module uffi-compat
:components
((:file "uffi-compat"))))
:depends-on (cffi))
;; vim: ft=lisp et
| 1,656 | Common Lisp | .asd | 38 | 41.973684 | 73 | 0.73808 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 526f8731c877b27f844c6199d395eab49bd62b85099923fdb8010a67ab61659e | 887 | [
336907,
444257
] |
888 | cffi-examples.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/cffi-examples.asd | ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; cffi-examples.asd --- ASDF system definition for CFFI examples.
;;;
;;; Copyright (C) 2005-2006, James Bielman <[email protected]>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
;;;
(defsystem cffi-examples
:description "CFFI Examples"
:author "James Bielman <[email protected]>"
:components
((:module examples
:components
((:file "examples")
(:file "gethostname")
(:file "gettimeofday"))))
:depends-on (cffi))
| 1,556 | Common Lisp | .asd | 36 | 41.416667 | 70 | 0.735352 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 18e9c8562c915387d6e5c26c03264065f852407e50b1ffe269efea45f7a80295 | 888 | [
19947,
392239
] |
889 | cffi.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/cffi.asd | ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; cffi.asd --- ASDF system definition for CFFI.
;;;
;;; Copyright (C) 2005-2006, James Bielman <[email protected]>
;;; Copyright (C) 2005-2010, Luis Oliveira <[email protected]>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
;;;
(in-package :asdf)
#-(or openmcl mcl sbcl cmu scl clisp lispworks ecl allegro cormanlisp abcl mkcl)
(error "Sorry, this Lisp is not yet supported. Patches welcome!")
(defsystem :cffi
:description "The Common Foreign Function Interface"
:author "James Bielman <[email protected]>"
:maintainer "Luis Oliveira <[email protected]>"
:licence "MIT"
:depends-on (:alexandria :trivial-features :babel)
:components
((:module "src"
:serial t
:components
(#+openmcl (:file "cffi-openmcl")
#+mcl (:file "cffi-mcl")
#+sbcl (:file "cffi-sbcl")
#+cmu (:file "cffi-cmucl")
#+scl (:file "cffi-scl")
#+clisp (:file "cffi-clisp")
#+lispworks (:file "cffi-lispworks")
#+ecl (:file "cffi-ecl")
#+allegro (:file "cffi-allegro")
#+cormanlisp (:file "cffi-corman")
#+abcl (:file "cffi-abcl")
#+mkcl (:file "cffi-mkcl")
(:file "package")
(:file "utils")
(:file "libraries")
(:file "early-types")
(:file "types")
(:file "enum")
(:file "strings")
(:file "structures")
(:file "functions")
(:file "foreign-vars")
(:file "features")))))
(defmethod operation-done-p ((o test-op) (c (eql (find-system :cffi))))
nil)
(defmethod perform ((o test-op) (c (eql (find-system :cffi))))
(operate 'asdf:load-op :cffi-tests)
(operate 'asdf:test-op :cffi-tests))
;; vim: ft=lisp et
| 2,807 | Common Lisp | .asd | 69 | 37.536232 | 80 | 0.670937 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 6576ca3fd24595766d2fd4cfe9a254587b9e9867b7b7d103c632beb25552ad5f | 889 | [
-1
] |
890 | cffi-libffi.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/cffi-libffi.asd | ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; cffi-libffi.asd --- Foreign Structures By Value
;;;
;;; Copyright (C) 2011 Liam M. Healy
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
;;;
(in-package :asdf)
(eval-when (:compile-toplevel :execute)
(asdf:oos 'asdf:load-op :cffi-grovel)
(asdf:oos 'asdf:load-op :trivial-features))
(defsystem cffi-libffi
:description "Foreign structures by value"
:author "Liam Healy <[email protected]>"
:maintainer "Liam Healy <[email protected]>"
:defsystem-depends-on (#:trivial-features #:cffi-grovel)
:components
((:module libffi
:serial t
:components
((:file "init")
(cffi-grovel:grovel-file
"libffi"
:pathname #+unix "libffi-unix" #+windows "libffi-win32")
(:file "built-in-types")
(:file "cstruct")
(:file "cif")
(:file "functions"))))
:depends-on (#:cffi #:cffi-grovel #:trivial-features))
| 1,973 | Common Lisp | .asd | 48 | 38.645833 | 70 | 0.718522 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 7b70a52c1eb65420d6bc578c496f78448b9e14debf598daa969070bc8d808643 | 890 | [
424947
] |
891 | cffi-tests.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/cffi-tests.asd | ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; cffi-tests.asd --- ASDF system definition for CFFI unit tests.
;;;
;;; Copyright (C) 2005-2006, James Bielman <[email protected]>
;;; Copyright (C) 2005-2011, Luis Oliveira <[email protected]>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
;;;
(defpackage #:cffi-tests-system
(:use #:cl #:asdf))
(in-package #:cffi-tests-system)
(eval-when (:compile-toplevel :load-toplevel :execute)
(oos 'load-op 'trivial-features))
(defvar *tests-dir* (append (pathname-directory *load-truename*) '("tests")))
(defclass c-test-lib (c-source-file)
())
(defmethod perform ((o load-op) (c c-test-lib))
nil)
(defmethod perform ((o load-source-op) (c c-test-lib))
nil)
(defmethod perform ((o compile-op) (c c-test-lib))
#-windows
(unless (zerop (run-shell-command
"cd ~A; make"
(namestring (make-pathname :name nil :type nil
:directory *tests-dir*))))
(error 'operation-error :component c :operation o)))
;; For the convenience of ECL users.
#+ecl (require 'rt)
(defsystem cffi-tests
:description "Unit tests for CFFI."
:depends-on (cffi-libffi bordeaux-threads #-ecl rt)
:components
((:module "tests"
:serial t
:components
((:c-test-lib "libtest")
(:file "package")
(:file "bindings")
(:file "funcall")
(:file "defcfun")
(:file "callbacks")
(:file "foreign-globals")
(:file "memory")
(:file "strings")
(:file "struct")
(:file "fsbv")
(:file "union")
(:file "enum")
(:file "misc-types")
(:file "misc")))))
(defmethod operation-done-p ((o test-op) (c (eql (find-system :cffi-tests))))
nil)
(defmethod perform ((o test-op) (c (eql (find-system :cffi-tests))))
(flet ((run-tests (&rest args)
(apply (intern (string '#:run-cffi-tests) '#:cffi-tests) args)))
(run-tests :compiled nil)
(run-tests :compiled t)))
;;; vim: ft=lisp et
| 3,053 | Common Lisp | .asd | 78 | 35.269231 | 77 | 0.670267 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 73bf183312ee502cd525a772826b5c170052bec9c88a30cece057a40a5b15711 | 891 | [
-1
] |
892 | uffi.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/uffi-compat/uffi.asd | ;;;; uffi.asd -*- Mode: Lisp -*-
(defsystem uffi :depends-on (cffi-uffi-compat))
| 82 | Common Lisp | .asd | 2 | 39.5 | 47 | 0.64557 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | f57575c53bda35b8f5c4f8922113657567b383aafb5da5f6c18f220e6a0ddc86 | 892 | [
260945,
366440
] |
893 | babel.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/babel/babel.asd | ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; babel.asd --- ASDF system definition for Babel.
;;;
;;; Copyright (C) 2007, Luis Oliveira <[email protected]>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
(defsystem babel
:description "Babel, a charset conversion library."
:author "Luis Oliveira <[email protected]>"
:licence "MIT"
:depends-on (trivial-features alexandria)
:components
((:module src
:serial t
:components
((:file "packages")
(:file "encodings")
(:file "enc-ascii")
(:file "enc-ebcdic")
(:file "enc-iso-8859")
(:file "enc-unicode")
(:file "enc-cp1251")
(:file "enc-cp1252")
(:file "jpn-table")
(:file "enc-jpn")
(:file "enc-gbk")
(:file "external-format")
(:file "strings")
(:file "gbk-map")
(:file "sharp-backslash")))))
(defmethod perform ((o test-op) (c (eql (find-system :babel))))
(operate 'load-op :babel-tests)
(operate 'test-op :babel-tests))
(defmethod operation-done-p ((o test-op) (c (eql (find-system :babel))))
nil)
| 2,128 | Common Lisp | .asd | 54 | 36.5 | 72 | 0.696765 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | d431dbb98710cb5e028698dff3f1573c9c3df813a9ce7b9b7254e6e26c63998a | 893 | [
-1
] |
894 | babel-tests.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/babel/babel-tests.asd | ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; babel-tests.asd --- ASDF system definition for Babel unit tests.
;;;
;;; Copyright (C) 2007, Luis Oliveira <[email protected]>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
(defsystem babel-tests
:description "Unit tests for Babel."
:depends-on (babel hu.dwim.stefil)
:components
((:module "tests"
:serial t
:components
((:file "tests")))))
(defmethod perform ((o test-op) (c (eql (find-system :babel-tests))))
(funcall (intern (string '#:run) '#:babel-tests)))
(defmethod operation-done-p ((o test-op) (c (eql (find-system :babel-tests))))
nil)
;;; vim: ft=lisp et
| 1,714 | Common Lisp | .asd | 38 | 43.368421 | 78 | 0.727273 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 62ed3e3c6c2551d98a79114f3b743dab3f2b74651dc332d8d66d837737d3b117 | 894 | [
335,
111715
] |
895 | babel-streams.asd | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/babel/babel-streams.asd | ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; babel-streams.asd --- ASDF system definition for Babel streams.
;;;
;;; Copyright (C) 2008, Attila Lendvai <[email protected]>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
(defsystem :babel-streams
:description "Some useful streams based on Babel's encoding code"
:author ("Dr. Edmund Weitz"
"Attila Lendvai <[email protected]>")
:version "0.1.0"
:licence "MIT"
:depends-on (:babel :alexandria :trivial-gray-streams)
:components
((:module "src"
:serial t
:components
((:file "streams")))))
| 1,654 | Common Lisp | .asd | 37 | 42.675676 | 70 | 0.733292 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 3f5a837280c14783f8bb2721aca49e9b0ceefb002612348b2a15c1c1922ae012 | 895 | [
188159,
388922
] |
896 | yason.asd | cac-t-u-s_om-sharp/src/lisp-externals/Yason/yason.asd | ;;;; -*- Mode: Lisp -*-
;; This file is part of yason, a Common Lisp JSON parser/encoder
;;
;; Copyright (c) 2008-2012 Hans Huebner and contributors
;; All rights reserved.
;;
;; Please see the file LICENSE in the distribution.
(in-package :cl-user)
(defpackage :yason.system
(:use :cl :asdf))
(in-package :yason.system)
(defsystem :yason
:name "YASON"
:author "Hans Huebner <[email protected]>"
:version "0.6.2"
:maintainer "Hans Huebner <[email protected]>"
:licence "BSD"
:description "JSON parser/encoder"
:long-description "YASON is a Common Lisp library for encoding and
decoding data in the JSON interchange format. JSON is used as a
lightweight alternative to XML. YASON has the sole purpose of
encoding and decoding data and does not impose any object model on
the Common Lisp application that uses it."
:depends-on (:alexandria :trivial-gray-streams)
:components ((:file "package")
(:file "encode" :depends-on ("package"))
(:file "parse" :depends-on ("package"))))
| 1,033 | Common Lisp | .asd | 27 | 35.111111 | 70 | 0.714 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 0bfae3251a9aafb1108036bae9c657bd50abcb128c087ca696db4379a016107c | 896 | [
-1
] |
897 | lispworks-udp.asd | cac-t-u-s_om-sharp/src/lisp-externals/lispworks-udp/lispworks-udp.asd | ;;;; -*- Mode: Lisp -*-
;;;; $Id: lispworks-udp.asd 659 2008-11-22 12:45:13Z binghe $
;;;; System Definition for LispWorks UDP
(in-package :asdf)
;;; Load COMM package
(require "comm")
#+(and lispworks4 win32)
(pushnew :mswindows *features*)
(defsystem lispworks-udp
:description "UDP support for LispWorks"
:license "MIT"
:version "4.1"
:author "Chun Tian (binghe) <[email protected]>"
:serial t
:components ((:file "package")
(:file "rtt")
(:file "lispworks-udp")
(:file "class")
#-mswindows
(:file "wait-for-input")
(:file "condition")
(:file "multicast")
(:file "udp-client")
(:file "udp-server")
(:file "rtt-client")
#-mswindows
(:file "unix")
#-mswindows
(:file "unix-server")
#-mswindows
(:file "icmp")))
| 965 | Common Lisp | .asd | 31 | 22.096774 | 61 | 0.515054 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | ca717e7807650e2d054924c888a4e06c6ccb496bb083e81f4041b61e05b53b65 | 897 | [
-1
] |
898 | cl-svg.asd | cac-t-u-s_om-sharp/src/lisp-externals/cl-svg/cl-svg.asd | ;;; -*- mode: lisp; syntax: common-lisp; package: cl-svg; encoding: utf-8 -*-
;;; $Id$
;;;
;;; Copyright (c) 2008 William S. Annis. All rights reserved.
;;;
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;; 1. Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;; 2. Redistributions in binary form must reproduce the above copyright
;;; notice, this list of conditions and the following disclaimer in the
;;; documentation and/or other materials provided with the distribution.
;;;
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
;;; SUCH DAMAGE.
(in-package :asdf)
(defsystem :cl-svg
:name "CL-SVG"
:author "William S. Annis <[email protected]>"
:version "0.01"
:maintainer "William S. Annis <[email protected]>"
:licence "MIT License"
:description "Produce Scalable Vector Graphics (SVG) files"
:components ((:file "package")
(:file "path")
(:file "format-xml")
(:file "svg"))
:serial t)
| 1,875 | Common Lisp | .asd | 38 | 46.552632 | 78 | 0.72459 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 4857e83aa694a08c7c08b23798c57c2b938967cf362cb8b53859387dc6264707 | 898 | [
-1
] |
899 | midi.asd | cac-t-u-s_om-sharp/src/packages/midi/midi-api/CL-MIDI/midi-20070618/midi.asd | (defsystem midi
:name "midi"
:author "Robert Strandh and others"
:version "1"
:licence "GNU Lesser General Public License (version 2)"
:description "A library for MIDI and Midifiles."
:components ((:file "midi")))
| 239 | Common Lisp | .asd | 7 | 29.571429 | 61 | 0.676724 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 68b929a8f8a1f354fbfc39932488fbc16aaa41d3dcf45da1feb405fe6e2b5a1b | 899 | [
-1
] |
900 | osc.asd | cac-t-u-s_om-sharp/src/packages/osc/cl-osc/osc.asd | ;; -*- mode: lisp -*-
(in-package #:asdf)
(defsystem osc
:name "osc"
:author "nik gaffney <[email protected]>"
:licence "LLGPL"
:description "The Open Sound Control protocol, aka OSC"
:version "0.5"
:components ((:file "osc")))
| 246 | Common Lisp | .asd | 9 | 23.444444 | 59 | 0.617021 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | e3524ded749bb976a71b771e2c8f036b7d9630a66843d47cd228f9cb948932ec | 900 | [
-1
] |
925 | cercle.tif | cac-t-u-s_om-sharp/resources/icons/boxes/cercle.tif | MM * : а
а
<?xpacket begin='яЛП' id='W5M0MpCehiHzreSzNTczkc9d'?><x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='XMP toolkit 2.9-9, framework 1.6'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:iX='http://ns.adobe.com/iX/1.0/'>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end='w'?> ў ( R М ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџџЬ џџЬ џџЬ џ3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџ3ffџ3ffџџЬ џџЬ џџЬ џ3ffџ3ffџ3ffџ3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџ3ffџ3ffџннн џЬ џџЬ џџЬ џннн ннн 3ffџ3ffџ3ffџџЬ џџЬ џџЬ џннн ннн ннн ннн ннн ннн Ь fџЬ fџЬ fџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџџЬ џџЬ џџЬ џннн ннн ннн ннн ннн ннн Ь fџЬ fџЬ fџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн џЬ џџЬ џџЬ џннн ннн ннн ннн ннн 3ffџЬ fџЬ fџЬ fџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџннн ннн ннн 3ffџ3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџ3ffџннн ннн 3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџннн ннн 3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџннн 3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџЬ fџЬ fџЬ fџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн Ь fџЬ fџЬ fџЬ fџЬ fџЬ fџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн Ь fџЬ fџЬ fџЬ fџЬ fџЬ fџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн Ь fџЬ fџЬ fџ3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџ3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџннн 3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџннн ннн 3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџннн ннн 3ffџ3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџ3ffџннн ннн ннн Ь fџЬ fџЬ fџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн џЬ џџЬ џџЬ џннн ннн ннн ннн Ь fџЬ fџЬ fџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн џЬ џџЬ џџЬ џннн ннн ннн ннн Ь fџЬ fџЬ fџ3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџџЬ џџЬ џџЬ џннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџ3ffџ3ffџннн ннн џЬ џџЬ џџЬ џннн 3ffџ3ffџ3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџ3ffџ3ffџ3ffџџЬ џџЬ џџЬ џ3ffџ3ffџ3ffџ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн ннн 3ffџ3ffџџЬ џџЬ џџЬ џ3ffџннн ннн ннн ннн ннн ннн ннн ннн ннн | 2,816 | Common Lisp | .cl | 7 | 401.285714 | 2,521 | 0.716981 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 7f3c31124b283284848da4782c0c933f7535022bf4c5f69caa1aa09d6e19753c | 925 | [
-1
] |
926 | n-cercle.opat | cac-t-u-s_om-sharp/help-patches/Basic data structures/n-cercle.opat |
(:patch
(:name "n-cercle")
(:doc "")
(:info
(:created "2019/09/20 17:22:47")
(:modified "2021/06/13 23:39:58")
(:by "om-sharp")
(:version 1.0301))
(:window (:size (1212 721)) (:position (468 178)))
(:grid nil)
(:lock nil)
(:boxes
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name nil)
(:x 669)
(:y 227)
(:w 140)
(:h 100)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size (331 245)) (:position (148 138)))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots ((:n 12) (:puntos (:list (:list 2 6 9)))))))
(:id 0))
(:box
(:type :function)
(:reference chord2c)
(:group-id nil)
(:name "chord2c")
(:x 728)
(:y 165)
(:w 81)
(:h 29)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:icon :left)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "APPROX")
(:value 2)
(:reactive nil)))
(:outputs (:output (:name "out") (:reactive nil)))
(:id 1))
(:box
(:type :object)
(:reference chord)
(:group-id nil)
(:name nil)
(:x 669)
(:y 77)
(:w 82)
(:h 83)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:show-markers t)
(:lock :locked)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "LMIDIC")
(:value (:list 6000))
(:reactive nil))
(:input
(:type :standard)
(:name "LVEL")
(:value (:list 80))
(:reactive nil))
(:input
(:type :standard)
(:name "LOFFSET")
(:value (:list 0))
(:reactive nil))
(:input
(:type :standard)
(:name "LDUR")
(:value (:list 1000))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "LMIDIC") (:reactive nil))
(:output (:name "LVEL") (:reactive nil))
(:output (:name "LOFFSET") (:reactive nil))
(:output (:name "LDUR") (:reactive nil)))
(:window (:size (500 498)) (:position (237 142)))
(:edition-params)
(:value
(:object
(:class chord)
(:slots
((:symbolic-date nil)
(:symbolic-dur nil)
(:symbolic-dur-extent 0)
(:extras nil)
(:group-ids nil)
(:onset 0)
(:item-internal-time nil)
(:item-type nil)
(:attributes nil)
(:lmidic (:list 6600 7400 8100))
(:lvel (:list 80 80 80))
(:loffset (:list 0 0 0))
(:ldur (:list 1000 1000 1000))
(:lchan (:list 1 1 1))
(:lport (:list nil nil nil))))))
(:id 2))
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name nil)
(:x 44)
(:y 368)
(:w 136)
(:h 141)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size (nil nil)) (:position (nil nil)))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots ((:n 12) (:puntos (:list (:list 0 5 7) (:list 1 3 9)))))))
(:id 3))
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name nil)
(:x 51)
(:y 137)
(:w 136)
(:h 141)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size (nil nil)) (:position (nil nil)))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots ((:n 12) (:puntos (:list (:list 0 5 7)))))))
(:id 4))
(:comment
(:x 102)
(:y 44)
(:w 84)
(:h 30)
(:fgcolor nil)
(:bgcolor nil)
(:border (:number-or-nil (:number 0.0) (:t-or-nil t)))
(:roundness nil)
(:text-font
(:font-or-nil
(:font (:font (:face "Calibri") (:size 18) (:style :bold)))
(:t-or-nil t)))
(:align nil)
(:text "N-CERCLE")
(:id 5))
(:box
(:type :value)
(:reference cons)
(:group-id nil)
(:name "value box")
(:x 137)
(:y 102)
(:w 49)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value (:list 0 5 7))
(:id 6))
(:box
(:type :value)
(:reference fixnum)
(:group-id nil)
(:name "value box")
(:x 103)
(:y 102)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value 12)
(:id 7))
(:box
(:type :value)
(:reference fixnum)
(:group-id nil)
(:name "value box")
(:x 96)
(:y 333)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value 12)
(:id 8))
(:box
(:type :value)
(:reference cons)
(:group-id nil)
(:name "value box")
(:x 130)
(:y 333)
(:w 90)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value (:list (:list 0 5 7) (:list 1 3 9)))
(:id 9))
(:box
(:type :value)
(:reference fixnum)
(:group-id nil)
(:name "value box")
(:x 770)
(:y 130)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value 2)
(:id 10))
(:box
(:type :function)
(:reference c2chord)
(:group-id nil)
(:name "c2chord")
(:x 728)
(:y 372)
(:w 81)
(:h 29)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:icon :left)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "INDEX")
(:value 0)
(:reactive nil))
(:input
(:type :standard)
(:name "BASE")
(:value 6000)
(:reactive nil))
(:input
(:type :standard)
(:name "APPROX")
(:value 100)
(:reactive nil)))
(:outputs (:output (:name "out") (:reactive nil)))
(:id 11))
(:box
(:type :object)
(:reference chord)
(:group-id nil)
(:name nil)
(:x 672)
(:y 441)
(:w 137)
(:h 103)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:show-markers t)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "LMIDIC")
(:value (:list 6000))
(:reactive nil))
(:input
(:type :standard)
(:name "LVEL")
(:value (:list 80))
(:reactive nil))
(:input
(:type :standard)
(:name "LOFFSET")
(:value (:list 0))
(:reactive nil))
(:input
(:type :standard)
(:name "LDUR")
(:value (:list 1000))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "LMIDIC") (:reactive nil))
(:output (:name "LVEL") (:reactive nil))
(:output (:name "LOFFSET") (:reactive nil))
(:output (:name "LDUR") (:reactive nil)))
(:window (:size (nil nil)) (:position (nil nil)))
(:edition-params)
(:value
(:object
(:class chord)
(:slots
((:symbolic-date nil)
(:symbolic-dur nil)
(:symbolic-dur-extent 0)
(:extras nil)
(:group-ids nil)
(:onset 0)
(:item-internal-time nil)
(:item-type nil)
(:attributes nil)
(:lmidic (:list 6200 6600 6900))
(:lvel (:list 80 80 80))
(:loffset (:list 0 0 0))
(:ldur (:list 1000 1000 1000))
(:lchan (:list 1 1 1))
(:lport (:list nil nil nil))))))
(:id 12))
(:comment
(:x 264)
(:y 12)
(:w 295)
(:h 120)
(:fgcolor nil)
(:bgcolor nil)
(:border (:number-or-nil (:number 0.0) (:t-or-nil t)))
(:roundness nil)
(:text-font
(:font-or-nil
(:font (:font (:face "Calibri") (:size 12) (:style :plain)))
(:t-or-nil t)))
(:align nil)
(:text
"N-CERCLE can be used to represent chords following the pitch-class set theory, or cyclic rhythmic patterns.
<n> is the 'modulo' of the space
<puntos> is a list of points in this space.
Note: N-CERCLE can also contain a set of chords/patterns: in this case, <puntos> is a list of lists.")
(:id 13))
(:box
(:type :function)
(:reference c2chord-seq)
(:group-id nil)
(:name "c2chord-seq")
(:x 945)
(:y 188)
(:w 106)
(:h 29)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:icon :left)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "BASE")
(:value 6000)
(:reactive nil))
(:input
(:type :standard)
(:name "APPROX")
(:value 100)
(:reactive nil)))
(:outputs (:output (:name "out") (:reactive nil)))
(:id 14))
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name nil)
(:x 940)
(:y 61)
(:w 135)
(:h 109)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock :locked)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size (nil nil)) (:position (nil nil)))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots ((:n 12) (:puntos (:list (:list 0 5 7) (:list 1 3 9)))))))
(:id 15))
(:box
(:type :value)
(:reference fixnum)
(:group-id nil)
(:name "value box")
(:x 992)
(:y 26)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value 12)
(:id 16))
(:box
(:type :value)
(:reference cons)
(:group-id nil)
(:name "value box")
(:x 1026)
(:y 26)
(:w 90)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value (:list (:list 0 5 7) (:list 1 3 9)))
(:id 17))
(:box
(:type :object)
(:reference chord-seq)
(:group-id nil)
(:name nil)
(:x 928)
(:y 241)
(:w 228)
(:h 81)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:show-markers t)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "LMIDIC")
(:value (:list (:list 6000)))
(:reactive nil))
(:input
(:type :standard)
(:name "LONSET")
(:value (:list 0 1000))
(:reactive nil))
(:input
(:type :standard)
(:name "LDUR")
(:value (:list (:list 1000)))
(:reactive nil))
(:input
(:type :standard)
(:name "LVEL")
(:value 100)
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "LMIDIC") (:reactive nil))
(:output (:name "LONSET") (:reactive nil))
(:output (:name "LDUR") (:reactive nil))
(:output (:name "LVEL") (:reactive nil)))
(:window (:size (nil nil)) (:position (nil nil)))
(:edition-params)
(:value
(:object
(:class chord-seq)
(:slots
((:onset 0)
(:duration 3000)
(:interpol (:number-or-nil (:number 50) (:t-or-nil nil)))
(:name "CHORD-SEQ")
(:symbolic-date nil)
(:symbolic-dur nil)
(:symbolic-dur-extent 0)
(:extras nil)
(:group-ids nil)
(:lmidic
(:list
(:list 6000 6500 6700)
(:list 6100 6300 6900)
(:list 6100 6300 6900)))
(:lonset (:list 0 1000 2000 3000))
(:ldur (:list 1000 1000 1000))
(:lvel (:list 100 100 100))
(:loffset (:list 0 0 0))
(:lchan (:list 1 1 1))
(:lport (:list nil nil nil))
(:llegato nil)))))
(:id 18))
(:box
(:type :function)
(:reference chord-seq2c)
(:group-id nil)
(:name "chord-seq2c")
(:x 925)
(:y 364)
(:w 106)
(:h 29)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:icon :left)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "APPROX")
(:value 2)
(:reactive nil)))
(:outputs (:output (:name "out") (:reactive nil)))
(:id 19))
(:box
(:type :value)
(:reference fixnum)
(:group-id nil)
(:name "value box")
(:x 986)
(:y 329)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value 2)
(:id 20))
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name nil)
(:x 925)
(:y 419)
(:w 144)
(:h 139)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size (nil nil)) (:position (nil nil)))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots ((:n 12) (:puntos (:list (:list 0 5 7) (:list 1 3 9)))))))
(:id 21))
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name nil)
(:x 350)
(:y 193)
(:w 111)
(:h 100)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock :locked)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size (nil nil)) (:position (nil nil)))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots ((:n 12) (:puntos (:list (:list 0 5 7)))))))
(:id 22))
(:box
(:type :function)
(:reference nc-complement)
(:group-id nil)
(:name "nc-complement")
(:x 287)
(:y 528)
(:w 123)
(:h 29)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:icon :left)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil)))
(:outputs (:output (:name "out") (:reactive nil)))
(:id 23))
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name nil)
(:x 287)
(:y 570)
(:w 111)
(:h 100)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size (nil nil)) (:position (nil nil)))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots ((:n 12) (:puntos (:list (:list 0 1 2 4 6 7 8 9 11)))))))
(:id 24))
(:box
(:type :function)
(:reference nc-rotate)
(:group-id nil)
(:name "nc-rotate")
(:x 432)
(:y 352)
(:w 89)
(:h 29)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:icon :left)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 1) (:reactive nil)))
(:outputs (:output (:name "out") (:reactive nil)))
(:id 25))
(:box
(:type :value)
(:reference fixnum)
(:group-id nil)
(:name "value box")
(:x 480)
(:y 317)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value 2)
(:id 26))
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name nil)
(:x 454)
(:y 400)
(:w 111)
(:h 100)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock :locked)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size (nil nil)) (:position (nil nil)))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots ((:n 12) (:puntos (:list (:list 2 7 9)))))))
(:id 27))
(:box
(:type :function)
(:reference nc-inverse)
(:group-id nil)
(:name "nc-inverse")
(:x 428)
(:y 528)
(:w 95)
(:h 29)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:icon :left)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil)))
(:outputs (:output (:name "out") (:reactive nil)))
(:id 28))
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name nil)
(:x 454)
(:y 573)
(:w 112)
(:h 97)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size (nil nil)) (:position (nil nil)))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots ((:n 12) (:puntos (:list (:list -9 -7 -2)))))))
(:id 29)))
(:connections
(:connection (:from (:box 0 :out 0)) (:to (:box 11 :in 0)))
(:connection (:from (:box 1 :out 0)) (:to (:box 0 :in 0)))
(:connection (:from (:box 2 :out 0)) (:to (:box 1 :in 0)))
(:connection (:from (:box 6 :out 0)) (:to (:box 4 :in 2)))
(:connection (:from (:box 7 :out 0)) (:to (:box 4 :in 1)))
(:connection (:from (:box 8 :out 0)) (:to (:box 3 :in 1)))
(:connection (:from (:box 9 :out 0)) (:to (:box 3 :in 2)))
(:connection (:from (:box 10 :out 0)) (:to (:box 1 :in 1)))
(:connection (:from (:box 11 :out 0)) (:to (:box 12 :in 0)))
(:connection (:from (:box 14 :out 0)) (:to (:box 18 :in 0)))
(:connection (:from (:box 15 :out 0)) (:to (:box 14 :in 0)))
(:connection (:from (:box 16 :out 0)) (:to (:box 15 :in 1)))
(:connection (:from (:box 17 :out 0)) (:to (:box 15 :in 2)))
(:connection (:from (:box 18 :out 0)) (:to (:box 19 :in 0)))
(:connection (:from (:box 19 :out 0)) (:to (:box 21 :in 0)))
(:connection (:from (:box 20 :out 0)) (:to (:box 19 :in 1)))
(:connection (:from (:box 22 :out 0)) (:to (:box 25 :in 0)))
(:connection (:from (:box 23 :out 0)) (:to (:box 24 :in 0)))
(:connection (:from (:box 25 :out 0)) (:to (:box 27 :in 0)))
(:connection (:from (:box 26 :out 0)) (:to (:box 25 :in 1)))
(:connection (:from (:box 27 :out 0)) (:to (:box 28 :in 0)))
(:connection (:from (:box 28 :out 0)) (:to (:box 29 :in 0)))
(:connection (:from (:box 29 :out 0)) (:to (:box 23 :in 0))))) | 23,953 | Common Lisp | .cl | 1,057 | 18.017975 | 112 | 0.527649 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 7b37c68a11ed3e42161587854fba400f46b8517ef9c40b1664c7f16527ec9475 | 926 | [
-1
] |
927 | n-cercle-rhythm.opat | cac-t-u-s_om-sharp/help-patches/Basic data structures/n-cercle-rhythm.opat |
(:patch
(:name "n-cercle-rhythm")
(:doc "")
(:info
(:created "2019/09/20 22:08:12")
(:modified "2020/01/02 8:45:59")
(:by "om-sharp")
(:version 1.0))
(:window (:size (1089 636)) (:position (413 180)))
(:grid nil)
(:lock nil)
(:boxes
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name "N-CERCLE1")
(:x 394)
(:y 465)
(:w 121)
(:h 118)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size nil) (:position nil))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots
((:n 3)
(:puntos
(:list
(:list
0
2
3
5
6
8
9
11
12
14
15
17
18
20
21
23
24
26
27
29
30
32
33
35)))))))
(:id 0))
(:box
(:type :value)
(:reference fixnum)
(:group-id nil)
(:name "aux11")
(:x 421)
(:y 335)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value 3)
(:id 1))
(:box
(:type :function)
(:reference rhythm2c)
(:group-id nil)
(:name "rhythm2c")
(:x 376)
(:y 374)
(:w 85)
(:h 30)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:icon :left)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil)))
(:outputs (:output (:name "out") (:reactive nil)))
(:id 2))
(:box
(:type :value)
(:reference fixnum)
(:group-id nil)
(:name "aux10")
(:x 277)
(:y 340)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value 12)
(:id 3))
(:box
(:type :value)
(:reference fixnum)
(:group-id nil)
(:name "aux9")
(:x 158)
(:y 340)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value 3)
(:id 4))
(:box
(:type :value)
(:reference cons)
(:group-id nil)
(:name "aux8")
(:x 110)
(:y 340)
(:w 46)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value (:list 12 8))
(:id 5))
(:box
(:type :value)
(:reference fixnum)
(:group-id nil)
(:name "aux7")
(:x 73)
(:y 340)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value 0)
(:id 6))
(:box
(:type :value)
(:reference fixnum)
(:group-id nil)
(:name "aux6")
(:x 909)
(:y 300)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value 3)
(:id 7))
(:box
(:type :value)
(:reference cons)
(:group-id nil)
(:name "aux5")
(:x 868)
(:y 300)
(:w 40)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value (:list 3 8))
(:id 8))
(:box
(:type :value)
(:reference fixnum)
(:group-id nil)
(:name "aux4")
(:x 849)
(:y 268)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value 0)
(:id 9))
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name "N-CERCLE2")
(:x 735)
(:y 213)
(:w 100)
(:h 118)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock :locked)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 3) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size nil) (:position nil))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots ((:n 3) (:puntos (:list (:list 0 2)))))))
(:id 10))
(:box
(:type :object)
(:reference voice)
(:group-id nil)
(:name "VOICE")
(:x 733)
(:y 404)
(:w 258)
(:h 99)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:show-markers t)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "TREE")
(:value (:list ? (:list (:list |4//4| (:list 1 1 1 1)))))
(:reactive nil))
(:input
(:type :standard)
(:name "LMIDIC")
(:value (:list (:list 6000)))
(:reactive nil))
(:input
(:type :standard)
(:name "TEMPO")
(:value 60)
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "TREE") (:reactive nil))
(:output (:name "LMIDIC") (:reactive nil))
(:output (:name "TEMPO") (:reactive nil)))
(:window (:size nil) (:position nil))
(:edition-params
(:time-map
(:list
(:list -1000 0)
(:list 0 7.5)
(:list 1000 13.0)
(:list 1500 23.25)
(:list 2500 28.75)
(:list 3000 39.0)
(:list 4000 44.5)))
(:staff :g))
(:value
(:object
(:class voice)
(:slots
((:onset 0)
(:duration 4499)
(:interpol (:number-or-nil (:number 50) (:t-or-nil nil)))
(:name "VOICE")
(:symbolic-date nil)
(:symbolic-dur nil)
(:symbolic-dur-extent 0)
(:extras nil)
(:tree
(:list
3
(:list
(:list (:list 3 8) (:list 2 1))
(:list (:list 3 8) (:list 2 1))
(:list (:list 3 8) (:list 2 1)))))
(:lmidic (:list 6000))
(:lonset (:list 0 1000 1500 2500 3000 4000 4500))
(:ldur
(:list
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)))
(:lvel (:list 100))
(:loffset (:list 0))
(:lchan (:list 1))
(:lport (:list nil))
(:llegato nil)
(:tempo 60)))))
(:id 11))
(:box
(:type :function)
(:reference c2rhythm)
(:group-id nil)
(:name "c2rhythm")
(:x 832)
(:y 340)
(:w 85)
(:h 30)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:icon :left)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "INDEX")
(:value 0)
(:reactive nil))
(:input
(:type :standard)
(:name "SIGNATURE")
(:value (:list 3 8))
(:reactive nil))
(:input
(:type :standard)
(:name "TIMES")
(:value 3)
(:reactive nil)))
(:outputs (:output (:name "out") (:reactive nil)))
(:id 12))
(:box
(:type :value)
(:reference fixnum)
(:group-id nil)
(:name "aux2")
(:x 568)
(:y 425)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value 3)
(:id 13))
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name "N-CERCLE2")
(:x 528)
(:y 465)
(:w 113)
(:h 118)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 3) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size nil) (:position nil))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots ((:n 3) (:puntos (:list (:list 0 2 3 5 6 8 9 11)))))))
(:id 14))
(:box
(:type :object)
(:reference voice)
(:group-id nil)
(:name "VOICE")
(:x 230)
(:y 206)
(:w 185)
(:h 99)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:show-markers t)
(:lock :locked)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "TREE")
(:value (:list ? (:list (:list |4//4| (:list 1 1 1 1)))))
(:reactive nil))
(:input
(:type :standard)
(:name "LMIDIC")
(:value (:list (:list 6000)))
(:reactive nil))
(:input
(:type :standard)
(:name "TEMPO")
(:value 60)
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "TREE") (:reactive nil))
(:output (:name "LMIDIC") (:reactive nil))
(:output (:name "TEMPO") (:reactive nil)))
(:window (:size nil) (:position nil))
(:edition-params
(:time-map
(:list
(:list -1000 0)
(:list 0 7.5)
(:list 1000 13.0)
(:list 1500 17.25)
(:list 2500 22.75)
(:list 3000 27.0)
(:list 4000 32.5)
(:list 4500 36.75)
(:list 5500 42.25)
(:list 6000 52.5)
(:list 7000 58.0)
(:list 7500 62.25)
(:list 8500 67.75)
(:list 9000 72.0)
(:list 10000 77.5)
(:list 10500 81.75)
(:list 11500 87.25)
(:list 12000 97.5)
(:list 13000 103.0)
(:list 13500 107.25)
(:list 14500 112.75)
(:list 15000 117.0)
(:list 16000 122.5)
(:list 16500 126.75)
(:list 17500 132.25)))
(:staff :g))
(:value
(:object
(:class voice)
(:slots
((:onset 0)
(:duration 17999)
(:interpol (:number-or-nil (:number 50) (:t-or-nil nil)))
(:name "VOICE")
(:symbolic-date nil)
(:symbolic-dur nil)
(:symbolic-dur-extent 0)
(:extras nil)
(:tree
(:list
9/2
(:list
(:list (:list 12 8) (:list 2 1 2 1 2 1 2 1))
(:list (:list 12 8) (:list 2 1 2 1 2 1 2 1))
(:list (:list 12 8) (:list 2 1 2 1 2 1 2 1)))))
(:lmidic (:list 6000))
(:lonset
(:list
0
1000
1500
2500
3000
4000
4500
5500
6000
7000
7500
8500
9000
10000
10500
11500
12000
13000
13500
14500
15000
16000
16500
17500
18000))
(:ldur
(:list
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)))
(:lvel (:list 100))
(:loffset (:list 0))
(:lchan (:list 1))
(:lport (:list nil))
(:llegato nil)
(:tempo 60)))))
(:id 15))
(:box
(:type :function)
(:reference rhythm2c)
(:group-id nil)
(:name "rhythm2c")
(:x 232)
(:y 374)
(:w 85)
(:h 30)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:icon :left)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil)))
(:outputs (:output (:name "out") (:reactive nil)))
(:id 16))
(:box
(:type :object)
(:reference voice)
(:group-id nil)
(:name "VOICE")
(:x 34)
(:y 466)
(:w 185)
(:h 99)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:show-markers t)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "TREE")
(:value (:list ? (:list (:list |4//4| (:list 1 1 1 1)))))
(:reactive nil))
(:input
(:type :standard)
(:name "LMIDIC")
(:value (:list (:list 6000)))
(:reactive nil))
(:input
(:type :standard)
(:name "TEMPO")
(:value 60)
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "TREE") (:reactive nil))
(:output (:name "LMIDIC") (:reactive nil))
(:output (:name "TEMPO") (:reactive nil)))
(:window (:size nil) (:position nil))
(:edition-params
(:time-map
(:list
(:list -1000 0)
(:list 0 7.5)
(:list 1000 13.0)
(:list 1500 17.25)
(:list 2500 22.75)
(:list 3000 27.0)
(:list 4000 32.5)
(:list 4500 36.75)
(:list 5500 42.25)
(:list 6000 52.5)
(:list 7000 58.0)
(:list 7500 62.25)
(:list 8500 67.75)
(:list 9000 72.0)
(:list 10000 77.5)
(:list 10500 81.75)
(:list 11500 87.25)
(:list 12000 97.5)
(:list 13000 103.0)
(:list 13500 107.25)
(:list 14500 112.75)
(:list 15000 117.0)
(:list 16000 122.5)
(:list 16500 126.75)
(:list 17500 132.25)))
(:staff :g))
(:value
(:object
(:class voice)
(:slots
((:onset 0)
(:duration 17999)
(:interpol (:number-or-nil (:number 50) (:t-or-nil nil)))
(:name "VOICE")
(:symbolic-date nil)
(:symbolic-dur nil)
(:symbolic-dur-extent 0)
(:extras nil)
(:tree
(:list
3
(:list
(:list (:list 12 8) (:list 2 1 2 1 2 1 2 1))
(:list (:list 12 8) (:list 2 1 2 1 2 1 2 1))
(:list (:list 12 8) (:list 2 1 2 1 2 1 2 1)))))
(:lmidic (:list 6000))
(:lonset
(:list
0
1000
1500
2500
3000
4000
4500
5500
6000
7000
7500
8500
9000
10000
10500
11500
12000
13000
13500
14500
15000
16000
16500
17500
18000))
(:ldur
(:list
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)
(:list 999)
(:list 499)))
(:lvel (:list 100))
(:loffset (:list 0))
(:lchan (:list 1))
(:lport (:list nil))
(:llegato nil)
(:tempo 60)))))
(:id 17))
(:box
(:type :function)
(:reference c2rhythm)
(:group-id nil)
(:name "c2rhythm")
(:x 47)
(:y 384)
(:w 109)
(:h 30)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:icon :left)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "INDEX")
(:value 0)
(:reactive nil))
(:input
(:type :standard)
(:name "SIGNATURE")
(:value (:list 12 8))
(:reactive nil))
(:input
(:type :standard)
(:name "TIMES")
(:value 3)
(:reactive nil)))
(:outputs (:output (:name "out") (:reactive nil)))
(:id 18))
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name "N-CERCLE1")
(:x 250)
(:y 466)
(:w 122)
(:h 119)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size nil) (:position nil))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots
((:n 12)
(:puntos
(:list
(:list
0
2
3
5
6
8
9
11
12
14
15
17
18
20
21
23
24
26
27
29
30
32
33
35)))))))
(:id 19))
(:box
(:type :value)
(:reference cons)
(:group-id nil)
(:name "aux")
(:x 425)
(:y 143)
(:w 99)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value (:list 0 2 3 5 6 8 9 11))
(:id 20))
(:box
(:type :object)
(:reference n-cercle)
(:group-id nil)
(:name "N-CERCLE")
(:x 35)
(:y 186)
(:w 153)
(:h 141)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock nil)
(:lambda nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input (:type :standard) (:name "N") (:value 12) (:reactive nil))
(:input
(:type :standard)
(:name "PUNTOS")
(:value (:list 0 5 7))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "N") (:reactive nil))
(:output (:name "PUNTOS") (:reactive nil)))
(:window (:size nil) (:position nil))
(:edition-params)
(:value
(:object
(:class n-cercle)
(:slots ((:n 12) (:puntos (:list (:list 0 2 3 5 6 8 9 11)))))))
(:id 21))
(:comment
(:x 61)
(:y 30)
(:w 82)
(:h 52)
(:fgcolor nil)
(:bgcolor nil)
(:border (:number-or-nil (:number 0.0) (:t-or-nil t)))
(:roundness nil)
(:text-font
(:font-or-nil
(:font (:font (:face "Calibri") (:size 18) (:style :bold)))
(:t-or-nil t)))
(:align nil)
(:text
"N-CERCLE
(Rhythm)")
(:id 22))
(:comment
(:x 170)
(:y 28)
(:w 531)
(:h 64)
(:fgcolor nil)
(:bgcolor nil)
(:border (:number-or-nil (:number 0.0) (:t-or-nil t)))
(:roundness nil)
(:text-font
(:font-or-nil
(:font (:font (:face "Calibri") (:size 12) (:style :plain)))
(:t-or-nil t)))
(:align nil)
(:text
"N-CERCLE can be used to represent chords following the pitch-class set theory, or cyclic rhythmic patterns.
<n> is the 'modulo' of the space
<puntos> is a list of points in this space.")
(:id 23)))
(:connections
(:connection (:from (:box 1 :out 0)) (:to (:box 2 :in 1)))
(:connection (:from (:box 2 :out 0)) (:to (:box 0 :in 0)))
(:connection (:from (:box 3 :out 0)) (:to (:box 16 :in 1)))
(:connection (:from (:box 4 :out 0)) (:to (:box 18 :in 3)))
(:connection (:from (:box 5 :out 0)) (:to (:box 18 :in 2)))
(:connection (:from (:box 6 :out 0)) (:to (:box 18 :in 1)))
(:connection (:from (:box 7 :out 0)) (:to (:box 12 :in 3)))
(:connection (:from (:box 8 :out 0)) (:to (:box 12 :in 2)))
(:connection (:from (:box 9 :out 0)) (:to (:box 12 :in 1)))
(:connection (:from (:box 10 :out 0)) (:to (:box 12 :in 0)))
(:connection (:from (:box 12 :out 0)) (:to (:box 11 :in 0)))
(:connection (:from (:box 13 :out 0)) (:to (:box 14 :in 1)))
(:connection (:from (:box 15 :out 0)) (:to (:box 2 :in 0)))
(:connection (:from (:box 15 :out 0)) (:to (:box 16 :in 0)))
(:connection (:from (:box 16 :out 0)) (:to (:box 19 :in 0)))
(:connection (:from (:box 18 :out 0)) (:to (:box 17 :in 0)))
(:connection (:from (:box 20 :out 0)) (:to (:box 14 :in 2)))
(:connection (:from (:box 20 :out 0)) (:to (:box 21 :in 2)))
(:connection (:from (:box 21 :out 0)) (:to (:box 18 :in 0))))) | 23,019 | Common Lisp | .cl | 1,065 | 15.885446 | 112 | 0.490229 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | d78f360b1f2d9c4a6485805d377d3ea0416cf0dfd7c0d09996f1b72b8e448347 | 927 | [
-1
] |
928 | sdif-classes.opat | cac-t-u-s_om-sharp/help-patches/SDIF/sdif-classes.opat |
(:patch
(:name "sdif-classes")
(:doc "")
(:info
(:created "2019/09/23 11:58:39")
(:modified "2022/04/28 23:41:36")
(:by "om-sharp")
(:version 1.06))
(:window (:size (873 594)) (:position (299 205)))
(:grid nil)
(:lock nil)
(:boxes
(:comment
(:x 297)
(:y 471)
(:w 141)
(:h 64)
(:fgcolor (:color 0 0 0 1.0))
(:bgcolor nil)
(:border 0)
(:roundness nil)
(:text-font (:font-or-nil (:font nil) (:t-or-nil nil)))
(:align nil)
(:text
"- type signature
- time
- streamID
- List of SDIFMatrix")
(:id 0))
(:comment
(:x 187)
(:y 388)
(:w 113)
(:h 29)
(:fgcolor (:color 0 0 0 1.0))
(:bgcolor nil)
(:border 0)
(:roundness nil)
(:text-font
(:font-or-nil
(:font (:font (:face "Consolas") (:size 18) (:style :plain)))
(:t-or-nil t)))
(:align nil)
(:text "SDIFFRAME")
(:id 1))
(:box
(:type :object)
(:reference sdifframe)
(:group-id nil)
(:name "SDIFFRAME")
(:x 178)
(:y 466)
(:w 118)
(:h 84)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :text)
(:showname nil)
(:lock nil)
(:lambda nil)
(:reactive nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "FRAMETYPE")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "FTIME")
(:value 0.0)
(:reactive nil))
(:input
(:type :standard)
(:name "STREAMID")
(:value 0)
(:reactive nil))
(:input
(:type :standard)
(:name "LMATRIX")
(:value nil)
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "FRAMETYPE") (:reactive nil))
(:output (:name "FTIME") (:reactive nil))
(:output (:name "STREAMID") (:reactive nil))
(:output (:name "LMATRIX") (:reactive nil)))
(:window (:size nil) (:position nil))
(:edition-params)
(:value
(:object
(:class sdifframe)
(:slots
((:onset 0)
(:item-internal-time nil)
(:item-type nil)
(:attributes nil)
(:frametype nil)
(:ftime 0.0)
(:streamid 0)
(:lmatrix nil)))))
(:id 2))
(:comment
(:x 505)
(:y 106)
(:w 118)
(:h 27)
(:fgcolor (:color 0 0 0 1.0))
(:bgcolor nil)
(:border 0)
(:roundness nil)
(:text-font
(:font-or-nil
(:font (:font (:face "Consolas") (:size 16) (:style :plain)))
(:t-or-nil t)))
(:align nil)
(:text "SDIFMATRIX")
(:id 3))
(:comment
(:x 59)
(:y 101)
(:w 96)
(:h 27)
(:fgcolor (:color 0 0 0 1.0))
(:bgcolor nil)
(:border 0)
(:roundness nil)
(:text-font
(:font-or-nil
(:font (:font (:face "Consolas") (:size 16) (:style :plain)))
(:t-or-nil t)))
(:align nil)
(:text "SDIFTYPE")
(:id 4))
(:comment
(:x 607)
(:y 109)
(:w 134)
(:h 22)
(:fgcolor (:color 0 0 0 1.0))
(:bgcolor nil)
(:border 0)
(:roundness nil)
(:text-font (:font-or-nil (:font nil) (:t-or-nil nil)))
(:align nil)
(:text "(a simple 2D-ARRAY)")
(:id 5))
(:comment
(:x 661)
(:y 248)
(:w 154)
(:h 50)
(:fgcolor (:color 0 0 0 1.0))
(:bgcolor nil)
(:border 0)
(:roundness nil)
(:text-font (:font-or-nil (:font nil) (:t-or-nil nil)))
(:align nil)
(:text
"- Type signature
- Data (list of lists)
- Field names")
(:id 6))
(:comment
(:x 196)
(:y 88)
(:w 218)
(:h 50)
(:fgcolor (:color 0 0 0 1.0))
(:bgcolor nil)
(:border 0)
(:roundness nil)
(:text-font (:font-or-nil (:font nil) (:t-or-nil nil)))
(:align nil)
(:text
"When creating an SDIF file, all new (user-defined) types must be declared")
(:id 7))
(:comment
(:x 165)
(:y 201)
(:w 160)
(:h 50)
(:fgcolor (:color 0 0 0 1.0))
(:bgcolor nil)
(:border 0)
(:roundness nil)
(:text-font (:font-or-nil (:font nil) (:t-or-nil nil)))
(:align nil)
(:text
"- frame or matrix?
- Signature (\"XXXX\")
- Description")
(:id 8))
(:comment
(:x 46)
(:y 45)
(:w 273)
(:h 22)
(:fgcolor (:color 0 0 0 1.0))
(:bgcolor nil)
(:border 0)
(:roundness nil)
(:text-font (:font-or-nil (:font nil) (:t-or-nil nil)))
(:align nil)
(:text "Create and process your own SDIF data...")
(:id 9))
(:comment
(:x 45)
(:y 17)
(:w 161)
(:h 31)
(:fgcolor (:color 0.19215687 0.2627451 0.42352942 1.0))
(:bgcolor nil)
(:border 0)
(:roundness nil)
(:text-font
(:font-or-nil
(:font (:font (:face "Consolas") (:size 20) (:style :bold)))
(:t-or-nil t)))
(:align nil)
(:text "SDIF Classes")
(:id 10))
(:box
(:type :object)
(:reference sdiftype)
(:group-id nil)
(:name "SDIFTYPE")
(:x 45)
(:y 332)
(:w 114)
(:h 63)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :text)
(:showname nil)
(:lock nil)
(:lambda nil)
(:reactive nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "STRUCT")
(:value m)
(:reactive nil))
(:input
(:type :standard)
(:name "SIGNATURE")
(:value "XMAT")
(:reactive nil))
(:input
(:type :standard)
(:name "DESCRIPTION")
(:value (:list "par1" "par2" "par3"))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "STRUCT") (:reactive nil))
(:output (:name "SIGNATURE") (:reactive nil))
(:output (:name "DESCRIPTION") (:reactive nil)))
(:window (:size nil) (:position nil))
(:edition-params)
(:value
(:object
(:class sdiftype)
(:slots
((:struct m)
(:signature "XMAT")
(:description (:list "par1" "par2" "par3"))))))
(:id 11))
(:box
(:type :value)
(:reference (:symbol "SIMPLE-TEXT-STRING" "LISPWORKS"))
(:group-id nil)
(:name "aux2")
(:x 512)
(:y 209)
(:w 52)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:reactive nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value "XMAT")
(:id 12))
(:box
(:type :object)
(:reference sdiftype)
(:group-id nil)
(:name "SDIFTYPE")
(:x 53)
(:y 192)
(:w 96)
(:h 62)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :text)
(:showname nil)
(:lock nil)
(:lambda nil)
(:reactive nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "STRUCT")
(:value f)
(:reactive nil))
(:input
(:type :standard)
(:name "SIGNATURE")
(:value "XFRA")
(:reactive nil))
(:input
(:type :standard)
(:name "DESCRIPTION")
(:value (:list (:list "XNFO" "InfoMat") (:list "XMAT" "datamat")))
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "STRUCT") (:reactive nil))
(:output (:name "SIGNATURE") (:reactive nil))
(:output (:name "DESCRIPTION") (:reactive nil)))
(:window (:size nil) (:position nil))
(:edition-params)
(:value
(:object
(:class sdiftype)
(:slots
((:struct f)
(:signature "XFRA")
(:description
(:list (:list "XNFO" "InfoMat") (:list "XMAT" "datamat")))))))
(:id 13))
(:box
(:type :object)
(:reference sdifmatrix)
(:group-id nil)
(:name "SDIFMATRIX1")
(:x 473)
(:y 244)
(:w 180)
(:h 111)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :mini-view)
(:showname nil)
(:lock nil)
(:lambda nil)
(:reactive nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "MATRIXTYPE")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "DATA")
(:value nil)
(:reactive nil))
(:input
(:type :key)
(:name "field-names")
(:value nil)
(:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "MATRIXTYPE") (:reactive nil))
(:output (:name "DATA") (:reactive nil))
(:output (:name "field-names") (:reactive nil)))
(:window (:size nil) (:position nil))
(:edition-params)
(:value
(:object
(:class sdifmatrix)
(:slots
((:field-names (:list "f1" "f2" "f3"))
(:data
(:list
(:list 1.0 2.0 4.0 9.0 7.0)
(:list 2.0 4.0 9.0 7.0 8.0)
(:list 1.0 2.0 7.0 12.0 15)))
(:matrixtype "XMAT")))))
(:id 14))
(:box
(:type :value)
(:reference cons)
(:group-id nil)
(:name "value box")
(:x 600)
(:y 205)
(:w 126)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:reactive nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value (:list "f1" "f2" "f3"))
(:id 15))
(:box
(:type :value)
(:reference cons)
(:group-id nil)
(:name "value box")
(:x 128)
(:y 294)
(:w 146)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:reactive nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value (:list "par1" "par2" "par3"))
(:id 16))
(:box
(:type :value)
(:reference (:symbol "SIMPLE-TEXT-STRING" "LISPWORKS"))
(:group-id nil)
(:name "value box")
(:x 87)
(:y 262)
(:w 57)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:reactive nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value "XMAT")
(:id 17))
(:box
(:type :value)
(:reference symbol)
(:group-id nil)
(:name "value box")
(:x 73)
(:y 294)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:reactive nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value m)
(:id 18))
(:box
(:type :value)
(:reference symbol)
(:group-id nil)
(:name "value box")
(:x 48)
(:y 160)
(:w 32)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:reactive nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value f)
(:id 19))
(:box
(:type :value)
(:reference (:symbol "SIMPLE-TEXT-STRING" "LISPWORKS"))
(:group-id nil)
(:name "value box")
(:x 86)
(:y 160)
(:w 53)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:reactive nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value "XFRA")
(:id 20))
(:box
(:type :value)
(:reference cons)
(:group-id nil)
(:name "value box")
(:x 142)
(:y 157)
(:w 254)
(:h 29)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:reactive nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value (:list (:list "XNFO" "InfoMat") (:list "XMAT" "datamat")))
(:id 21))
(:box
(:type :value)
(:reference (:symbol "SIMPLE-TEXT-STRING" "LISPWORKS"))
(:group-id nil)
(:name "value box")
(:x 189)
(:y 424)
(:w 53)
(:h 30)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:reactive nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value "XFRA")
(:id 22))
(:box
(:type :value)
(:reference cons)
(:group-id nil)
(:name "value box")
(:x 504)
(:y 142)
(:w 149)
(:h 61)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:reactive nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value
(:list
(:list 1.0 2.0 4.0 9.0 7.0)
(:list 2.0 4.0 9.0 7.0 8.0)
(:list 1.0 2.0 7.0 12.0 15)))
(:id 23))
(:box
(:type :object)
(:reference sdifnvt)
(:group-id nil)
(:name nil)
(:x 560)
(:y 464)
(:w 216)
(:h 64)
(:color nil)
(:border nil)
(:roundness nil)
(:text-font nil)
(:align :center)
(:display :text)
(:showname nil)
(:lock nil)
(:lambda nil)
(:reactive nil)
(:inputs
(:input
(:type :standard)
(:name "SELF")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "NV-PAIRS")
(:value nil)
(:reactive nil))
(:input
(:type :standard)
(:name "TABLENAME")
(:value "Info")
(:reactive nil))
(:input (:type :standard) (:name "ID") (:value 0) (:reactive nil)))
(:outputs
(:output (:name "SELF") (:reactive nil))
(:output (:name "NV-PAIRS") (:reactive nil))
(:output (:name "TABLENAME") (:reactive nil))
(:output (:name "ID") (:reactive nil)))
(:window (:size nil) (:position nil))
(:edition-params)
(:value
(:object
(:class sdifnvt)
(:slots
((:nv-pairs (:list (:list "Autor" "me") (:list "Version" "1.0")))
(:tablename "Info")
(:id 0)))))
(:id 24))
(:box
(:type :value)
(:reference cons)
(:group-id nil)
(:name "value box")
(:x 541)
(:y 413)
(:w 122)
(:h 43)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:reactive nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value (:list (:list "Autor" "me") (:list "Version" "1.0")))
(:id 25))
(:box
(:type :value)
(:reference (:symbol "SIMPLE-TEXT-STRING" "LISPWORKS"))
(:group-id nil)
(:name "value box")
(:x 667)
(:y 429)
(:w 54)
(:h 29)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:reactive nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value "Info")
(:id 26))
(:box
(:type :value)
(:reference (:symbol "SIMPLE-TEXT-STRING" "LISPWORKS"))
(:group-id nil)
(:name "value box")
(:x 667)
(:y 429)
(:w 54)
(:h 29)
(:color
(:color-or-nil (:color (:color 1.0 1.0 1.0 1.0)) (:t-or-nil t)))
(:border nil)
(:roundness nil)
(:text-font nil)
(:align nil)
(:lock nil)
(:reactive nil)
(:inputs)
(:outputs (:output (:name "value") (:reactive nil)))
(:value "Info")
(:id 27))
(:comment
(:x 678)
(:y 387)
(:w 78)
(:h 29)
(:fgcolor (:color 0 0 0 1.0))
(:bgcolor nil)
(:border 0)
(:roundness nil)
(:text-font
(:font-or-nil
(:font (:font (:face "Consolas") (:size 18) (:style :plain)))
(:t-or-nil t)))
(:align nil)
(:text "SDIFNVT")
(:id 28)))
(:connections
(:connection (:from (:box 12 :out 0)) (:to (:box 14 :in 1)))
(:connection (:from (:box 15 :out 0)) (:to (:box 14 :in 3)))
(:connection (:from (:box 16 :out 0)) (:to (:box 11 :in 3)))
(:connection (:from (:box 17 :out 0)) (:to (:box 11 :in 2)))
(:connection (:from (:box 18 :out 0)) (:to (:box 11 :in 1)))
(:connection (:from (:box 19 :out 0)) (:to (:box 13 :in 1)))
(:connection (:from (:box 20 :out 0)) (:to (:box 13 :in 2)))
(:connection (:from (:box 21 :out 0)) (:to (:box 13 :in 3)))
(:connection (:from (:box 22 :out 0)) (:to (:box 2 :in 1)))
(:connection (:from (:box 23 :out 0)) (:to (:box 14 :in 2)))
(:connection (:from (:box 25 :out 0)) (:to (:box 24 :in 1)))
(:connection (:from (:box 27 :out 0)) (:to (:box 24 :in 2))))) | 16,679 | Common Lisp | .cl | 758 | 17.616095 | 80 | 0.530055 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 4a0cf875d7c205877219bd052fce2141fa70fe7389ac79f529be5257fbdd4313 | 928 | [
-1
] |
930 | .gitmodules | cac-t-u-s_om-sharp/.gitmodules | [submodule "slime"]
path = src/lisp-externals/slime
url = https://github.com/cac-t-u-s/slime.git
ignore = dirty
| 115 | Common Lisp | .l | 4 | 27 | 45 | 0.72973 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 0120a50972c6f7fbf3dcb1565725c013d114bee2cb0e621f42e957798cd13db8 | 930 | [
-1
] |
931 | release | cac-t-u-s_om-sharp/release | #!/bin/bash
# 32bits:
# LWARCH=32-bit
# LWEXEC=lispworks-7-0-0-x86-darwin
LWARCH=64-bit
LWVERSION=7.1
LWEXEC=lispworks-7-1-0-amd64-darwin
OM_VERSION=$(<"VERSION")
BUILD_FOLDER="_BUILD"
APP_NAME="om-sharp"
CYAN='\033[0;36m'
BLUE='\033[0;34m'
RED='\033[0;31m'
GREEN='\033[92m'
NC='\033[0m' # No Color
deliver_app()
{
echo -e "${CYAN}***************************************************${NC}"
echo -e "${CYAN}COMPILING STANDALONE IMAGE${NC}"
echo -e "${CYAN}***************************************************${NC}"
rm -rf ./*.app/
/Applications/LispWorks\ $LWVERSION\ \($LWARCH\)/LispWorks\ \($LWARCH\).app/Contents/MacOS/$LWEXEC -build ./build/deliver.lisp
# update version
OM_VERSION=$(<"VERSION")
echo -e "${GREEN}=> IMAGE DONE!${NC}"
}
# deliver_app MUST have been called before..
pack_app()
{
echo -e "${CYAN}***************************************************${NC}"
echo -e "${CYAN}Packing $BUILD_FOLDER/$APP_NAME.app${NC}"
echo -e "${CYAN}***************************************************${NC}"
rm -Rf $BUILD_FOLDER
mkdir $BUILD_FOLDER
cp -R "$APP_NAME".app $BUILD_FOLDER
echo -e "${CYAN}=> Setting fonts....${NC}"
# cp om/resources/fonts/* "$BUILD_FOLDER"/"$APP_NAME".app/Contents/Resources/fonts/
cp "$BUILD_FOLDER"/"$APP_NAME".app/Contents/Info.plist .
defaults write $(pwd)/Info.plist ATSApplicationFontsPath -string "fonts/"
mv ./Info.plist "$BUILD_FOLDER"/"$APP_NAME".app/Contents/Info.plist
echo -e "${GREEN}=> PACKED IN BUILD FOLDER!${NC}"
}
# pack_app MUST have been called before..
create_simple_dmg()
{
DMG_NAME="$APP_NAME"-"$OM_VERSION"-macOS.dmg
echo -e "${CYAN}***************************************************${NC}"
echo -e "${CYAN}Preparing DMG distribution for $APP_NAME${NC}"
echo -e "${CYAN}***************************************************${NC}"
cd $BUILD_FOLDER
rm -f "$DMG_NAME"
rm -rf _DMG
mkdir _DMG
cp -R "$APP_NAME".app _DMG/
#cp "README.txt" "$BUILD_FOLDER"/_DMG/
#ln -s /Applications/ _DMG/Applications
hdiutil create -fs HFS+ -volname $DMG_NAME -srcfolder _DMG "$DMG_NAME"
rm -rf _DMG
cd ..
echo -e "${GREEN}=> DMG DONE: $DMG_NAME ${NC}"
}
zip_release()
{
ZIP_NAME="$APP_NAME"-"$OM_VERSION".zip
echo -e "${CYAN}***************************************************${NC}"
echo -e "${CYAN}Preparing ZIP distribution for $APP_NAME${NC}"
echo -e "${CYAN}***************************************************${NC}"
cd $BUILD_FOLDER
rm -f "$ZIP_NAME"
rm -rf "$APP_NAME"
mkdir "$APP_NAME"
cp -R "$APP_NAME".app "$APP_NAME"/
zip -r -q -dg "$ZIP_NAME" "$APP_NAME"
rm -rf "$APP_NAME"
cd ..
echo -e "${GREEN}=> ZIP DONE: $ZIP_NAME ${NC}"
}
sign_release()
{
echo -e "${CYAN}***************************************************${NC}"
echo -e "${CYAN}Code Signature (calling external script)${NC}"
echo -e "${CYAN}***************************************************${NC}"
./codesign.sh "$BUILD_FOLDER"/"$APP_NAME".app
echo -e "${GREEN}=> CODE SIGNATURE: DONE${NC}"
}
notarize_dmg()
{
DMG_NAME="$APP_NAME"-"$OM_VERSION"-macOS.dmg
echo -e "${CYAN}***************************************************${NC}"
echo -e "${CYAN}Notarization (calling external script)${NC}"
echo -e "${CYAN}***************************************************${NC}"
./notarize.sh "$BUILD_FOLDER"/"$DMG_NAME"
}
change_permission()
{
# this function change the permission for a given folder
# $1 : the folder
echo -e "${CYAN}Setting permissions for $1${NC}"
sudo chown -R root "$1"
sudo chgrp -R admin "$1"
sudo chmod -R o+rx "$1"
sudo chmod -R ug+rwx "$1"
}
#=============================
# MAIN SCRIPT
#=============================
if [ "$1" = "-d" ]; then deliver_app
elif [ "$1" = "-p" ]; then pack_app
elif [ "$1" = "-dp" ]; then deliver_app; pack_app
elif [ "$1" = "-dmg" ]; then create_simple_dmg
elif [ "$1" = "-zip" ]; then zip_release
elif [ "$1" = "-sign" ]; then sign_release
elif [ "$1" = "-notarize" ]; then notarize_dmg
elif [ "$1" = "-dpd" ]; then deliver_app; pack_app; sign_release;create_simple_dmg
elif [ "$1" = "-dpz" ]; then deliver_app; pack_app; sign_release; zip_release
elif [ "$1" = "-all" ]; then deliver_app; pack_app; sign_release; zip_release; create_simple_dmg
else
echo "Dont'know what to do! :("
echo "Options:"
echo "-d = deliver app"
echo "-p = pack delivered app as a separate folder (including fonts) "
echo "-dp = deliver and pack"
echo "-sign = sign delivered package"
echo "-zip = create ZIP from previously packed app"
echo "-dmg = create DMG from previously packed app"
echo "-dpd = deliver, pack, sign and create DMG"
echo "-dpz = deliver, pack, sign and zip"
echo "-all = deliver, pack, SIGN and create zip + DGM"
fi
exit 0
| 4,697 | Common Lisp | .l | 130 | 34.123077 | 127 | 0.560133 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 3aa07b79e66f2287c1f90b582a55bcce6e6634055329bec0449aea039f6a17d6 | 931 | [
-1
] |
932 | release.bat | cac-t-u-s_om-sharp/release.bat | cd build\
"C:\\Program Files (x86)\\LispWorks\\lispworks-7-1-0-x86-win32.exe" -build deliver.lisp
cd ..
rmdir _BUILD
mkdir _BUILD\om-sharp\
xcopy help-patches _BUILD\om-sharp\help-patches\ /s/e/y
xcopy init _BUILD\om-sharp\init\ /s/e/y
xcopy resources _BUILD\om-sharp\resources\ /s/e/y
xcopy src _BUILD\om-sharp\src\ /s/e/y
xcopy om-sharp.exe _BUILD\om-sharp\ /y
del /S _BUILD\om-sharp\*.*~
del /S _BUILD\om-sharp\resources\fonts\*.otf
del /S _BUILD\om-sharp\src\*.ofasl
del /F/Q/S _BUILD\om-sharp\resources\lib\*.* > NUL
rmdir /Q/S _BUILD\om-sharp\resources\lib\
copy "resources\lib\win32\libportmidi.dll" _BUILD\om-sharp\
copy "resources\lib\win32\libsndfile-1.dll" _BUILD\om-sharp\
copy "resources\lib\win32\libsamplerate-0.dll" _BUILD\om-sharp\
copy "resources\lib\win32\OMAudioLib.dll" _BUILD\om-sharp\
copy "resources\lib\win32\libsdif.dll" _BUILD\om-sharp\
| 876 | Common Lisp | .l | 20 | 42.45 | 87 | 0.744405 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | ede3fb14ae9c63eafdf89e7f4512bee0671cee265ae39eb7e48227c61ffeab64 | 932 | [
-1
] |
940 | Makefile | cac-t-u-s_om-sharp/build/linux/Makefile | SHELL = /bin/sh
INSTALL_PROGRAM = install
compress = gzip
LISPFLAGS = -build
LISP = $(HOME)/bin/lw $(LISPFLAGS)
PREFIX = /usr
# DESTDIR for local builds, ie. by rpmbuild etc.
bindir = $(DESTDIR)$(PREFIX)/bin
libdir = $(DESTDIR)$(PREFIX)/lib64/om-sharp
datadir = $(DESTDIR)$(PREFIX)/share
omfontsdir = $(DESTDIR)$(PREFIX)/share/fonts/om-sharp-fonts
omroot = $(datadir)/$(APPNAME)
ICONDIR = $(datadir)/icons/hicolor/64x64/apps
OMROOT = ../../
thisfile = $(lastword $(MAKEFILE_LIST))
thisdir = $(dir $(thisfile))
builddir = $(shell cd $(dir $(thisfile)) && cd $(OMROOT) && pwd)
BUILDROOT = $(builddir)
APPNAME = om-sharp
INSTALLRES = $(BUILDROOT)/build/linux
OM_VERSION = $(shell cat $(OMROOT)/VERSION)
OM_RELEASE = 1
TARBALL = $(shell cd $(OMROOT)/.. && pwd)/om-sharp-Linux-$(OM_VERSION)-$(OM_RELEASE).tar.bz2
RPMDIR = $(HOME)/rpmbuild/SOURCES
app_name_version = om-sharp
faslname = 64ufasl
rubbish = *.$(faslname)
# include dspec database in install and tarball
dspec_database = resources/dspec-database.$(faslname)
include_dspec = --include '$(dspec_database)'
include_dirs = --include 'slime/*'
include_slime_fasls = --include 'slime/fasl/*ufasl' --include 'slime/fasl/*/*ufasl'
# rsyncflags = -v -rlt -z
rsyncflags = -v -rlt -O -z -C --include '*.so'
exclude_fasl = --exclude '$(rubbish)'
slime_dir = ./om-sharp/src/lisp-externals/slime
exclude_mac = --exclude 'build/mac/' --exclude '*.finderinfo' --exclude 'resources/lib/mac'
exclude_win = --exclude 'build/win/' --exclude 'resources/lib/win*'
exclude_oses = $(exclude_mac) $(exclude_win)
checkname = $(shell ls $(BUILDROOT) | grep "om-sharp_")
ifdef $(checkname)
releaseappname = $(checkname)
else
releaseappname = $(app_name_version)
endif
all: compile
help:
@echo BUILDROOT: $(BUILDROOT)
@echo Makefile: $(thisfile)
@echo THISDIR: $(thisdir)
@echo BUILDROOT: $(BUILDROOT)
@echo buildname: $(buildname)
@echo IMAGENAME: $(IMAGENAME)
@echo releaseappname: $(releaseappname)
@echo targets: '(default=compile, all), compile, all (=compile), install, uninstall, clean, tardist, preparerpm, help'
compile:
cd $(BUILDROOT)
@echo building $(releaseappname) in source tree: $(BUILDROOT)
$(LISP) $(BUILDROOT)/build/deliver.lisp
install: $(BUILDROOT)/$(releaseappname)
mkdir -p $(omroot)
cd $(BUILDROOT) && \
rsync $(rsyncflags) $(include_dspec) $(include_dirs) $(include_slime_fasls) \
$(exclude_fasl) $(exclude_oses) --exclude 'Makefile' --exclude $(releaseappname) \
. $(omroot)
mkdir -p $(libdir)
cd $(BUILDROOT)/resources/lib/linux && rsync $(rsyncflags) . $(libdir)
cd $(BUILDROOT) && $(INSTALL_PROGRAM) -D -m 0755 $(releaseappname) $(bindir)/$(releaseappname)
mkdir -p $(datadir)/applications/
cd $(INSTALLRES) && $(INSTALL_PROGRAM) -D -m 0644 OM-sharp.desktop $(datadir)/applications/
mkdir -p $(ICONDIR)
cd $(BUILDROOT)/resources/ && $(INSTALL_PROGRAM) -D -m 0644 om-sharp.png $(ICONDIR)
mkdir -p $(omfontsdir)/
cd $(BUILDROOT)/resources/fonts && rsync $(rsyncflags) *.otf $(omfontsdir)
uninstall:
rm -rf $(omroot)
rm -f $(bindir)/$(APPNAME)
rm -f $(bindir)/$(releaseappname)
rm -f $(datadir)/applications/OM-sharp.desktop
rm -f $(ICONDIR)/om-sharp.png
rm -rf $(omfontsdir)
rm -rf $(libdir)
clean:
cd $(BUILDROOT)/src && find . -name $(rubbish) -delete
rm -f $(BUILDROOT)/$(releaseappname)
# exclude various mac/win-related, fasls, but take care to include
# everything inside slime directory (including fasls):
tardist:
$(echo bygger $(TARBALL) i $(BUILDROOT)../)
cd $(BUILDROOT)/../ && \
tar cvjf $(TARBALL) \
./om-sharp/$(dspec_database) \
$(slime_dir) \
--exclude=.git* \
$(exclude_fasl) \
$(exclude_mac) \
$(exclude_win) \
./om-sharp
@echo tarball: $(shell ls $(TARBALL))
preparerpm: $(TARBALL)
cp -v $(TARBALL) $(RPMDIR)
| 3,804 | Common Lisp | .l | 101 | 35.633663 | 119 | 0.693983 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 9003a762d4ac0decc6192c637c4d91ec18463e15722f40edbead0f609980179a | 940 | [
-1
] |
944 | release.sh | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/trivial-features/release.sh | #!/bin/bash
### Configuration
PROJECT_NAME='trivial-features'
ASDF_FILE="$PROJECT_NAME.asd"
HOST="common-lisp.net"
RELEASE_DIR="public_html/tarballs/trivial-features/"
VERSION_FILE=""
#VERSION_FILE="VERSION"
#VERSION_FILE_DIR="/project/$PROJECT_NAME/public_html"
set -e
### Process options
FORCE=0
VERSION=""
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
echo "No help, sorry. Read the source."
exit 0
;;
-f|--force)
FORCE=1
shift
;;
-v|--version)
VERSION="$2"
shift 2
;;
*)
echo "Unrecognized argument '$1'"
exit 1
;;
esac
done
### Check for unrecorded changes
if darcs whatsnew; then
echo -n "Unrecorded changes. "
if [ "$FORCE" -ne 1 ]; then
echo "Aborting."
echo "Use -f or --force if you want to make a release anyway."
exit 1
else
echo "Continuing anyway."
fi
fi
### Determine new version number
if [ -z "$VERSION" ]; then
CURRENT_VERSION=$(grep :version $ASDF_FILE | cut -d\" -f2)
dots=$(echo "$CURRENT_VERSION" | tr -cd '.')
count=$(expr length "$dots" + 1)
declare -a versions
for i in $(seq $count); do
new=""
for j in $(seq $(expr $i - 1)); do
p=$(echo "$CURRENT_VERSION" | cut -d. -f$j)
new="$new$p."
done
part=$(expr 1 + $(echo "$CURRENT_VERSION" | cut -d. -f$i))
new="$new$part"
for j in $(seq $(expr $i + 1) $count); do new="$new.0"; done
versions[$i]=$new
done
while true; do
echo "Current version is $CURRENT_VERSION. Which will be next one?"
for i in $(seq $count); do echo " $i) ${versions[$i]}"; done
echo -n "? "
read choice
if ((choice > 0)) && ((choice <= ${#versions[@]})); then
VERSION=${versions[$choice]}
break
fi
done
fi
### Do it
TARBALL_NAME="${PROJECT_NAME}_${VERSION}"
TARBALL="$TARBALL_NAME.tar.gz"
SIGNATURE="$TARBALL.asc"
echo "Updating $ASDF_FILE with new version: $VERSION"
sed -e "s/:version \"$CURRENT_VERSION\"/:version \"$VERSION\"/" \
"$ASDF_FILE" > "$ASDF_FILE.tmp"
mv "$ASDF_FILE.tmp" "$ASDF_FILE"
darcs record -m "update $ASDF_FILE for version $VERSION"
echo "Tagging the tree..."
darcs tag "$VERSION"
echo "Creating distribution..."
darcs dist -d "$TARBALL_NAME"
echo "Signing tarball..."
gpg -b -a "$TARBALL"
echo "Copying tarball to web server..."
scp "$TARBALL" "$SIGNATURE" "$HOST:$RELEASE_DIR"
echo "Uploaded $TARBALL and $SIGNATURE."
echo "Updating ${PROJECT_NAME}_latest links..."
ssh $HOST ln -sf "$TARBALL" "$RELEASE_DIR/${PROJECT_NAME}_latest.tar.gz"
ssh $HOST ln -sf "$SIGNATURE" "$RELEASE_DIR/${PROJECT_NAME}_latest.tar.gz.asc"
if [ "$VERSION_FILE" ]; then
echo "Uploading $VERSION_FILE..."
echo -n "$VERSION" > "$VERSION_FILE"
scp "$VERSION_FILE" "$HOST":"$VERSION_FILE_DIR"
rm "$VERSION_FILE"
fi
while true; do
echo -n "Clean local tarball and signature? [y] "
read -n 1 response
case "$response" in
y|'')
echo
rm "$TARBALL" "$SIGNATURE"
break
;;
n)
break
;;
*)
echo "Invalid response '$response'. Try again."
;;
esac
done
#echo "Building and uploading documentation..."
#make -C doc upload-docs
echo "Pushing changes..."
darcs push
| 3,497 | Common Lisp | .l | 120 | 23.15 | 78 | 0.576418 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | f9b17ae619fc347625ddbcfb10f805badd10dbb2afcec3f506bdd84ab2031819 | 944 | [
-1
] |
984 | alexandria.html | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/alexandria/doc/alexandria.html | <html lang="en">
<head>
<title>Alexandria Manual - draft version</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Alexandria Manual - draft version">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="top" href="#Top">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Alexandria software and associated documentation are in the public
domain:
Authors dedicate this work to public domain, for the benefit of
the public at large and to the detriment of the authors' heirs
and successors. Authors intends this dedication to be an overt
act of relinquishment in perpetuity of all present and future
rights under copyright law, whether vested or contingent, in the
work. Authors understands that such relinquishment of all rights
includes the relinquishment of all rights to enforce (by lawsuit
or otherwise) those copyrights in the work.
Authors recognize that, once placed in the public domain, the work
may be freely reproduced, distributed, transmitted, used,
modified, built upon, or otherwise exploited by anyone for any
purpose, commercial or non-commercial, and in any way, including
by methods that have not yet been invented or conceived.
In those legislations where public domain dedications are not
recognized or possible, Alexandria is distributed under the following
terms and conditions:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<h1 class="settitle">Alexandria Manual - draft version</h1>
<div class="contents">
<h2>Table of Contents</h2>
<ul>
<li><a name="toc_Top" href="#Top">Alexandria</a>
<li><a name="toc_Hash-Tables" href="#Hash-Tables">1 Hash Tables</a>
<li><a name="toc_Data-and-Control-Flow" href="#Data-and-Control-Flow">2 Data and Control Flow</a>
<li><a name="toc_Conses" href="#Conses">3 Conses</a>
<li><a name="toc_Sequences" href="#Sequences">4 Sequences</a>
<li><a name="toc_IO" href="#IO">5 IO</a>
<li><a name="toc_Macro-Writing" href="#Macro-Writing">6 Macro Writing</a>
<li><a name="toc_Symbols" href="#Symbols">7 Symbols</a>
<li><a name="toc_Arrays" href="#Arrays">8 Arrays</a>
<li><a name="toc_Types" href="#Types">9 Types</a>
<li><a name="toc_Numbers" href="#Numbers">10 Numbers</a>
</li></ul>
</div>
<div class="node">
<a name="Top"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Hash-Tables">Hash Tables</a>,
Up: <a rel="up" accesskey="u" href="#dir">(dir)</a>
</div>
<!-- node-name, next, previous, up -->
<h2 class="unnumbered">Alexandria</h2>
<p>Alexandria software and associated documentation are in the public
domain:
<blockquote>
Authors dedicate this work to public domain, for the benefit of the
public at large and to the detriment of the authors' heirs and
successors. Authors intends this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights under
copyright law, whether vested or contingent, in the work. Authors
understands that such relinquishment of all rights includes the
relinquishment of all rights to enforce (by lawsuit or otherwise)
those copyrights in the work.
<p>Authors recognize that, once placed in the public domain, the work
may be freely reproduced, distributed, transmitted, used, modified,
built upon, or otherwise exploited by anyone for any purpose,
commercial or non-commercial, and in any way, including by methods
that have not yet been invented or conceived.
</blockquote>
<p>In those legislations where public domain dedications are not
recognized or possible, Alexandria is distributed under the following
terms and conditions:
<blockquote>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</blockquote>
<ul class="menu">
<li><a accesskey="1" href="#Hash-Tables">Hash Tables</a>
<li><a accesskey="2" href="#Data-and-Control-Flow">Data and Control Flow</a>
<li><a accesskey="3" href="#Conses">Conses</a>
<li><a accesskey="4" href="#Sequences">Sequences</a>
<li><a accesskey="5" href="#IO">IO</a>
<li><a accesskey="6" href="#Macro-Writing">Macro Writing</a>
<li><a accesskey="7" href="#Symbols">Symbols</a>
<li><a accesskey="8" href="#Arrays">Arrays</a>
<li><a accesskey="9" href="#Types">Types</a>
<li><a href="#Numbers">Numbers</a>
</ul>
<div class="node">
<a name="Hash-Tables"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Data-and-Control-Flow">Data and Control Flow</a>,
Previous: <a rel="previous" accesskey="p" href="#Top">Top</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<!-- node-name, next, previous, up -->
<h2 class="chapter">1 Hash Tables</h2>
<p><a name="Macro-ensure_002dgethash"></a>
<div class="defun">
— Macro: <b>ensure-gethash</b><var> key hash-table &optional default<a name="index-ensure_002dgethash-1"></a></var><br>
<blockquote><p><a name="index-ensure_002dgethash-2"></a>Like <code>gethash</code>, but if <code>key</code> is not found in the <code>hash-table</code> saves the <code>default</code>
under key before returning it. Secondary return value is true if key was
already in the table.
</p></blockquote></div>
<p><a name="Function-copy_002dhash_002dtable"></a>
<div class="defun">
— Function: <b>copy-hash-table</b><var> table &key key test size rehash-size rehash-threshold<a name="index-copy_002dhash_002dtable-3"></a></var><br>
<blockquote><p><a name="index-copy_002dhash_002dtable-4"></a>Returns a copy of hash table <code>table</code>, with the same keys and values
as the <code>table</code>. The copy has the same properties as the original, unless
overridden by the keyword arguments.
<p>Before each of the original values is set into the new hash-table, <code>key</code>
is invoked on the value. As <code>key</code> defaults to <code>cl:identity</code>, a shallow
copy is returned by default.
</p></blockquote></div>
<p><a name="Function-maphash_002dkeys"></a>
<div class="defun">
— Function: <b>maphash-keys</b><var> function table<a name="index-maphash_002dkeys-5"></a></var><br>
<blockquote><p><a name="index-maphash_002dkeys-6"></a>Like <code>maphash</code>, but calls <code>function</code> with each key in the hash table <code>table</code>.
</p></blockquote></div>
<p><a name="Function-maphash_002dvalues"></a>
<div class="defun">
— Function: <b>maphash-values</b><var> function table<a name="index-maphash_002dvalues-7"></a></var><br>
<blockquote><p><a name="index-maphash_002dvalues-8"></a>Like <code>maphash</code>, but calls <code>function</code> with each value in the hash table <code>table</code>.
</p></blockquote></div>
<p><a name="Function-hash_002dtable_002dkeys"></a>
<div class="defun">
— Function: <b>hash-table-keys</b><var> table<a name="index-hash_002dtable_002dkeys-9"></a></var><br>
<blockquote><p><a name="index-hash_002dtable_002dkeys-10"></a>Returns a list containing the keys of hash table <code>table</code>.
</p></blockquote></div>
<p><a name="Function-hash_002dtable_002dvalues"></a>
<div class="defun">
— Function: <b>hash-table-values</b><var> table<a name="index-hash_002dtable_002dvalues-11"></a></var><br>
<blockquote><p><a name="index-hash_002dtable_002dvalues-12"></a>Returns a list containing the values of hash table <code>table</code>.
</p></blockquote></div>
<p><a name="Function-hash_002dtable_002dalist"></a>
<div class="defun">
— Function: <b>hash-table-alist</b><var> table<a name="index-hash_002dtable_002dalist-13"></a></var><br>
<blockquote><p><a name="index-hash_002dtable_002dalist-14"></a>Returns an association list containing the keys and values of hash table
<code>table</code>.
</p></blockquote></div>
<p><a name="Function-hash_002dtable_002dplist"></a>
<div class="defun">
— Function: <b>hash-table-plist</b><var> table<a name="index-hash_002dtable_002dplist-15"></a></var><br>
<blockquote><p><a name="index-hash_002dtable_002dplist-16"></a>Returns a property list containing the keys and values of hash table
<code>table</code>.
</p></blockquote></div>
<p><a name="Function-alist_002dhash_002dtable"></a>
<div class="defun">
— Function: <b>alist-hash-table</b><var> alist &rest hash-table-initargs<a name="index-alist_002dhash_002dtable-17"></a></var><br>
<blockquote><p><a name="index-alist_002dhash_002dtable-18"></a>Returns a hash table containing the keys and values of the association list
<code>alist</code>. Hash table is initialized using the <code>hash-table-initargs</code>.
</p></blockquote></div>
<p><a name="Function-plist_002dhash_002dtable"></a>
<div class="defun">
— Function: <b>plist-hash-table</b><var> plist &rest hash-table-initargs<a name="index-plist_002dhash_002dtable-19"></a></var><br>
<blockquote><p><a name="index-plist_002dhash_002dtable-20"></a>Returns a hash table containing the keys and values of the property list
<code>plist</code>. Hash table is initialized using the <code>hash-table-initargs</code>.
</p></blockquote></div>
<div class="node">
<a name="Data-and-Control-Flow"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Conses">Conses</a>,
Previous: <a rel="previous" accesskey="p" href="#Hash-Tables">Hash Tables</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<!-- node-name, next, previous, up -->
<h2 class="chapter">2 Data and Control Flow</h2>
<p><a name="Macro-define_002dconstant"></a>
<div class="defun">
— Macro: <b>define-constant</b><var> name initial-value &key test documentation<a name="index-define_002dconstant-21"></a></var><br>
<blockquote><p><a name="index-define_002dconstant-22"></a>Ensures that the global variable named by <code>name</code> is a constant with a value
that is equal under <code>test</code> to the result of evaluating <code>initial-value</code>. <code>test</code> is a
/function designator/ that defaults to <code>eql</code>. If <code>documentation</code> is given, it
becomes the documentation string of the constant.
<p>Signals an error if <code>name</code> is already a bound non-constant variable.
<p>Signals an error if <code>name</code> is already a constant variable whose value is not
equal under <code>test</code> to result of evaluating <code>initial-value</code>.
</p></blockquote></div>
<p><a name="Macro-destructuring_002dcase"></a>
<div class="defun">
— Macro: <b>destructuring-case</b><var> keyform &body clauses<a name="index-destructuring_002dcase-23"></a></var><br>
<blockquote><p><a name="index-destructuring_002dcase-24"></a><code>destructuring-case</code>, <code>-ccase</code>, and <code>-ecase</code> are a combination of <code>case</code> and <code>destructuring-bind</code>.
<code>keyform</code> must evaluate to a <code>cons</code>.
<p>Clauses are of the form:
<pre class="lisp"> ((CASE-KEYS . DESTRUCTURING-LAMBDA-LIST) FORM*)
</pre>
<p>The clause whose <code>case-keys</code> matches <code>car</code> of <code>key</code>, as if by <code>case</code>, <code>ccase</code>, or <code>ecase</code>,
is selected, and FORMs are then executed with <code>cdr</code> of <code>key</code> is destructured and
bound by the <code>destructuring-lambda-list</code>.
<p>Example:
<pre class="lisp"> (defun dcase (x)
(destructuring-case x
((:foo a b)
(format nil "foo: ~S, ~S" a b))
((:bar &key a b)
(format nil "bar, ~S, ~S" a b))
(((:alt1 :alt2) a)
(format nil "alt: ~S" a))
((t &rest rest)
(format nil "unknown: ~S" rest))))
</pre>
<pre class="lisp"> (dcase (list :foo 1 2)) ; => "foo: 1, 2"
(dcase (list :bar :a 1 :b 2)) ; => "bar: 1, 2"
(dcase (list :alt1 1)) ; => "alt: 1"
(dcase (list :alt2 2)) ; => "alt: 2"
(dcase (list :quux 1 2 3)) ; => "unknown: 1, 2, 3"
</pre>
<pre class="lisp"> (defun decase (x)
(destructuring-case x
((:foo a b)
(format nil "foo: ~S, ~S" a b))
((:bar &key a b)
(format nil "bar, ~S, ~S" a b))
(((:alt1 :alt2) a)
(format nil "alt: ~S" a))))
</pre>
<pre class="lisp"> (decase (list :foo 1 2)) ; => "foo: 1, 2"
(decase (list :bar :a 1 :b 2)) ; => "bar: 1, 2"
(decase (list :alt1 1)) ; => "alt: 1"
(decase (list :alt2 2)) ; => "alt: 2"
(decase (list :quux 1 2 3)) ; =| error
</pre>
</blockquote></div>
<p><a name="Macro-ensure_002dfunctionf"></a>
<div class="defun">
— Macro: <b>ensure-functionf</b><var> &rest places<a name="index-ensure_002dfunctionf-25"></a></var><br>
<blockquote><p><a name="index-ensure_002dfunctionf-26"></a>Multiple-place modify macro for <code>ensure-function:</code> ensures that each of
<code>places</code> contains a function.
</p></blockquote></div>
<p><a name="Macro-multiple_002dvalue_002dprog2"></a>
<div class="defun">
— Macro: <b>multiple-value-prog2</b><var> first-form second-form &body forms<a name="index-multiple_002dvalue_002dprog2-27"></a></var><br>
<blockquote><p><a name="index-multiple_002dvalue_002dprog2-28"></a>Evaluates <code>first-form</code>, then <code>second-form</code>, and then <code>forms</code>. Yields as its value
all the value returned by <code>second-form</code>.
</p></blockquote></div>
<p><a name="Macro-named_002dlambda"></a>
<div class="defun">
— Macro: <b>named-lambda</b><var> name lambda-list &body body<a name="index-named_002dlambda-29"></a></var><br>
<blockquote><p><a name="index-named_002dlambda-30"></a>Expands into a lambda-expression within whose <code>body</code> <code>name</code> denotes the
corresponding function.
</p></blockquote></div>
<p><a name="Macro-nth_002dvalue_002dor"></a>
<div class="defun">
— Macro: <b>nth-value-or</b><var> nth-value &body forms<a name="index-nth_002dvalue_002dor-31"></a></var><br>
<blockquote><p><a name="index-nth_002dvalue_002dor-32"></a>Evaluates <code>form</code> arguments one at a time, until the <code>nth-value</code> returned by one
of the forms is true. It then returns all the values returned by evaluating
that form. If none of the forms return a true nth value, this form returns
<code>nil</code>.
</p></blockquote></div>
<p><a name="Macro-if_002dlet"></a>
<div class="defun">
— Macro: <b>if-let</b><var> bindings &body </var>(<var>then-form &optional else-form</var>)<var><a name="index-if_002dlet-33"></a></var><br>
<blockquote><p><a name="index-if_002dlet-34"></a>Creates new variable bindings, and conditionally executes either
<code>then-form</code> or <code>else-form</code>. <code>else-form</code> defaults to <code>nil</code>.
<p><code>bindings</code> must be either single binding of the form:
<pre class="lisp"> (variable initial-form)
</pre>
<p>or a list of bindings of the form:
<pre class="lisp"> ((variable-1 initial-form-1)
(variable-2 initial-form-2)
...
(variable-n initial-form-n))
</pre>
<p>All initial-forms are executed sequentially in the specified order. Then all
the variables are bound to the corresponding values.
<p>If all variables were bound to true values, the <code>then-form</code> is executed with the
bindings in effect, otherwise the <code>else-form</code> is executed with the bindings in
effect.
</p></blockquote></div>
<p><a name="Macro-when_002dlet"></a>
<div class="defun">
— Macro: <b>when-let</b><var> bindings &body forms<a name="index-when_002dlet-35"></a></var><br>
<blockquote><p><a name="index-when_002dlet-36"></a>Creates new variable bindings, and conditionally executes <code>forms</code>.
<p><code>bindings</code> must be either single binding of the form:
<pre class="lisp"> (variable initial-form)
</pre>
<p>or a list of bindings of the form:
<pre class="lisp"> ((variable-1 initial-form-1)
(variable-2 initial-form-2)
...
(variable-n initial-form-n))
</pre>
<p>All initial-forms are executed sequentially in the specified order. Then all
the variables are bound to the corresponding values.
<p>If all variables were bound to true values, then <code>forms</code> are executed as an
implicit <code>progn</code>.
</p></blockquote></div>
<p><a name="Macro-when_002dlet_002a"></a>
<div class="defun">
— Macro: <b>when-let*</b><var> bindings &body forms<a name="index-when_002dlet_002a-37"></a></var><br>
<blockquote><p><a name="index-when_002dlet_002a-38"></a>Creates new variable bindings, and conditionally executes <code>forms</code>.
<p><code>bindings</code> must be either single binding of the form:
<pre class="lisp"> (variable initial-form)
</pre>
<p>or a list of bindings of the form:
<pre class="lisp"> ((variable-1 initial-form-1)
(variable-2 initial-form-2)
...
(variable-n initial-form-n))
</pre>
<p>Each initial-form is executed in turn, and the variable bound to the
corresponding value. Initial-form expressions can refer to variables
previously bound by the <code>when-let*</code>.
<p>Execution of <code>when-let*</code> stops immediately if any initial-form evaluates to <code>nil</code>.
If all initial-forms evaluate to true, then <code>forms</code> are executed as an implicit
<code>progn</code>.
</p></blockquote></div>
<p><a name="Macro-switch"></a>
<div class="defun">
— Macro: <b>switch</b><var> whole </var>(<var>object &key test key</var>)<var> &body clauses<a name="index-switch-39"></a></var><br>
<blockquote><p><a name="index-switch-40"></a>Evaluates first matching clause, returning its values, or evaluates and
returns the values of <code>default</code> if no keys match.
</p></blockquote></div>
<p><a name="Macro-cswitch"></a>
<div class="defun">
— Macro: <b>cswitch</b><var> whole </var>(<var>object &key test key</var>)<var> &body clauses<a name="index-cswitch-41"></a></var><br>
<blockquote><p><a name="index-cswitch-42"></a>Like <code>switch</code>, but signals a continuable error if no key matches.
</p></blockquote></div>
<p><a name="Macro-eswitch"></a>
<div class="defun">
— Macro: <b>eswitch</b><var> whole </var>(<var>object &key test key</var>)<var> &body clauses<a name="index-eswitch-43"></a></var><br>
<blockquote><p><a name="index-eswitch-44"></a>Like <code>switch</code>, but signals an error if no key matches.
</p></blockquote></div>
<p><a name="Macro-whichever"></a>
<div class="defun">
— Macro: <b>whichever</b><var> &rest possibilities env<a name="index-whichever-45"></a></var><br>
<blockquote><p><a name="index-whichever-46"></a>Evaluates exactly one of <code>possibilities</code>, chosen at random.
</p></blockquote></div>
<p><a name="Macro-xor"></a>
<div class="defun">
— Macro: <b>xor</b><var> &rest datums<a name="index-xor-47"></a></var><br>
<blockquote><p><a name="index-xor-48"></a>Evaluates its arguments one at a time, from left to right. If more then one
argument evaluates to a true value no further <code>datums</code> are evaluated, and <code>nil</code> is
returned as both primary and secondary value. If exactly one argument
evaluates to true, its value is returned as the primary value after all the
arguments have been evaluated, and <code>t</code> is returned as the secondary value. If no
arguments evaluate to true <code>nil</code> is retuned as primary, and <code>t</code> as secondary
value.
</p></blockquote></div>
<p><a name="Function-disjoin"></a>
<div class="defun">
— Function: <b>disjoin</b><var> predicate &rest more-predicates<a name="index-disjoin-49"></a></var><br>
<blockquote><p><a name="index-disjoin-50"></a>Returns a function that applies each of <code>predicate</code> and <code>more-predicate</code>
functions in turn to its arguments, returning the primary value of the first
predicate that returns true, without calling the remaining predicates.
If none of the predicates returns true, <code>nil</code> is returned.
</p></blockquote></div>
<p><a name="Function-conjoin"></a>
<div class="defun">
— Function: <b>conjoin</b><var> predicate &rest more-predicates<a name="index-conjoin-51"></a></var><br>
<blockquote><p><a name="index-conjoin-52"></a>Returns a function that applies each of <code>predicate</code> and <code>more-predicate</code>
functions in turn to its arguments, returning <code>nil</code> if any of the predicates
returns false, without calling the remaining predicates. If none of the
predicates returns false, returns the primary value of the last predicate.
</p></blockquote></div>
<p><a name="Function-compose"></a>
<div class="defun">
— Function: <b>compose</b><var> function &rest more-functions<a name="index-compose-53"></a></var><br>
<blockquote><p><a name="index-compose-54"></a>Returns a function composed of <code>function</code> and <code>more-functions</code> that applies its
arguments to to each in turn, starting from the rightmost of <code>more-functions</code>,
and then calling the next one with the primary value of the last.
</p></blockquote></div>
<p><a name="Function-ensure_002dfunction"></a>
<div class="defun">
— Function: <b>ensure-function</b><var> function-designator<a name="index-ensure_002dfunction-55"></a></var><br>
<blockquote><p><a name="index-ensure_002dfunction-56"></a>Returns the function designated by <code>function-designator:</code>
if <code>function-designator</code> is a function, it is returned, otherwise
it must be a function name and its <code>fdefinition</code> is returned.
</p></blockquote></div>
<p><a name="Function-multiple_002dvalue_002dcompose"></a>
<div class="defun">
— Function: <b>multiple-value-compose</b><var> function &rest more-functions<a name="index-multiple_002dvalue_002dcompose-57"></a></var><br>
<blockquote><p><a name="index-multiple_002dvalue_002dcompose-58"></a>Returns a function composed of <code>function</code> and <code>more-functions</code> that applies
its arguments to each in turn, starting from the rightmost of
<code>more-functions</code>, and then calling the next one with all the return values of
the last.
</p></blockquote></div>
<p><a name="Function-curry"></a>
<div class="defun">
— Function: <b>curry</b><var> function &rest arguments<a name="index-curry-59"></a></var><br>
<blockquote><p><a name="index-curry-60"></a>Returns a function that applies <code>arguments</code> and the arguments
it is called with to <code>function</code>.
</p></blockquote></div>
<p><a name="Function-rcurry"></a>
<div class="defun">
— Function: <b>rcurry</b><var> function &rest arguments<a name="index-rcurry-61"></a></var><br>
<blockquote><p><a name="index-rcurry-62"></a>Returns a function that applies the arguments it is called
with and <code>arguments</code> to <code>function</code>.
</p></blockquote></div>
<div class="node">
<a name="Conses"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Sequences">Sequences</a>,
Previous: <a rel="previous" accesskey="p" href="#Data-and-Control-Flow">Data and Control Flow</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<!-- node-name, next, previous, up -->
<h2 class="chapter">3 Conses</h2>
<p><a name="Type-proper_002dlist"></a>
<div class="defun">
— Type: <b>proper-list</b><var><a name="index-proper_002dlist-63"></a></var><br>
<blockquote><p><a name="index-proper_002dlist-64"></a>Type designator for proper lists. Implemented as a <code>satisfies</code> type, hence
not recommended for performance intensive use. Main usefullness as a type
designator of the expected type in a <code>type-error</code>.
</p></blockquote></div>
<p><a name="Type-circular_002dlist"></a>
<div class="defun">
— Type: <b>circular-list</b><var><a name="index-circular_002dlist-65"></a></var><br>
<blockquote><p><a name="index-circular_002dlist-66"></a>Type designator for circular lists. Implemented as a <code>satisfies</code> type, so not
recommended for performance intensive use. Main usefullness as the
expected-type designator of a <code>type-error</code>.
</p></blockquote></div>
<p><a name="Macro-appendf"></a>
<div class="defun">
— Macro: <b>appendf</b><var> place &rest lists env<a name="index-appendf-67"></a></var><br>
<blockquote><p><a name="index-appendf-68"></a>Modify-macro for <code>append</code>. Appends <code>lists</code> to the place designated by the first
argument.
</p></blockquote></div>
<p><a name="Macro-nconcf"></a>
<div class="defun">
— Macro: <b>nconcf</b><var> place &rest lists env<a name="index-nconcf-69"></a></var><br>
<blockquote><p><a name="index-nconcf-70"></a>Modify-macro for <code>nconc</code>. Concatenates <code>lists</code> to place designated by the first
argument.
</p></blockquote></div>
<p><a name="Macro-remove_002dfrom_002dplistf"></a>
<div class="defun">
— Macro: <b>remove-from-plistf</b><var> place &rest keys env<a name="index-remove_002dfrom_002dplistf-71"></a></var><br>
<blockquote><p><a name="index-remove_002dfrom_002dplistf-72"></a>Modify macro for <code>remove-from-plist</code>.
</p></blockquote></div>
<p><a name="Macro-delete_002dfrom_002dplistf"></a>
<div class="defun">
— Macro: <b>delete-from-plistf</b><var> place &rest keys env<a name="index-delete_002dfrom_002dplistf-73"></a></var><br>
<blockquote><p><a name="index-delete_002dfrom_002dplistf-74"></a>Modify macro for <code>delete-from-plist</code>.
</p></blockquote></div>
<p><a name="Macro-reversef"></a>
<div class="defun">
— Macro: <b>reversef</b><var> place env<a name="index-reversef-75"></a></var><br>
<blockquote><p><a name="index-reversef-76"></a>Modify-macro for <code>reverse</code>. Copies and reverses the list stored in the given
place and saves back the result into the place.
</p></blockquote></div>
<p><a name="Macro-nreversef"></a>
<div class="defun">
— Macro: <b>nreversef</b><var> place env<a name="index-nreversef-77"></a></var><br>
<blockquote><p><a name="index-nreversef-78"></a>Modify-macro for <code>nreverse</code>. Reverses the list stored in the given place by
destructively modifying it and saves back the result into the place.
</p></blockquote></div>
<p><a name="Macro-unionf"></a>
<div class="defun">
— Macro: <b>unionf</b><var> place list &rest args env<a name="index-unionf-79"></a></var><br>
<blockquote><p><a name="index-unionf-80"></a>Modify-macro for <code>union</code>. Saves the union of <code>list</code> and the contents of the
place designated by the first argument to the designated place.
</p></blockquote></div>
<p><a name="Macro-nunionf"></a>
<div class="defun">
— Macro: <b>nunionf</b><var> place list &rest args env<a name="index-nunionf-81"></a></var><br>
<blockquote><p><a name="index-nunionf-82"></a>Modify-macro for <code>nunion</code>. Saves the union of <code>list</code> and the contents of the
place designated by the first argument to the designated place. May modify
either argument.
</p></blockquote></div>
<p><a name="Macro-doplist"></a>
<div class="defun">
— Macro: <b>doplist</b> (<var>key val plist &optional values</var>)<var> &body body<a name="index-doplist-83"></a></var><br>
<blockquote><p><a name="index-doplist-84"></a>Iterates over elements of <code>plist</code>. <code>body</code> can be preceded by
declarations, and is like a <code>tagbody</code>. <code>return</code> may be used to terminate
the iteration early. If <code>return</code> is not used, returns <code>values</code>.
</p></blockquote></div>
<p><a name="Function-circular_002dlist_002dp"></a>
<div class="defun">
— Function: <b>circular-list-p</b><var> object<a name="index-circular_002dlist_002dp-85"></a></var><br>
<blockquote><p><a name="index-circular_002dlist_002dp-86"></a>Returns true if <code>object</code> is a circular list, <code>nil</code> otherwise.
</p></blockquote></div>
<p><a name="Function-circular_002dtree_002dp"></a>
<div class="defun">
— Function: <b>circular-tree-p</b><var> object<a name="index-circular_002dtree_002dp-87"></a></var><br>
<blockquote><p><a name="index-circular_002dtree_002dp-88"></a>Returns true if <code>object</code> is a circular tree, <code>nil</code> otherwise.
</p></blockquote></div>
<p><a name="Function-proper_002dlist_002dp"></a>
<div class="defun">
— Function: <b>proper-list-p</b><var> object<a name="index-proper_002dlist_002dp-89"></a></var><br>
<blockquote><p><a name="index-proper_002dlist_002dp-90"></a>Returns true if <code>object</code> is a proper list.
</p></blockquote></div>
<p><a name="Function-alist_002dplist"></a>
<div class="defun">
— Function: <b>alist-plist</b><var> alist<a name="index-alist_002dplist-91"></a></var><br>
<blockquote><p><a name="index-alist_002dplist-92"></a>Returns a property list containing the same keys and values as the
association list <code>alist</code> in the same order.
</p></blockquote></div>
<p><a name="Function-plist_002dalist"></a>
<div class="defun">
— Function: <b>plist-alist</b><var> plist<a name="index-plist_002dalist-93"></a></var><br>
<blockquote><p><a name="index-plist_002dalist-94"></a>Returns an association list containing the same keys and values as the
property list <code>plist</code> in the same order.
</p></blockquote></div>
<p><a name="Function-circular_002dlist"></a>
<div class="defun">
— Function: <b>circular-list</b><var> &rest elements<a name="index-circular_002dlist-95"></a></var><br>
<blockquote><p><a name="index-circular_002dlist-96"></a>Creates a circular list of <code>elements</code>.
</p></blockquote></div>
<p><a name="Function-make_002dcircular_002dlist"></a>
<div class="defun">
— Function: <b>make-circular-list</b><var> length &key initial-element<a name="index-make_002dcircular_002dlist-97"></a></var><br>
<blockquote><p><a name="index-make_002dcircular_002dlist-98"></a>Creates a circular list of <code>length</code> with the given <code>initial-element</code>.
</p></blockquote></div>
<p><a name="Function-ensure_002dcar"></a>
<div class="defun">
— Function: <b>ensure-car</b><var> thing<a name="index-ensure_002dcar-99"></a></var><br>
<blockquote><p><a name="index-ensure_002dcar-100"></a>If <code>thing</code> is a <code>cons</code>, its <code>car</code> is returned. Otherwise <code>thing</code> is returned.
</p></blockquote></div>
<p><a name="Function-ensure_002dcons"></a>
<div class="defun">
— Function: <b>ensure-cons</b><var> cons<a name="index-ensure_002dcons-101"></a></var><br>
<blockquote><p><a name="index-ensure_002dcons-102"></a>If <code>cons</code> is a cons, it is returned. Otherwise returns a fresh cons with <code>cons</code>
in the car, and <code>nil</code> in the cdr.
</p></blockquote></div>
<p><a name="Function-ensure_002dlist"></a>
<div class="defun">
— Function: <b>ensure-list</b><var> list<a name="index-ensure_002dlist-103"></a></var><br>
<blockquote><p><a name="index-ensure_002dlist-104"></a>If <code>list</code> is a list, it is returned. Otherwise returns the list designated by <code>list</code>.
</p></blockquote></div>
<p><a name="Function-flatten"></a>
<div class="defun">
— Function: <b>flatten</b><var> tree<a name="index-flatten-105"></a></var><br>
<blockquote><p><a name="index-flatten-106"></a>Traverses the tree in order, collecting non-null leaves into a list.
</p></blockquote></div>
<p><a name="Function-lastcar"></a>
<div class="defun">
— Function: <b>lastcar</b><var> list<a name="index-lastcar-107"></a></var><br>
<blockquote><p><a name="index-lastcar-108"></a>Returns the last element of <code>list</code>. Signals a type-error if <code>list</code> is not a
proper list.
</p></blockquote></div>
<p><a name="Function-_0028setf-lastcar_0029"></a>
<div class="defun">
— Function: <b>(setf lastcar)</b><var><a name="index-g_t_0028setf-lastcar_0029-109"></a></var><br>
<blockquote><p><a name="index-g_t_0028setf-lastcar_0029-110"></a>Sets the last element of <code>list</code>. Signals a type-error if <code>list</code> is not a proper
list.
</p></blockquote></div>
<p><a name="Function-proper_002dlist_002dlength"></a>
<div class="defun">
— Function: <b>proper-list-length</b><var> list<a name="index-proper_002dlist_002dlength-111"></a></var><br>
<blockquote><p><a name="index-proper_002dlist_002dlength-112"></a>Returns length of <code>list</code>, signalling an error if it is not a proper list.
</p></blockquote></div>
<p><a name="Function-mappend"></a>
<div class="defun">
— Function: <b>mappend</b><var> function &rest lists<a name="index-mappend-113"></a></var><br>
<blockquote><p><a name="index-mappend-114"></a>Applies <code>function</code> to respective element(s) of each <code>list</code>, appending all the
all the result list to a single list. <code>function</code> must return a list.
</p></blockquote></div>
<p><a name="Function-map_002dproduct"></a>
<div class="defun">
— Function: <b>map-product</b><var> function list &rest more-lists<a name="index-map_002dproduct-115"></a></var><br>
<blockquote><p><a name="index-map_002dproduct-116"></a>Returns a list containing the results of calling <code>function</code> with one argument
from <code>list</code>, and one from each of <code>more-lists</code> for each combination of arguments.
In other words, returns the product of <code>list</code> and <code>more-lists</code> using <code>function</code>.
<p>Example:
<pre class="lisp"> (map-product 'list '(1 2) '(3 4) '(5 6))
=> ((1 3 5) (1 3 6) (1 4 5) (1 4 6)
(2 3 5) (2 3 6) (2 4 5) (2 4 6))
</pre>
</blockquote></div>
<p><a name="Function-remove_002dfrom_002dplist"></a>
<div class="defun">
— Function: <b>remove-from-plist</b><var> plist &rest keys<a name="index-remove_002dfrom_002dplist-117"></a></var><br>
<blockquote><p><a name="index-remove_002dfrom_002dplist-118"></a>Returns a propery-list with same keys and values as <code>plist</code>, except that keys
in the list designated by <code>keys</code> and values corresponding to them are removed.
The returned property-list may share structure with the <code>plist</code>, but <code>plist</code> is
not destructively modified. Keys are compared using <code>eq</code>.
</p></blockquote></div>
<p><a name="Function-delete_002dfrom_002dplist"></a>
<div class="defun">
— Function: <b>delete-from-plist</b><var> plist &rest keys<a name="index-delete_002dfrom_002dplist-119"></a></var><br>
<blockquote><p><a name="index-delete_002dfrom_002dplist-120"></a>Just like <code>remove-from-plist</code>, but this version may destructively modify the
provided plist.
</p></blockquote></div>
<p><a name="Function-set_002dequal"></a>
<div class="defun">
— Function: <b>set-equal</b><var> list1 list2 &key test key<a name="index-set_002dequal-121"></a></var><br>
<blockquote><p><a name="index-set_002dequal-122"></a>Returns true if every element of <code>list1</code> matches some element of <code>list2</code> and
every element of <code>list2</code> matches some element of <code>list1</code>. Otherwise returns false.
</p></blockquote></div>
<p><a name="Function-setp"></a>
<div class="defun">
— Function: <b>setp</b><var> object &key test key<a name="index-setp-123"></a></var><br>
<blockquote><p><a name="index-setp-124"></a>Returns true if <code>object</code> is a list that denotes a set, <code>nil</code> otherwise. A list
denotes a set if each element of the list is unique under <code>key</code> and <code>test</code>.
</p></blockquote></div>
<div class="node">
<a name="Sequences"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#IO">IO</a>,
Previous: <a rel="previous" accesskey="p" href="#Conses">Conses</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<!-- node-name, next, previous, up -->
<h2 class="chapter">4 Sequences</h2>
<p><a name="Type-proper_002dsequence"></a>
<div class="defun">
— Type: <b>proper-sequence</b><var><a name="index-proper_002dsequence-125"></a></var><br>
<blockquote><p><a name="index-proper_002dsequence-126"></a>Type designator for proper sequences, that is proper lists and sequences
that are not lists.
</p></blockquote></div>
<p><a name="Macro-deletef"></a>
<div class="defun">
— Macro: <b>deletef</b><var> place item &rest remove-keywords env<a name="index-deletef-127"></a></var><br>
<blockquote><p><a name="index-deletef-128"></a>Modify-macro for <code>delete</code>. Sets place designated by the first argument to
the result of calling <code>delete</code> with <code>item</code>, place, and the <code>remove-keywords</code>.
</p></blockquote></div>
<p><a name="Macro-removef"></a>
<div class="defun">
— Macro: <b>removef</b><var> place item &rest remove-keywords env<a name="index-removef-129"></a></var><br>
<blockquote><p><a name="index-removef-130"></a>Modify-macro for <code>remove</code>. Sets place designated by the first argument to
the result of calling <code>remove</code> with <code>item</code>, place, and the <code>remove-keywords</code>.
</p></blockquote></div>
<p><a name="Function-rotate"></a>
<div class="defun">
— Function: <b>rotate</b><var> sequence &optional n<a name="index-rotate-131"></a></var><br>
<blockquote><p><a name="index-rotate-132"></a>Returns a sequence of the same type as <code>sequence</code>, with the elements of
<code>sequence</code> rotated by <code>n:</code> <code>n</code> elements are moved from the end of the sequence to
the front if <code>n</code> is positive, and <code>-n</code> elements moved from the front to the end if
<code>n</code> is negative. <code>sequence</code> must be a proper sequence. <code>n</code> must be an integer,
defaulting to <code>1</code>.
<p>If absolute value of <code>n</code> is greater then the length of the sequence, the results
are identical to calling <code>rotate</code> with
<pre class="lisp"> (* (signum n) (mod n (length sequence))).
</pre>
<p>Note: the original sequence may be destructively altered, and result sequence may
share structure with it.
</p></blockquote></div>
<p><a name="Function-shuffle"></a>
<div class="defun">
— Function: <b>shuffle</b><var> sequence &key start end<a name="index-shuffle-133"></a></var><br>
<blockquote><p><a name="index-shuffle-134"></a>Returns a random permutation of <code>sequence</code> bounded by <code>start</code> and <code>end</code>.
Original sequece may be destructively modified, and share storage with
the original one. Signals an error if <code>sequence</code> is not a proper
sequence.
</p></blockquote></div>
<p><a name="Function-random_002delt"></a>
<div class="defun">
— Function: <b>random-elt</b><var> sequence &key start end<a name="index-random_002delt-135"></a></var><br>
<blockquote><p><a name="index-random_002delt-136"></a>Returns a random element from <code>sequence</code> bounded by <code>start</code> and <code>end</code>. Signals an
error if the <code>sequence</code> is not a proper non-empty sequence, or if <code>end</code> and <code>start</code>
are not proper bounding index designators for <code>sequence</code>.
</p></blockquote></div>
<p><a name="Function-emptyp"></a>
<div class="defun">
— Function: <b>emptyp</b><var> sequence<a name="index-emptyp-137"></a></var><br>
<blockquote><p><a name="index-emptyp-138"></a>Returns true if <code>sequence</code> is an empty sequence. Signals an error if <code>sequence</code>
is not a sequence.
</p></blockquote></div>
<p><a name="Function-sequence_002dof_002dlength_002dp"></a>
<div class="defun">
— Function: <b>sequence-of-length-p</b><var> sequence length<a name="index-sequence_002dof_002dlength_002dp-139"></a></var><br>
<blockquote><p><a name="index-sequence_002dof_002dlength_002dp-140"></a>Return true if <code>sequence</code> is a sequence of length <code>length</code>. Signals an error if
<code>sequence</code> is not a sequence. Returns <code>false</code> for circular lists.
</p></blockquote></div>
<p><a name="Function-length_003d"></a>
<div class="defun">
— Function: <b>length=</b><var> &rest sequences<a name="index-length_003d-141"></a></var><br>
<blockquote><p><a name="index-length_003d-142"></a>Takes any number of sequences or integers in any order. Returns true iff
the length of all the sequences and the integers are equal. Hint: there's a
compiler macro that expands into more efficient code if the first argument
is a literal integer.
</p></blockquote></div>
<p><a name="Function-copy_002dsequence"></a>
<div class="defun">
— Function: <b>copy-sequence</b><var> type sequence<a name="index-copy_002dsequence-143"></a></var><br>
<blockquote><p><a name="index-copy_002dsequence-144"></a>Returns a fresh sequence of <code>type</code>, which has the same elements as
<code>sequence</code>.
</p></blockquote></div>
<p><a name="Function-first_002delt"></a>
<div class="defun">
— Function: <b>first-elt</b><var> sequence<a name="index-first_002delt-145"></a></var><br>
<blockquote><p><a name="index-first_002delt-146"></a>Returns the first element of <code>sequence</code>. Signals a type-error if <code>sequence</code> is
not a sequence, or is an empty sequence.
</p></blockquote></div>
<p><a name="Function-_0028setf-first_002delt_0029"></a>
<div class="defun">
— Function: <b>(setf first-elt)</b><var><a name="index-g_t_0028setf-first_002delt_0029-147"></a></var><br>
<blockquote><p><a name="index-g_t_0028setf-first_002delt_0029-148"></a>Sets the first element of <code>sequence</code>. Signals a type-error if <code>sequence</code> is
not a sequence, is an empty sequence, or if <code>object</code> cannot be stored in <code>sequence</code>.
</p></blockquote></div>
<p><a name="Function-last_002delt"></a>
<div class="defun">
— Function: <b>last-elt</b><var> sequence<a name="index-last_002delt-149"></a></var><br>
<blockquote><p><a name="index-last_002delt-150"></a>Returns the last element of <code>sequence</code>. Signals a type-error if <code>sequence</code> is
not a proper sequence, or is an empty sequence.
</p></blockquote></div>
<p><a name="Function-_0028setf-last_002delt_0029"></a>
<div class="defun">
— Function: <b>(setf last-elt)</b><var><a name="index-g_t_0028setf-last_002delt_0029-151"></a></var><br>
<blockquote><p><a name="index-g_t_0028setf-last_002delt_0029-152"></a>Sets the last element of <code>sequence</code>. Signals a type-error if <code>sequence</code> is not a proper
sequence, is an empty sequence, or if <code>object</code> cannot be stored in <code>sequence</code>.
</p></blockquote></div>
<p><a name="Function-starts_002dwith"></a>
<div class="defun">
— Function: <b>starts-with</b><var> object sequence &key test key<a name="index-starts_002dwith-153"></a></var><br>
<blockquote><p><a name="index-starts_002dwith-154"></a>Returns true if <code>sequence</code> is a sequence whose first element is <code>eql</code> to <code>object</code>.
Returns <code>nil</code> if the <code>sequence</code> is not a sequence or is an empty sequence.
</p></blockquote></div>
<p><a name="Function-starts_002dwith_002dsubseq"></a>
<div class="defun">
— Function: <b>starts-with-subseq</b><var> prefix sequence &rest args &key return-suffix &allow-other-keys<a name="index-starts_002dwith_002dsubseq-155"></a></var><br>
<blockquote><p><a name="index-starts_002dwith_002dsubseq-156"></a>Test whether the first elements of <code>sequence</code> are the same (as per TEST) as the elements of <code>prefix</code>.
<p>If <code>return-suffix</code> is <code>t</code> the functions returns, as a second value, a
displaced array pointing to the sequence after <code>prefix</code>.
</p></blockquote></div>
<p><a name="Function-ends_002dwith"></a>
<div class="defun">
— Function: <b>ends-with</b><var> object sequence &key test key<a name="index-ends_002dwith-157"></a></var><br>
<blockquote><p><a name="index-ends_002dwith-158"></a>Returns true if <code>sequence</code> is a sequence whose last element is <code>eql</code> to <code>object</code>.
Returns <code>nil</code> if the <code>sequence</code> is not a sequence or is an empty sequence. Signals
an error if <code>sequence</code> is an improper list.
</p></blockquote></div>
<p><a name="Function-ends_002dwith_002dsubseq"></a>
<div class="defun">
— Function: <b>ends-with-subseq</b><var> suffix sequence &key test<a name="index-ends_002dwith_002dsubseq-159"></a></var><br>
<blockquote><p><a name="index-ends_002dwith_002dsubseq-160"></a>Test whether <code>sequence</code> ends with <code>suffix</code>. In other words: return true if
the last (length SUFFIX) elements of <code>sequence</code> are equal to <code>suffix</code>.
</p></blockquote></div>
<p><a name="Function-map_002dcombinations"></a>
<div class="defun">
— Function: <b>map-combinations</b><var> function sequence &key start end length copy<a name="index-map_002dcombinations-161"></a></var><br>
<blockquote><p><a name="index-map_002dcombinations-162"></a>Calls <code>function</code> with each combination of <code>length</code> constructable from the
elements of the subsequence of <code>sequence</code> delimited by <code>start</code> and <code>end</code>. <code>start</code>
defaults to <code>0</code>, <code>end</code> to length of <code>sequence</code>, and <code>length</code> to the length of the
delimited subsequence. (So unless <code>length</code> is specified there is only a single
combination, which has the same elements as the delimited subsequence.) If
<code>copy</code> is true (the default) each combination is freshly allocated. If <code>copy</code> is
false all combinations are <code>eq</code> to each other, in which case consequences are
specified if a combination is modified by <code>function</code>.
</p></blockquote></div>
<p><a name="Function-map_002dderangements"></a>
<div class="defun">
— Function: <b>map-derangements</b><var> function sequence &key start end copy<a name="index-map_002dderangements-163"></a></var><br>
<blockquote><p><a name="index-map_002dderangements-164"></a>Calls <code>function</code> with each derangement of the subsequence of <code>sequence</code> denoted
by the bounding index designators <code>start</code> and <code>end</code>. Derangement is a permutation
of the sequence where no element remains in place. <code>sequence</code> is not modified,
but individual derangements are <code>eq</code> to each other. Consequences are unspecified
if calling <code>function</code> modifies either the derangement or <code>sequence</code>.
</p></blockquote></div>
<p><a name="Function-map_002dpermutations"></a>
<div class="defun">
— Function: <b>map-permutations</b><var> function sequence &key start end length copy<a name="index-map_002dpermutations-165"></a></var><br>
<blockquote><p><a name="index-map_002dpermutations-166"></a>Calls function with each permutation of <code>length</code> constructable
from the subsequence of <code>sequence</code> delimited by <code>start</code> and <code>end</code>. <code>start</code>
defaults to <code>0</code>, <code>end</code> to length of the sequence, and <code>length</code> to the
length of the delimited subsequence.
</p></blockquote></div>
<div class="node">
<a name="IO"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Macro-Writing">Macro Writing</a>,
Previous: <a rel="previous" accesskey="p" href="#Sequences">Sequences</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<!-- node-name, next, previous, up -->
<h2 class="chapter">5 IO</h2>
<p><a name="Function-read_002dfile_002dinto_002dstring"></a>
<div class="defun">
— Function: <b>read-file-into-string</b><var> pathname &key buffer-size external-format<a name="index-read_002dfile_002dinto_002dstring-167"></a></var><br>
<blockquote><p><a name="index-read_002dfile_002dinto_002dstring-168"></a>Return the contents of the file denoted by <code>pathname</code> as a fresh string.
<p>The <code>external-format</code> parameter will be passed directly to <code>with-open-file</code>
unless it's <code>nil</code>, which means the system default.
</p></blockquote></div>
<p><a name="Function-read_002dfile_002dinto_002dbyte_002dvector"></a>
<div class="defun">
— Function: <b>read-file-into-byte-vector</b><var> pathname<a name="index-read_002dfile_002dinto_002dbyte_002dvector-169"></a></var><br>
<blockquote><p><a name="index-read_002dfile_002dinto_002dbyte_002dvector-170"></a>Read <code>pathname</code> into a freshly allocated (unsigned-byte 8) vector.
</p></blockquote></div>
<div class="node">
<a name="Macro-Writing"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Symbols">Symbols</a>,
Previous: <a rel="previous" accesskey="p" href="#IO">IO</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<!-- node-name, next, previous, up -->
<h2 class="chapter">6 Macro Writing</h2>
<p><a name="Macro-once_002donly"></a>
<div class="defun">
— Macro: <b>once-only</b><var> specs &body forms<a name="index-once_002donly-171"></a></var><br>
<blockquote><p><a name="index-once_002donly-172"></a>Evaluates <code>forms</code> with symbols specified in <code>specs</code> rebound to temporary
variables, ensuring that each initform is evaluated only once.
<p>Each of <code>specs</code> must either be a symbol naming the variable to be rebound, or of
the form:
<pre class="lisp"> (symbol initform)
</pre>
<p>Bare symbols in <code>specs</code> are equivalent to
<pre class="lisp"> (symbol symbol)
</pre>
<p>Example:
<pre class="lisp"> (defmacro cons1 (x) (once-only (x) `(cons ,x ,x)))
(let ((y 0)) (cons1 (incf y))) => (1 . 1)
</pre>
</blockquote></div>
<p><a name="Macro-with_002dgensyms"></a>
<div class="defun">
— Macro: <b>with-gensyms</b><var> names &body forms<a name="index-with_002dgensyms-173"></a></var><br>
<blockquote><p><a name="index-with_002dgensyms-174"></a>Binds each variable named by a symbol in <code>names</code> to a unique symbol around
<code>forms</code>. Each of <code>names</code> must either be either a symbol, or of the form:
<pre class="lisp"> (symbol string-designator)
</pre>
<p>Bare symbols appearing in <code>names</code> are equivalent to:
<pre class="lisp"> (symbol symbol)
</pre>
<p>The string-designator is used as the argument to <code>gensym</code> when constructing the
unique symbol the named variable will be bound to.
</p></blockquote></div>
<p><a name="Macro-with_002dunique_002dnames"></a>
<div class="defun">
— Macro: <b>with-unique-names</b><var> names &body forms<a name="index-with_002dunique_002dnames-175"></a></var><br>
<blockquote><p><a name="index-with_002dunique_002dnames-176"></a>Alias for <code>with-gensyms</code>.
</p></blockquote></div>
<p><a name="Function-featurep"></a>
<div class="defun">
— Function: <b>featurep</b><var> feature-expression<a name="index-featurep-177"></a></var><br>
<blockquote><p><a name="index-featurep-178"></a>Returns <code>t</code> if the argument matches the state of the <code>*features*</code>
list and <code>nil</code> if it does not. <code>feature-expression</code> can be any atom
or list acceptable to the reader macros <code>#+</code> and <code>#-</code>.
</p></blockquote></div>
<p><a name="Function-parse_002dbody"></a>
<div class="defun">
— Function: <b>parse-body</b><var> body &key documentation whole<a name="index-parse_002dbody-179"></a></var><br>
<blockquote><p><a name="index-parse_002dbody-180"></a>Parses <code>body</code> into (values remaining-forms declarations doc-string).
Documentation strings are recognized only if <code>documentation</code> is true.
Syntax errors in body are signalled and <code>whole</code> is used in the signal
arguments when given.
</p></blockquote></div>
<p><a name="Function-parse_002dordinary_002dlambda_002dlist"></a>
<div class="defun">
— Function: <b>parse-ordinary-lambda-list</b><var> lambda-list &key normalize allow-specializers normalize-optional normalize-keyword normalize-auxilary<a name="index-parse_002dordinary_002dlambda_002dlist-181"></a></var><br>
<blockquote><p><a name="index-parse_002dordinary_002dlambda_002dlist-182"></a>Parses an ordinary lambda-list, returning as multiple values:
<p><code>1</code>. Required parameters.
<p><code>2</code>. Optional parameter specifications, normalized into form:
<pre class="lisp"> (name init suppliedp)
</pre>
<p><code>3</code>. Name of the rest parameter, or <code>nil</code>.
<p><code>4</code>. Keyword parameter specifications, normalized into form:
<pre class="lisp"> ((keyword-name name) init suppliedp)
</pre>
<p><code>5</code>. Boolean indicating <code>&allow-other-keys</code> presence.
<p><code>6</code>. <code>&aux</code> parameter specifications, normalized into form
<pre class="lisp"> (name init).
</pre>
<p><code>7</code>. Existence of <code>&key</code> in the lambda-list.
<p>Signals a <code>program-error</code> is the lambda-list is malformed.
</p></blockquote></div>
<div class="node">
<a name="Symbols"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Arrays">Arrays</a>,
Previous: <a rel="previous" accesskey="p" href="#Macro-Writing">Macro Writing</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<!-- node-name, next, previous, up -->
<h2 class="chapter">7 Symbols</h2>
<p><a name="Function-ensure_002dsymbol"></a>
<div class="defun">
— Function: <b>ensure-symbol</b><var> name &optional package<a name="index-ensure_002dsymbol-183"></a></var><br>
<blockquote><p><a name="index-ensure_002dsymbol-184"></a>Returns a symbol with name designated by <code>name</code>, accessible in package
designated by <code>package</code>. If symbol is not already accessible in <code>package</code>, it is
interned there. Returns a secondary value reflecting the status of the symbol
in the package, which matches the secondary return value of <code>intern</code>.
<p>Example:
<pre class="lisp"> (ensure-symbol :cons :cl) => cl:cons, :external
</pre>
</blockquote></div>
<p><a name="Function-format_002dsymbol"></a>
<div class="defun">
— Function: <b>format-symbol</b><var> package control &rest arguments<a name="index-format_002dsymbol-185"></a></var><br>
<blockquote><p><a name="index-format_002dsymbol-186"></a>Constructs a string by applying <code>arguments</code> to string designator <code>control</code> as
if by <code>format</code> within <code>with-standard-io-syntax</code>, and then creates a symbol named
by that string.
<p>If <code>package</code> is <code>nil</code>, returns an uninterned symbol, if package is <code>t</code>, returns a
symbol interned in the current package, and otherwise returns a symbol
interned in the package designated by <code>package</code>.
</p></blockquote></div>
<p><a name="Function-make_002dkeyword"></a>
<div class="defun">
— Function: <b>make-keyword</b><var> name<a name="index-make_002dkeyword-187"></a></var><br>
<blockquote><p><a name="index-make_002dkeyword-188"></a>Interns the string designated by <code>name</code> in the <code>keyword</code> package.
</p></blockquote></div>
<p><a name="Function-make_002dgensym"></a>
<div class="defun">
— Function: <b>make-gensym</b><var> name<a name="index-make_002dgensym-189"></a></var><br>
<blockquote><p><a name="index-make_002dgensym-190"></a>If <code>name</code> is a non-negative integer, calls <code>gensym</code> using it. Otherwise <code>name</code>
must be a string designator, in which case calls <code>gensym</code> using the designated
string as the argument.
</p></blockquote></div>
<p><a name="Function-make_002dgensym_002dlist"></a>
<div class="defun">
— Function: <b>make-gensym-list</b><var> length &optional x<a name="index-make_002dgensym_002dlist-191"></a></var><br>
<blockquote><p><a name="index-make_002dgensym_002dlist-192"></a>Returns a list of <code>length</code> gensyms, each generated as if with a call to <code>make-gensym</code>,
using the second (optional, defaulting to "G") argument.
</p></blockquote></div>
<p><a name="Function-symbolicate"></a>
<div class="defun">
— Function: <b>symbolicate</b><var> &rest things<a name="index-symbolicate-193"></a></var><br>
<blockquote><p><a name="index-symbolicate-194"></a>Concatenate together the names of some strings and symbols,
producing a symbol in the current package.
</p></blockquote></div>
<div class="node">
<a name="Arrays"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Types">Types</a>,
Previous: <a rel="previous" accesskey="p" href="#Symbols">Symbols</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<!-- node-name, next, previous, up -->
<h2 class="chapter">8 Arrays</h2>
<p><a name="Type-array_002dindex"></a>
<div class="defun">
— Type: <b>array-index</b><var><a name="index-array_002dindex-195"></a></var><br>
<blockquote><p><a name="index-array_002dindex-196"></a>Type designator for an index into array of <code>length:</code> an integer between
<code>0</code> (inclusive) and <code>length</code> (exclusive). <code>length</code> defaults to
<code>array-dimension-limit</code>.
</p></blockquote></div>
<p><a name="Type-array_002dlength"></a>
<div class="defun">
— Type: <b>array-length</b><var><a name="index-array_002dlength-197"></a></var><br>
<blockquote><p><a name="index-array_002dlength-198"></a>Type designator for a dimension of an array of <code>length:</code> an integer between
<code>0</code> (inclusive) and <code>length</code> (inclusive). <code>length</code> defaults to
<code>array-dimension-limit</code>.
</p></blockquote></div>
<p><a name="Function-copy_002darray"></a>
<div class="defun">
— Function: <b>copy-array</b><var> array &key element-type fill-pointer adjustable<a name="index-copy_002darray-199"></a></var><br>
<blockquote><p><a name="index-copy_002darray-200"></a>Returns an undisplaced copy of <code>array</code>, with same fill-pointer and
adjustability (if any) as the original, unless overridden by the keyword
arguments.
</p></blockquote></div>
<div class="node">
<a name="Types"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Numbers">Numbers</a>,
Previous: <a rel="previous" accesskey="p" href="#Arrays">Arrays</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<!-- node-name, next, previous, up -->
<h2 class="chapter">9 Types</h2>
<p><a name="Type-string_002ddesignator"></a>
<div class="defun">
— Type: <b>string-designator</b><var><a name="index-string_002ddesignator-201"></a></var><br>
<blockquote><p><a name="index-string_002ddesignator-202"></a>A string designator type. A string designator is either a string, a symbol,
or a character.
</p></blockquote></div>
<p><a name="Macro-coercef"></a>
<div class="defun">
— Macro: <b>coercef</b><var> place type-spec env<a name="index-coercef-203"></a></var><br>
<blockquote><p><a name="index-coercef-204"></a>Modify-macro for <code>coerce</code>.
</p></blockquote></div>
<p><a name="Function-of_002dtype"></a>
<div class="defun">
— Function: <b>of-type</b><var> type<a name="index-of_002dtype-205"></a></var><br>
<blockquote><p><a name="index-of_002dtype-206"></a>Returns a function of one argument, which returns true when its argument is
of <code>type</code>.
</p></blockquote></div>
<p><a name="Function-type_003d"></a>
<div class="defun">
— Function: <b>type=</b><var> type1 type2<a name="index-type_003d-207"></a></var><br>
<blockquote><p><a name="index-type_003d-208"></a>Returns a primary value of <code>t</code> is <code>type1</code> and <code>type2</code> are the same type,
and a secondary value that is true is the type equality could be reliably
determined: primary value of <code>nil</code> and secondary value of <code>t</code> indicates that the
types are not equivalent.
</p></blockquote></div>
<div class="node">
<a name="Numbers"></a>
<p><hr>
Previous: <a rel="previous" accesskey="p" href="#Types">Types</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<!-- node-name, next, previous, up -->
<h2 class="chapter">10 Numbers</h2>
<p><a name="Macro-maxf"></a>
<div class="defun">
— Macro: <b>maxf</b><var> place &rest numbers env<a name="index-maxf-209"></a></var><br>
<blockquote><p><a name="index-maxf-210"></a>Modify-macro for <code>max</code>. Sets place designated by the first argument to the
maximum of its original value and <code>numbers</code>.
</p></blockquote></div>
<p><a name="Macro-minf"></a>
<div class="defun">
— Macro: <b>minf</b><var> place &rest numbers env<a name="index-minf-211"></a></var><br>
<blockquote><p><a name="index-minf-212"></a>Modify-macro for <code>min</code>. Sets place designated by the first argument to the
minimum of its original value and <code>numbers</code>.
</p></blockquote></div>
<p><a name="Function-binomial_002dcoefficient"></a>
<div class="defun">
— Function: <b>binomial-coefficient</b><var> n k<a name="index-binomial_002dcoefficient-213"></a></var><br>
<blockquote><p><a name="index-binomial_002dcoefficient-214"></a>Binomial coefficient of <code>n</code> and <code>k</code>, also expressed as <code>n</code> choose <code>k</code>. This is the
number of <code>k</code> element combinations given <code>n</code> choises. <code>n</code> must be equal to or
greater then <code>k</code>.
</p></blockquote></div>
<p><a name="Function-count_002dpermutations"></a>
<div class="defun">
— Function: <b>count-permutations</b><var> n &optional k<a name="index-count_002dpermutations-215"></a></var><br>
<blockquote><p><a name="index-count_002dpermutations-216"></a>Number of <code>k</code> element permutations for a sequence of <code>n</code> objects.
<code>k</code> defaults to <code>n</code>
</p></blockquote></div>
<p><a name="Function-clamp"></a>
<div class="defun">
— Function: <b>clamp</b><var> number min max<a name="index-clamp-217"></a></var><br>
<blockquote><p><a name="index-clamp-218"></a>Clamps the <code>number</code> into [min, max] range. Returns <code>min</code> if <code>number</code> is lesser then
<code>min</code> and <code>max</code> if <code>number</code> is greater then <code>max</code>, otherwise returns <code>number</code>.
</p></blockquote></div>
<p><a name="Function-lerp"></a>
<div class="defun">
— Function: <b>lerp</b><var> v a b<a name="index-lerp-219"></a></var><br>
<blockquote><p><a name="index-lerp-220"></a>Returns the result of linear interpolation between A and <code>b</code>, using the
interpolation coefficient <code>v</code>.
</p></blockquote></div>
<p><a name="Function-factorial"></a>
<div class="defun">
— Function: <b>factorial</b><var> n<a name="index-factorial-221"></a></var><br>
<blockquote><p><a name="index-factorial-222"></a>Factorial of non-negative integer <code>n</code>.
</p></blockquote></div>
<p><a name="Function-subfactorial"></a>
<div class="defun">
— Function: <b>subfactorial</b><var> n<a name="index-subfactorial-223"></a></var><br>
<blockquote><p><a name="index-subfactorial-224"></a>Subfactorial of the non-negative integer <code>n</code>.
</p></blockquote></div>
<p><a name="Function-gaussian_002drandom"></a>
<div class="defun">
— Function: <b>gaussian-random</b><var> &optional min max<a name="index-gaussian_002drandom-225"></a></var><br>
<blockquote><p><a name="index-gaussian_002drandom-226"></a>Returns two gaussian random double floats as the primary and secondary value,
optionally constrained by <code>min</code> and <code>max</code>. Gaussian random numbers form a standard
normal distribution around <code>0</code>.0d0.
<p>Sufficiently positive <code>min</code> or negative <code>max</code> will cause the algorithm used to
take a very long time. If <code>min</code> is positive it should be close to zero, and
similarly if <code>max</code> is negative it should be close to zero.
</p></blockquote></div>
<p><a name="Function-iota"></a>
<div class="defun">
— Function: <b>iota</b><var> n &key start step<a name="index-iota-227"></a></var><br>
<blockquote><p><a name="index-iota-228"></a>Return a list of n numbers, starting from <code>start</code> (with numeric contagion
from <code>step</code> applied), each consequtive number being the sum of the previous one
and <code>step</code>. <code>start</code> defaults to <code>0</code> and <code>step</code> to <code>1</code>.
<p>Examples:
<pre class="lisp"> (iota 4) => (0 1 2 3)
(iota 3 :start 1 :step 1.0) => (1.0 2.0 3.0)
(iota 3 :start -1 :step -1/2) => (-1 -3/2 -2)
</pre>
</blockquote></div>
<p><a name="Function-map_002diota"></a>
<div class="defun">
— Function: <b>map-iota</b><var> function n &key start step<a name="index-map_002diota-229"></a></var><br>
<blockquote><p><a name="index-map_002diota-230"></a>Calls <code>function</code> with <code>n</code> numbers, starting from <code>start</code> (with numeric contagion
from <code>step</code> applied), each consequtive number being the sum of the previous one
and <code>step</code>. <code>start</code> defaults to <code>0</code> and <code>step</code> to <code>1</code>. Returns <code>n</code>.
<p>Examples:
<pre class="lisp"> (map-iota #'print 3 :start 1 :step 1.0) => 3
;;; 1.0
;;; 2.0
;;; 3.0
</pre>
</blockquote></div>
<p><a name="Function-mean"></a>
<div class="defun">
— Function: <b>mean</b><var> sample<a name="index-mean-231"></a></var><br>
<blockquote><p><a name="index-mean-232"></a>Returns the mean of <code>sample</code>. <code>sample</code> must be a sequence of numbers.
</p></blockquote></div>
<p><a name="Function-median"></a>
<div class="defun">
— Function: <b>median</b><var> sample<a name="index-median-233"></a></var><br>
<blockquote><p><a name="index-median-234"></a>Returns median of <code>sample</code>. <code>sample</code> must be a sequence of real numbers.
</p></blockquote></div>
<p><a name="Function-variance"></a>
<div class="defun">
— Function: <b>variance</b><var> sample &key biased<a name="index-variance-235"></a></var><br>
<blockquote><p><a name="index-variance-236"></a>Variance of <code>sample</code>. Returns the biased variance if <code>biased</code> is true (the default),
and the unbiased estimator of variance if <code>biased</code> is false. <code>sample</code> must be a
sequence of numbers.
</p></blockquote></div>
<p><a name="Function-standard_002ddeviation"></a>
<div class="defun">
— Function: <b>standard-deviation</b><var> sample &key biased<a name="index-standard_002ddeviation-237"></a></var><br>
<blockquote><p><a name="index-standard_002ddeviation-238"></a>Standard deviation of <code>sample</code>. Returns the biased standard deviation if
<code>biased</code> is true (the default), and the square root of the unbiased estimator
for variance if <code>biased</code> is false (which is not the same as the unbiased
estimator for standard deviation). <code>sample</code> must be a sequence of numbers.
</p></blockquote></div>
</body></html>
| 70,721 | Common Lisp | .l | 1,123 | 60.114871 | 235 | 0.700162 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 9975a975be44c5882ff93021cbe8d11b55b02f0fce398f155402075affa5b01b | 984 | [
-1
] |
985 | Makefile | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/alexandria/doc/Makefile | .PHONY: clean html pdf include clean-include clean-crap info doc
doc: pdf html info clean-crap
clean-include:
rm -rf include
clean-crap:
rm -f *.aux *.cp *.fn *.fns *.ky *.log *.pg *.toc *.tp *.tps *.vr
clean: clean-include
rm -f *.pdf *.html *.info
include:
sbcl --no-userinit --eval '(require :asdf)' \
--eval '(let ((asdf:*central-registry* (list "../"))) (require :alexandria))' \
--load docstrings.lisp \
--eval '(sb-texinfo:generate-includes "include/" (list :alexandria) :base-package :alexandria)' \
--eval '(quit)'
pdf: include
texi2pdf alexandria.texinfo
html: include
makeinfo --html --no-split alexandria.texinfo
info: include
makeinfo alexandria.texinfo
| 687 | Common Lisp | .l | 20 | 32.4 | 98 | 0.707132 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 8af594c86508da7353a0638d151c2eda5846d641ea3737799ae6f26991fe3095 | 985 | [
-1
] |
986 | alexandria.texinfo | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/alexandria/doc/alexandria.texinfo | \input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename alexandria.info
@settitle Alexandria Manual
@c %**end of header
@settitle Alexandria Manual -- draft version
@c for install-info
@dircategory Software development
@direntry
* alexandria: Common Lisp utilities.
@end direntry
@copying
Alexandria software and associated documentation are in the public
domain:
@quotation
Authors dedicate this work to public domain, for the benefit of the
public at large and to the detriment of the authors' heirs and
successors. Authors intends this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights under
copyright law, whether vested or contingent, in the work. Authors
understands that such relinquishment of all rights includes the
relinquishment of all rights to enforce (by lawsuit or otherwise)
those copyrights in the work.
Authors recognize that, once placed in the public domain, the work
may be freely reproduced, distributed, transmitted, used, modified,
built upon, or otherwise exploited by anyone for any purpose,
commercial or non-commercial, and in any way, including by methods
that have not yet been invented or conceived.
@end quotation
In those legislations where public domain dedications are not
recognized or possible, Alexandria is distributed under the following
terms and conditions:
@quotation
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@end quotation
@end copying
@titlepage
@title Alexandria Manual
@subtitle draft version
@c The following two commands start the copyright page.
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
@ifnottex
@include include/ifnottex.texinfo
@node Top
@comment node-name, next, previous, up
@top Alexandria
@insertcopying
@menu
* Hash Tables::
* Data and Control Flow::
* Conses::
* Sequences::
* IO::
* Macro Writing::
* Symbols::
* Arrays::
* Types::
* Numbers::
@end menu
@end ifnottex
@node Hash Tables
@comment node-name, next, previous, up
@chapter Hash Tables
@include include/macro-alexandria-ensure-gethash.texinfo
@include include/fun-alexandria-copy-hash-table.texinfo
@include include/fun-alexandria-maphash-keys.texinfo
@include include/fun-alexandria-maphash-values.texinfo
@include include/fun-alexandria-hash-table-keys.texinfo
@include include/fun-alexandria-hash-table-values.texinfo
@include include/fun-alexandria-hash-table-alist.texinfo
@include include/fun-alexandria-hash-table-plist.texinfo
@include include/fun-alexandria-alist-hash-table.texinfo
@include include/fun-alexandria-plist-hash-table.texinfo
@node Data and Control Flow
@comment node-name, next, previous, up
@chapter Data and Control Flow
@include include/macro-alexandria-define-constant.texinfo
@include include/macro-alexandria-destructuring-case.texinfo
@include include/macro-alexandria-ensure-functionf.texinfo
@include include/macro-alexandria-multiple-value-prog2.texinfo
@include include/macro-alexandria-named-lambda.texinfo
@include include/macro-alexandria-nth-value-or.texinfo
@include include/macro-alexandria-if-let.texinfo
@include include/macro-alexandria-when-let.texinfo
@include include/macro-alexandria-when-let-star.texinfo
@include include/macro-alexandria-switch.texinfo
@include include/macro-alexandria-cswitch.texinfo
@include include/macro-alexandria-eswitch.texinfo
@include include/macro-alexandria-whichever.texinfo
@include include/macro-alexandria-xor.texinfo
@include include/fun-alexandria-disjoin.texinfo
@include include/fun-alexandria-conjoin.texinfo
@include include/fun-alexandria-compose.texinfo
@include include/fun-alexandria-ensure-function.texinfo
@include include/fun-alexandria-multiple-value-compose.texinfo
@include include/fun-alexandria-curry.texinfo
@include include/fun-alexandria-rcurry.texinfo
@node Conses
@comment node-name, next, previous, up
@chapter Conses
@include include/type-alexandria-proper-list.texinfo
@include include/type-alexandria-circular-list.texinfo
@include include/macro-alexandria-appendf.texinfo
@include include/macro-alexandria-nconcf.texinfo
@include include/macro-alexandria-remove-from-plistf.texinfo
@include include/macro-alexandria-delete-from-plistf.texinfo
@include include/macro-alexandria-reversef.texinfo
@include include/macro-alexandria-nreversef.texinfo
@include include/macro-alexandria-unionf.texinfo
@include include/macro-alexandria-nunionf.texinfo
@include include/macro-alexandria-doplist.texinfo
@include include/fun-alexandria-circular-list-p.texinfo
@include include/fun-alexandria-circular-tree-p.texinfo
@include include/fun-alexandria-proper-list-p.texinfo
@include include/fun-alexandria-alist-plist.texinfo
@include include/fun-alexandria-plist-alist.texinfo
@include include/fun-alexandria-circular-list.texinfo
@include include/fun-alexandria-make-circular-list.texinfo
@include include/fun-alexandria-ensure-car.texinfo
@include include/fun-alexandria-ensure-cons.texinfo
@include include/fun-alexandria-ensure-list.texinfo
@include include/fun-alexandria-flatten.texinfo
@include include/fun-alexandria-lastcar.texinfo
@include include/fun-alexandria-setf-lastcar.texinfo
@include include/fun-alexandria-proper-list-length.texinfo
@include include/fun-alexandria-mappend.texinfo
@include include/fun-alexandria-map-product.texinfo
@include include/fun-alexandria-remove-from-plist.texinfo
@include include/fun-alexandria-delete-from-plist.texinfo
@include include/fun-alexandria-set-equal.texinfo
@include include/fun-alexandria-setp.texinfo
@node Sequences
@comment node-name, next, previous, up
@chapter Sequences
@include include/type-alexandria-proper-sequence.texinfo
@include include/macro-alexandria-deletef.texinfo
@include include/macro-alexandria-removef.texinfo
@include include/fun-alexandria-rotate.texinfo
@include include/fun-alexandria-shuffle.texinfo
@include include/fun-alexandria-random-elt.texinfo
@include include/fun-alexandria-emptyp.texinfo
@include include/fun-alexandria-sequence-of-length-p.texinfo
@include include/fun-alexandria-length-equals.texinfo
@include include/fun-alexandria-copy-sequence.texinfo
@include include/fun-alexandria-first-elt.texinfo
@include include/fun-alexandria-setf-first-elt.texinfo
@include include/fun-alexandria-last-elt.texinfo
@include include/fun-alexandria-setf-last-elt.texinfo
@include include/fun-alexandria-starts-with.texinfo
@include include/fun-alexandria-starts-with-subseq.texinfo
@include include/fun-alexandria-ends-with.texinfo
@include include/fun-alexandria-ends-with-subseq.texinfo
@include include/fun-alexandria-map-combinations.texinfo
@include include/fun-alexandria-map-derangements.texinfo
@include include/fun-alexandria-map-permutations.texinfo
@node IO
@comment node-name, next, previous, up
@chapter IO
@include include/fun-alexandria-read-file-into-string.texinfo
@include include/fun-alexandria-read-file-into-byte-vector.texinfo
@node Macro Writing
@comment node-name, next, previous, up
@chapter Macro Writing
@include include/macro-alexandria-once-only.texinfo
@include include/macro-alexandria-with-gensyms.texinfo
@include include/macro-alexandria-with-unique-names.texinfo
@include include/fun-alexandria-featurep.texinfo
@include include/fun-alexandria-parse-body.texinfo
@include include/fun-alexandria-parse-ordinary-lambda-list.texinfo
@node Symbols
@comment node-name, next, previous, up
@chapter Symbols
@include include/fun-alexandria-ensure-symbol.texinfo
@include include/fun-alexandria-format-symbol.texinfo
@include include/fun-alexandria-make-keyword.texinfo
@include include/fun-alexandria-make-gensym.texinfo
@include include/fun-alexandria-make-gensym-list.texinfo
@include include/fun-alexandria-symbolicate.texinfo
@node Arrays
@comment node-name, next, previous, up
@chapter Arrays
@include include/type-alexandria-array-index.texinfo
@include include/type-alexandria-array-length.texinfo
@include include/fun-alexandria-copy-array.texinfo
@node Types
@comment node-name, next, previous, up
@chapter Types
@include include/type-alexandria-string-designator.texinfo
@include include/macro-alexandria-coercef.texinfo
@include include/fun-alexandria-of-type.texinfo
@include include/fun-alexandria-type-equals.texinfo
@node Numbers
@comment node-name, next, previous, up
@chapter Numbers
@include include/macro-alexandria-maxf.texinfo
@include include/macro-alexandria-minf.texinfo
@include include/fun-alexandria-binomial-coefficient.texinfo
@include include/fun-alexandria-count-permutations.texinfo
@include include/fun-alexandria-clamp.texinfo
@include include/fun-alexandria-lerp.texinfo
@include include/fun-alexandria-factorial.texinfo
@include include/fun-alexandria-subfactorial.texinfo
@include include/fun-alexandria-gaussian-random.texinfo
@include include/fun-alexandria-iota.texinfo
@include include/fun-alexandria-map-iota.texinfo
@include include/fun-alexandria-mean.texinfo
@include include/fun-alexandria-median.texinfo
@include include/fun-alexandria-variance.texinfo
@include include/fun-alexandria-standard-deviation.texinfo
@bye
| 10,000 | Common Lisp | .l | 227 | 42.603524 | 72 | 0.839075 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | cf4f1e08b32c51fbf36b78e78a45f347115ec173a2b654d106a27d165861fd31 | 986 | [
-1
] |
987 | alexandria.info | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/alexandria/doc/alexandria.info | This is alexandria.info, produced by makeinfo version 4.13 from
alexandria.texinfo.
INFO-DIR-SECTION Software development
START-INFO-DIR-ENTRY
* alexandria: Common Lisp utilities.
END-INFO-DIR-ENTRY
Alexandria software and associated documentation are in the public
domain:
Authors dedicate this work to public domain, for the benefit of
the public at large and to the detriment of the authors' heirs
and successors. Authors intends this dedication to be an overt
act of relinquishment in perpetuity of all present and future
rights under copyright law, whether vested or contingent, in the
work. Authors understands that such relinquishment of all rights
includes the relinquishment of all rights to enforce (by lawsuit
or otherwise) those copyrights in the work.
Authors recognize that, once placed in the public domain, the work
may be freely reproduced, distributed, transmitted, used,
modified, built upon, or otherwise exploited by anyone for any
purpose, commercial or non-commercial, and in any way, including
by methods that have not yet been invented or conceived.
In those legislations where public domain dedications are not
recognized or possible, Alexandria is distributed under the following
terms and conditions:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
File: alexandria.info, Node: Top, Next: Hash Tables, Up: (dir)
Alexandria
**********
Alexandria software and associated documentation are in the public
domain:
Authors dedicate this work to public domain, for the benefit of
the public at large and to the detriment of the authors' heirs
and successors. Authors intends this dedication to be an overt
act of relinquishment in perpetuity of all present and future
rights under copyright law, whether vested or contingent, in the
work. Authors understands that such relinquishment of all rights
includes the relinquishment of all rights to enforce (by lawsuit
or otherwise) those copyrights in the work.
Authors recognize that, once placed in the public domain, the work
may be freely reproduced, distributed, transmitted, used,
modified, built upon, or otherwise exploited by anyone for any
purpose, commercial or non-commercial, and in any way, including
by methods that have not yet been invented or conceived.
In those legislations where public domain dedications are not
recognized or possible, Alexandria is distributed under the following
terms and conditions:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
* Menu:
* Hash Tables::
* Data and Control Flow::
* Conses::
* Sequences::
* IO::
* Macro Writing::
* Symbols::
* Arrays::
* Types::
* Numbers::
File: alexandria.info, Node: Hash Tables, Next: Data and Control Flow, Prev: Top, Up: Top
1 Hash Tables
*************
-- Macro: ensure-gethash key hash-table &optional default
Like `gethash', but if `key' is not found in the `hash-table'
saves the `default' under key before returning it. Secondary
return value is true if key was already in the table.
-- Function: copy-hash-table table &key key test size rehash-size
rehash-threshold
Returns a copy of hash table `table', with the same keys and values
as the `table'. The copy has the same properties as the original,
unless overridden by the keyword arguments.
Before each of the original values is set into the new hash-table,
`key' is invoked on the value. As `key' defaults to `cl:identity',
a shallow copy is returned by default.
-- Function: maphash-keys function table
Like `maphash', but calls `function' with each key in the hash
table `table'.
-- Function: maphash-values function table
Like `maphash', but calls `function' with each value in the hash
table `table'.
-- Function: hash-table-keys table
Returns a list containing the keys of hash table `table'.
-- Function: hash-table-values table
Returns a list containing the values of hash table `table'.
-- Function: hash-table-alist table
Returns an association list containing the keys and values of hash
table `table'.
-- Function: hash-table-plist table
Returns a property list containing the keys and values of hash
table `table'.
-- Function: alist-hash-table alist &rest hash-table-initargs
Returns a hash table containing the keys and values of the
association list `alist'. Hash table is initialized using the
`hash-table-initargs'.
-- Function: plist-hash-table plist &rest hash-table-initargs
Returns a hash table containing the keys and values of the
property list `plist'. Hash table is initialized using the
`hash-table-initargs'.
File: alexandria.info, Node: Data and Control Flow, Next: Conses, Prev: Hash Tables, Up: Top
2 Data and Control Flow
***********************
-- Macro: define-constant name initial-value &key test documentation
Ensures that the global variable named by `name' is a constant
with a value that is equal under `test' to the result of
evaluating `initial-value'. `test' is a /function designator/ that
defaults to `eql'. If `documentation' is given, it becomes the
documentation string of the constant.
Signals an error if `name' is already a bound non-constant
variable.
Signals an error if `name' is already a constant variable whose
value is not equal under `test' to result of evaluating
`initial-value'.
-- Macro: destructuring-case keyform &body clauses
`destructuring-case', `-ccase', and `-ecase' are a combination of
`case' and `destructuring-bind'. `keyform' must evaluate to a
`cons'.
Clauses are of the form:
((CASE-KEYS . DESTRUCTURING-LAMBDA-LIST) FORM*)
The clause whose `case-keys' matches `car' of `key', as if by
`case', `ccase', or `ecase', is selected, and FORMs are then
executed with `cdr' of `key' is destructured and bound by the
`destructuring-lambda-list'.
Example:
(defun dcase (x)
(destructuring-case x
((:foo a b)
(format nil "foo: ~S, ~S" a b))
((:bar &key a b)
(format nil "bar, ~S, ~S" a b))
(((:alt1 :alt2) a)
(format nil "alt: ~S" a))
((t &rest rest)
(format nil "unknown: ~S" rest))))
(dcase (list :foo 1 2)) ; => "foo: 1, 2"
(dcase (list :bar :a 1 :b 2)) ; => "bar: 1, 2"
(dcase (list :alt1 1)) ; => "alt: 1"
(dcase (list :alt2 2)) ; => "alt: 2"
(dcase (list :quux 1 2 3)) ; => "unknown: 1, 2, 3"
(defun decase (x)
(destructuring-case x
((:foo a b)
(format nil "foo: ~S, ~S" a b))
((:bar &key a b)
(format nil "bar, ~S, ~S" a b))
(((:alt1 :alt2) a)
(format nil "alt: ~S" a))))
(decase (list :foo 1 2)) ; => "foo: 1, 2"
(decase (list :bar :a 1 :b 2)) ; => "bar: 1, 2"
(decase (list :alt1 1)) ; => "alt: 1"
(decase (list :alt2 2)) ; => "alt: 2"
(decase (list :quux 1 2 3)) ; =| error
-- Macro: ensure-functionf &rest places
Multiple-place modify macro for `ensure-function:' ensures that
each of `places' contains a function.
-- Macro: multiple-value-prog2 first-form second-form &body forms
Evaluates `first-form', then `second-form', and then `forms'.
Yields as its value all the value returned by `second-form'.
-- Macro: named-lambda name lambda-list &body body
Expands into a lambda-expression within whose `body' `name'
denotes the corresponding function.
-- Macro: nth-value-or nth-value &body forms
Evaluates `form' arguments one at a time, until the `nth-value'
returned by one of the forms is true. It then returns all the
values returned by evaluating that form. If none of the forms
return a true nth value, this form returns `nil'.
-- Macro: if-let bindings &body (then-form &optional else-form)
Creates new variable bindings, and conditionally executes either
`then-form' or `else-form'. `else-form' defaults to `nil'.
`bindings' must be either single binding of the form:
(variable initial-form)
or a list of bindings of the form:
((variable-1 initial-form-1)
(variable-2 initial-form-2)
...
(variable-n initial-form-n))
All initial-forms are executed sequentially in the specified
order. Then all the variables are bound to the corresponding
values.
If all variables were bound to true values, the `then-form' is
executed with the bindings in effect, otherwise the `else-form' is
executed with the bindings in effect.
-- Macro: when-let bindings &body forms
Creates new variable bindings, and conditionally executes `forms'.
`bindings' must be either single binding of the form:
(variable initial-form)
or a list of bindings of the form:
((variable-1 initial-form-1)
(variable-2 initial-form-2)
...
(variable-n initial-form-n))
All initial-forms are executed sequentially in the specified
order. Then all the variables are bound to the corresponding
values.
If all variables were bound to true values, then `forms' are
executed as an implicit `progn'.
-- Macro: when-let* bindings &body forms
Creates new variable bindings, and conditionally executes `forms'.
`bindings' must be either single binding of the form:
(variable initial-form)
or a list of bindings of the form:
((variable-1 initial-form-1)
(variable-2 initial-form-2)
...
(variable-n initial-form-n))
Each initial-form is executed in turn, and the variable bound to
the corresponding value. Initial-form expressions can refer to
variables previously bound by the `when-let*'.
Execution of `when-let*' stops immediately if any initial-form
evaluates to `nil'. If all initial-forms evaluate to true, then
`forms' are executed as an implicit `progn'.
-- Macro: switch whole (object &key test key) &body clauses
Evaluates first matching clause, returning its values, or
evaluates and returns the values of `default' if no keys match.
-- Macro: cswitch whole (object &key test key) &body clauses
Like `switch', but signals a continuable error if no key matches.
-- Macro: eswitch whole (object &key test key) &body clauses
Like `switch', but signals an error if no key matches.
-- Macro: whichever &rest possibilities env
Evaluates exactly one of `possibilities', chosen at random.
-- Macro: xor &rest datums
Evaluates its arguments one at a time, from left to right. If more
then one argument evaluates to a true value no further `datums'
are evaluated, and `nil' is returned as both primary and secondary
value. If exactly one argument evaluates to true, its value is
returned as the primary value after all the arguments have been
evaluated, and `t' is returned as the secondary value. If no
arguments evaluate to true `nil' is retuned as primary, and `t' as
secondary value.
-- Function: disjoin predicate &rest more-predicates
Returns a function that applies each of `predicate' and
`more-predicate' functions in turn to its arguments, returning the
primary value of the first predicate that returns true, without
calling the remaining predicates. If none of the predicates
returns true, `nil' is returned.
-- Function: conjoin predicate &rest more-predicates
Returns a function that applies each of `predicate' and
`more-predicate' functions in turn to its arguments, returning
`nil' if any of the predicates returns false, without calling the
remaining predicates. If none of the predicates returns false,
returns the primary value of the last predicate.
-- Function: compose function &rest more-functions
Returns a function composed of `function' and `more-functions'
that applies its arguments to to each in turn, starting from the
rightmost of `more-functions', and then calling the next one with
the primary value of the last.
-- Function: ensure-function function-designator
Returns the function designated by `function-designator:' if
`function-designator' is a function, it is returned, otherwise it
must be a function name and its `fdefinition' is returned.
-- Function: multiple-value-compose function &rest more-functions
Returns a function composed of `function' and `more-functions'
that applies its arguments to each in turn, starting from the
rightmost of `more-functions', and then calling the next one with
all the return values of the last.
-- Function: curry function &rest arguments
Returns a function that applies `arguments' and the arguments it
is called with to `function'.
-- Function: rcurry function &rest arguments
Returns a function that applies the arguments it is called with
and `arguments' to `function'.
File: alexandria.info, Node: Conses, Next: Sequences, Prev: Data and Control Flow, Up: Top
3 Conses
********
-- Type: proper-list
Type designator for proper lists. Implemented as a `satisfies'
type, hence not recommended for performance intensive use. Main
usefullness as a type designator of the expected type in a
`type-error'.
-- Type: circular-list
Type designator for circular lists. Implemented as a `satisfies'
type, so not recommended for performance intensive use. Main
usefullness as the expected-type designator of a `type-error'.
-- Macro: appendf place &rest lists env
Modify-macro for `append'. Appends `lists' to the place designated
by the first argument.
-- Macro: nconcf place &rest lists env
Modify-macro for `nconc'. Concatenates `lists' to place designated
by the first argument.
-- Macro: remove-from-plistf place &rest keys env
Modify macro for `remove-from-plist'.
-- Macro: delete-from-plistf place &rest keys env
Modify macro for `delete-from-plist'.
-- Macro: reversef place env
Modify-macro for `reverse'. Copies and reverses the list stored in
the given place and saves back the result into the place.
-- Macro: nreversef place env
Modify-macro for `nreverse'. Reverses the list stored in the given
place by destructively modifying it and saves back the result into
the place.
-- Macro: unionf place list &rest args env
Modify-macro for `union'. Saves the union of `list' and the
contents of the place designated by the first argument to the
designated place.
-- Macro: nunionf place list &rest args env
Modify-macro for `nunion'. Saves the union of `list' and the
contents of the place designated by the first argument to the
designated place. May modify either argument.
-- Macro: doplist (key val plist &optional values) &body body
Iterates over elements of `plist'. `body' can be preceded by
declarations, and is like a `tagbody'. `return' may be used to
terminate the iteration early. If `return' is not used, returns
`values'.
-- Function: circular-list-p object
Returns true if `object' is a circular list, `nil' otherwise.
-- Function: circular-tree-p object
Returns true if `object' is a circular tree, `nil' otherwise.
-- Function: proper-list-p object
Returns true if `object' is a proper list.
-- Function: alist-plist alist
Returns a property list containing the same keys and values as the
association list `alist' in the same order.
-- Function: plist-alist plist
Returns an association list containing the same keys and values as
the property list `plist' in the same order.
-- Function: circular-list &rest elements
Creates a circular list of `elements'.
-- Function: make-circular-list length &key initial-element
Creates a circular list of `length' with the given
`initial-element'.
-- Function: ensure-car thing
If `thing' is a `cons', its `car' is returned. Otherwise `thing'
is returned.
-- Function: ensure-cons cons
If `cons' is a cons, it is returned. Otherwise returns a fresh
cons with `cons' in the car, and `nil' in the cdr.
-- Function: ensure-list list
If `list' is a list, it is returned. Otherwise returns the list
designated by `list'.
-- Function: flatten tree
Traverses the tree in order, collecting non-null leaves into a
list.
-- Function: lastcar list
Returns the last element of `list'. Signals a type-error if `list'
is not a proper list.
-- Function: (setf lastcar)
Sets the last element of `list'. Signals a type-error if `list' is
not a proper list.
-- Function: proper-list-length list
Returns length of `list', signalling an error if it is not a
proper list.
-- Function: mappend function &rest lists
Applies `function' to respective element(s) of each `list',
appending all the all the result list to a single list. `function'
must return a list.
-- Function: map-product function list &rest more-lists
Returns a list containing the results of calling `function' with
one argument from `list', and one from each of `more-lists' for
each combination of arguments. In other words, returns the
product of `list' and `more-lists' using `function'.
Example:
(map-product 'list '(1 2) '(3 4) '(5 6))
=> ((1 3 5) (1 3 6) (1 4 5) (1 4 6)
(2 3 5) (2 3 6) (2 4 5) (2 4 6))
-- Function: remove-from-plist plist &rest keys
Returns a propery-list with same keys and values as `plist',
except that keys in the list designated by `keys' and values
corresponding to them are removed. The returned property-list may
share structure with the `plist', but `plist' is not destructively
modified. Keys are compared using `eq'.
-- Function: delete-from-plist plist &rest keys
Just like `remove-from-plist', but this version may destructively
modify the provided plist.
-- Function: set-equal list1 list2 &key test key
Returns true if every element of `list1' matches some element of
`list2' and every element of `list2' matches some element of
`list1'. Otherwise returns false.
-- Function: setp object &key test key
Returns true if `object' is a list that denotes a set, `nil'
otherwise. A list denotes a set if each element of the list is
unique under `key' and `test'.
File: alexandria.info, Node: Sequences, Next: IO, Prev: Conses, Up: Top
4 Sequences
***********
-- Type: proper-sequence
Type designator for proper sequences, that is proper lists and
sequences that are not lists.
-- Macro: deletef place item &rest remove-keywords env
Modify-macro for `delete'. Sets place designated by the first
argument to the result of calling `delete' with `item', place, and
the `remove-keywords'.
-- Macro: removef place item &rest remove-keywords env
Modify-macro for `remove'. Sets place designated by the first
argument to the result of calling `remove' with `item', place, and
the `remove-keywords'.
-- Function: rotate sequence &optional n
Returns a sequence of the same type as `sequence', with the
elements of `sequence' rotated by `n:' `n' elements are moved from
the end of the sequence to the front if `n' is positive, and `-n'
elements moved from the front to the end if `n' is negative.
`sequence' must be a proper sequence. `n' must be an integer,
defaulting to `1'.
If absolute value of `n' is greater then the length of the
sequence, the results are identical to calling `rotate' with
(* (signum n) (mod n (length sequence))).
Note: the original sequence may be destructively altered, and
result sequence may share structure with it.
-- Function: shuffle sequence &key start end
Returns a random permutation of `sequence' bounded by `start' and
`end'. Original sequece may be destructively modified, and share
storage with the original one. Signals an error if `sequence' is
not a proper sequence.
-- Function: random-elt sequence &key start end
Returns a random element from `sequence' bounded by `start' and
`end'. Signals an error if the `sequence' is not a proper
non-empty sequence, or if `end' and `start' are not proper
bounding index designators for `sequence'.
-- Function: emptyp sequence
Returns true if `sequence' is an empty sequence. Signals an error
if `sequence' is not a sequence.
-- Function: sequence-of-length-p sequence length
Return true if `sequence' is a sequence of length `length'.
Signals an error if `sequence' is not a sequence. Returns `false'
for circular lists.
-- Function: length= &rest sequences
Takes any number of sequences or integers in any order. Returns
true iff the length of all the sequences and the integers are
equal. Hint: there's a compiler macro that expands into more
efficient code if the first argument is a literal integer.
-- Function: copy-sequence type sequence
Returns a fresh sequence of `type', which has the same elements as
`sequence'.
-- Function: first-elt sequence
Returns the first element of `sequence'. Signals a type-error if
`sequence' is not a sequence, or is an empty sequence.
-- Function: (setf first-elt)
Sets the first element of `sequence'. Signals a type-error if
`sequence' is not a sequence, is an empty sequence, or if `object'
cannot be stored in `sequence'.
-- Function: last-elt sequence
Returns the last element of `sequence'. Signals a type-error if
`sequence' is not a proper sequence, or is an empty sequence.
-- Function: (setf last-elt)
Sets the last element of `sequence'. Signals a type-error if
`sequence' is not a proper sequence, is an empty sequence, or if
`object' cannot be stored in `sequence'.
-- Function: starts-with object sequence &key test key
Returns true if `sequence' is a sequence whose first element is
`eql' to `object'. Returns `nil' if the `sequence' is not a
sequence or is an empty sequence.
-- Function: starts-with-subseq prefix sequence &rest args &key
return-suffix &allow-other-keys
Test whether the first elements of `sequence' are the same (as per
TEST) as the elements of `prefix'.
If `return-suffix' is `t' the functions returns, as a second
value, a displaced array pointing to the sequence after `prefix'.
-- Function: ends-with object sequence &key test key
Returns true if `sequence' is a sequence whose last element is
`eql' to `object'. Returns `nil' if the `sequence' is not a
sequence or is an empty sequence. Signals an error if `sequence'
is an improper list.
-- Function: ends-with-subseq suffix sequence &key test
Test whether `sequence' ends with `suffix'. In other words: return
true if the last (length SUFFIX) elements of `sequence' are equal
to `suffix'.
-- Function: map-combinations function sequence &key start end length
copy
Calls `function' with each combination of `length' constructable
from the elements of the subsequence of `sequence' delimited by
`start' and `end'. `start' defaults to `0', `end' to length of
`sequence', and `length' to the length of the delimited
subsequence. (So unless `length' is specified there is only a
single combination, which has the same elements as the delimited
subsequence.) If `copy' is true (the default) each combination is
freshly allocated. If `copy' is false all combinations are `eq' to
each other, in which case consequences are specified if a
combination is modified by `function'.
-- Function: map-derangements function sequence &key start end copy
Calls `function' with each derangement of the subsequence of
`sequence' denoted by the bounding index designators `start' and
`end'. Derangement is a permutation of the sequence where no
element remains in place. `sequence' is not modified, but
individual derangements are `eq' to each other. Consequences are
unspecified if calling `function' modifies either the derangement
or `sequence'.
-- Function: map-permutations function sequence &key start end length
copy
Calls function with each permutation of `length' constructable
from the subsequence of `sequence' delimited by `start' and `end'.
`start' defaults to `0', `end' to length of the sequence, and
`length' to the length of the delimited subsequence.
File: alexandria.info, Node: IO, Next: Macro Writing, Prev: Sequences, Up: Top
5 IO
****
-- Function: read-file-into-string pathname &key buffer-size
external-format
Return the contents of the file denoted by `pathname' as a fresh
string.
The `external-format' parameter will be passed directly to
`with-open-file' unless it's `nil', which means the system default.
-- Function: read-file-into-byte-vector pathname
Read `pathname' into a freshly allocated (unsigned-byte 8) vector.
File: alexandria.info, Node: Macro Writing, Next: Symbols, Prev: IO, Up: Top
6 Macro Writing
***************
-- Macro: once-only specs &body forms
Evaluates `forms' with symbols specified in `specs' rebound to
temporary variables, ensuring that each initform is evaluated only
once.
Each of `specs' must either be a symbol naming the variable to be
rebound, or of the form:
(symbol initform)
Bare symbols in `specs' are equivalent to
(symbol symbol)
Example:
(defmacro cons1 (x) (once-only (x) `(cons ,x ,x)))
(let ((y 0)) (cons1 (incf y))) => (1 . 1)
-- Macro: with-gensyms names &body forms
Binds each variable named by a symbol in `names' to a unique
symbol around `forms'. Each of `names' must either be either a
symbol, or of the form:
(symbol string-designator)
Bare symbols appearing in `names' are equivalent to:
(symbol symbol)
The string-designator is used as the argument to `gensym' when
constructing the unique symbol the named variable will be bound to.
-- Macro: with-unique-names names &body forms
Alias for `with-gensyms'.
-- Function: featurep feature-expression
Returns `t' if the argument matches the state of the `*features*'
list and `nil' if it does not. `feature-expression' can be any atom
or list acceptable to the reader macros `#+' and `#-'.
-- Function: parse-body body &key documentation whole
Parses `body' into (values remaining-forms declarations
doc-string). Documentation strings are recognized only if
`documentation' is true. Syntax errors in body are signalled and
`whole' is used in the signal arguments when given.
-- Function: parse-ordinary-lambda-list lambda-list &key normalize
allow-specializers normalize-optional normalize-keyword
normalize-auxilary
Parses an ordinary lambda-list, returning as multiple values:
`1'. Required parameters.
`2'. Optional parameter specifications, normalized into form:
(name init suppliedp)
`3'. Name of the rest parameter, or `nil'.
`4'. Keyword parameter specifications, normalized into form:
((keyword-name name) init suppliedp)
`5'. Boolean indicating `&allow-other-keys' presence.
`6'. `&aux' parameter specifications, normalized into form
(name init).
`7'. Existence of `&key' in the lambda-list.
Signals a `program-error' is the lambda-list is malformed.
File: alexandria.info, Node: Symbols, Next: Arrays, Prev: Macro Writing, Up: Top
7 Symbols
*********
-- Function: ensure-symbol name &optional package
Returns a symbol with name designated by `name', accessible in
package designated by `package'. If symbol is not already
accessible in `package', it is interned there. Returns a secondary
value reflecting the status of the symbol in the package, which
matches the secondary return value of `intern'.
Example:
(ensure-symbol :cons :cl) => cl:cons, :external
-- Function: format-symbol package control &rest arguments
Constructs a string by applying `arguments' to string designator
`control' as if by `format' within `with-standard-io-syntax', and
then creates a symbol named by that string.
If `package' is `nil', returns an uninterned symbol, if package is
`t', returns a symbol interned in the current package, and
otherwise returns a symbol interned in the package designated by
`package'.
-- Function: make-keyword name
Interns the string designated by `name' in the `keyword' package.
-- Function: make-gensym name
If `name' is a non-negative integer, calls `gensym' using it.
Otherwise `name' must be a string designator, in which case calls
`gensym' using the designated string as the argument.
-- Function: make-gensym-list length &optional x
Returns a list of `length' gensyms, each generated as if with a
call to `make-gensym', using the second (optional, defaulting to
"G") argument.
-- Function: symbolicate &rest things
Concatenate together the names of some strings and symbols,
producing a symbol in the current package.
File: alexandria.info, Node: Arrays, Next: Types, Prev: Symbols, Up: Top
8 Arrays
********
-- Type: array-index
Type designator for an index into array of `length:' an integer
between `0' (inclusive) and `length' (exclusive). `length'
defaults to `array-dimension-limit'.
-- Type: array-length
Type designator for a dimension of an array of `length:' an
integer between `0' (inclusive) and `length' (inclusive). `length'
defaults to `array-dimension-limit'.
-- Function: copy-array array &key element-type fill-pointer adjustable
Returns an undisplaced copy of `array', with same fill-pointer and
adjustability (if any) as the original, unless overridden by the
keyword arguments.
File: alexandria.info, Node: Types, Next: Numbers, Prev: Arrays, Up: Top
9 Types
*******
-- Type: string-designator
A string designator type. A string designator is either a string,
a symbol, or a character.
-- Macro: coercef place type-spec env
Modify-macro for `coerce'.
-- Function: of-type type
Returns a function of one argument, which returns true when its
argument is of `type'.
-- Function: type= type1 type2
Returns a primary value of `t' is `type1' and `type2' are the same
type, and a secondary value that is true is the type equality
could be reliably determined: primary value of `nil' and secondary
value of `t' indicates that the types are not equivalent.
File: alexandria.info, Node: Numbers, Prev: Types, Up: Top
10 Numbers
**********
-- Macro: maxf place &rest numbers env
Modify-macro for `max'. Sets place designated by the first
argument to the maximum of its original value and `numbers'.
-- Macro: minf place &rest numbers env
Modify-macro for `min'. Sets place designated by the first
argument to the minimum of its original value and `numbers'.
-- Function: binomial-coefficient n k
Binomial coefficient of `n' and `k', also expressed as `n' choose
`k'. This is the number of `k' element combinations given `n'
choises. `n' must be equal to or greater then `k'.
-- Function: count-permutations n &optional k
Number of `k' element permutations for a sequence of `n' objects.
`k' defaults to `n'
-- Function: clamp number min max
Clamps the `number' into [min, max] range. Returns `min' if
`number' is lesser then `min' and `max' if `number' is greater
then `max', otherwise returns `number'.
-- Function: lerp v a b
Returns the result of linear interpolation between A and `b',
using the interpolation coefficient `v'.
-- Function: factorial n
Factorial of non-negative integer `n'.
-- Function: subfactorial n
Subfactorial of the non-negative integer `n'.
-- Function: gaussian-random &optional min max
Returns two gaussian random double floats as the primary and
secondary value, optionally constrained by `min' and `max'.
Gaussian random numbers form a standard normal distribution around
`0'.0d0.
Sufficiently positive `min' or negative `max' will cause the
algorithm used to take a very long time. If `min' is positive it
should be close to zero, and similarly if `max' is negative it
should be close to zero.
-- Function: iota n &key start step
Return a list of n numbers, starting from `start' (with numeric
contagion from `step' applied), each consequtive number being the
sum of the previous one and `step'. `start' defaults to `0' and
`step' to `1'.
Examples:
(iota 4) => (0 1 2 3)
(iota 3 :start 1 :step 1.0) => (1.0 2.0 3.0)
(iota 3 :start -1 :step -1/2) => (-1 -3/2 -2)
-- Function: map-iota function n &key start step
Calls `function' with `n' numbers, starting from `start' (with
numeric contagion from `step' applied), each consequtive number
being the sum of the previous one and `step'. `start' defaults to
`0' and `step' to `1'. Returns `n'.
Examples:
(map-iota #'print 3 :start 1 :step 1.0) => 3
;;; 1.0
;;; 2.0
;;; 3.0
-- Function: mean sample
Returns the mean of `sample'. `sample' must be a sequence of
numbers.
-- Function: median sample
Returns median of `sample'. `sample' must be a sequence of real
numbers.
-- Function: variance sample &key biased
Variance of `sample'. Returns the biased variance if `biased' is
true (the default), and the unbiased estimator of variance if
`biased' is false. `sample' must be a sequence of numbers.
-- Function: standard-deviation sample &key biased
Standard deviation of `sample'. Returns the biased standard
deviation if `biased' is true (the default), and the square root
of the unbiased estimator for variance if `biased' is false (which
is not the same as the unbiased estimator for standard deviation).
`sample' must be a sequence of numbers.
Tag Table:
Node: Top2337
Node: Hash Tables4699
Ref: Macro ensure-gethash4825
Ref: Function copy-hash-table5077
Ref: Function maphash-keys5554
Ref: Function maphash-values5685
Ref: Function hash-table-keys5820
Ref: Function hash-table-values5920
Ref: Function hash-table-alist6024
Ref: Function hash-table-plist6154
Ref: Function alist-hash-table6280
Ref: Function plist-hash-table6503
Node: Data and Control Flow6723
Ref: Macro define-constant6872
Ref: Macro destructuring-case7489
Ref: Macro ensure-functionf9307
Ref: Macro multiple-value-prog29461
Ref: Macro named-lambda9662
Ref: Macro nth-value-or9821
Ref: Macro if-let10126
Ref: Macro when-let10931
Ref: Macro when-let*11571
Ref: Macro switch12341
Ref: Macro cswitch12535
Ref: Macro eswitch12669
Ref: Macro whichever12792
Ref: Macro xor12903
Ref: Function disjoin13442
Ref: Function conjoin13803
Ref: Function compose14180
Ref: Function ensure-function14478
Ref: Function multiple-value-compose14730
Ref: Function curry15044
Ref: Function rcurry15195
Node: Conses15347
Ref: Type proper-list15464
Ref: Type circular-list15707
Ref: Macro appendf15936
Ref: Macro nconcf16078
Ref: Macro remove-from-plistf16219
Ref: Macro delete-from-plistf16314
Ref: Macro reversef16409
Ref: Macro nreversef16575
Ref: Macro unionf16767
Ref: Macro nunionf16967
Ref: Macro doplist17197
Ref: Function circular-list-p17479
Ref: Function circular-tree-p17584
Ref: Function proper-list-p17689
Ref: Function alist-plist17773
Ref: Function plist-alist17927
Ref: Function circular-list18082
Ref: Function make-circular-list18170
Ref: Function ensure-car18312
Ref: Function ensure-cons18432
Ref: Function ensure-list18590
Ref: Function flatten18718
Ref: Function lastcar18825
Ref: Function (setf lastcar)18952
Ref: Function proper-list-length19078
Ref: Function mappend19201
Ref: Function map-product19407
Ref: Function remove-from-plist19892
Ref: Function delete-from-plist20263
Ref: Function set-equal20416
Ref: Function setp20642
Node: Sequences20853
Ref: Type proper-sequence20957
Ref: Macro deletef21087
Ref: Macro removef21311
Ref: Function rotate21535
Ref: Function shuffle22247
Ref: Function random-elt22534
Ref: Function emptyp22828
Ref: Function sequence-of-length-p22968
Ref: Function length=23181
Ref: Function copy-sequence23486
Ref: Function first-elt23618
Ref: Function (setf first-elt)23782
Ref: Function last-elt23990
Ref: Function (setf last-elt)24159
Ref: Function starts-with24372
Ref: Function starts-with-subseq24603
Ref: Function ends-with24961
Ref: Function ends-with-subseq25246
Ref: Function map-combinations25465
Ref: Function map-derangements26207
Ref: Function map-permutations26703
Node: IO27055
Ref: Function read-file-into-string27152
Ref: Function read-file-into-byte-vector27462
Node: Macro Writing27585
Ref: Macro once-only27702
Ref: Macro with-gensyms28236
Ref: Macro with-unique-names28710
Ref: Function featurep28789
Ref: Function parse-body29036
Ref: Function parse-ordinary-lambda-list29345
Node: Symbols30147
Ref: Function ensure-symbol30256
Ref: Function format-symbol30709
Ref: Function make-keyword31183
Ref: Function make-gensym31287
Ref: Function make-gensym-list31516
Ref: Function symbolicate31726
Node: Arrays31879
Ref: Type array-index31978
Ref: Type array-length32176
Ref: Function copy-array32379
Node: Types32619
Ref: Type string-designator32716
Ref: Macro coercef32847
Ref: Function of-type32919
Ref: Function type=33044
Node: Numbers33351
Ref: Macro maxf33439
Ref: Macro minf33610
Ref: Function binomial-coefficient33781
Ref: Function count-permutations34015
Ref: Function clamp34159
Ref: Function lerp34373
Ref: Function factorial34512
Ref: Function subfactorial34583
Ref: Function gaussian-random34664
Ref: Function iota35165
Ref: Function map-iota35621
Ref: Function mean36061
Ref: Function median36168
Ref: Function variance36280
Ref: Function standard-deviation36524
End Tag Table
| 40,902 | Common Lisp | .l | 836 | 43.671053 | 96 | 0.713238 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | db32f1a87ce8fb02aa719ab2c6ae3c97112eae9b57cf059aa6a619bcdf3542fc | 987 | [
-1
] |
990 | Makefile | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/Makefile | # -*- Mode: Makefile; tab-width: 3; indent-tabs-mode: t -*-
#
# Makefile --- Make targets for various tasks.
#
# Copyright (C) 2005-2006, James Bielman <[email protected]>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use, copy,
# modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# This way you can easily run the tests for different versions
# of each lisp with, e.g. ALLEGRO=/path/to/some/lisp make test-allegro
CMUCL ?= lisp
OPENMCL ?= openmcl
SBCL ?= sbcl
CLISP ?= clisp
ALLEGRO ?= alisp
SCL ?= scl
shlibs:
@$(MAKE) -wC tests shlibs
clean:
@$(MAKE) -wC tests clean
find . -name ".fasls" | xargs rm -rf
find . \( -name "*.dfsl" -o -name "*.fasl" -o -name "*.fas" -o -name "*.lib" -o -name "*.x86f" -o -name "*.amd64f" -o -name "*.sparcf" -o -name "*.sparc64f" -o -name "*.hpf" -o -name "*.hp64f" -o -name "*.ppcf" -o -name "*.nfasl" -o -name "*.ufsl" -o -name "*.fsl" -o -name "*.lx64fsl" \) -exec rm {} \;
test-openmcl:
@-$(OPENMCL) --load tests/run-tests.lisp
test-sbcl:
@-$(SBCL) --noinform --load tests/run-tests.lisp
test-cmucl:
@-$(CMUCL) -load tests/run-tests.lisp
test-scl:
@-$(SCL) -load tests/run-tests.lisp
test-clisp:
@-$(CLISP) -q -x '(load "tests/run-tests.lisp")'
test-clisp-modern:
@-$(CLISP) -modern -q -x '(load "tests/run-tests.lisp")'
test-allegro:
@-$(ALLEGRO) -L tests/run-tests.lisp
test: test-openmcl test-sbcl test-cmucl test-clisp
# vim: ft=make ts=3 noet
| 2,384 | Common Lisp | .l | 56 | 41.160714 | 304 | 0.711572 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 3cc00372c105b26c1ca569663d9d1b729bbe6d08ce80fb5c1996ad23e3516c35 | 990 | [
-1
] |
1,032 | compile.bat | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/tests/compile.bat | rem
rem script for compiling the test lib with the free MSVC++ toolkit.
rem
cl /LD /DWIN32=1 /Tc libtest.c
del libtest.obj libtest.exp
cl /LD /DWIN32=1 /Tc libtest2.c
del libtest2.obj libtest2.exp
| 208 | Common Lisp | .l | 7 | 27.142857 | 68 | 0.761421 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 9ae11738f8f36f7eb25d5a996cd88660afc99f702979c5d9f481abb3e746d714 | 1,032 | [
-1
] |
1,033 | GNUmakefile | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/tests/GNUmakefile | # -*- Mode: Makefile; tab-width: 3; indent-tabs-mode: t -*-
#
# Makefile --- Make targets for various tasks.
#
# Copyright (C) 2005, James Bielman <[email protected]>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use, copy,
# modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
OSTYPE = $(shell uname)
ARCH = $(shell uname -m)
CC := gcc
CFLAGS := -Wall -std=c99 -pedantic
SHLIB_CFLAGS := -shared
SHLIB_EXT := .so
ifneq ($(if $(filter Linux %BSD,$(OSTYPE)),OK), OK)
ifeq ($(OSTYPE), Darwin)
SHLIB_CFLAGS := -dynamiclib
SHLIB_EXT := .dylib
ifeq ($(shell sysctl -n hw.optional.x86_64), 1)
ARCH := x86_64
CFLAGS_64 := -m64
endif
else
ifeq ($(OSTYPE), SunOS)
CFLAGS := -m64 -fPIC -c -Wall -std=c99 -pedantic
else
# Let's assume this is win32
SHLIB_EXT := .dll
endif
endif
endif
ifneq ($(ARCH), x86_64)
CFLAGS += -lm
endif
ifeq ($(ARCH), x86_64)
CFLAGS_64 += -fPIC
endif
# Are all G5s ppc970s?
ifeq ($(ARCH), ppc970)
CFLAGS_64 += -m64
endif
SHLIBS = libtest$(SHLIB_EXT) libtest2$(SHLIB_EXT) libfsbv$(SHLIB_EXT)
ifeq ($(ARCH), x86_64)
SHLIBS += libtest32$(SHLIB_EXT) libtest2_32$(SHLIB_EXT) libfsbv_32$(SHLIB_EXT)
endif
shlibs: $(SHLIBS)
libtest$(SHLIB_EXT): libtest.c
$(CC) -o $@ $(SHLIB_CFLAGS) $(CFLAGS) $(CFLAGS_64) $<
libtest2$(SHLIB_EXT): libtest2.c
$(CC) -o $@ $(SHLIB_CFLAGS) $(CFLAGS) $(CFLAGS_64) $<
libfsbv$(SHLIB_EXT): libfsbv.c
$(CC) -o $@ $(SHLIB_CFLAGS) $(CFLAGS) $(CFLAGS_64) $<
ifeq ($(ARCH), x86_64)
libtest32$(SHLIB_EXT): libtest.c
-$(CC) -m32 -o $@ $(SHLIB_CFLAGS) $(CFLAGS) $<
libtest2_32$(SHLIB_EXT): libtest2.c
-$(CC) -m32 -o $@ $(SHLIB_CFLAGS) $(CFLAGS) $<
libfsbv_32$(SHLIB_EXT): libfsbv.c
-$(CC) -m32 -o $@ $(SHLIB_CFLAGS) $(CFLAGS) $<
endif
clean:
rm -f *.so *.dylib *.dll *.bundle
# vim: ft=make ts=3 noet
| 2,771 | Common Lisp | .l | 81 | 32.91358 | 78 | 0.69884 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | eaf4dfa1d2d3bd48dd9c7ea5e2a073bd60df446a0c295558e0cbdac6b2eee8db | 1,033 | [
-1
] |
1,038 | cffi-manual.texinfo | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/doc/cffi-manual.texinfo | \input texinfo @c -*- Mode: Texinfo; Mode: auto-fill -*-
@c %**start of header
@setfilename cffi.info
@settitle CFFI User Manual
@exampleindent 2
@c @documentencoding utf-8
@c Style notes:
@c
@c * The reference section names and "See Also" list are roman, not
@c @code. This is to follow the format of CLHS.
@c
@c * How it looks in HTML is the priority.
@c ============================= Macros =============================
@c The following macros are used throughout this manual.
@macro Function {args}
@defun \args\
@end defun
@end macro
@macro Macro {args}
@defmac \args\
@end defmac
@end macro
@macro Accessor {args}
@deffn {Accessor} \args\
@end deffn
@end macro
@macro GenericFunction {args}
@deffn {Generic Function} \args\
@end deffn
@end macro
@macro ForeignType {args}
@deftp {Foreign Type} \args\
@end deftp
@end macro
@macro Variable {args}
@defvr {Special Variable} \args\
@end defvr
@end macro
@macro Condition {args}
@deftp {Condition Type} \args\
@end deftp
@end macro
@macro cffi
@acronym{CFFI}
@end macro
@macro impnote {text}
@quotation
@strong{Implementor's note:} @emph{\text\}
@end quotation
@end macro
@c Info "requires" that x-refs end in a period or comma, or ) in the
@c case of @pxref. So the following implements that requirement for
@c the "See also" subheadings that permeate this manual, but only in
@c Info mode.
@ifinfo
@macro seealso {name}
@ref{\name\}.
@end macro
@end ifinfo
@ifnotinfo
@alias seealso = ref
@end ifnotinfo
@c Typeset comments in roman font for the TeX output.
@iftex
@alias lispcmt = r
@end iftex
@ifnottex
@alias lispcmt = asis
@end ifnottex
@c My copy of makeinfo is not generating any HTML for @result{} for
@c some odd reason. (It certainly used to...)
@ifhtml
@macro result
=>
@end macro
@end ifhtml
@c Similar macro to @result. Its purpose is to work around the fact
@c that ⇒ does not work properly inside @lisp.
@ifhtml
@macro res
@html
⇒
@end html
@end macro
@end ifhtml
@ifnothtml
@alias res = result
@end ifnothtml
@c ============================= Macros =============================
@c Show types, functions, and concepts in the same index.
@syncodeindex tp cp
@syncodeindex fn cp
@copying
Copyright @copyright{} 2005 James Bielman <jamesjb at jamesjb.com> @*
Copyright @copyright{} 2005-2010 Lu@'{@dotless{i}}s Oliveira
<loliveira at common-lisp.net> @*
Copyright @copyright{} 2005-2006 Dan Knapp <danka at accela.net>
Copyright @copyright{} 2005-2006 Emily Backes <lucca at accela.net>
Copyright @copyright{} 2006 Stephen Compall <s11 at member.fsf.org>
@quotation
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
``Software''), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
@sc{The software is provided ``as is'', without warranty of any kind,
express or implied, including but not limited to the warranties of
merchantability, fitness for a particular purpose and noninfringement.
In no event shall the authors or copyright holders be liable for any
claim, damages or other liability, whether in an action of contract,
tort or otherwise, arising from, out of or in connection with the
software or the use or other dealings in the software.}
@end quotation
@end copying
@c %**end of header
@dircategory Software development
@direntry
* CFFI Manual: (cffi-manual). CFFI Manual.
@end direntry
@titlepage
@title CFFI User Manual
@c @subtitle Version X.X
@c @author James Bielman
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
@ifnottex
@node Top, Introduction, (dir), (dir)
@top cffi
@insertcopying
@end ifnottex
@menu
* Introduction:: What is CFFI?
* Installation::
* Implementation Support::
* Tutorial:: Interactive intro to using CFFI.
* Wrapper generators:: CFFI forms from munging C source code.
* Foreign Types::
* Pointers::
* Strings::
* Variables::
* Functions::
* Libraries::
* Callbacks::
* The Groveller::
* Limitations::
* Platform-specific features:: Details about the underlying system.
* Glossary:: List of CFFI-specific terms and meanings.
* Comprehensive Index::
@detailmenu
--- Dictionary ---
Foreign Types
* convert-from-foreign:: Outside interface to backward type translator.
* convert-to-foreign:: Outside interface to forward type translator.
* defbitfield:: Defines a bitfield.
* defcstruct:: Defines a C structure type.
* defcunion:: Defines a C union type.
* defctype:: Defines a foreign typedef.
* defcenum:: Defines a C enumeration.
* define-foreign-type:: Defines a foreign type specifier.
* define-parse-method:: Specifies how a type should be parsed.
@c * explain-foreign-slot-value:: <unimplemented>
* foreign-bitfield-symbols:: Returns a list of symbols for a bitfield type.
* foreign-bitfield-value:: Calculates a value for a bitfield type.
* foreign-enum-keyword:: Finds a keyword in an enum type.
* foreign-enum-value:: Finds a value in an enum type.
* foreign-slot-names:: Returns a list of slot names in a foreign struct.
* foreign-slot-offset:: Returns the offset of a slot in a foreign struct.
* foreign-slot-pointer:: Returns a pointer to a slot in a foreign struct.
* foreign-slot-value:: Returns the value of a slot in a foreign struct.
* foreign-type-alignment:: Returns the alignment of a foreign type.
* foreign-type-size:: Returns the size of a foreign type.
* free-converted-object:: Outside interface to typed object deallocators.
* free-translated-object:: Defines how to free a oreign object.
* translate-from-foreign:: Defines a foreign-to-Lisp object translation.
* translate-to-foreign:: Defines a Lisp-to-foreign object translation.
* with-foreign-object:: Allocates a foreign object with dynamic extent.
* with-foreign-objects:: Plural form of @code{with-foreign-object}.
* with-foreign-slots:: Accesses the slots of a foreign structure.
Pointers
* foreign-free:: Deallocates memory.
* foreign-alloc:: Allocates memory.
* foreign-symbol-pointer:: Returns a pointer to a foreign symbol.
* inc-pointer:: Increments the address held by a pointer.
* incf-pointer:: Increments the pointer address in a place.
* make-pointer:: Returns a pointer to a given address.
* mem-aptr:: The pointer to an element of an array.
* mem-aref:: Accesses the value of an index in an array.
* mem-ref:: Dereferences a pointer.
* null-pointer:: Returns a NULL pointer.
* null-pointer-p:: Tests a pointer for NULL value.
* pointerp:: Tests whether an object is a pointer or not.
* pointer-address:: Returns the address pointed to by a pointer.
* pointer-eq:: Tests if two pointers point to the same address.
* with-foreign-pointer:: Allocates memory with dynamic extent.
Strings
* *default-foreign-encoding*:: Default encoding for the string types.
* foreign-string-alloc:: Converts a Lisp string to a foreign string.
* foreign-string-free:: Deallocates memory used by a foreign string.
* foreign-string-to-lisp:: Converts a foreign string to a Lisp string.
* lisp-string-to-foreign:: Copies a Lisp string into a foreign string.
* with-foreign-string:: Allocates a foreign string with dynamic extent.
* with-foreign-strings:: Plural form of @code{with-foreign-string}.
* with-foreign-pointer-as-string:: Similar to CL's with-output-to-string.
Variables
* defcvar:: Defines a C global variable.
* get-var-pointer:: Returns a pointer to a defined global variable.
Functions
* defcfun:: Defines a foreign function.
* foreign-funcall:: Performs a call to a foreign function.
* foreign-funcall-pointer:: Performs a call through a foreign pointer.
* translate-camelcase-name:: Converts a camelCase foreign name to/from a Lisp name.
* translate-name-from-foreign:: Converts a foreign name to a Lisp name.
* translate-name-to-foreign:: Converts a Lisp name to a foreign name.
* translate-underscore-separated-name:: Converts an underscore_separated foreign name to/from a Lisp name.
Libraries
* close-foreign-library:: Closes a foreign library.
* *darwin-framework-directories*:: Search path for Darwin frameworks.
* define-foreign-library:: Explain how to load a foreign library.
* *foreign-library-directories*:: Search path for shared libraries.
* load-foreign-library:: Load a foreign library.
* load-foreign-library-error:: Signalled on failure of its namesake.
@c * reload-foreign-libraries:: Reload foreign libraries.
* use-foreign-library:: Load a foreign library when needed.
Callbacks
* callback:: Returns a pointer to a defined callback.
* defcallback:: Defines a Lisp callback.
* get-callback:: Returns a pointer to a defined callback.
@end detailmenu
@end menu
@c ===================================================================
@c CHAPTER: Introduction
@node Introduction, Installation, Top, Top
@chapter Introduction
@cffi{} is the Common Foreign Function Interface for @acronym{ANSI}
Common Lisp systems. By @dfn{foreign function} we mean a function
written in another programming language and having different data and
calling conventions than Common Lisp, namely, C. @cffi{} allows you
to call foreign functions and access foreign variables, all without
leaving the Lisp image.
We consider this manual ever a work in progress. If you have
difficulty with anything @cffi{}-specific presented in the manual,
please contact @email{cffi-devel@@common-lisp.net,the developers} with
details.
@heading Motivation
@xref{Tutorial-Comparison,, What makes Lisp different}, for
an argument in favor of @acronym{FFI} in general.
@cffi{}'s primary role in any image is to mediate between Lisp
developers and the widely varying @acronym{FFI}s present in the
various Lisp implementations it supports. With @cffi{}, you can
define foreign function interfaces while still maintaining portability
between implementations. It is not the first Common Lisp package with
this objective; however, it is meant to be a more malleable framework
than similar packages.
@heading Design Philosophy
@itemize
@item
Pointers do not carry around type information. Instead, type
information is supplied when pointers are dereferenced.
@item
A type safe pointer interface can be developed on top of an
untyped one. It is difficult to do the opposite.
@item
Functions are better than macros. When a macro could be used
for performance, use a compiler-macro instead.
@end itemize
@c ===================================================================
@c CHAPTER: Installation
@node Installation, Implementation Support, Introduction, Top
@chapter Installation
@cffi{} can be obtained through one of the following means available
through its @uref{http://common-lisp.net/project/cffi/,,website}:
@itemize
@item
@uref{http://common-lisp.net/project/cffi/releases/?M=D,,official release
tarballs}
@item
@uref{http://common-lisp.net/gitweb?p=projects/cffi/cffi.git,,git
repository}
@c snapshots have been disabled as of
@c @item
@c @uref{http://common-lisp.net/project/cffi/tarballs/?M=D,,nightly-generated
@c snapshots}
@end itemize
In addition, you will need to obtain and install the following
dependencies:
@itemize
@item
@uref{http://common-lisp.net/project/babel/,,Babel}, a charset
encoding/decoding library.
@item
@uref{http://common-lisp.net/project/alexandria/,,Alexandria}, a
collection of portable public-domain utilities.
@item
@uref{http://www.cliki.net/trivial-features,,trivial-features}, a
portability layer that ensures consistent @code{*features*} across
multiple Common Lisp implementations.
@end itemize
Furthermore, if you wish to run the testsuite,
@uref{http://www.cliki.net/rt,,RT} is required.
You may find mechanisms such as
@uref{http://common-lisp.net/project/clbuild/,,clbuild} (recommended)
or @uref{http://www.cliki.net/ASDF-Install,,ASDF-Install} (not as
recommendable) helpful in getting and managing @cffi{} and its
dependencies.
@c ===================================================================
@c CHAPTER: Implementation Support
@node Implementation Support, Tutorial, Installation, Top
@chapter Implementation Support
@cffi{} supports various free and commercial Lisp implementations:
Allegro CL, Corman CL, @sc{clisp}, @acronym{CMUCL}, @acronym{ECL},
LispWorks, Clozure CL, @acronym{SBCL} and the Scieneer CL.
In general, you should work with the latest versions of each
implementation since those will usually be tested against recent
versions of CFFI more often and might include necessary features or
bug fixes. Reasonable patches for compatibility with earlier versions
are welcome nevertheless.
@section Limitations
Some features are not supported in all implementations.
@c TODO: describe these features here.
@c flat-namespace too
@subheading Allegro CL
@itemize
@item
Does not support the @code{:long-long} type natively.
@item
Unicode support is limited to the Basic Multilingual Plane (16-bit
code points).
@end itemize
@subheading CMUCL
@itemize
@item
No Unicode support. (8-bit code points)
@end itemize
@subheading Corman CL
@itemize
@item
Does not support @code{foreign-funcall}.
@end itemize
@subheading @acronym{ECL}
@itemize
@item
On platforms where ECL's dynamic FFI is not supported (ie. when
@code{:dffi} is not present in @code{*features*}),
@code{cffi:load-foreign-library} does not work and you must use ECL's
own @code{ffi:load-foreign-library} with a constant string argument.
@item
Does not support the @code{:long-long} type natively.
@item
Unicode support is not enabled by default.
@end itemize
@subheading Lispworks
@itemize
@item
Does not completely support the @code{:long-long} type natively in
32-bit platforms.
@item
Unicode support is limited to the Basic Multilingual Plane (16-bit
code points).
@end itemize
@subheading @acronym{SBCL}
@itemize
@item
Not all platforms support callbacks.
@end itemize
@c ===================================================================
@c CHAPTER: An Introduction to Foreign Interfaces and CFFI
@c This macro is merely a marker that I don't think I'll use after
@c all.
@macro tutorialsource {text}
@c \text\
@end macro
@c because I don't want to type this over and over
@macro clikicffi
http://www.cliki.net/CFFI
@end macro
@c TeX puts spurious newlines in when you use the above macro
@c in @examples &c. So it is expanded below in some places.
@node Tutorial, Wrapper generators, Implementation Support, Top
@chapter An Introduction to Foreign Interfaces and @acronym{CFFI}
@c Above, I don't use the cffi macro because it breaks TeX.
@cindex tutorial, @cffi{}
Users of many popular languages bearing semantic similarity to Lisp,
such as Perl and Python, are accustomed to having access to popular C
libraries, such as @acronym{GTK}, by way of ``bindings''. In Lisp, we
do something similar, but take a fundamentally different approach.
This tutorial first explains this difference, then explains how you
can use @cffi{}, a powerful system for calling out to C and C++ and
access C data from many Common Lisp implementations.
@cindex foreign functions and data
The concept can be generalized to other languages; at the time of
writing, only @cffi{}'s C support is fairly complete, but C++
support is being worked on. Therefore, we will interchangeably refer
to @dfn{foreign functions} and @dfn{foreign data}, and ``C functions''
and ``C data''. At no time will the word ``foreign'' carry its usual,
non-programming meaning.
This tutorial expects you to have a working understanding of both
Common Lisp and C, including the Common Lisp macro system.
@menu
* Tutorial-Comparison:: Why FFI?
* Tutorial-Getting a URL:: An FFI use case.
* Tutorial-Loading:: Load libcurl.so.
* Tutorial-Initializing:: Call a function in libcurl.so.
* Tutorial-easy_setopt:: An advanced libcurl function.
* Tutorial-Abstraction:: Why breaking it is necessary.
* Tutorial-Lisp easy_setopt:: Semi-Lispy option interface.
* Tutorial-Memory:: In C, you collect the garbage.
* Tutorial-Callbacks:: Make useful C function pointers.
* Tutorial-Completion:: Minimal get-url functionality.
* Tutorial-Types:: Defining new foreign types.
* Tutorial-Conclusion:: What's next?
@end menu
@node Tutorial-Comparison, Tutorial-Getting a URL, Tutorial, Tutorial
@section What makes Lisp different
The following sums up how bindings to foreign libraries are usually
implemented in other languages, then in Common Lisp:
@table @asis
@item Perl, Python, Java, other one-implementation languages
@cindex @acronym{SWIG}
@cindex Perl
@cindex Python
Bindings are implemented as shared objects written in C. In some
cases, the C code is generated by a tool, such as @acronym{SWIG}, but
the result is the same: a new C library that manually translates
between the language implementation's objects, such as @code{PyObject}
in Python, and whatever C object is called for, often using C
functions provided by the implementation. It also translates between
the calling conventions of the language and C.
@item Common Lisp
@cindex @acronym{SLIME}
Bindings are written in Lisp. They can be created at-will by Lisp
programs. Lisp programmers can write new bindings and add them to the
image, using a listener such as @acronym{SLIME}, as easily as with
regular Lisp definitions. The only foreign library to load is the one
being wrapped---the one with the pure C interface; no C or other
non-Lisp compilation is required.
@end table
@cindex advantages of @acronym{FFI}
@cindex benefits of @acronym{FFI}
We believe the advantages of the Common Lisp approach far outweigh any
disadvantages. Incremental development with a listener can be as
productive for C binding development as it is with other Lisp
development. Keeping it ``in the [Lisp] family'', as it were, makes
it much easier for you and other Lisp programmers to load and use the
bindings. Common Lisp implementations such as @acronym{CMUCL}, freed
from having to provide a C interface to their own objects, are thus
freed to be implemented in another language (as @acronym{CMUCL} is)
while still allowing programmers to call foreign functions.
@cindex minimal bindings
Perhaps the greatest advantage is that using an @acronym{FFI} doesn't
obligate you to become a professional binding developer. Writers of
bindings for other languages usually end up maintaining or failing to
maintain complete bindings to the foreign library. Using an
@acronym{FFI}, however, means if you only need one or two functions,
you can write bindings for only those functions, and be assured that
you can just as easily add to the bindings if need be.
@cindex C abstractions
@cindex abstractions in C
The removal of the C compiler, or C interpretation of any kind,
creates the main disadvantage: some of C's ``abstractions'' are not
available, violating information encapsulation. For example,
@code{struct}s that must be passed on the stack, or used as return
values, without corresponding functional abstractions to create and
manage the @code{struct}s, must be declared explicitly in Lisp. This
is fine for structs whose contents are ``public'', but is not so
pleasant when a struct is supposed to be ``opaque'' by convention,
even though it is not so defined.@footnote{Admittedly, this is an
advanced issue, and we encourage you to leave this text until you are
more familiar with how @cffi{} works.}
Without an abstraction to create the struct, Lisp needs to be able to
lay out the struct in memory, so must know its internal details.
@cindex workaround for C
In these cases, you can create a minimal C library to provide the
missing abstractions, without destroying all the advantages of the
Common Lisp approach discussed above. In the case of @code{struct}s,
you can write simple, pure C functions that tell you how many bytes a
struct requires or allocate new structs, read and write fields of the
struct, or whatever operations are supposed to be
public.@footnote{This does not apply to structs whose contents are
intended to be part of the public library interface. In those cases,
a pure Lisp struct definition is always preferred. In fact, many
prefer to stay in Lisp and break the encapsulation anyway, placing the
burden of correct library interface definition on the library.}
@impnote{cffi-grovel, a project not yet part of @cffi{}, automates
this and other processes.}
Another disadvantage appears when you would rather use the foreign
language than Lisp. However, someone who prefers C to Lisp is not a
likely candidate for developing a Lisp interface to a C library.
@node Tutorial-Getting a URL, Tutorial-Loading, Tutorial-Comparison, Tutorial
@section Getting a @acronym{URL}
@cindex c@acronym{URL}
The widely available @code{libcurl} is a library for downloading files
over protocols like @acronym{HTTP}. We will use @code{libcurl} with
@cffi{} to download a web page.
Please note that there are many other ways to download files from the
web, not least the @sc{cl-curl} project to provide bindings to
@code{libcurl} via a similar @acronym{FFI}.@footnote{Specifically,
@acronym{UFFI}, an older @acronym{FFI} that takes a somewhat different
approach compared to @cffi{}. I believe that these days (December
2005) @cffi{} is more portable and actively developed, though not as
mature yet. Consensus in the free @sc{unix} Common Lisp community
seems to be that @cffi{} is preferred for new development, though
@acronym{UFFI} will likely go on for quite some time as many projects
already use it. @cffi{} includes the @code{UFFI-COMPAT} package for
complete compatibility with @acronym{UFFI}.}
@uref{http://curl.haxx.se/libcurl/c/libcurl-tutorial.html,,libcurl-tutorial(3)}
is a tutorial for @code{libcurl} programming in C. We will follow
that to develop a binding to download a file. We will also use
@file{curl.h}, @file{easy.h}, and the @command{man} pages for the
@code{libcurl} function, all available in the @samp{curl-dev} package
or equivalent for your system, or in the c@acronym{URL} source code
package. If you have the development package, the headers should be
installed in @file{/usr/include/curl/}, and the @command{man} pages
may be accessed through your favorite @command{man} facility.
@node Tutorial-Loading, Tutorial-Initializing, Tutorial-Getting a URL, Tutorial
@section Loading foreign libraries
@cindex loading @cffi{}
@cindex requiring @cffi{}
First of all, we will create a package to work in. You can save these
forms in a file, or just send them to the listener as they are. If
creating bindings for an @acronym{ASDF} package of yours, you will
want to add @code{:cffi} to the @code{:depends-on} list in your
@file{.asd} file. Otherwise, just use the @code{asdf:oos} function to
load @cffi{}.
@tutorialsource{Initialization}
@lisp
(asdf:oos 'asdf:load-op :cffi)
;;; @lispcmt{Nothing special about the "CFFI-USER" package. We're just}
;;; @lispcmt{using it as a substitute for your own CL package.}
(defpackage :cffi-user
(:use :common-lisp :cffi))
(in-package :cffi-user)
(define-foreign-library libcurl
(:unix (:or "libcurl.so.3" "libcurl.so"))
(t (:default "libcurl")))
(use-foreign-library libcurl)
@end lisp
@cindex foreign library load
@cindex library, foreign
Using @code{define-foreign-library} and @code{use-foreign-library}, we
have loaded @code{libcurl} into Lisp, much as the linker does when you
start a C program, or @code{common-lisp:load} does with a Lisp source
file or @acronym{FASL} file. We special-cased for @sc{unix} machines
to always load a particular version, the one this tutorial was tested
with; for those who don't care, the @code{define-foreign-library}
clause @code{(t (:default "libcurl"))} should be satisfactory, and
will adapt to various operating systems.
@node Tutorial-Initializing, Tutorial-easy_setopt, Tutorial-Loading, Tutorial
@section Initializing @code{libcurl}
@cindex function definition
After the introductory matter, the tutorial goes on to present the
first function you should use.
@example
CURLcode curl_global_init(long flags);
@end example
@noindent
Let's pick this apart into appropriate Lisp code:
@tutorialsource{First CURLcode}
@lisp
;;; @lispcmt{A CURLcode is the universal error code. curl/curl.h says}
;;; @lispcmt{no return code will ever be removed, and new ones will be}
;;; @lispcmt{added to the end.}
(defctype curl-code :int)
;;; @lispcmt{Initialize libcurl with FLAGS.}
(defcfun "curl_global_init" curl-code
(flags :long))
@end lisp
@impnote{By default, CFFI assumes the UNIX viewpoint that there is one
C symbol namespace, containing all symbols in all loaded objects.
This is not so on Windows and Darwin, but we emulate UNIX's behaviour
there. @ref{defcfun} for more details.}
Note the parallels with the original C declaration. We've defined
@code{curl-code} as a wrapping type for @code{:int}; right now, it
only marks it as special, but later we will do something more
interesting with it. The point is that we don't have to do it yet.
@cindex calling foreign functions
Looking at @file{curl.h}, @code{CURL_GLOBAL_NOTHING}, a possible value
for @code{flags} above, is defined as @samp{0}. So we can now call
the function:
@example
@sc{cffi-user>} (curl-global-init 0)
@result{} 0
@end example
@cindex looks like it worked
Looking at @file{curl.h} again, @code{0} means @code{CURLE_OK}, so it
looks like the call succeeded. Note that @cffi{} converted the
function name to a Lisp-friendly name. You can specify your own name
if you want; use @code{("curl_global_init" @var{your-name-here})} as
the @var{name} argument to @code{defcfun}.
The tutorial goes on to have us allocate a handle. For good measure,
we should also include the deallocator. Let's look at these
functions:
@example
CURL *curl_easy_init( );
void curl_easy_cleanup(CURL *handle);
@end example
Advanced users may want to define special pointer types; we will
explore this possibility later. For now, just treat every pointer as
the same:
@tutorialsource{curl_easy handles}
@lisp
(defcfun "curl_easy_init" :pointer)
(defcfun "curl_easy_cleanup" :void
(easy-handle :pointer))
@end lisp
Now we can continue with the tutorial:
@example
@sc{cffi-user>} (defparameter *easy-handle* (curl-easy-init))
@result{} *EASY-HANDLE*
@sc{cffi-user>} *easy-handle*
@result{} #<FOREIGN-ADDRESS #x09844EE0>
@end example
@cindex pointers in Lisp
Note the print representation of a pointer. It changes depending on
what Lisp you are using, but that doesn't make any difference to
@cffi{}.
@node Tutorial-easy_setopt, Tutorial-Abstraction, Tutorial-Initializing, Tutorial
@section Setting download options
The @code{libcurl} tutorial says we'll want to set many options before
performing any download actions. This is done through
@code{curl_easy_setopt}:
@c That is literally ..., not an ellipsis.
@example
CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...);
@end example
@cindex varargs
@cindex foreign arguments
We've introduced a new twist: variable arguments. There is no obvious
translation to the @code{defcfun} form, particularly as there are four
possible argument types. Because of the way C works, we could define
four wrappers around @code{curl_easy_setopt}, one for each type; in
this case, however, we'll use the general-purpose macro
@code{foreign-funcall} to call this function.
@cindex enumeration, C
To make things easier on ourselves, we'll create an enumeration of the
kinds of options we want to set. The @code{enum CURLoption} isn't the
most straightforward, but reading the @code{CINIT} C macro definition
should be enlightening.
@tutorialsource{CURLoption enumeration}
@lisp
(defmacro define-curl-options (name type-offsets &rest enum-args)
"As with CFFI:DEFCENUM, except each of ENUM-ARGS is as follows:
(NAME TYPE NUMBER)
Where the arguments are as they are with the CINIT macro defined
in curl.h, except NAME is a keyword.
TYPE-OFFSETS is a plist of TYPEs to their integer offsets, as
defined by the CURLOPTTYPE_LONG et al constants in curl.h."
(flet ((enumerated-value (type offset)
(+ (getf type-offsets type) offset)))
`(progn
(defcenum ,name
,@@(loop for (name type number) in enum-args
collect (list name (enumerated-value type number))))
',name))) ;@lispcmt{for REPL users' sanity}
(define-curl-options curl-option
(long 0 objectpoint 10000 functionpoint 20000 off-t 30000)
(:noprogress long 43)
(:nosignal long 99)
(:errorbuffer objectpoint 10)
(:url objectpoint 2))
@end lisp
With some well-placed Emacs @code{query-replace-regexp}s, you could
probably similarly define the entire @code{CURLoption} enumeration. I
have selected to transcribe a few that we will use in this tutorial.
If you're having trouble following the macrology, just macroexpand the
@code{curl-option} definition, or see the following macroexpansion,
conveniently downcased and reformatted:
@tutorialsource{DEFINE-CURL-OPTIONS macroexpansion}
@lisp
(progn
(defcenum curl-option
(:noprogress 43)
(:nosignal 99)
(:errorbuffer 10010)
(:url 10002))
'curl-option)
@end lisp
@noindent
That seems more than reasonable. You may notice that we only use the
@var{type} to compute the real enumeration offset; we will also need
the type information later.
First, however, let's make sure a simple call to the foreign function
works:
@example
@sc{cffi-user>} (foreign-funcall "curl_easy_setopt"
:pointer *easy-handle*
curl-option :nosignal :long 1 curl-code)
@result{} 0
@end example
@code{foreign-funcall}, despite its surface simplicity, can be used to
call any C function. Its first argument is a string, naming the
function to be called. Next, for each argument, we pass the name of
the C type, which is the same as in @code{defcfun}, followed by a Lisp
object representing the data to be passed as the argument. The final
argument is the return type, for which we use the @code{curl-code}
type defined earlier.
@code{defcfun} just puts a convenient fa@,cade on
@code{foreign-funcall}.@footnote{This isn't entirely true; some Lisps
don't support @code{foreign-funcall}, so @code{defcfun} is implemented
without it. @code{defcfun} may also perform optimizations that
@code{foreign-funcall} cannot.} Our earlier call to
@code{curl-global-init} could have been written as follows:
@example
@sc{cffi-user>} (foreign-funcall "curl_global_init" :long 0
curl-code)
@result{} 0
@end example
Before we continue, we will take a look at what @cffi{} can and can't
do, and why this is so.
@node Tutorial-Abstraction, Tutorial-Lisp easy_setopt, Tutorial-easy_setopt, Tutorial
@section Breaking the abstraction
@cindex breaking the abstraction
@cindex abstraction breaking
In @ref{Tutorial-Comparison,, What makes Lisp different}, we mentioned
that writing an @acronym{FFI} sometimes requires depending on
information not provided as part of the interface. The easy option
@code{CURLOPT_WRITEDATA}, which we will not provide as part of the
Lisp interface, illustrates this issue.
Strictly speaking, the @code{curl-option} enumeration is not
necessary; we could have used @code{:int 99} instead of
@code{curl-option :nosignal} in our call to @code{curl_easy_setopt}
above. We defined it anyway, in part to hide the fact that we are
breaking the abstraction that the C @code{enum} provides. If the
c@acronym{URL} developers decide to change those numbers later, we
must change the Lisp enumeration, because enumeration values are not
provided in the compiled C library, @code{libcurl.so.3}.
@cffi{} works because the most useful things in C libraries ---
non-static functions and non-static variables --- are included
accessibly in @code{libcurl.so.3}. A C compiler that violated this
would be considered a worthless compiler.
The other thing @code{define-curl-options} does is give the ``type''
of the third argument passed to @code{curl_easy_setopt}. Using this
information, we can tell that the @code{:nosignal} option should
accept a long integer argument. We can implicitly assume @code{t}
@equiv{} 1 and @code{nil} @equiv{} 0, as it is in C, which takes care
of the fact that @code{CURLOPT_NOSIGNAL} is really asking for a
boolean.
The ``type'' of @code{CURLOPT_WRITEDATA} is @code{objectpoint}.
However, it is really looking for a @code{FILE*}.
@code{CURLOPT_ERRORBUFFER} is looking for a @code{char*}, so there is
no obvious @cffi{} type but @code{:pointer}.
The first thing to note is that nowhere in the C interface includes
this information; it can only be found in the manual. We could
disjoin these clearly different types ourselves, by splitting
@code{objectpoint} into @code{filepoint} and @code{charpoint}, but we
are still breaking the abstraction, because we have to augment the
entire enumeration form with this additional
information.@footnote{Another possibility is to allow the caller to
specify the desired C type of the third argument. This is essentially
what happens in a call to the function written in C.}
@cindex streams and C
@cindex @sc{file}* and streams
The second is that the @code{CURLOPT_WRITEDATA} argument is completely
incompatible with the desired Lisp data, a
stream.@footnote{@xref{Other Kinds of Streams,,, libc, GNU C Library
Reference}, for a @acronym{GNU}-only way to extend the @code{FILE*}
type. You could use this to convert Lisp streams to the needed C
data. This would be quite involved and far outside the scope of this
tutorial.} It is probably acceptable if we are controlling every file
we might want to use as this argument, in which case we can just call
the foreign function @code{fopen}. Regardless, though, we can't write
to arbitrary streams, which is exactly what we want to do for this
application.
Finally, note that the @code{curl_easy_setopt} interface itself is a
hack, intended to work around some of the drawbacks of C. The
definition of @code{Curl_setopt}, while long, is far less cluttered
than the equivalent disjoint-function set would be; in addition,
setting a new option in an old @code{libcurl} can generate a run-time
error rather than breaking the compile. Lisp can just as concisely
generate functions as compare values, and the ``undefined function''
error is just as useful as any explicit error we could define here
might be.
@node Tutorial-Lisp easy_setopt, Tutorial-Memory, Tutorial-Abstraction, Tutorial
@section Option functions in Lisp
We could use @code{foreign-funcall} directly every time we wanted to
call @code{curl_easy_setopt}. However, we can encapsulate some of the
necessary information with the following.
@lisp
;;; @lispcmt{We will use this type later in a more creative way. For}
;;; @lispcmt{now, just consider it a marker that this isn't just any}
;;; @lispcmt{pointer.}
(defctype easy-handle :pointer)
(defmacro curl-easy-setopt (easy-handle enumerated-name
value-type new-value)
"Call `curl_easy_setopt' on EASY-HANDLE, using ENUMERATED-NAME
as the OPTION. VALUE-TYPE is the CFFI foreign type of the third
argument, and NEW-VALUE is the Lisp data to be translated to the
third argument. VALUE-TYPE is not evaluated."
`(foreign-funcall "curl_easy_setopt" easy-handle ,easy-handle
curl-option ,enumerated-name
,value-type ,new-value curl-code))
@end lisp
Now we define a function for each kind of argument that encodes the
correct @code{value-type} in the above. This can be done reasonably
in the @code{define-curl-options} macroexpansion; after all, that is
where the different options are listed!
@cindex Lispy C functions
We could make @code{cl:defun} forms in the expansion that simply call
@code{curl-easy-setopt}; however, it is probably easier and clearer to
use @code{defcfun}. @code{define-curl-options} was becoming unwieldy,
so I defined some helpers in this new definition.
@smalllisp
(defun curry-curl-option-setter (function-name option-keyword)
"Wrap the function named by FUNCTION-NAME with a version that
curries the second argument as OPTION-KEYWORD.
This function is intended for use in DEFINE-CURL-OPTION-SETTER."
(setf (symbol-function function-name)
(let ((c-function (symbol-function function-name)))
(lambda (easy-handle new-value)
(funcall c-function easy-handle option-keyword
new-value)))))
(defmacro define-curl-option-setter (name option-type
option-value foreign-type)
"Define (with DEFCFUN) a function NAME that calls
curl_easy_setopt. OPTION-TYPE and OPTION-VALUE are the CFFI
foreign type and value to be passed as the second argument to
easy_setopt, and FOREIGN-TYPE is the CFFI foreign type to be used
for the resultant function's third argument.
This macro is intended for use in DEFINE-CURL-OPTIONS."
`(progn
(defcfun ("curl_easy_setopt" ,name) curl-code
(easy-handle easy-handle)
(option ,option-type)
(new-value ,foreign-type))
(curry-curl-option-setter ',name ',option-value)))
(defmacro define-curl-options (type-name type-offsets &rest enum-args)
"As with CFFI:DEFCENUM, except each of ENUM-ARGS is as follows:
(NAME TYPE NUMBER)
Where the arguments are as they are with the CINIT macro defined
in curl.h, except NAME is a keyword.
TYPE-OFFSETS is a plist of TYPEs to their integer offsets, as
defined by the CURLOPTTYPE_LONG et al constants in curl.h.
Also, define functions for each option named
set-`TYPE-NAME'-`OPTION-NAME', where OPTION-NAME is the NAME from
the above destructuring."
(flet ((enumerated-value (type offset)
(+ (getf type-offsets type) offset))
;; @lispcmt{map PROCEDURE, destructuring each of ENUM-ARGS}
(map-enum-args (procedure)
(mapcar (lambda (arg) (apply procedure arg)) enum-args))
;; @lispcmt{build a name like SET-CURL-OPTION-NOSIGNAL}
(make-setter-name (option-name)
(intern (concatenate
'string "SET-" (symbol-name type-name)
"-" (symbol-name option-name)))))
`(progn
(defcenum ,type-name
,@@(map-enum-args
(lambda (name type number)
(list name (enumerated-value type number)))))
,@@(map-enum-args
(lambda (name type number)
(declare (ignore number))
`(define-curl-option-setter ,(make-setter-name name)
,type-name ,name ,(ecase type
(long :long)
(objectpoint :pointer)
(functionpoint :pointer)
(off-t :long)))))
',type-name)))
@end smalllisp
@noindent
Macroexpanding our @code{define-curl-options} form once more, we
see something different:
@lisp
(progn
(defcenum curl-option
(:noprogress 43)
(:nosignal 99)
(:errorbuffer 10010)
(:url 10002))
(define-curl-option-setter set-curl-option-noprogress
curl-option :noprogress :long)
(define-curl-option-setter set-curl-option-nosignal
curl-option :nosignal :long)
(define-curl-option-setter set-curl-option-errorbuffer
curl-option :errorbuffer :pointer)
(define-curl-option-setter set-curl-option-url
curl-option :url :pointer)
'curl-option)
@end lisp
@noindent
Macroexpanding one of the new @code{define-curl-option-setter}
forms yields the following:
@lisp
(progn
(defcfun ("curl_easy_setopt" set-curl-option-nosignal) curl-code
(easy-handle easy-handle)
(option curl-option)
(new-value :long))
(curry-curl-option-setter 'set-curl-option-nosignal ':nosignal))
@end lisp
@noindent
Finally, let's try this out:
@example
@sc{cffi-user>} (set-curl-option-nosignal *easy-handle* 1)
@result{} 0
@end example
@noindent
Looks like it works just as well. This interface is now reasonably
high-level to wash out some of the ugliness of the thinnest possible
@code{curl_easy_setopt} @acronym{FFI}, without obscuring the remaining
C bookkeeping details we will explore.
@node Tutorial-Memory, Tutorial-Callbacks, Tutorial-Lisp easy_setopt, Tutorial
@section Memory management
According to the documentation for @code{curl_easy_setopt}, the type
of the third argument when @var{option} is @code{CURLOPT_ERRORBUFFER}
is @code{char*}. Above, we've defined
@code{set-curl-option-errorbuffer} to accept a @code{:pointer} as the
new option value. However, there is a @cffi{} type @code{:string},
which translates Lisp strings to C strings when passed as arguments to
foreign function calls. Why not, then, use @code{:string} as the
@cffi{} type of the third argument? There are two reasons, both
related to the necessity of breaking abstraction described in
@ref{Tutorial-Abstraction,, Breaking the abstraction}.
The first reason also applies to @code{CURLOPT_URL}, which we will use
to illustrate the point. Assuming we have changed the type of the
third argument underlying @code{set-curl-option-url} to
@code{:string}, look at these two equivalent forms.
@lisp
(set-curl-option-url *easy-handle* "http://www.cliki.net/CFFI")
@equiv{} (with-foreign-string (url "http://www.cliki.net/CFFI")
(foreign-funcall "curl_easy_setopt" easy-handle *easy-handle*
curl-option :url :pointer url curl-code))
@end lisp
@noindent
The latter, in fact, is mostly equivalent to what a foreign function
call's macroexpansion actually does. As you can see, the Lisp string
@code{"@clikicffi{}"} is copied into a @code{char} array and
null-terminated; the pointer to beginning of this array, now a C
string, is passed as a @cffi{} @code{:pointer} to the foreign
function.
@cindex dynamic extent
@cindex foreign values with dynamic extent
Unfortunately, the C abstraction has failed us, and we must break it.
While @code{:string} works well for many @code{char*} arguments, it
does not for cases like this. As the @code{curl_easy_setopt}
documentation explains, ``The string must remain present until curl no
longer needs it, as it doesn't copy the string.'' The C string
created by @code{with-foreign-string}, however, only has dynamic
extent: it is ``deallocated'' when the body (above containing the
@code{foreign-funcall} form) exits.
@cindex premature deallocation
If we are supposed to keep the C string around, but it goes away, what
happens when some @code{libcurl} function tries to access the
@acronym{URL} string? We have reentered the dreaded world of C
``undefined behavior''. In some Lisps, it will probably get a chunk
of the Lisp/C stack. You may segfault. You may get some random piece
of other data from the heap. Maybe, in a world where ``dynamic
extent'' is defined to be ``infinite extent'', everything will turn
out fine. Regardless, results are likely to be almost universally
unpleasant.@footnote{``@i{But I thought Lisp was supposed to protect
me from all that buggy C crap!}'' Before asking a question like that,
remember that you are a stranger in a foreign land, whose residents
have a completely different set of values.}
Returning to the current @code{set-curl-option-url} interface, here is
what we must do:
@lisp
(let (easy-handle)
(unwind-protect
(with-foreign-string (url "http://www.cliki.net/CFFI")
(setf easy-handle (curl-easy-init))
(set-curl-option-url easy-handle url)
#|@lispcmt{do more with the easy-handle, like actually get the URL}|#)
(when easy-handle
(curl-easy-cleanup easy-handle))))
@end lisp
@c old comment to luis: I go on to say that this isn't obviously
@c extensible to new option settings that require C strings to stick
@c around, as it would involve re-evaluating the unwind-protect form
@c with more dynamic memory allocation. So I plan to show how to
@c write something similar to ObjC's NSAutoreleasePool, to be managed
@c with a simple unwind-protect form.
@noindent
That is fine for the single string defined here, but for every string
option we want to pass, we have to surround the body of
@code{with-foreign-string} with another @code{with-foreign-string}
wrapper, or else do some extremely error-prone pointer manipulation
and size calculation in advance. We could alleviate some of the pain
with a recursively expanding macro, but this would not remove the need
to modify the block every time we want to add an option, anathema as
it is to a modular interface.
Before modifying the code to account for this case, consider the other
reason we can't simply use @code{:string} as the foreign type. In C,
a @code{char *} is a @code{char *}, not necessarily a string. The
option @code{CURLOPT_ERRORBUFFER} accepts a @code{char *}, but does
not expect anything about the data there. However, it does expect
that some @code{libcurl} function we call later can write a C string
of up to 255 characters there. We, the callers of the function, are
expected to read the C string at a later time, exactly the opposite of
what @code{:string} implies.
With the semantics for an input string in mind --- namely, that the
string should be kept around until we @code{curl_easy_cleanup} the
easy handle --- we are ready to extend the Lisp interface:
@lisp
(defvar *easy-handle-cstrings* (make-hash-table)
"Hashtable of easy handles to lists of C strings that may be
safely freed after the handle is freed.")
(defun make-easy-handle ()
"Answer a new CURL easy interface handle, to which the lifetime
of C strings may be tied. See `add-curl-handle-cstring'."
(let ((easy-handle (curl-easy-init)))
(setf (gethash easy-handle *easy-handle-cstrings*) '())
easy-handle))
(defun free-easy-handle (handle)
"Free CURL easy interface HANDLE and any C strings created to
be its options."
(curl-easy-cleanup handle)
(mapc #'foreign-string-free
(gethash handle *easy-handle-cstrings*))
(remhash handle *easy-handle-cstrings*))
(defun add-curl-handle-cstring (handle cstring)
"Add CSTRING to be freed when HANDLE is, answering CSTRING."
(car (push cstring (gethash handle *easy-handle-cstrings*))))
@end lisp
@noindent
Here we have redefined the interface to create and free handles, to
associate a list of allocated C strings with each handle while it
exists. The strategy of using different function names to wrap around
simple foreign functions is more common than the solution implemented
earlier with @code{curry-curl-option-setter}, which was to modify the
function name's function slot.@footnote{There are advantages and
disadvantages to each approach; I chose to @code{(setf
symbol-function)} earlier because it entailed generating fewer magic
function names.}
Incidentally, the next step is to redefine
@code{curry-curl-option-setter} to allocate C strings for the
appropriate length of time, given a Lisp string as the
@code{new-value} argument:
@lisp
(defun curry-curl-option-setter (function-name option-keyword)
"Wrap the function named by FUNCTION-NAME with a version that
curries the second argument as OPTION-KEYWORD.
This function is intended for use in DEFINE-CURL-OPTION-SETTER."
(setf (symbol-function function-name)
(let ((c-function (symbol-function function-name)))
(lambda (easy-handle new-value)
(funcall c-function easy-handle option-keyword
(if (stringp new-value)
(add-curl-handle-cstring
easy-handle
(foreign-string-alloc new-value))
new-value))))))
@end lisp
@noindent
A quick analysis of the code shows that you need only reevaluate the
@code{curl-option} enumeration definition to take advantage of these
new semantics. Now, for good measure, let's reallocate the handle
with the new functions we just defined, and set its @acronym{URL}:
@example
@sc{cffi-user>} (curl-easy-cleanup *easy-handle*)
@result{} NIL
@sc{cffi-user>} (setf *easy-handle* (make-easy-handle))
@result{} #<FOREIGN-ADDRESS #x09844EE0>
@sc{cffi-user>} (set-curl-option-nosignal *easy-handle* 1)
@result{} 0
@sc{cffi-user>} (set-curl-option-url *easy-handle*
"http://www.cliki.net/CFFI")
@result{} 0
@end example
@cindex strings
For fun, let's inspect the Lisp value of the C string that was created
to hold @code{"@clikicffi{}"}. By virtue of the implementation of
@code{add-curl-handle-cstring}, it should be accessible through the
hash table defined:
@example
@sc{cffi-user>} (foreign-string-to-lisp
(car (gethash *easy-handle* *easy-handle-cstrings*)))
@result{} "http://www.cliki.net/CFFI"
@end example
@noindent
Looks like that worked, and @code{libcurl} now knows what
@acronym{URL} we want to retrieve.
Finally, we turn back to the @code{:errorbuffer} option mentioned at
the beginning of this section. Whereas the abstraction added to
support string inputs works fine for cases like @code{CURLOPT_URL}, it
hides the detail of keeping the C string; for @code{:errorbuffer},
however, we need that C string.
In a moment, we'll define something slightly cleaner, but for now,
remember that you can always hack around anything. We're modifying
handle creation, so make sure you free the old handle before
redefining @code{free-easy-handle}.
@smalllisp
(defvar *easy-handle-errorbuffers* (make-hash-table)
"Hashtable of easy handles to C strings serving as error
writeback buffers.")
;;; @lispcmt{An extra byte is very little to pay for peace of mind.}
(defparameter *curl-error-size* 257
"Minimum char[] size used by cURL to report errors.")
(defun make-easy-handle ()
"Answer a new CURL easy interface handle, to which the lifetime
of C strings may be tied. See `add-curl-handle-cstring'."
(let ((easy-handle (curl-easy-init)))
(setf (gethash easy-handle *easy-handle-cstrings*) '())
(setf (gethash easy-handle *easy-handle-errorbuffers*)
(foreign-alloc :char :count *curl-error-size*
:initial-element 0))
easy-handle))
(defun free-easy-handle (handle)
"Free CURL easy interface HANDLE and any C strings created to
be its options."
(curl-easy-cleanup handle)
(foreign-free (gethash handle *easy-handle-errorbuffers*))
(remhash handle *easy-handle-errorbuffers*)
(mapc #'foreign-string-free
(gethash handle *easy-handle-cstrings*))
(remhash handle *easy-handle-cstrings*))
(defun get-easy-handle-error (handle)
"Answer a string containing HANDLE's current error message."
(foreign-string-to-lisp
(gethash handle *easy-handle-errorbuffers*)))
@end smalllisp
Be sure to once again set the options we've set thus far. You may
wish to define yet another wrapper function to do this.
@node Tutorial-Callbacks, Tutorial-Completion, Tutorial-Memory, Tutorial
@section Calling Lisp from C
If you have been reading
@uref{http://curl.haxx.se/libcurl/c/curl_easy_setopt.html,,
@code{curl_easy_setopt(3)}}, you should have noticed that some options
accept a function pointer. In particular, we need one function
pointer to set as @code{CURLOPT_WRITEFUNCTION}, to be called by
@code{libcurl} rather than the reverse, in order to receive data as it
is downloaded.
A binding writer without the aid of @acronym{FFI} usually approaches
this problem by writing a C function that accepts C data, converts to
the language's internal objects, and calls the callback provided by
the user, again in a reverse of usual practices.
The @cffi{} approach to callbacks precisely mirrors its differences
with the non-@acronym{FFI} approach on the ``calling C from Lisp''
side, which we have dealt with exclusively up to now. That is, you
define a callback function in Lisp using @code{defcallback}, and
@cffi{} effectively creates a C function to be passed as a function
pointer.
@impnote{This is much trickier than calling C functions from Lisp, as
it literally involves somehow generating a new C function that is as
good as any created by the compiler. Therefore, not all Lisps support
them. @xref{Implementation Support}, for information about @cffi{}
support issues in this and other areas. You may want to consider
changing to a Lisp that supports callbacks in order to continue with
this tutorial.}
@cindex callback definition
@cindex defining callbacks
Defining a callback is very similar to defining a callout; the main
difference is that we must provide some Lisp forms to be evaluated as
part of the callback. Here is the signature for the function the
@code{:writefunction} option takes:
@example
size_t
@var{function}(void *ptr, size_t size, size_t nmemb, void *stream);
@end example
@impnote{size_t is almost always an unsigned int. You can get this
and many other types using feature tests for your system by using
cffi-grovel.}
The above signature trivially translates into a @cffi{}
@code{defcallback} form, as follows.
@lisp
;;; @lispcmt{Alias in case size_t changes.}
(defctype size :unsigned-int)
;;; @lispcmt{To be set as the CURLOPT_WRITEFUNCTION of every easy handle.}
(defcallback easy-write size ((ptr :pointer) (size size)
(nmemb size) (stream :pointer))
(let ((data-size (* size nmemb)))
(handler-case
;; @lispcmt{We use the dynamically-bound *easy-write-procedure* to}
;; @lispcmt{call a closure with useful lexical context.}
(progn (funcall (symbol-value '*easy-write-procedure*)
(foreign-string-to-lisp ptr data-size nil))
data-size) ;@lispcmt{indicates success}
;; @lispcmt{The WRITEFUNCTION should return something other than the}
;; @lispcmt{#bytes available to signal an error.}
(error () (if (zerop data-size) 1 0)))))
@end lisp
First, note the correlation of the first few forms, used to declare
the C function's signature, with the signature in C syntax. We
provide a Lisp name for the function, its return type, and a name and
type for each argument.
In the body, we call the dynamically-bound
@code{*easy-write-procedure*} with a ``finished'' translation, of
pulling together the raw data and size into a Lisp string, rather than
deal with the data directly. As part of calling
@code{curl_easy_perform} later, we'll bind that variable to a closure
with more useful lexical bindings than the top-level
@code{defcallback} form.
Finally, we make a halfhearted effort to prevent non-local exits from
unwinding the C stack, covering the most likely case with an
@code{error} handler, which is usually triggered
unexpectedly.@footnote{Unfortunately, we can't protect against
@emph{all} non-local exits, such as @code{return}s and @code{throw}s,
because @code{unwind-protect} cannot be used to ``short-circuit'' a
non-local exit in Common Lisp, due to proposal @code{minimal} in
@uref{http://www.lisp.org/HyperSpec/Issues/iss152-writeup.html,
@acronym{ANSI} issue @sc{Exit-Extent}}. Furthermore, binding an
@code{error} handler prevents higher-up code from invoking restarts
that may be provided under the callback's dynamic context. Such is
the way of compromise.} The reason is that most C code is written to
understand its own idiosyncratic error condition, implemented above in
the case of @code{curl_easy_perform}, and more ``undefined behavior''
can result if we just wipe C stack frames without allowing them to
execute whatever cleanup actions as they like.
Using the @code{CURLoption} enumeration in @file{curl.h} once more, we
can describe the new option by modifying and reevaluating
@code{define-curl-options}.
@lisp
(define-curl-options curl-option
(long 0 objectpoint 10000 functionpoint 20000 off-t 30000)
(:noprogress long 43)
(:nosignal long 99)
(:errorbuffer objectpoint 10)
(:url objectpoint 2)
(:writefunction functionpoint 11)) ;@lispcmt{new item here}
@end lisp
Finally, we can use the defined callback and the new
@code{set-curl-option-writefunction} to finish configuring the easy
handle, using the @code{callback} macro to retrieve a @cffi{}
@code{:pointer}, which works like a function pointer in C code.
@example
@sc{cffi-user>} (set-curl-option-writefunction
*easy-handle* (callback easy-write))
@result{} 0
@end example
@node Tutorial-Completion, Tutorial-Types, Tutorial-Callbacks, Tutorial
@section A complete @acronym{FFI}?
@c TeX goes insane on @uref{@clikicffi{}}
With all options finally set and a medium-level interface developed,
we can finish the definition and retrieve
@uref{http://www.cliki.net/CFFI}, as is done in the tutorial.
@lisp
(defcfun "curl_easy_perform" curl-code
(handle easy-handle))
@end lisp
@example
@sc{cffi-user>} (with-output-to-string (contents)
(let ((*easy-write-procedure*
(lambda (string)
(write-string string contents))))
(declare (special *easy-write-procedure*))
(curl-easy-perform *easy-handle*)))
@result{} "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
@enddots{}
Now fear, comprehensively</P>
"
@end example
Of course, that itself is slightly unwieldy, so you may want to define
a function around it that simply retrieves a @acronym{URL}. I will
leave synthesis of all the relevant @acronym{REPL} forms presented
thus far into a single function as an exercise for the reader.
The remaining sections of this tutorial explore some advanced features
of @cffi{}; the definition of new types will receive special
attention. Some of these features are essential for particular
foreign function calls; some are very helpful when trying to develop a
Lispy interface to C.
@node Tutorial-Types, Tutorial-Conclusion, Tutorial-Completion, Tutorial
@section Defining new types
We've occasionally used the @code{defctype} macro in previous sections
as a kind of documentation, much what you'd use @code{typedef} for in
C. We also tried one special kind of type definition, the
@code{defcenum} type. @xref{defcstruct}, for a definition macro that
may come in handy if you need to use C @code{struct}s as data.
@cindex type definition
@cindex data in Lisp and C
@cindex translating types
However, all of these are mostly sugar for the powerful underlying
foreign type interface called @dfn{type translators}. You can easily
define new translators for any simple named foreign type. Since we've
defined the new type @code{curl-code} to use as the return type for
various @code{libcurl} functions, we can use that to directly convert
c@acronym{URL} errors to Lisp errors.
@code{defctype}'s purpose is to define simple @code{typedef}-like
aliases. In order to use @dfn{type translators} we must use the
@code{define-foreign-type} macro. So let's redefine @code{curl-code}
using it.
@lisp
(define-foreign-type curl-code-type ()
()
(:actual-type :int)
(:simple-parser curl-code))
@end lisp
@code{define-foreign-type} is a thin wrapper around @code{defclass}.
For now, all you need to know in the context of this example is that
it does what @code{(defctype curl-code :int)} would do and,
additionally, defines a new class @code{curl-code-type} which we will
take advantage of shortly.
The @code{CURLcode} enumeration seems to follow the typical error code
convention of @samp{0} meaning all is well, and each non-zero integer
indicating a different kind of error. We can apply that trivially to
differentiate between normal exits and error exits.
@lisp
(define-condition curl-code-error (error)
(($code :initarg :curl-code :reader curl-error-code))
(:report (lambda (c stream)
(format stream "libcurl function returned error ~A"
(curl-error-code c))))
(:documentation "Signalled when a libcurl function answers
a code other than CURLE_OK."))
(defmethod translate-from-foreign (value (type curl-code-type))
"Raise a CURL-CODE-ERROR if VALUE, a curl-code, is non-zero."
(if (zerop value)
:curle-ok
(error 'curl-code-error :curl-code value)))
@end lisp
@noindent
The heart of this translator is new method
@code{translate-from-foreign}. By specializing the @var{type}
parameter on @code{curl-code-type}, we immediately modify the behavior
of every function that returns a @code{curl-code} to pass the result
through this new method.
To see the translator in action, try invoking a function that returns
a @code{curl-code}. You need to reevaluate the respective
@code{defcfun} form so that it picks up the new @code{curl-code}
definition.
@example
@sc{cffi-user>} (set-curl-option-nosignal *easy-handle* 1)
@result{} :CURLE-OK
@end example
@noindent
As the result was @samp{0}, the new method returned @code{:curle-ok},
just as specified.@footnote{It might be better to return
@code{(values)} than @code{:curle-ok} in real code, but this is good
for illustration.} I will leave disjoining the separate
@code{CURLcode}s into condition types and improving the @code{:report}
function as an exercise for you.
The creation of @code{*easy-handle-cstrings*} and
@code{*easy-handle-errorbuffers*} as properties of @code{easy-handle}s
is a kluge. What we really want is a Lisp structure that stores these
properties along with the C pointer. Unfortunately,
@code{easy-handle} is currently just a fancy name for the foreign type
@code{:pointer}; the actual pointer object varies from Common Lisp
implementation to implementation, needing only to satisfy
@code{pointerp} and be returned from @code{make-pointer} and friends.
One solution that would allow us to define a new Lisp structure to
represent @code{easy-handle}s would be to write a wrapper around every
function that currently takes an @code{easy-handle}; the wrapper would
extract the pointer and pass it to the foreign function. However, we
can use type translators to more elegantly integrate this
``translation'' into the foreign function calling framework, using
@code{translate-to-foreign}.
@smalllisp
(defclass easy-handle ()
((pointer :initform (curl-easy-init)
:documentation "Foreign pointer from curl_easy_init")
(error-buffer
:initform (foreign-alloc :char :count *curl-error-size*
:initial-element 0)
:documentation "C string describing last error")
(c-strings :initform '()
:documentation "C strings set as options"))
(:documentation "I am a parameterization you may pass to
curl-easy-perform to perform a cURL network protocol request."))
(defmethod initialize-instance :after ((self easy-handle) &key)
(set-curl-option-errorbuffer self (slot-value self 'error-buffer)))
(defun add-curl-handle-cstring (handle cstring)
"Add CSTRING to be freed when HANDLE is, answering CSTRING."
(car (push cstring (slot-value handle 'c-strings))))
(defun get-easy-handle-error (handle)
"Answer a string containing HANDLE's current error message."
(foreign-string-to-lisp
(slot-value handle 'error-buffer)))
(defun free-easy-handle (handle)
"Free CURL easy interface HANDLE and any C strings created to
be its options."
(with-slots (pointer error-buffer c-strings) handle
(curl-easy-cleanup pointer)
(foreign-free error-buffer)
(mapc #'foreign-string-free c-strings)))
(define-foreign-type easy-handle-type ()
()
(:actual-type :pointer)
(:simple-parser easy-handle))
(defmethod translate-to-foreign (handle (type easy-handle-type))
"Extract the pointer from an easy-HANDLE."
(slot-value handle 'pointer))
@end smalllisp
While we changed some of the Lisp functions defined earlier to use
@acronym{CLOS} slots rather than hash tables, the foreign functions
work just as well as they did before.
@cindex limitations of type translators
The greatest strength, and the greatest limitation, of the type
translator comes from its generalized interface. As stated
previously, we could define all foreign function calls in terms of the
primitive foreign types provided by @cffi{}. The type translator
interface allows us to cleanly specify the relationship between Lisp
and C data, independent of where it appears in a function call. This
independence comes at a price; for example, it cannot be used to
modify translation semantics based on other arguments to a function
call. In these cases, you should rely on other features of Lisp,
rather than the powerful, yet domain-specific, type translator
interface.
@node Tutorial-Conclusion, , Tutorial-Types, Tutorial
@section What's next?
@cffi{} provides a rich and powerful foundation for communicating with
foreign libraries; as we have seen, it is up to you to make that
experience a pleasantly Lispy one. This tutorial does not cover all
the features of @cffi{}; please see the rest of the manual for
details. In particular, if something seems obviously missing, it is
likely that either code or a good reason for lack of code is already
present.
@impnote{There are some other things in @cffi{} that might deserve
tutorial sections, such as free-translated-object, or structs. Let us
know which ones you care about.}
@c ===================================================================
@c CHAPTER: Wrapper generators
@node Wrapper generators, Foreign Types, Tutorial, Top
@chapter Wrapper generators
@cffi{}'s interface is designed for human programmers, being aimed at
aesthetic as well as technical sophistication. However, there are a
few programs aimed at translating C and C++ header files, or
approximations thereof, into @cffi{} forms constituting a foreign
interface to the symbols in those files.
These wrapper generators are known to support output of @cffi{} forms.
@table @asis
@item @uref{http://www.cliki.net/Verrazano,Verrazano}
Designed specifically for Common Lisp. Uses @acronym{GCC}'s parser
output in @acronym{XML} format to discover functions, variables, and
other header file data. This means you need @acronym{GCC} to generate
forms; on the other hand, the parser employed is mostly compliant with
@acronym{ANSI} C.
@item @uref{http://www.cliki.net/SWIG,SWIG}
A foreign interface generator originally designed to generate Python
bindings, it has been ported to many other systems, including @cffi{}
in version 1.3.28. Includes its own C declaration munger, not
intended to be fully-compliant with @acronym{ANSI} C.
@end table
First, this manual does not describe use of these other programs; they
have documentation of their own. If you have problems using a
generated interface, please look at the output @cffi{} forms and
verify that they are a correct @cffi{} interface to the library in
question; if they are correct, contact @cffi{} developers with
details, keeping in mind that they communicate in terms of those forms
rather than any particular wrapper generator. Otherwise, contact the
maintainers of the wrapper generator you are using, provided you can
reasonably expect more accuracy from the generator.
When is more accuracy an unreasonable expectation? As described in
the tutorial (@pxref{Tutorial-Abstraction,, Breaking the
abstraction}), the information in C declarations is insufficient to
completely describe every interface. In fact, it is quite common to
run into an interface that cannot be handled automatically, and
generators should be excused from generating a complete interface in
these cases.
As further described in the tutorial, the thinnest Lisp interface to a
C function is not always the most pleasant one. In many cases, you
will want to manually write a Lispier interface to the C functions
that interest you.
Wrapper generators should be treated as time-savers, not complete
automation of the full foreign interface writing job. Reports of the
amount of work done by generators vary from 30% to 90%. The
incremental development style enabled by @cffi{} generally reduces
this proportion below that for languages like Python.
@c Where I got the above 30-90% figures:
@c 30%: lemonodor's post about SWIG
@c 90%: Balooga on #lisp. He said 99%, but that's probably an
@c exaggeration (leave it to me to pass judgement :)
@c -stephen
@c ===================================================================
@c CHAPTER: Foreign Types
@node Foreign Types, Pointers, Wrapper generators, Top
@chapter Foreign Types
Foreign types describe how data is translated back and forth between C
and Lisp. @cffi{} provides various built-in types and allows the user to
define new types.
@menu
* Built-In Types::
* Other Types::
* Defining Foreign Types::
* Foreign Type Translators::
* Optimizing Type Translators::
* Foreign Structure Types::
* Allocating Foreign Objects::
Dictionary
* convert-from-foreign::
* convert-to-foreign::
* defbitfield::
* defcstruct::
* defcunion::
* defctype::
* defcenum::
@c * define-type-spec-parser::
* define-foreign-type::
* define-parse-method::
@c * explain-foreign-slot-value:
* foreign-bitfield-symbols::
* foreign-bitfield-value::
* foreign-enum-keyword::
* foreign-enum-value::
* foreign-slot-names::
* foreign-slot-offset::
* foreign-slot-pointer::
* foreign-slot-value::
* foreign-type-alignment::
* foreign-type-size::
* free-converted-object::
* free-translated-object::
* translate-from-foreign::
* translate-to-foreign::
* translate-into-foreign-memory::
* with-foreign-slots::
@end menu
@node Built-In Types, Other Types, Foreign Types, Foreign Types
@section Built-In Types
@ForeignType{:char}
@ForeignType{:unsigned-char}
@ForeignType{:short}
@ForeignType{:unsigned-short}
@ForeignType{:int}
@ForeignType{:unsigned-int}
@ForeignType{:long}
@ForeignType{:unsigned-long}
@ForeignType{:long-long}
@ForeignType{:unsigned-long-long}
These types correspond to the native C integer types according to the
@acronym{ABI} of the Lisp implementation's host system.
@code{:long-long} and @code{:unsigned-long-long} are not supported
natively on all implementations. However, they are emulated by
@code{mem-ref} and @code{mem-set}.
When those types are @strong{not} available, the symbol
@code{cffi-sys::no-long-long} is pushed into @code{*features*}.
@ForeignType{:uchar}
@ForeignType{:ushort}
@ForeignType{:uint}
@ForeignType{:ulong}
@ForeignType{:llong}
@ForeignType{:ullong}
For convenience, the above types are provided as shortcuts for
@code{unsigned-char}, @code{unsigned-short}, @code{unsigned-int},
@code{unsigned-long}, @code{long-long} and @code{unsigned-long-long},
respectively.
@ForeignType{:int8}
@ForeignType{:uint8}
@ForeignType{:int16}
@ForeignType{:uint16}
@ForeignType{:int32}
@ForeignType{:uint32}
@ForeignType{:int64}
@ForeignType{:uint64}
Foreign integer types of specific sizes, corresponding to the C types
defined in @code{stdint.h}.
@c @ForeignType{:size}
@c @ForeignType{:ssize}
@c @ForeignType{:ptrdiff}
@c @ForeignType{:time}
@c Foreign integer types corresponding to the standard C types (without
@c the @code{_t} suffix).
@c @impnote{These are not implemented yet. --luis}
@c @impnote{I'm sure there are more of these that could be useful, let's
@c add any types that can't be defined portably to this list as
@c necessary. --james}
@ForeignType{:float}
@ForeignType{:double}
On all systems, the @code{:float} and @code{:double} types represent a
C @code{float} and @code{double}, respectively. On most but not all
systems, @code{:float} and @code{:double} represent a Lisp
@code{single-float} and @code{double-float}, respectively. It is not
so useful to consider the relationship between Lisp types and C types
as isomorphic, as simply to recognize the relationship, and relative
precision, among each respective category.
@ForeignType{:long-double}
This type is only supported on SCL.
@ForeignType{:pointer &optional type}
A foreign pointer to an object of any type, corresponding to
@code{void *}. You can optionally specify type of pointer
(e.g. @code{(:pointer :char)}). Although @cffi{} won't do anything
with that information yet, it is useful for documentation purposes.
@ForeignType{:void}
No type at all. Only valid as the return type of a function.
@node Other Types, Defining Foreign Types, Built-In Types, Foreign Types
@section Other Types
@cffi{} also provides a few useful types that aren't built-in C
types.
@ForeignType{:string}
The @code{:string} type performs automatic conversion between Lisp and
C strings. Note that, in the case of functions the converted C string
will have dynamic extent (i.e.@: it will be automatically freed after
the foreign function returns).
In addition to Lisp strings, this type will accept foreign pointers
and pass them unmodified.
A method for @ref{free-translated-object} is specialized for this
type. So, for example, foreign strings allocated by this type and
passed to a foreign function will be freed after the function
returns.
@lisp
CFFI> (foreign-funcall "getenv" :string "SHELL" :string)
@result{} "/bin/bash"
CFFI> (with-foreign-string (str "abcdef")
(foreign-funcall "strlen" :string str :int))
@result{} 6
@end lisp
@ForeignType{:string+ptr}
Like @code{:string} but returns a list with two values when convert
from C to Lisp: a Lisp string and the C string's foreign pointer.
@lisp
CFFI> (foreign-funcall "getenv" :string "SHELL" :string+ptr)
@result{} ("/bin/bash" #.(SB-SYS:INT-SAP #XBFFFFC6F))
@end lisp
@ForeignType{:boolean &optional (base-type :int)}
The @code{:boolean} type converts between a Lisp boolean and a C
boolean. It canonicalizes to @var{base-type} which is @code{:int} by
default.
@lisp
(convert-to-foreign nil :boolean) @result{} 0
(convert-to-foreign t :boolean) @result{} 1
(convert-from-foreign 0 :boolean) @result{} nil
(convert-from-foreign 1 :boolean) @result{} t
@end lisp
@ForeignType{:wrapper base-type &key to-c from-c}
The @code{:wrapper} type stores two symbols passed to the @var{to-c}
and @var{from-c} arguments. When a value is being translated to or
from C, this type @code{funcall}s the respective symbol.
@code{:wrapper} types will be typedefs for @var{base-type} and will
inherit its translators, if any.
Here's an example of how the @code{:boolean} type could be defined in
terms of @code{:wrapper}.
@lisp
(defun bool-c-to-lisp (value)
(not (zerop value)))
(defun bool-lisp-to-c (value)
(if value 1 0))
(defctype my-bool (:wrapper :int :from-c bool-c-to-lisp
:to-c bool-lisp-to-c))
(convert-to-foreign nil 'my-bool) @result{} 0
(convert-from-foreign 1 'my-bool) @result{} t
@end lisp
@node Defining Foreign Types, Foreign Type Translators, Other Types, Foreign Types
@section Defining Foreign Types
You can define simple C-like @code{typedef}s through the
@code{defctype} macro. Defining a typedef is as simple as giving
@code{defctype} a new name and the name of the type to be wrapped.
@lisp
;;; @lispcmt{Define MY-INT as an alias for the built-in type :INT.}
(defctype my-int :int)
@end lisp
With this type definition, one can, for instance, declare arguments to
foreign functions as having the type @code{my-int}, and they will be
passed as integers.
@subheading More complex types
@cffi{} offers another way to define types through
@code{define-foreign-type}, a thin wrapper macro around
@code{defclass}. As an example, let's go through the steps needed to
define a @code{(my-string &key encoding)} type. First, we need to
define our type class:
@lisp
(define-foreign-type my-string-type ()
((encoding :reader string-type-encoding :initarg :encoding))
(:actual-type :pointer))
@end lisp
The @code{:actual-type} class option tells CFFI that this type will
ultimately be passed to and received from foreign code as a
@code{:pointer}. Now you need to tell CFFI how to parse a type
specification such as @code{(my-string :encoding :utf8)} into an
instance of @code{my-string-type}. We do that with
@code{define-parse-method}:
@lisp
(define-parse-method my-string (&key (encoding :utf-8))
(make-instance 'my-string-type :encoding encoding))
@end lisp
The next section describes how make this type actually translate
between C and Lisp strings.
@node Foreign Type Translators, Optimizing Type Translators, Defining Foreign Types, Foreign Types
@section Foreign Type Translators
Type translators are used to automatically convert Lisp values to or
from foreign values. For example, using type translators, one can
take the @code{my-string} type defined in the previous section and
specify that it should:
@itemize
@item
convert C strings to Lisp strings;
@item
convert Lisp strings to newly allocated C strings;
@item
free said C strings when they are no longer needed.
@end itemize
In order to tell @cffi{} how to automatically convert Lisp values to
foreign values, define a specialized method for the
@code{translate-to-foreign} generic function:
@lisp
;;; @lispcmt{Define a method that converts Lisp strings to C strings.}
(defmethod translate-to-foreign (string (type my-string-type))
(foreign-string-alloc string :encoding (string-type-encoding type)))
@end lisp
@noindent
From now on, whenever an object is passed as a @code{my-string} to a
foreign function, this method will be invoked to convert the Lisp
value. To perform the inverse operation, which is needed for functions
that return a @code{my-string}, specialize the
@code{translate-from-foreign} generic function in the same manner:
@lisp
;;; @lispcmt{Define a method that converts C strings to Lisp strings.}
(defmethod translate-from-foreign (pointer (type my-string-type))
(foreign-string-to-lisp pointer :encoding (string-type-encoding type)))
@end lisp
@noindent
When a @code{translate-to-foreign} method requires allocation of
foreign memory, you must also define a @code{free-translated-object}
method to free the memory once the foreign object is no longer needed,
otherwise you'll be faced with memory leaks. This generic function is
called automatically by @cffi{} when passing objects to foreign
functions. Let's do that:
@lisp
;;; @lispcmt{Free strings allocated by translate-to-foreign.}
(defmethod free-translated-object (pointer (type my-string-type) param)
(declare (ignore param))
(foreign-string-free pointer))
@end lisp
@noindent
In this specific example, we don't need the @var{param} argument, so
we ignore it. See @ref{free-translated-object}, for an explanation of
its purpose and how you can use it.
A type translator does not necessarily need to convert the value. For
example, one could define a typedef for @code{:pointer} that ensures,
in the @code{translate-to-foreign} method, that the value is not a
null pointer, signalling an error if a null pointer is passed. This
would prevent some pointer errors when calling foreign functions that
cannot handle null pointers.
@strong{Please note:} these methods are meant as extensible hooks
only, and you should not call them directly. Use
@code{convert-to-foreign}, @code{convert-from-foreign} and
@code{free-converted-object} instead.
@xref{Tutorial-Types,, Defining new types}, for another example of
type translators.
@node Optimizing Type Translators, Foreign Structure Types, Foreign Type Translators, Foreign Types
@section Optimizing Type Translators
@cindex type translators, optimizing
@cindex compiler macros for type translation
@cindex defining type-translation compiler macros
Being based on generic functions, the type translation mechanism
described above can add a bit of overhead. This is usually not
significant, but we nevertheless provide a way of getting rid of the
overhead for the cases where it matters.
A good way to understand this issue is to look at the code generated
by @code{defcfun}. Consider the following example using the previously
defined @code{my-string} type:
@lisp
CFFI> (macroexpand-1 '(defcfun foo my-string (x my-string)))
;; @lispcmt{(simplified, downcased, etc...)}
(defun foo (x)
(multiple-value-bind (#:G2019 #:PARAM3149)
(translate-to-foreign x #<MY-STRING-TYPE @{11ED5A79@}>)
(unwind-protect
(translate-from-foreign
(foreign-funcall "foo" :pointer #:G2019 :pointer)
#<MY-STRING-TYPE @{11ED5659@}>)
(free-translated-object #:G2019 #<MY-STRING-TYPE @{11ED51A79@}>
#:PARAM3149))))
@end lisp
@noindent
In order to get rid of those generic function calls, @cffi{} has
another set of extensible generic functions that provide functionality
similar to @acronym{CL}'s compiler macros:
@code{expand-to-foreign-dyn}, @code{expand-to-foreign} and
@code{expand-from-foreign}. Here's how one could define a
@code{my-boolean} with them:
@lisp
(define-foreign-type my-boolean-type ()
()
(:actual-type :int)
(:simple-parser my-boolean))
(defmethod expand-to-foreign (value (type my-boolean-type))
`(if ,value 1 0))
(defmethod expand-from-foreign (value (type my-boolean-type))
`(not (zerop ,value)))
@end lisp
@noindent
And here's what the macroexpansion of a function using this type would
look like:
@lisp
CFFI> (macroexpand-1 '(defcfun bar my-boolean (x my-boolean)))
;; @lispcmt{(simplified, downcased, etc...)}
(defun bar (x)
(let ((#:g3182 (if x 1 0)))
(not (zerop (foreign-funcall "bar" :int #:g3182 :int)))))
@end lisp
@noindent
No generic function overhead.
Let's go back to our @code{my-string} type. The expansion interface
has no equivalent of @code{free-translated-object}; you must instead
define a method on @code{expand-to-foreign-dyn}, the third generic
function in this interface. This is especially useful when you can
allocate something much more efficiently if you know the object has
dynamic extent, as is the case with function calls that don't save the
relevant allocated arguments.
This exactly what we need for the @code{my-string} type:
@lisp
(defmethod expand-from-foreign (form (type my-string-type))
`(foreign-string-to-lisp ,form))
(defmethod expand-to-foreign-dyn (value var body (type my-string-type))
(let ((encoding (string-type-encoding type)))
`(with-foreign-string (,var ,value :encoding ',encoding)
,@@body)))
@end lisp
@noindent
So let's look at the macro expansion:
@lisp
CFFI> (macroexpand-1 '(defcfun foo my-string (x my-string)))
;; @lispcmt{(simplified, downcased, etc...)}
(defun foo (x)
(with-foreign-string (#:G2021 X :encoding ':utf-8)
(foreign-string-to-lisp
(foreign-funcall "foo" :pointer #:g2021 :pointer))))
@end lisp
@noindent
Again, no generic function overhead.
@subheading Other details
To short-circuit expansion and use the @code{translate-*} functions
instead, simply call the next method. Return its result in cases
where your method cannot generate an appropriate replacement for it.
This analogous to the @code{&whole form} mechanism compiler macros
provide.
The @code{expand-*} methods have precedence over their
@code{translate-*} counterparts and are guaranteed to be used in
@code{defcfun}, @code{foreign-funcall}, @code{defcvar} and
@code{defcallback}. If you define a method on each of the
@code{expand-*} generic functions, you are guaranteed to have full
control over the expressions generated for type translation in these
macros.
They may or may not be used in other @cffi{} operators that need to
translate between Lisp and C data; you may only assume that
@code{expand-*} methods will probably only be called during Lisp
compilation.
@code{expand-to-foreign-dyn} has precedence over
@code{expand-to-foreign} and is only used in @code{defcfun} and
@code{foreign-funcall}, only making sense in those contexts.
@strong{Important note:} this set of generic functions is called at
macroexpansion time. Methods are defined when loaded or evaluated,
not compiled. You are responsible for ensuring that your
@code{expand-*} methods are defined when the @code{foreign-funcall} or
other forms that use them are compiled. One way to do this is to put
the method definitions earlier in the file and inside an appropriate
@code{eval-when} form; another way is to always load a separate Lisp
or @acronym{FASL} file containing your @code{expand-*} definitions
before compiling files with forms that ought to use them. Otherwise,
they will not be found and the runtime translators will be used
instead.
@node Foreign Structure Types, Allocating Foreign Objects, Optimizing Type Translators, Foreign Types
@section Foreign Structure Types
For more involved C types than simple aliases to built-in types, such
as you can make with @code{defctype}, @cffi{} allows declaration of
structures and unions with @code{defcstruct} and @code{defcunion}.
For example, consider this fictional C structure declaration holding
some personal information:
@example
struct person @{
int number;
char* reason;
@};
@end example
@noindent
The equivalent @code{defcstruct} form follows:
@lisp
(defcstruct person
(number :int)
(reason :string))
@end lisp
@c LMH structure translation
By default, @ref{convert-from-foreign} (and also @ref{mem-ref}) will
make a plist with slot names as keys, and @ref{convert-to-foreign} will
translate such a plist to a foreign structure. A user wishing to define
other translations should use the @code{:class} argument to
@ref{defcstruct}, and then define methods for
@ref{translate-from-foreign} and
@ref{translate-into-foreign-memory} that specialize on this class,
possibly calling @code{call-next-method} to translate from and to the
plists rather than provide a direct interface to the foreign object.
The macro @code{translation-forms-for-class} will generate the forms
necessary to translate a Lisp class into a foreign structure and vice
versa.
@c Write separate function doc section for translation-forms-for-class?
@c Examples, perhaps taken from the tests?
Please note that this interface is only for those that must know about
the values contained in a relevant struct. If the library you are
interfacing returns an opaque pointer that needs only be passed to
other C library functions, by all means just use @code{:pointer} or a
type-safe definition munged together with @code{defctype} and type
translation. To pass or return a structure by value to a function, load
the cffi-libffi system and specify the structure as @code{(:struct
@var{structure-name})}. To pass or return the pointer, you can use
either @code{:pointer} or @code{(:pointer (:struct
@var{structure-name}))}.
@emph{Compatibility note:} Previous versions of CFFI accepted the
``bare'' @var{structure-name} as a type specification, which was
interpreted as a pointer to the structure. This is deprecated and
produces a style warning. Using this deprecated form means that
@ref{mem-aref} retains its prior meaning and returns a pointer. Using
the @code{(:struct @var{structure-name})} form for the type,
@ref{mem-aref} provides a Lisp object translated from the
structure (by default a plist). Thus the semantics are consistent with all
types in returning the object as represented in Lisp, and not a pointer,
with the exception of the ``bare'' structure compatibility retained.
In order to obtain the pointer, you should use the function @ref{mem-aptr}.
See @ref{defcstruct} for more details.
@node Allocating Foreign Objects, convert-from-foreign, Foreign Structure Types, Foreign Types
@section Allocating Foreign Objects
@c I moved this because I moved with-foreign-object to the Pointers
@c chapter, where foreign-alloc is.
@xref{Allocating Foreign Memory}.
@c ===================================================================
@c CONVERT-FROM-FOREIGN
@page
@node convert-from-foreign, convert-to-foreign, Allocating Foreign Objects, Foreign Types
@heading convert-from-foreign
@subheading Syntax
@Function{convert-from-foreign foreign-value type @res{} value}
@subheading Arguments and Values
@table @var
@item foreign-value
The primitive C value as returned from a primitive foreign function or
from @code{convert-to-foreign}.
@item type
A @cffi{} type specifier.
@item value
The Lisp value translated from @var{foreign-value}.
@end table
@subheading Description
This is an external interface to the type translation facility. In
the implementation, all foreign functions are ultimately defined as
type translation wrappers around primitive foreign function
invocations.
This function is available mostly for inspection of the type
translation process, and possibly optimization of special cases of
your foreign function calls.
Its behavior is better described under @code{translate-from-foreign}'s
documentation.
@subheading Examples
@lisp
CFFI-USER> (convert-to-foreign "a boat" :string)
@result{} #<FOREIGN-ADDRESS #x097ACDC0>
@result{} T
CFFI-USER> (convert-from-foreign * :string)
@result{} "a boat"
@end lisp
@subheading See Also
@seealso{convert-to-foreign} @*
@seealso{free-converted-object} @*
@seealso{translate-from-foreign}
@c ===================================================================
@c CONVERT-TO-FOREIGN
@page
@node convert-to-foreign, defbitfield, convert-from-foreign, Foreign Types
@heading convert-to-foreign
@subheading Syntax
@Function{convert-to-foreign value type @res{} foreign-value, alloc-params}
@subheading Arguments and Values
@table @var
@item value
The Lisp object to be translated to a foreign object.
@item type
A @cffi{} type specifier.
@item foreign-value
The primitive C value, ready to be passed to a primitive foreign
function.
@item alloc-params
Something of a translation state; you must pass it to
@code{free-converted-object} along with the foreign value for that to
work.
@end table
@subheading Description
This is an external interface to the type translation facility. In
the implementation, all foreign functions are ultimately defined as
type translation wrappers around primitive foreign function
invocations.
This function is available mostly for inspection of the type
translation process, and possibly optimization of special cases of
your foreign function calls.
Its behavior is better described under @code{translate-to-foreign}'s
documentation.
@subheading Examples
@lisp
CFFI-USER> (convert-to-foreign t :boolean)
@result{} 1
@result{} NIL
CFFI-USER> (convert-to-foreign "hello, world" :string)
@result{} #<FOREIGN-ADDRESS #x097C5F80>
@result{} T
CFFI-USER> (code-char (mem-aref * :char 5))
@result{} #\,
@end lisp
@subheading See Also
@seealso{convert-from-foreign} @*
@seealso{free-converted-object} @*
@seealso{translate-to-foreign}
@c ===================================================================
@c DEFBITFIELD
@page
@node defbitfield, defcstruct, convert-to-foreign, Foreign Types
@heading defbitfield
@subheading Syntax
@Macro{defbitfield name-and-options &body masks}
masks ::= [docstring] @{ (symbol value) @}* @*
name-and-options ::= name | (name &optional (base-type :int))
@subheading Arguments and Values
@table @var
@item name
The name of the new bitfield type.
@item docstring
A documentation string, ignored.
@item base-type
A symbol denoting a foreign type.
@item symbol
A Lisp symbol.
@item value
An integer representing a bitmask.
@end table
@subheading Description
The @code{defbitfield} macro is used to define foreign types that map
lists of symbols to integer values.
If @var{value} is omitted, it will be computed as follows: find the
greatest @var{value} previously used, including those so computed,
with only a single 1-bit in its binary representation (that is, powers
of two), and left-shift it by one. This rule guarantees that a
computed @var{value} cannot clash with previous values, but may clash
with future explicitly specified values.
Symbol lists will be automatically converted to values and vice versa
when being passed as arguments to or returned from foreign functions,
respectively. The same applies to any other situations where an object
of a bitfield type is expected.
Types defined with @code{defbitfield} canonicalize to @var{base-type}
which is @code{:int} by default.
@subheading Examples
@lisp
(defbitfield open-flags
(:rdonly #x0000)
:wronly ;@lispcmt{#x0001}
:rdwr ;@lispcmt{@dots{}}
:nonblock
:append
(:creat #x0200))
;; @lispcmt{etc@dots{}}
CFFI> (foreign-bitfield-symbols 'open-flags #b1101)
@result{} (:RDONLY :WRONLY :NONBLOCK :APPEND)
CFFI> (foreign-bitfield-value 'open-flags '(:rdwr :creat))
@result{} 514 ; #x0202
(defcfun ("open" unix-open) :int
(path :string)
(flags open-flags)
(mode :uint16)) ; unportable
CFFI> (unix-open "/tmp/foo" '(:wronly :creat) #o644)
@result{} #<an fd>
;;; @lispcmt{Consider also the following lispier wrapper around open()}
(defun lispier-open (path mode &rest flags)
(unix-open path flags mode))
@end lisp
@subheading See Also
@seealso{foreign-bitfield-value} @*
@seealso{foreign-bitfield-symbols}
@c ===================================================================
@c DEFCSTRUCT
@page
@node defcstruct, defcunion, defbitfield, Foreign Types
@heading defcstruct
@subheading Syntax
@Macro{defcstruct name-and-options &body doc-and-slots @res{} name}
name-and-options ::= structure-name | (structure-name &key size)
doc-and-slots ::= [docstring] @{ (slot-name slot-type &key count offset) @}*
@subheading Arguments and Values
@table @var
@item structure-name
The name of new structure type.
@item docstring
A documentation string, ignored.
@item slot-name
A symbol naming the slot. It must be unique among slot names in this
structure.
@item size
Use this option to override the size (in bytes) of the struct.
@item slot-type
The type specifier for the slot.
@item count
Used to declare an array of size @var{count} inside the
structure. Defaults to @code{1} as such an array and a single element
are semantically equivalent.
@item offset
Overrides the slot's offset. The next slot's offset is calculated
based on this one.
@end table
@subheading Description
This defines a new @cffi{} aggregate type akin to C @code{struct}s.
In other words, it specifies that foreign objects of the type
@var{structure-name} are groups of different pieces of data, or
``slots'', of the @var{slot-type}s, distinguished from each other by
the @var{slot-name}s. Each structure is located in memory at a
position, and the slots are allocated sequentially beginning at that
point in memory (with some padding allowances as defined by the C
@acronym{ABI}, unless otherwise requested by specifying an
@var{offset} from the beginning of the structure (offset 0).
In other words, it is isomorphic to the C @code{struct}, giving
several extra features.
There are two kinds of slots, for the two kinds of @cffi{} types:
@table @dfn
@item Simple
Contain a single instance of a type that canonicalizes to a built-in
type, such as @code{:long} or @code{:pointer}. Used for simple
@cffi{} types.
@item Aggregate
Contain an embedded structure or union, or an array of objects. Used
for aggregate @cffi{} types.
@end table
The use of @acronym{CLOS} terminology for the structure-related
features is intentional; structure definitions are very much like
classes with (far) fewer features.
@subheading Examples
@lisp
(defcstruct point
"Point structure."
(x :int)
(y :int))
CFFI> (with-foreign-object (ptr 'point)
;; @lispcmt{Initialize the slots}
(setf (foreign-slot-value ptr 'point 'x) 42
(foreign-slot-value ptr 'point 'y) 42)
;; @lispcmt{Return a list with the coordinates}
(with-foreign-slots ((x y) ptr point)
(list x y)))
@result{} (42 42)
@end lisp
@lisp
;; @lispcmt{Using the :size and :offset options to define a partial structure.}
;; @lispcmt{(this is useful when you are interested in only a few slots}
;; @lispcmt{of a big foreign structure)}
(defcstruct (foo :size 32)
"Some struct with 32 bytes."
; @lispcmt{<16 bytes we don't care about>}
(x :int :offset 16) ; @lispcmt{an int at offset 16}
(y :int) ; @lispcmt{another int at offset 16+sizeof(int)}
; @lispcmt{<a couple more bytes we don't care about>}
(z :char :offset 24)) ; @lispcmt{a char at offset 24}
; @lispcmt{<7 more bytes ignored (since size is 32)>}
CFFI> (foreign-type-size 'foo)
@result{} 32
@end lisp
@lisp
;;; @lispcmt{Using :count to define arrays inside of a struct.}
(defcstruct video_tuner
(name :char :count 32))
@end lisp
@subheading See Also
@seealso{foreign-slot-pointer} @*
@seealso{foreign-slot-value} @*
@seealso{with-foreign-slots}
@c ===================================================================
@c DEFCUNION
@page
@node defcunion, defctype, defcstruct, Foreign Types
@heading defcunion
@subheading Syntax
@Macro{defcunion name &body doc-and-slots @res{} name}
doc-and-slots ::= [docstring] @{ (slot-name slot-type &key count) @}*
@subheading Arguments and Values
@table @var
@item name
The name of new union type.
@item docstring
A documentation string, ignored.
@item slot-name
A symbol naming the slot.
@item slot-type
The type specifier for the slot.
@item count
Used to declare an array of size @var{count} inside the
structure.
@end table
@subheading Description
A union is a structure in which all slots have an offset of zero. It
is isomorphic to the C @code{union}. Therefore, you should use the
usual foreign structure operations for accessing a union's slots.
@subheading Examples
@lisp
(defcunion uint32-bytes
(int-value :unsigned-int)
(bytes :unsigned-char :count 4))
@end lisp
@subheading See Also
@seealso{foreign-slot-pointer} @*
@seealso{foreign-slot-value}
@c ===================================================================
@c DEFCTYPE
@page
@node defctype, defcenum, defcunion, Foreign Types
@heading defctype
@subheading Syntax
@Macro{defctype name base-type &optional documentation}
@subheading Arguments and Values
@table @var
@item name
The name of the new foreign type.
@item base-type
A symbol or a list defining the new type.
@item documentation
A documentation string, currently ignored.
@end table
@subheading Description
The @code{defctype} macro provides a mechanism similar to C's
@code{typedef} to define new types. The new type inherits
@var{base-type}'s translators, if any. There is no way to define
translations for types defined with @code{defctype}. For that,
you should use @ref{define-foreign-type}.
@subheading Examples
@lisp
(defctype my-string :string
"My own string type.")
(defctype long-bools (:boolean :long)
"Booleans that map to C longs.")
@end lisp
@subheading See Also
@seealso{define-foreign-type}
@c ===================================================================
@c DEFCENUM
@page
@node defcenum, define-foreign-type, defctype, Foreign Types
@heading defcenum
@subheading Syntax
@Macro{defcenum name-and-options &body enum-list}
enum-list ::= [docstring] @{ keyword | (keyword value) @}*
name-and-options ::= name | (name &optional (base-type :int))
@subheading Arguments and Values
@table @var
@item name
The name of the new enum type.
@item docstring
A documentation string, ignored.
@item base-type
A symbol denoting a foreign type.
@item keyword
A keyword symbol.
@item value
An index value for a keyword.
@end table
@subheading Description
The @code{defcenum} macro is used to define foreign types that map
keyword symbols to integer values, similar to the C @code{enum} type.
If @var{value} is omitted its value will either be 0, if it's the
first entry, or it it will continue the progression from the last
specified value.
Keywords will be automatically converted to values and vice-versa when
being passed as arguments to or returned from foreign functions,
respectively. The same applies to any other situations where an object
of an @code{enum} type is expected.
Types defined with @code{defcenum} canonicalize to @var{base-type}
which is @code{:int} by default.
@subheading Examples
@lisp
(defcenum boolean
:no
:yes)
CFFI> (foreign-enum-value 'boolean :no)
@result{} 0
@end lisp
@lisp
(defcenum numbers
(:one 1)
:two
(:four 4))
CFFI> (foreign-enum-keyword 'numbers 2)
@result{} :TWO
@end lisp
@subheading See Also
@seealso{foreign-enum-value} @*
@seealso{foreign-enum-keyword}
@c ===================================================================
@c DEFINE-FOREIGN-TYPE
@page
@node define-foreign-type, define-parse-method, defcenum, Foreign Types
@heading define-foreign-type
@subheading Syntax
@Macro{define-foreign-type class-name supers slots &rest options @res{} class-name}
options ::= (@code{:actual-type} @var{type}) | @
(@code{:simple-parser} @var{symbol}) | @
@emph{regular defclass option}
@subheading Arguments and Values
@table @var
@item class-name
A symbol naming the new foreign type class.
@item supers
A list of symbols naming the super classes.
@item slots
A list of slot definitions, passed to @code{defclass}.
@end table
@subheading Description
@c TODO rewrite
The macro @code{define-foreign-type} defines a new class
@var{class-name}. It is a thin wrapper around @code{defclass}. Among
other things, it ensures that @var{class-name} becomes a subclass of
@var{foreign-type}, what you need to know about that is that there's
an initarg @code{:actual-type} which serves the same purpose as
@code{defctype}'s @var{base-type} argument.
@c TODO mention the type translators here
@c FIX FIX
@subheading Examples
Taken from @cffi{}'s @code{:boolean} type definition:
@lisp
(define-foreign-type :boolean (&optional (base-type :int))
"Boolean type. Maps to an :int by default. Only accepts integer types."
(ecase base-type
((:char
:unsigned-char
:int
:unsigned-int
:long
:unsigned-long) base-type)))
CFFI> (canonicalize-foreign-type :boolean)
@result{} :INT
CFFI> (canonicalize-foreign-type '(:boolean :long))
@result{} :LONG
CFFI> (canonicalize-foreign-type '(:boolean :float))
;; @lispcmt{@error{} signalled by ECASE.}
@end lisp
@subheading See Also
@seealso{defctype} @*
@seealso{define-parse-method}
@c ===================================================================
@c DEFINE-PARSE-METHOD
@page
@node define-parse-method, foreign-bitfield-symbols, define-foreign-type, Foreign Types
@heading define-parse-method
@subheading Syntax
@Macro{define-parse-method name lambda-list &body body @res{} name}
@subheading Arguments and Values
@table @var
@item type-name
A symbol naming the new foreign type.
@item lambda-list
A lambda list which is the argument list of the new foreign type.
@item body
One or more forms that provide a definition of the new foreign type.
@end table
@subheading Description
@c TODO: update example. The boolean type is probably a good choice.
@subheading Examples
Taken from @cffi{}'s @code{:boolean} type definition:
@lisp
(define-foreign-type :boolean (&optional (base-type :int))
"Boolean type. Maps to an :int by default. Only accepts integer types."
(ecase base-type
((:char
:unsigned-char
:int
:unsigned-int
:long
:unsigned-long) base-type)))
CFFI> (canonicalize-foreign-type :boolean)
@result{} :INT
CFFI> (canonicalize-foreign-type '(:boolean :long))
@result{} :LONG
CFFI> (canonicalize-foreign-type '(:boolean :float))
;; @lispcmt{@error{} signalled by ECASE.}
@end lisp
@subheading See Also
@seealso{define-foreign-type}
@c ===================================================================
@c EXPLAIN-FOREIGN-SLOT-VALUE
@c @node explain-foreign-slot-value
@c @heading explain-foreign-slot-value
@c @subheading Syntax
@c @Macro{explain-foreign-slot-value ptr type &rest slot-names}
@c @subheading Arguments and Values
@c @table @var
@c @item ptr
@c ...
@c @item type
@c ...
@c @item slot-names
@c ...
@c @end table
@c @subheading Description
@c This macro translates the slot access that would occur by calling
@c @code{foreign-slot-value} with the same arguments into an equivalent
@c expression in C and prints it to @code{*standard-output*}.
@c @emph{Note: this is not implemented yet.}
@c @subheading Examples
@c @lisp
@c CFFI> (explain-foreign-slot-value ptr 'timeval 'tv-secs)
@c @result{} ptr->tv_secs
@c CFFI> (explain-foreign-slot-value emp 'employee 'hire-date 'tv-usecs)
@c @result{} emp->hire_date.tv_usecs
@c @end lisp
@c @subheading See Also
@c ===================================================================
@c FOREIGN-BITFIELD-SYMBOLS
@page
@node foreign-bitfield-symbols, foreign-bitfield-value, define-parse-method, Foreign Types
@heading foreign-bitfield-symbols
@subheading Syntax
@Function{foreign-bitfield-symbols type value @res{} symbols}
@subheading Arguments and Values
@table @var
@item type
A bitfield type.
@item value
An integer.
@item symbols
A potentially shared list of symbols.
@code{nil}.
@end table
@subheading Description
The function @code{foreign-bitfield-symbols} returns a possibly shared
list of symbols that correspond to @var{value} in @var{type}.
@subheading Examples
@lisp
(defbitfield flags
(flag-a 1)
(flag-b 2)
(flag-c 4))
CFFI> (foreign-bitfield-symbols 'boolean #b101)
@result{} (FLAG-A FLAG-C)
@end lisp
@subheading See Also
@seealso{defbitfield} @*
@seealso{foreign-bitfield-value}
@c ===================================================================
@c FOREIGN-BITFIELD-VALUE
@page
@node foreign-bitfield-value, foreign-enum-keyword, foreign-bitfield-symbols, Foreign Types
@heading foreign-bitfield-value
@subheading Syntax
@Function{foreign-bitfield-value type symbols @res{} value}
@subheading Arguments and Values
@table @var
@item type
A @code{bitfield} type.
@item symbol
A Lisp symbol.
@item value
An integer.
@end table
@subheading Description
The function @code{foreign-bitfield-value} returns the @var{value} that
corresponds to the symbols in the @var{symbols} list.
@subheading Examples
@lisp
(defbitfield flags
(flag-a 1)
(flag-b 2)
(flag-c 4))
CFFI> (foreign-bitfield-value 'flags '(flag-a flag-c))
@result{} 5 ; #b101
@end lisp
@subheading See Also
@seealso{defbitfield} @*
@seealso{foreign-bitfield-symbols}
@c ===================================================================
@c FOREIGN-ENUM-KEYWORD
@page
@node foreign-enum-keyword, foreign-enum-value, foreign-bitfield-value, Foreign Types
@heading foreign-enum-keyword
@subheading Syntax
@Function{foreign-enum-keyword type value &key errorp @res{} keyword}
@subheading Arguments and Values
@table @var
@item type
An @code{enum} type.
@item value
An integer.
@item errorp
If true (the default), signal an error if @var{value} is not defined
in @var{type}. If false, @code{foreign-enum-keyword} returns
@code{nil}.
@item keyword
A keyword symbol.
@end table
@subheading Description
The function @code{foreign-enum-keyword} returns the keyword symbol
that corresponds to @var{value} in @var{type}.
An error is signaled if @var{type} doesn't contain such @var{value}
and @var{errorp} is true.
@subheading Examples
@lisp
(defcenum boolean
:no
:yes)
CFFI> (foreign-enum-keyword 'boolean 1)
@result{} :YES
@end lisp
@subheading See Also
@seealso{defcenum} @*
@seealso{foreign-enum-value}
@c ===================================================================
@c FOREIGN-ENUM-VALUE
@page
@node foreign-enum-value, foreign-slot-names, foreign-enum-keyword, Foreign Types
@heading foreign-enum-value
@subheading Syntax
@Function{foreign-enum-value type keyword &key errorp @res{} value}
@subheading Arguments and Values
@table @var
@item type
An @code{enum} type.
@item keyword
A keyword symbol.
@item errorp
If true (the default), signal an error if @var{keyword} is not
defined in @var{type}. If false, @code{foreign-enum-value} returns
@code{nil}.
@item value
An integer.
@end table
@subheading Description
The function @code{foreign-enum-value} returns the @var{value} that
corresponds to @var{keyword} in @var{type}.
An error is signaled if @var{type} doesn't contain such
@var{keyword}, and @var{errorp} is true.
@subheading Examples
@lisp
(defcenum boolean
:no
:yes)
CFFI> (foreign-enum-value 'boolean :yes)
@result{} 1
@end lisp
@subheading See Also
@seealso{defcenum} @*
@seealso{foreign-enum-keyword}
@c ===================================================================
@c FOREIGN-SLOT-NAMES
@page
@node foreign-slot-names, foreign-slot-offset, foreign-enum-value, Foreign Types
@heading foreign-slot-names
@subheading Syntax
@Function{foreign-slot-names type @res{} names}
@subheading Arguments and Values
@table @var
@item type
A foreign struct type.
@item names
A list.
@end table
@subheading Description
The function @code{foreign-slot-names} returns a potentially shared
list of slot @var{names} for the given structure @var{type}. This list
has no particular order.
@subheading Examples
@lisp
(defcstruct timeval
(tv-secs :long)
(tv-usecs :long))
CFFI> (foreign-slot-names '(:struct timeval))
@result{} (TV-SECS TV-USECS)
@end lisp
@subheading See Also
@seealso{defcstruct} @*
@seealso{foreign-slot-offset} @*
@seealso{foreign-slot-value} @*
@seealso{foreign-slot-pointer}
@c ===================================================================
@c FOREIGN-SLOT-OFFSET
@page
@node foreign-slot-offset, foreign-slot-pointer, foreign-slot-names, Foreign Types
@heading foreign-slot-offset
@subheading Syntax
@Function{foreign-slot-offset type slot-name @res{} offset}
@subheading Arguments and Values
@table @var
@item type
A foreign struct type.
@item slot-name
A symbol.
@item offset
An integer.
@end table
@subheading Description
The function @code{foreign-slot-offset} returns the @var{offset} in
bytes of a slot in a foreign struct type.
@subheading Examples
@lisp
(defcstruct timeval
(tv-secs :long)
(tv-usecs :long))
CFFI> (foreign-slot-offset '(:struct timeval) 'tv-secs)
@result{} 0
CFFI> (foreign-slot-offset '(:struct timeval) 'tv-usecs)
@result{} 4
@end lisp
@subheading See Also
@seealso{defcstruct} @*
@seealso{foreign-slot-names} @*
@seealso{foreign-slot-pointer} @*
@seealso{foreign-slot-value}
@c ===================================================================
@c FOREIGN-SLOT-POINTER
@page
@node foreign-slot-pointer, foreign-slot-value, foreign-slot-offset, Foreign Types
@heading foreign-slot-pointer
@subheading Syntax
@Function{foreign-slot-pointer ptr type slot-name @res{} pointer}
@subheading Arguments and Values
@table @var
@item ptr
A pointer to a structure.
@item type
A foreign structure type.
@item slot-names
A slot name in the @var{type}.
@item pointer
A pointer to the slot @var{slot-name}.
@end table
@subheading Description
Returns a pointer to the location of the slot @var{slot-name} in a
foreign object of type @var{type} at @var{ptr}. The returned pointer
points inside the structure. Both the pointer and the memory it points
to have the same extent as @var{ptr}.
For aggregate slots, this is the same value returned by
@code{foreign-slot-value}.
@subheading Examples
@lisp
(defcstruct point
"Pointer structure."
(x :int)
(y :int))
CFFI> (with-foreign-object (ptr '(:struct point))
(foreign-slot-pointer ptr '(:struct point) 'x))
@result{} #<FOREIGN-ADDRESS #xBFFF6E60>
;; @lispcmt{Note: the exact pointer representation varies from lisp to lisp.}
@end lisp
@subheading See Also
@seealso{defcstruct} @*
@seealso{foreign-slot-value} @*
@seealso{foreign-slot-names} @*
@seealso{foreign-slot-offset}
@c ===================================================================
@c FOREIGN-SLOT-VALUE
@page
@node foreign-slot-value, foreign-type-alignment, foreign-slot-pointer, Foreign Types
@heading foreign-slot-value
@subheading Syntax
@Accessor{foreign-slot-value ptr type slot-name @res{} object}
@subheading Arguments and Values
@table @var
@item ptr
A pointer to a structure.
@item type
A foreign structure type.
@item slot-name
A symbol naming a slot in the structure type.
@item object
The object contained in the slot specified by @var{slot-name}.
@end table
@subheading Description
For simple slots, @code{foreign-slot-value} returns the value of the
object, such as a Lisp integer or pointer. In C, this would be
expressed as @code{ptr->slot}.
For aggregate slots, a pointer inside the structure to the beginning
of the slot's data is returned. In C, this would be expressed as
@code{&ptr->slot}. This pointer and the memory it points to have the
same extent as @var{ptr}.
There are compiler macros for @code{foreign-slot-value} and its
@code{setf} expansion that open code the memory access when
@var{type} and @var{slot-names} are constant at compile-time.
@subheading Examples
@lisp
(defcstruct point
"Pointer structure."
(x :int)
(y :int))
CFFI> (with-foreign-object (ptr '(:struct point))
;; @lispcmt{Initialize the slots}
(setf (foreign-slot-value ptr '(:struct point) 'x) 42
(foreign-slot-value ptr '(:struct point) 'y) 42)
;; @lispcmt{Return a list with the coordinates}
(with-foreign-slots ((x y) ptr (:struct point))
(list x y)))
@result{} (42 42)
@end lisp
@subheading See Also
@seealso{defcstruct} @*
@seealso{foreign-slot-names} @*
@seealso{foreign-slot-offset} @*
@seealso{foreign-slot-pointer} @*
@seealso{with-foreign-slots}
@c ===================================================================
@c FOREIGN-TYPE-ALIGNMENT
@page
@node foreign-type-alignment, foreign-type-size, foreign-slot-value, Foreign Types
@heading foreign-type-alignment
@subheading Syntax
@c XXX: This is actually a generic function.
@Function{foreign-type-alignment type @res{} alignment}
@subheading Arguments and Values
@table @var
@item type
A foreign type.
@item alignment
An integer.
@end table
@subheading Description
The function @code{foreign-type-alignment} returns the
@var{alignment} of @var{type} in bytes.
@subheading Examples
@lisp
CFFI> (foreign-type-alignment :char)
@result{} 1
CFFI> (foreign-type-alignment :short)
@result{} 2
CFFI> (foreign-type-alignment :int)
@result{} 4
@end lisp
@lisp
(defcstruct foo
(a :char))
CFFI> (foreign-type-alignment '(:struct foo))
@result{} 1
@end lisp
@subheading See Also
@seealso{foreign-type-size}
@c ===================================================================
@c FOREIGN-TYPE-SIZE
@page
@node foreign-type-size, free-converted-object, foreign-type-alignment, Foreign Types
@heading foreign-type-size
@subheading Syntax
@c XXX: this is actually a generic function.
@Function{foreign-type-size type @res{} size}
@subheading Arguments and Values
@table @var
@item type
A foreign type.
@item size
An integer.
@end table
@subheading Description
The function @code{foreign-type-size} return the @var{size} of
@var{type} in bytes. This includes any padding within and following
the in-memory representation as needed to create an array of
@var{type} objects.
@subheading Examples
@lisp
(defcstruct foo
(a :double)
(c :char))
CFFI> (foreign-type-size :double)
@result{} 8
CFFI> (foreign-type-size :char)
@result{} 1
CFFI> (foreign-type-size '(:struct foo))
@result{} 16
@end lisp
@subheading See Also
@seealso{foreign-type-alignment}
@c ===================================================================
@c FREE-CONVERTED-OBJECT
@page
@node free-converted-object, free-translated-object, foreign-type-size, Foreign Types
@heading free-converted-object
@subheading Syntax
@Function{free-converted-object foreign-value type params}
@subheading Arguments and Values
@table @var
@item foreign-value
The C object to be freed.
@item type
A @cffi{} type specifier.
@item params
The state returned as the second value from @code{convert-to-foreign};
used to implement the third argument to @code{free-translated-object}.
@end table
@subheading Description
The return value is unspecified.
This is an external interface to the type translation facility. In
the implementation, all foreign functions are ultimately defined as
type translation wrappers around primitive foreign function
invocations.
This function is available mostly for inspection of the type
translation process, and possibly optimization of special cases of
your foreign function calls.
Its behavior is better described under @code{free-translated-object}'s
documentation.
@subheading Examples
@lisp
CFFI-USER> (convert-to-foreign "a boat" :string)
@result{} #<FOREIGN-ADDRESS #x097ACDC0>
@result{} T
CFFI-USER> (free-converted-object * :string t)
@result{} NIL
@end lisp
@subheading See Also
@seealso{convert-from-foreign} @*
@seealso{convert-to-foreign} @*
@seealso{free-translated-object}
@c ===================================================================
@c FREE-TRANSLATED-OBJECT
@c TODO: update
@page
@node free-translated-object, translate-from-foreign, free-converted-object, Foreign Types
@heading free-translated-object
@subheading Syntax
@GenericFunction{free-translated-object value type-name param}
@subheading Arguments and Values
@table @var
@item pointer
The foreign value returned by @code{translate-to-foreign}.
@item type-name
A symbol naming a foreign type defined by @code{defctype}.
@item param
The second value, if any, returned by @code{translate-to-foreign}.
@end table
@subheading Description
This generic function may be specialized by user code to perform
automatic deallocation of foreign objects as they are passed to C
functions.
Any methods defined on this generic function must EQL-specialize the
@var{type-name} parameter on a symbol defined as a foreign type by
the @code{defctype} macro.
@subheading See Also
@seealso{Foreign Type Translators} @*
@seealso{translate-to-foreign}
@c ===================================================================
@c TRANSLATE-FROM-FOREIGN
@c TODO: update
@page
@node translate-from-foreign, translate-to-foreign, free-translated-object, Foreign Types
@heading translate-from-foreign
@subheading Syntax
@GenericFunction{translate-from-foreign foreign-value type-name @
@res{} lisp-value}
@subheading Arguments and Values
@table @var
@item foreign-value
The foreign value to convert to a Lisp object.
@item type-name
A symbol naming a foreign type defined by @code{defctype}.
@item lisp-value
The lisp value to pass in place of @code{foreign-value} to Lisp code.
@end table
@subheading Description
This generic function is invoked by @cffi{} to convert a foreign value to
a Lisp value, such as when returning from a foreign function, passing
arguments to a callback function, or accessing a foreign variable.
To extend the @cffi{} type system by performing custom translations, this
method may be specialized by @sc{eql}-specializing @code{type-name} on a
symbol naming a foreign type defined with @code{defctype}. This
method should return the appropriate Lisp value to use in place of the
foreign value.
The results are undefined if the @code{type-name} parameter is
specialized in any way except an @sc{eql} specializer on a foreign type
defined with @code{defctype}. Specifically, translations may not be
defined for built-in types.
@subheading See Also
@seealso{Foreign Type Translators} @*
@seealso{translate-to-foreign} @*
@seealso{free-translated-object}
@c ===================================================================
@c TRANSLATE-TO-FOREIGN
@c TODO: update
@page
@node translate-to-foreign, translate-into-foreign-memory, translate-from-foreign, Foreign Types
@heading translate-to-foreign
@subheading Syntax
@GenericFunction{translate-to-foreign lisp-value type-name @
@res{} foreign-value, alloc-param}
@subheading Arguments and Values
@table @var
@item lisp-value
The Lisp value to convert to foreign representation.
@item type-name
A symbol naming a foreign type defined by @code{defctype}.
@item foreign-value
The foreign value to pass in place of @code{lisp-value} to foreign code.
@item alloc-param
If present, this value will be passed to
@code{free-translated-object}.
@end table
@subheading Description
This generic function is invoked by @cffi{} to convert a Lisp value to a
foreign value, such as when passing arguments to a foreign function,
returning a value from a callback, or setting a foreign variable. A
``foreign value'' is one appropriate for passing to the next-lowest
translator, including the low-level translators that are ultimately
invoked invisibly with @cffi{}.
To extend the @cffi{} type system by performing custom translations, this
method may be specialized by @sc{eql}-specializing @code{type-name} on a
symbol naming a foreign type defined with @code{defctype}. This
method should return the appropriate foreign value to use in place of
the Lisp value.
In cases where @cffi{} can determine the lifetime of the foreign object
returned by this method, it will invoke @code{free-translated-object}
on the foreign object at the appropriate time. If
@code{translate-to-foreign} returns a second value, it will be passed
as the @code{param} argument to @code{free-translated-object}. This
can be used to establish communication between the allocation and
deallocation methods.
The results are undefined if the @code{type-name} parameter is
specialized in any way except an @sc{eql} specializer on a foreign type
defined with @code{defctype}. Specifically, translations may not be
defined for built-in types.
@subheading See Also
@seealso{Foreign Type Translators} @*
@seealso{translate-from-foreign} @*
@seealso{free-translated-object}
@c ===================================================================
@c TRANSLATE-INTO-FOREIGN-MEMORY
@page
@node translate-into-foreign-memory, with-foreign-slots, translate-to-foreign, Foreign Types
@heading translate-into-foreign-memory
@subheading Syntax
@GenericFunction{translate-into-foreign-memory lisp-value type-name pointer}
@subheading Arguments and Values
@table @var
@item lisp-value
The Lisp value to convert to foreign representation.
@item type-name
A symbol or list @code{(:struct @var{structure-name})} naming a foreign type defined by @code{defctype}.
@item pointer
The foreign pointer where the translated object should be stored.
@end table
@subheading Description
Translate the Lisp value into the foreign memory location given by
pointer. The return value is not used.
@c ===================================================================
@c WITH-FOREIGN-SLOTS
@page
@node with-foreign-slots, , translate-into-foreign-memory, Foreign Types
@heading with-foreign-slots
@subheading Syntax
@Macro{with-foreign-slots (vars ptr type) &body body}
@subheading Arguments and Values
@table @var
@item vars
A list of symbols.
@item ptr
A foreign pointer to a structure.
@item type
A structure type.
@item body
A list of forms to be executed.
@end table
@subheading Description
The @code{with-foreign-slots} macro creates local symbol macros for
each var in @var{vars} to reference foreign slots in @var{ptr} of
@var{type}. It is similar to Common Lisp's @code{with-slots} macro.
@subheading Examples
@lisp
(defcstruct tm
(sec :int)
(min :int)
(hour :int)
(mday :int)
(mon :int)
(year :int)
(wday :int)
(yday :int)
(isdst :boolean)
(zone :string)
(gmtoff :long))
CFFI> (with-foreign-object (time :int)
(setf (mem-ref time :int)
(foreign-funcall "time" :pointer (null-pointer) :int))
(foreign-funcall "gmtime" :pointer time (:pointer (:struct tm))))
@result{} #<A Mac Pointer #x102A30>
CFFI> (with-foreign-slots ((sec min hour mday mon year) * (:struct tm))
(format nil "~A:~A:~A, ~A/~A/~A"
hour min sec (+ 1900 year) mon mday))
@result{} "7:22:47, 2005/8/2"
@end lisp
@subheading See Also
@seealso{defcstruct} @*
@seealso{defcunion} @*
@seealso{foreign-slot-value}
@c ===================================================================
@c CHAPTER: Pointers
@node Pointers, Strings, Foreign Types, Top
@chapter Pointers
All C data in @cffi{} is referenced through pointers. This includes
defined C variables that hold immediate values, and integers.
To see why this is, consider the case of the C integer. It is not
only an arbitrary representation for an integer, congruent to Lisp's
fixnums; the C integer has a specific bit pattern in memory defined by
the C @acronym{ABI}. Lisp has no such constraint on its fixnums;
therefore, it only makes sense to think of fixnums as C integers if
you assume that @cffi{} converts them when necessary, such as when
storing one for use in a C function call, or as the value of a C
variable. This requires defining an area of memory@footnote{The
definition of @dfn{memory} includes the @acronym{CPU} registers.},
represented through an effective address, and storing it there.
Due to this compartmentalization, it only makes sense to manipulate
raw C data in Lisp through pointers to it. For example, while there
may be a Lisp representation of a @code{struct} that is converted to C
at store time, you may only manipulate its raw data through a pointer.
The C compiler does this also, albeit informally.
@menu
* Basic Pointer Operations::
* Allocating Foreign Memory::
* Accessing Foreign Memory::
Dictionary
* foreign-free::
* foreign-alloc::
* foreign-symbol-pointer::
* inc-pointer::
* incf-pointer::
* make-pointer::
* mem-aptr::
* mem-aref::
* mem-ref::
* null-pointer::
* null-pointer-p::
* pointerp::
* pointer-address::
* pointer-eq::
* with-foreign-object::
* with-foreign-objects::
* with-foreign-pointer::
@end menu
@node Basic Pointer Operations, Allocating Foreign Memory, Pointers, Pointers
@section Basic Pointer Operations
Manipulating pointers proper can be accomplished through most of the
other operations defined in the Pointers dictionary, such as
@code{make-pointer}, @code{pointer-address}, and @code{pointer-eq}.
When using them, keep in mind that they merely manipulate the Lisp
representation of pointers, not the values they point to.
@deftp {Lisp Type} foreign-pointer
The pointers' representations differ from implementation to
implementation and have different types. @code{foreign-pointer}
provides a portable type alias to each of these types.
@end deftp
@node Allocating Foreign Memory, Accessing Foreign Memory, Basic Pointer Operations, Pointers
@section Allocating Foreign Memory
@cffi{} provides support for stack and heap C memory allocation.
Stack allocation, done with @code{with-foreign-object}, is sometimes
called ``dynamic'' allocation in Lisp, because memory allocated as
such has dynamic extent, much as with @code{let} bindings of special
variables.
This should not be confused with what C calls ``dynamic'' allocation,
or that done with @code{malloc} and friends. This sort of heap
allocation is done with @code{foreign-alloc}, creating objects that
exist until freed with @code{foreign-free}.
@node Accessing Foreign Memory, foreign-free, Allocating Foreign Memory, Pointers
@section Accessing Foreign Memory
When manipulating raw C data, consider that all pointers are pointing
to an array. When you only want one C value, such as a single
@code{struct}, this array only has one such value. It is worthwhile
to remember that everything is an array, though, because this is also
the semantic that C imposes natively.
C values are accessed as the @code{setf}-able places defined by
@code{mem-aref} and @code{mem-ref}. Given a pointer and a @cffi{}
type (@pxref{Foreign Types}), either of these will dereference the
pointer, translate the C data there back to Lisp, and return the
result of said translation, performing the reverse operation when
@code{setf}-ing. To decide which one to use, consider whether you
would use the array index operator @code{[@var{n}]} or the pointer
dereference @code{*} in C; use @code{mem-aref} for array indexing and
@code{mem-ref} for pointer dereferencing.
@c ===================================================================
@c FOREIGN-FREE
@page
@node foreign-free, foreign-alloc, Accessing Foreign Memory, Pointers
@heading foreign-free
@subheading Syntax
@Function{foreign-free ptr @res{} undefined}
@subheading Arguments and Values
@table @var
@item ptr
A foreign pointer.
@end table
@subheading Description
The @code{foreign-free} function frees a @code{ptr} previously
allocated by @code{foreign-alloc}. The consequences of freeing a given
pointer twice are undefined.
@subheading Examples
@lisp
CFFI> (foreign-alloc :int)
@result{} #<A Mac Pointer #x1022E0>
CFFI> (foreign-free *)
@result{} NIL
@end lisp
@subheading See Also
@seealso{foreign-alloc} @*
@seealso{with-foreign-pointer}
@c ===================================================================
@c FOREIGN-ALLOC
@page
@node foreign-alloc, foreign-symbol-pointer, foreign-free, Pointers
@heading foreign-alloc
@subheading Syntax
@Function{foreign-alloc type &key initial-element initial-contents (count 1) @
null-terminated-p @res{} pointer}
@subheading Arguments and Values
@table @var
@item type
A foreign type.
@item initial-element
A Lisp object.
@item initial-contents
A sequence.
@item count
An integer. Defaults to 1 or the length of @var{initial-contents} if
supplied.
@item null-terminated-p
A boolean, false by default.
@item pointer
A foreign pointer to the newly allocated memory.
@end table
@subheading Description
The @code{foreign-alloc} function allocates enough memory to hold
@var{count} objects of type @var{type} and returns a
@var{pointer}. This memory must be explicitly freed using
@code{foreign-free} once it is no longer needed.
If @var{initial-element} is supplied, it is used to initialize the
@var{count} objects the newly allocated memory holds.
If an @var{initial-contents} sequence is supplied, it must have a
length less than or equal to @var{count} and each of its elements
will be used to initialize the contents of the newly allocated
memory.
If @var{count} is omitted and @var{initial-contents} is specified, it
will default to @code{(length @var{initial-contents})}.
@var{initial-element} and @var{initial-contents} are mutually
exclusive.
When @var{null-terminated-p} is true,
@code{(1+ (max @var{count} (length @var{initial-contents})))} elements
are allocated and the last one is set to @code{NULL}. Note that in
this case @var{type} must be a pointer type (ie. a type that
canonicalizes to @code{:pointer}), otherwise an error is signaled.
@subheading Examples
@lisp
CFFI> (foreign-alloc :char)
@result{} #<A Mac Pointer #x102D80> ; @lispcmt{A pointer to 1 byte of memory.}
CFFI> (foreign-alloc :char :count 20)
@result{} #<A Mac Pointer #x1024A0> ; @lispcmt{A pointer to 20 bytes of memory.}
CFFI> (foreign-alloc :int :initial-element 12)
@result{} #<A Mac Pointer #x1028B0>
CFFI> (mem-ref * :int)
@result{} 12
CFFI> (foreign-alloc :int :initial-contents '(1 2 3))
@result{} #<A Mac Pointer #x102950>
CFFI> (loop for i from 0 below 3
collect (mem-aref * :int i))
@result{} (1 2 3)
CFFI> (foreign-alloc :int :initial-contents #(1 2 3))
@result{} #<A Mac Pointer #x102960>
CFFI> (loop for i from 0 below 3
collect (mem-aref * :int i))
@result{} (1 2 3)
;;; @lispcmt{Allocate a char** pointer that points to newly allocated memory}
;;; @lispcmt{by the :string type translator for the string "foo".}
CFFI> (foreign-alloc :string :initial-element "foo")
@result{} #<A Mac Pointer #x102C40>
@end lisp
@lisp
;;; @lispcmt{Allocate a null-terminated array of strings.}
;;; @lispcmt{(Note: FOREIGN-STRING-TO-LISP returns NIL when passed a null pointer)}
CFFI> (foreign-alloc :string
:initial-contents '("foo" "bar" "baz")
:null-terminated-p t)
@result{} #<A Mac Pointer #x102D20>
CFFI> (loop for i from 0 below 4
collect (mem-aref * :string i))
@result{} ("foo" "bar" "baz" NIL)
CFFI> (progn
(dotimes (i 3)
(foreign-free (mem-aref ** :pointer i)))
(foreign-free **))
@result{} nil
@end lisp
@subheading See Also
@seealso{foreign-free} @*
@seealso{with-foreign-object} @*
@seealso{with-foreign-pointer}
@c ===================================================================
@c FOREIGN-SYMBOL-POINTER
@page
@node foreign-symbol-pointer, inc-pointer, foreign-alloc, Pointers
@heading foreign-symbol-pointer
@subheading Syntax
@Function{foreign-symbol-pointer foreign-name &key library @res{} pointer}
@subheading Arguments and Values
@table @var
@item foreign-name
A string.
@item pointer
A foreign pointer, or @code{nil}.
@item library
A Lisp symbol or an instance of @code{foreign-library}.
@end table
@subheading Description
The function @code{foreign-symbol-pointer} will return a foreign
pointer corresponding to the foreign symbol denoted by the string
@var{foreign-name}. If a foreign symbol named @var{foreign-name}
doesn't exist, @code{nil} is returned.
ABI name manglings will be performed on @var{foreign-name} by
@code{foreign-symbol-pointer} if necessary. (eg: adding a leading
underscore on darwin/ppc)
@var{library} should name a foreign library as defined by
@code{define-foreign-library}, @code{:default} (which is the default)
or an instance of @code{foreign-library} as returned by
@code{load-foreign-library}.
@strong{Important note:} do not keep these pointers across saved Lisp
cores as the foreign-library may move across sessions.
@subheading Examples
@lisp
CFFI> (foreign-symbol-pointer "errno")
@result{} #<A Mac Pointer #xA0008130>
CFFI> (foreign-symbol-pointer "strerror")
@result{} #<A Mac Pointer #x9002D0F8>
CFFI> (foreign-funcall-pointer * () :int (mem-ref ** :int) :string)
@result{} "No such file or directory"
CFFI> (foreign-symbol-pointer "inexistent symbol")
@result{} NIL
@end lisp
@subheading See Also
@seealso{defcvar}
@c ===================================================================
@c INC-POINTER
@page
@node inc-pointer, incf-pointer, foreign-symbol-pointer, Pointers
@heading inc-pointer
@subheading Syntax
@Function{inc-pointer pointer offset @res{} new-pointer}
@subheading Arguments and Values
@table @var
@item pointer
@itemx new-pointer
A foreign pointer.
@item offset
An integer.
@end table
@subheading Description
The function @code{inc-pointer} will return a @var{new-pointer} pointing
@var{offset} bytes past @var{pointer}.
@subheading Examples
@lisp
CFFI> (foreign-string-alloc "Common Lisp")
@result{} #<A Mac Pointer #x102EA0>
CFFI> (inc-pointer * 7)
@result{} #<A Mac Pointer #x102EA7>
CFFI> (foreign-string-to-lisp *)
@result{} "Lisp"
@end lisp
@subheading See Also
@seealso{incf-pointer} @*
@seealso{make-pointer} @*
@seealso{pointerp} @*
@seealso{null-pointer} @*
@seealso{null-pointer-p}
@c ===================================================================
@c INCF-POINTER
@page
@node incf-pointer, make-pointer, inc-pointer, Pointers
@heading incf-pointer
@subheading Syntax
@Macro{incf-pointer place &optional (offset 1) @res{} new-pointer}
@subheading Arguments and Values
@table @var
@item place
A @code{setf} place.
@item new-pointer
A foreign pointer.
@item offset
An integer.
@end table
@subheading Description
The @code{incf-pointer} macro takes the foreign pointer from
@var{place} and creates a @var{new-pointer} incremented by
@var{offset} bytes and which is stored in @var{place}.
@subheading Examples
@lisp
CFFI> (defparameter *two-words* (foreign-string-alloc "Common Lisp"))
@result{} *TWO-WORDS*
CFFI> (defparameter *one-word* *two-words*)
@result{} *ONE-WORD*
CFFI> (incf-pointer *one-word* 7)
@result{} #.(SB-SYS:INT-SAP #X00600457)
CFFI> (foreign-string-to-lisp *one-word*)
@result{} "Lisp"
CFFI> (foreign-string-to-lisp *two-words*)
@result{} "Common Lisp"
@end lisp
@subheading See Also
@seealso{inc-pointer} @*
@seealso{make-pointer} @*
@seealso{pointerp} @*
@seealso{null-pointer} @*
@seealso{null-pointer-p}
@c ===================================================================
@c MAKE-POINTER
@page
@node make-pointer, mem-aptr, incf-pointer, Pointers
@heading make-pointer
@subheading Syntax
@Function{make-pointer address @res{} ptr}
@subheading Arguments and Values
@table @var
@item address
An integer.
@item ptr
A foreign pointer.
@end table
@subheading Description
The function @code{make-pointer} will return a foreign pointer
pointing to @var{address}.
@subheading Examples
@lisp
CFFI> (make-pointer 42)
@result{} #<FOREIGN-ADDRESS #x0000002A>
CFFI> (pointerp *)
@result{} T
CFFI> (pointer-address **)
@result{} 42
CFFI> (inc-pointer *** -42)
@result{} #<FOREIGN-ADDRESS #x00000000>
CFFI> (null-pointer-p *)
@result{} T
CFFI> (typep ** 'foreign-pointer)
@result{} T
@end lisp
@subheading See Also
@seealso{inc-pointer} @*
@seealso{null-pointer} @*
@seealso{null-pointer-p} @*
@seealso{pointerp} @*
@seealso{pointer-address} @*
@seealso{pointer-eq} @*
@seealso{mem-ref}
@c ===================================================================
@c MEM-APTR
@page
@node mem-aptr, mem-aref, make-pointer, Pointers
@heading mem-aptr
@subheading Syntax
@Accessor{mem-aptr ptr type &optional (index 0)}
@subheading Arguments and Values
@table @var
@item ptr
A foreign pointer.
@item type
A foreign type.
@item index
An integer.
@item new-value
A Lisp value compatible with @var{type}.
@end table
@subheading Description
The @code{mem-aptr} function finds the pointer to an element of the array.
@lisp
(mem-aptr ptr type n)
;; @lispcmt{is identical to:}
(inc-pointer ptr (* n (foreign-type-size type)))
@end lisp
@subheading Examples
@lisp
CFFI> (with-foreign-string (str "Hello, foreign world!")
(mem-aptr str :char 6))
@result{} #.(SB-SYS:INT-SAP #X0063D4B6)
@end lisp
@c ===================================================================
@c MEM-AREF
@page
@node mem-aref, mem-ref, mem-aptr, Pointers
@heading mem-aref
@subheading Syntax
@Accessor{mem-aref ptr type &optional (index 0)}
(setf (@strong{mem-aref} @emph{ptr type &optional (index 0)) new-value})
@subheading Arguments and Values
@table @var
@item ptr
A foreign pointer.
@item type
A foreign type.
@item index
An integer.
@item new-value
A Lisp value compatible with @var{type}.
@end table
@subheading Description
The @code{mem-aref} function is similar to @code{mem-ref} but will
automatically calculate the offset from an @var{index}.
@lisp
(mem-aref ptr type n)
;; @lispcmt{is identical to:}
(mem-ref ptr type (* n (foreign-type-size type)))
@end lisp
@subheading Examples
@lisp
CFFI> (with-foreign-string (str "Hello, foreign world!")
(mem-aref str :char 6))
@result{} 32
CFFI> (code-char *)
@result{} #\Space
CFFI> (with-foreign-object (array :int 10)
(loop for i below 10
do (setf (mem-aref array :int i) (random 100)))
(loop for i below 10 collect (mem-aref array :int i)))
@result{} (22 7 22 52 69 1 46 93 90 65)
@end lisp
@subheading Compatibility Note
For compatibility with older versions of CFFI, @ref{mem-aref} will
produce a pointer for the deprecated bare structure specification, but
it is consistent with other types for the current specification form
@code{(:struct @var{structure-name})} and provides a Lisp object
translated from the structure (by default a plist). In order to obtain
the pointer, you should use the new function @ref{mem-aptr}.
@subheading See Also
@seealso{mem-ref} @*
@seealso{mem-aptr}
@c ===================================================================
@c MEM-REF
@page
@node mem-ref, null-pointer, mem-aref, Pointers
@heading mem-ref
@subheading Syntax
@Accessor{mem-ref ptr type &optional offset @res{} object}
@subheading Arguments and Values
@table @var
@item ptr
A pointer.
@item type
A foreign type.
@item offset
An integer (in byte units).
@item object
The value @var{ptr} points to.
@end table
@subheading Description
@subheading Examples
@lisp
CFFI> (with-foreign-string (ptr "Saluton")
(setf (mem-ref ptr :char 3) (char-code #\a))
(loop for i from 0 below 8
collect (code-char (mem-ref ptr :char i))))
@result{} (#\S #\a #\l #\a #\t #\o #\n #\Null)
CFFI> (setq ptr-to-int (foreign-alloc :int))
@result{} #<A Mac Pointer #x1047D0>
CFFI> (mem-ref ptr-to-int :int)
@result{} 1054619
CFFI> (setf (mem-ref ptr-to-int :int) 1984)
@result{} 1984
CFFI> (mem-ref ptr-to-int :int)
@result{} 1984
@end lisp
@subheading See Also
@seealso{mem-aref}
@c ===================================================================
@c NULL-POINTER
@page
@node null-pointer, null-pointer-p, mem-ref, Pointers
@heading null-pointer
@subheading Syntax
@Function{null-pointer @res{} pointer}
@subheading Arguments and Values
@table @var
@item pointer
A @code{NULL} pointer.
@end table
@subheading Description
The function @code{null-pointer} returns a null pointer.
@subheading Examples
@lisp
CFFI> (null-pointer)
@result{} #<A Null Mac Pointer>
CFFI> (pointerp *)
@result{} T
@end lisp
@subheading See Also
@seealso{null-pointer-p} @*
@seealso{make-pointer}
@c ===================================================================
@c NULL-POINTER-P
@page
@node null-pointer-p, pointerp, null-pointer, Pointers
@heading null-pointer-p
@subheading Syntax
@Function{null-pointer-p ptr @res{} boolean}
@subheading Arguments and Values
@table @var
@item ptr
A foreign pointer that may be a null pointer.
@item boolean
@code{T} or @code{NIL}.
@end table
@subheading Description
The function @code{null-pointer-p} returns true if @var{ptr} is a null
pointer and false otherwise.
@subheading Examples
@lisp
CFFI> (null-pointer-p (null-pointer))
@result{} T
@end lisp
@lisp
(defun contains-str-p (big little)
(not (null-pointer-p
(foreign-funcall "strstr" :string big :string little :pointer))))
CFFI> (contains-str-p "Popcorns" "corn")
@result{} T
CFFI> (contains-str-p "Popcorns" "salt")
@result{} NIL
@end lisp
@subheading See Also
@seealso{null-pointer} @*
@seealso{pointerp}
@c ===================================================================
@c POINTERP
@page
@node pointerp, pointer-address, null-pointer-p, Pointers
@heading pointerp
@subheading Syntax
@Function{pointerp ptr @res{} boolean}
@subheading Arguments and Values
@table @var
@item ptr
An object that may be a foreign pointer.
@item boolean
@code{T} or @code{NIL}.
@end table
@subheading Description
The function @code{pointerp} returns true if @var{ptr} is a foreign
pointer and false otherwise.
@subheading Implementation-specific Notes
In Allegro CL, foreign pointers are integers thus in this
implementation @code{pointerp} will return true for any ordinary integer.
@subheading Examples
@lisp
CFFI> (foreign-alloc 32)
@result{} #<A Mac Pointer #x102D20>
CFFI> (pointerp *)
@result{} T
CFFI> (pointerp "this is not a pointer")
@result{} NIL
@end lisp
@subheading See Also
@seealso{make-pointer}
@seealso{null-pointer-p}
@c ===================================================================
@c POINTER-ADDRESS
@page
@node pointer-address, pointer-eq, pointerp, Pointers
@heading pointer-address
@subheading Syntax
@Function{pointer-address ptr @res{} address}
@subheading Arguments and Values
@table @var
@item ptr
A foreign pointer.
@item address
An integer.
@end table
@subheading Description
The function @code{pointer-address} will return the @var{address} of
a foreign pointer @var{ptr}.
@subheading Examples
@lisp
CFFI> (pointer-address (null-pointer))
@result{} 0
CFFI> (pointer-address (make-pointer 123))
@result{} 123
@end lisp
@subheading See Also
@seealso{make-pointer} @*
@seealso{inc-pointer} @*
@seealso{null-pointer} @*
@seealso{null-pointer-p} @*
@seealso{pointerp} @*
@seealso{pointer-eq} @*
@seealso{mem-ref}
@c ===================================================================
@c POINTER-EQ
@page
@node pointer-eq, with-foreign-object, pointer-address, Pointers
@heading pointer-eq
@subheading Syntax
@Function{pointer-eq ptr1 ptr2 @res{} boolean}
@subheading Arguments and Values
@table @var
@item ptr1
@itemx ptr2
A foreign pointer.
@item boolean
@code{T} or @code{NIL}.
@end table
@subheading Description
The function @code{pointer-eq} returns true if @var{ptr1} and
@var{ptr2} point to the same memory address and false otherwise.
@subheading Implementation-specific Notes
The representation of foreign pointers varies across the various Lisp
implementations as does the behaviour of the built-in Common Lisp
equality predicates. Comparing two pointers that point to the same
address with @code{EQ} Lisps will return true on some Lisps, others require
more general predicates like @code{EQL} or @code{EQUALP} and finally
some will return false using any of these predicates. Therefore, for
portability, you should use @code{POINTER-EQ}.
@subheading Examples
This is an example using @acronym{SBCL}, see the
implementation-specific notes above.
@lisp
CFFI> (eql (null-pointer) (null-pointer))
@result{} NIL
CFFI> (pointer-eq (null-pointer) (null-pointer))
@result{} T
@end lisp
@subheading See Also
@seealso{inc-pointer}
@c ===================================================================
@c WITH-FOREIGN-OBJECT
@page
@node with-foreign-object, with-foreign-pointer, pointer-eq, Pointers
@heading with-foreign-object, with-foreign-objects
@subheading Syntax
@Macro{with-foreign-object (var type &optional count) &body body}
@anchor{with-foreign-objects}
@Macro{with-foreign-objects (bindings) &body body}
bindings ::= @{(var type &optional count)@}*
@subheading Arguments and Values
@table @var
@item var
A symbol.
@item type
A foreign type, evaluated.
@item count
An integer.
@end table
@subheading Description
The macros @code{with-foreign-object} and @code{with-foreign-objects}
bind @var{var} to a pointer to @var{count} newly allocated objects
of type @var{type} during @var{body}. The buffer has dynamic extent
and may be stack allocated if supported by the host Lisp.
@subheading Examples
@lisp
CFFI> (with-foreign-object (array :int 10)
(dotimes (i 10)
(setf (mem-aref array :int i) (random 100)))
(loop for i below 10
collect (mem-aref array :int i)))
@result{} (22 7 22 52 69 1 46 93 90 65)
@end lisp
@subheading See Also
@seealso{foreign-alloc}
@c ===================================================================
@c WITH-FOREIGN-POINTER
@page
@node with-foreign-pointer, , with-foreign-object, Pointers
@heading with-foreign-pointer
@subheading Syntax
@Macro{with-foreign-pointer (var size &optional size-var) &body body}
@subheading Arguments and Values
@table @var
@item var
@itemx size-var
A symbol.
@item size
An integer.
@item body
A list of forms to be executed.
@end table
@subheading Description
The @code{with-foreign-pointer} macro, binds @var{var} to @var{size}
bytes of foreign memory during @var{body}. The pointer in @var{var}
is invalid beyond the dynamic extend of @var{body} and may be
stack-allocated if supported by the implementation.
If @var{size-var} is supplied, it will be bound to @var{size} during
@var{body}.
@subheading Examples
@lisp
CFFI> (with-foreign-pointer (string 4 size)
(setf (mem-ref string :char (1- size)) 0)
(lisp-string-to-foreign "Popcorns" string size)
(loop for i from 0 below size
collect (code-char (mem-ref string :char i))))
@result{} (#\P #\o #\p #\Null)
@end lisp
@subheading See Also
@seealso{foreign-alloc} @*
@seealso{foreign-free}
@c ===================================================================
@c CHAPTER: Strings
@node Strings, Variables, Pointers, Top
@chapter Strings
As with many languages, Lisp and C have special support for logical
arrays of characters, going so far as to give them a special name,
``strings''. In that spirit, @cffi{} provides special support for
translating between Lisp and C strings.
The @code{:string} type and the symbols related below also serve as an
example of what you can do portably with @cffi{}; were it not
included, you could write an equally functional @file{strings.lisp}
without referring to any implementation-specific symbols.
@menu
Dictionary
* *default-foreign-encoding*::
* foreign-string-alloc::
* foreign-string-free::
* foreign-string-to-lisp::
* lisp-string-to-foreign::
* with-foreign-string::
* with-foreign-strings::
* with-foreign-pointer-as-string::
@end menu
@c ===================================================================
@c *DEFAULT-FOREIGN-ENCODING*
@page
@node *default-foreign-encoding*, foreign-string-alloc, Strings, Strings
@heading *default-foreign-encoding*
@subheading Syntax
@Variable{*default-foreign-encoding*}
@subheading Value type
A keyword.
@subheading Initial value
@code{:utf-8}
@subheading Description
This special variable holds the default foreign encoding.
@subheading Examples
@lisp
CFFI> *default-foreign-encoding*
:utf-8
CFFI> (foreign-funcall "strdup" (:string :encoding :utf-16) "foo" :string)
"f"
CFFI> (let ((*default-foreign-encoding* :utf-16))
(foreign-funcall "strdup" (:string :encoding :utf-16) "foo" :string))
"foo"
@end lisp
@subheading See also
@seealso{Other Types} (@code{:string} type) @*
@seealso{foreign-string-alloc} @*
@seealso{foreign-string-to-lisp} @*
@seealso{lisp-string-to-foreign} @*
@seealso{with-foreign-string} @*
@seealso{with-foreign-pointer-as-string}
@c ===================================================================
@c FOREIGN-STRING-ALLOC
@page
@node foreign-string-alloc, foreign-string-free, *default-foreign-encoding*, Strings
@heading foreign-string-alloc
@subheading Syntax
@Function{foreign-string-alloc string &key encoding null-terminated-p @
start end @res{} pointer}
@subheading Arguments and Values
@table @emph
@item @var{string}
A Lisp string.
@item @var{encoding}
Foreign encoding. Defaults to @code{*default-foreign-encoding*}.
@item @var{null-terminated-p}
Boolean, defaults to true.
@item @var{start}, @var{end}
Bounding index designators of @var{string}. 0 and @code{nil}, by
default.
@item @var{pointer}
A pointer to the newly allocated foreign string.
@end table
@subheading Description
The @code{foreign-string-alloc} function allocates foreign memory
holding a copy of @var{string} converted using the specified
@var{encoding}. @var{Start} specifies an offset into @var{string} and
@var{end} marks the position following the last element of the foreign
string.
This string must be freed with @code{foreign-string-free}.
If @var{null-terminated-p} is false, the string will not be
null-terminated.
@subheading Examples
@lisp
CFFI> (defparameter *str* (foreign-string-alloc "Hello, foreign world!"))
@result{} #<FOREIGN-ADDRESS #x00400560>
CFFI> (foreign-funcall "strlen" :pointer *str* :int)
@result{} 21
@end lisp
@subheading See Also
@seealso{foreign-string-free} @*
@seealso{with-foreign-string}
@c @seealso{:string}
@c ===================================================================
@c FOREIGN-STRING-FREE
@page
@node foreign-string-free, foreign-string-to-lisp, foreign-string-alloc, Strings
@heading foreign-string-free
@subheading Syntax
@Function{foreign-string-free pointer}
@subheading Arguments and Values
@table @var
@item pointer
A pointer to a string allocated by @code{foreign-string-alloc}.
@end table
@subheading Description
The @code{foreign-string-free} function frees a foreign string
allocated by @code{foreign-string-alloc}.
@subheading Examples
@subheading See Also
@seealso{foreign-string-alloc}
@c ===================================================================
@c FOREIGN-STRING-TO-LISP
@page
@node foreign-string-to-lisp, lisp-string-to-foreign, foreign-string-free, Strings
@heading foreign-string-to-lisp
@subheading Syntax
@Function{foreign-string-to-lisp ptr &key offset count max-chars @
encoding @res{} string}
@subheading Arguments and Values
@table @var
@item ptr
A pointer.
@item offset
An integer greater than or equal to 0. Defauls to 0.
@item count
Either @code{nil} (the default), or an integer greater than or equal to 0.
@item max-chars
An integer greater than or equal to 0.
@code{(1- array-total-size-limit)}, by default.
@item encoding
Foreign encoding. Defaults to @code{*default-foreign-encoding*}.
@item string
A Lisp string.
@end table
@subheading Description
The @code{foreign-string-to-lisp} function converts at most
@var{count} octets from @var{ptr} into a Lisp string, using the
defined @var{encoding}.
If @var{count} is @code{nil} (the default), characters are copied
until @var{max-chars} is reached or a @code{NULL} character is found.
If @var{ptr} is a null pointer, returns @code{nil}.
Note that the @code{:string} type will automatically convert between
Lisp strings and foreign strings.
@subheading Examples
@lisp
CFFI> (foreign-funcall "getenv" :string "HOME" :pointer)
@result{} #<FOREIGN-ADDRESS #xBFFFFFD5>
CFFI> (foreign-string-to-lisp *)
@result{} "/Users/luis"
@end lisp
@subheading See Also
@seealso{lisp-string-to-foreign} @*
@seealso{foreign-string-alloc}
@c @seealso{:string}
@c ===================================================================
@c LISP-STRING-TO-FOREIGN
@page
@node lisp-string-to-foreign, with-foreign-string, foreign-string-to-lisp, Strings
@heading lisp-string-to-foreign
@subheading Syntax
@Function{lisp-string-to-foreign string buffer bufsize &key start @
end offset encoding @res{} buffer}
@subheading Arguments and Values
@table @emph
@item @var{string}
A Lisp string.
@item @var{buffer}
A foreign pointer.
@item @var{bufsize}
An integer.
@item @var{start}, @var{end}
Bounding index designators of @var{string}. 0 and @code{nil}, by
default.
@item @var{offset}
An integer greater than or equal to 0. Defauls to 0.
@item @var{encoding}
Foreign encoding. Defaults to @code{*default-foreign-encoding*}.
@end table
@subheading Description
The @code{lisp-string-to-foreign} function copies at most
@var{bufsize}-1 octets from a Lisp @var{string} using the specified
@var{encoding} into @var{buffer}+@var{offset}. The foreign string will
be null-terminated.
@var{Start} specifies an offset into @var{string} and
@var{end} marks the position following the last element of the foreign
string.
@subheading Examples
@lisp
CFFI> (with-foreign-pointer-as-string (str 255)
(lisp-string-to-foreign "Hello, foreign world!" str 6))
@result{} "Hello"
@end lisp
@subheading See Also
@seealso{foreign-string-alloc} @*
@seealso{foreign-string-to-lisp} @*
@seealso{with-foreign-pointer-as-string}
@c ===================================================================
@c WITH-FOREIGN-STRING
@page
@node with-foreign-string, with-foreign-pointer-as-string, lisp-string-to-foreign, Strings
@heading with-foreign-string, with-foreign-strings
@subheading Syntax
@Macro{with-foreign-string (var-or-vars string &rest args) &body body}
@anchor{with-foreign-strings}
@Macro{with-foreign-strings (bindings) &body body}
var-or-vars ::= var | (var &optional octet-size-var)
bindings ::= @{(var-or-vars string &rest args)@}*
@subheading Arguments and Values
@table @emph
@item @var{var}, @var{byte-size-var}
A symbol.
@item @var{string}
A Lisp string.
@item @var{body}
A list of forms to be executed.
@end table
@subheading Description
The @code{with-foreign-string} macro will bind @var{var} to a newly
allocated foreign string containing @var{string}. @var{Args} is passed
to the underlying @code{foreign-string-alloc} call.
If @var{octet-size-var} is provided, it will be bound the length of
foreign string in octets including the null terminator.
@subheading Examples
@lisp
CFFI> (with-foreign-string (foo "12345")
(foreign-funcall "strlen" :pointer foo :int))
@result{} 5
CFFI> (let ((array (coerce #(84 117 114 97 110 103 97)
'(array (unsigned-byte 8)))))
(with-foreign-string (foreign-string array)
(foreign-string-to-lisp foreign-string)))
@result{} "Turanga"
@end lisp
@subheading See Also
@seealso{foreign-string-alloc} @*
@seealso{with-foreign-pointer-as-string}
@c ===================================================================
@c WITH-FOREIGN-POINTER-AS-STRING
@page
@node with-foreign-pointer-as-string, , with-foreign-string, Strings
@heading with-foreign-pointer-as-string
@subheading Syntax
@Macro{with-foreign-pointer-as-string (var size &optional size-var @
&rest args) &body body @res{} string}
@subheading Arguments and Values
@table @var
@item var
A symbol.
@item string
A Lisp string.
@item body
List of forms to be executed.
@end table
@subheading Description
The @code{with-foreign-pointer-as-string} macro is similar to
@code{with-foreign-pointer} except that @var{var} is used as the
returned value of an implicit @code{progn} around @var{body}, after
being converted to a Lisp string using the provided @var{args}.
@subheading Examples
@lisp
CFFI> (with-foreign-pointer-as-string (str 6 str-size :encoding :ascii)
(lisp-string-to-foreign "Hello, foreign world!" str str-size))
@result{} "Hello"
@end lisp
@subheading See Also
@seealso{foreign-string-alloc} @*
@seealso{with-foreign-string}
@c ===================================================================
@c CHAPTER: Variables
@node Variables, Functions, Strings, Top
@chapter Variables
@menu
Dictionary
* defcvar::
* get-var-pointer::
@end menu
@c ===================================================================
@c DEFCVAR
@page
@node defcvar, get-var-pointer, Variables, Variables
@heading defcvar
@subheading Syntax
@Macro{defcvar name-and-options type &optional documentation @res{} lisp-name}
@var{name-and-options} ::= name | (name &key read-only (library :default)) @*
@var{name} ::= lisp-name [foreign-name] | foreign-name [lisp-name]
@subheading Arguments and Values
@table @var
@item foreign-name
A string denoting a foreign function.
@item lisp-name
A symbol naming the Lisp function to be created.
@item type
A foreign type.
@item read-only
A boolean.
@item documentation
A Lisp string; not evaluated.
@end table
@subheading Description
The @code{defcvar} macro defines a symbol macro @var{lisp-name} that looks
up @var{foreign-name} and dereferences it acording to @var{type}. It
can also be @code{setf}ed, unless @var{read-only} is true, in which
case an error will be signaled.
When one of @var{lisp-name} or @var{foreign-name} is omitted, the
other is automatically derived using the following rules:
@itemize
@item
Foreign names are converted to Lisp names by uppercasing, replacing
underscores with hyphens, and wrapping around asterisks.
@item
Lisp names are converted to foreign names by lowercasing, replacing
hyphens with underscores, and removing asterisks, if any.
@end itemize
@subheading Examples
@lisp
CFFI> (defcvar "errno" :int)
@result{} *ERRNO*
CFFI> (foreign-funcall "strerror" :int *errno* :string)
@result{} "Inappropriate ioctl for device"
CFFI> (setf *errno* 1)
@result{} 1
CFFI> (foreign-funcall "strerror" :int *errno* :string)
@result{} "Operation not permitted"
@end lisp
Trying to modify a read-only foreign variable:
@lisp
CFFI> (defcvar ("errno" +error-number+ :read-only t) :int)
@result{} +ERROR-NUMBER+
CFFI> (setf +error-number+ 12)
;; @lispcmt{@error{} Trying to modify read-only foreign var: +ERROR-NUMBER+.}
@end lisp
@emph{Note that accessing @code{errno} this way won't work with every
implementation of the C standard library.}
@subheading See Also
@seealso{get-var-pointer}
@c ===================================================================
@c GET-VAR-POINTER
@page
@node get-var-pointer, , defcvar, Variables
@heading get-var-pointer
@subheading Syntax
@Function{get-var-pointer symbol @res{} pointer}
@subheading Arguments and Values
@table @var
@item symbol
A symbol denoting a foreign variable defined with @code{defcvar}.
@item pointer
A foreign pointer.
@end table
@subheading Description
The function @code{get-var-pointer} will return a @var{pointer} to the
foreign global variable @var{symbol} previously defined with
@code{defcvar}.
@subheading Examples
@lisp
CFFI> (defcvar "errno" :int :read-only t)
@result{} *ERRNO*
CFFI> *errno*
@result{} 25
CFFI> (get-var-pointer '*errno*)
@result{} #<A Mac Pointer #xA0008130>
CFFI> (mem-ref * :int)
@result{} 25
@end lisp
@subheading See Also
@seealso{defcvar}
@c ===================================================================
@c CHAPTER: Functions
@node Functions, Libraries, Variables, Top
@chapter Functions
@menu
@c * Defining Foreign Functions::
@c * Calling Foreign Functions::
Dictionary
* defcfun::
* foreign-funcall::
* foreign-funcall-pointer::
* translate-camelcase-name::
* translate-name-from-foreign::
* translate-name-to-foreign::
* translate-underscore-separated-name::
@end menu
@c @node Calling Foreign Functions
@c @section Calling Foreign Functions
@c @node Defining Foreign Functions
@c @section Defining Foreign Functions
@c ===================================================================
@c DEFCFUN
@page
@node defcfun, foreign-funcall, Functions, Functions
@heading defcfun
@subheading Syntax
@Macro{defcfun name-and-options return-type &body [docstring] arguments [&rest] @
@res{} lisp-name}
@var{name-and-options} ::= name | (name &key library convention) @*
@var{name} ::= @var{lisp-name} [@var{foreign-name}] | @var{foreign-name} [@var{lisp-name}] @*
@var{arguments} ::= @{ (arg-name arg-type) @}* @*
@subheading Arguments and Values
@table @var
@item foreign-name
A string denoting a foreign function.
@item lisp-name
A symbol naming the Lisp function to be created.
@item arg-name
A symbol.
@item return-type
@itemx arg-type
A foreign type.
@item convention
One of @code{:cdecl} (default) or @code{:stdcall}.
@item library
A symbol designating a foreign library.
@item docstring
A documentation string.
@end table
@subheading Description
The @code{defcfun} macro provides a declarative interface for defining
Lisp functions that call foreign functions.
When one of @var{lisp-name} or @var{foreign-name} is omitted, the
other is automatically derived using the following rules:
@itemize
@item
Foreign names are converted to Lisp names by uppercasing and replacing
underscores with hyphens.
@item
Lisp names are converted to foreign names by lowercasing and replacing
hyphens with underscores.
@end itemize
If you place the symbol @code{&rest} in the end of the argument list
after the fixed arguments, @code{defcfun} will treat the foreign
function as a @strong{variadic function}. The variadic arguments
should be passed in a way similar to what @code{foreign-funcall} would
expect. Unlike @code{foreign-funcall} though, @code{defcfun} will take
care of doing argument promotion. Note that in this case
@code{defcfun} will generate a Lisp @emph{macro} instead of a
function and will only work for Lisps that support
@code{foreign-funcall.}
If a foreign structure is to be passed or returned by value (that is,
the type is of the form @code{(:struct ...)}), then the cffi-libffi system
must be loaded, which in turn depends on
@uref{http://sourceware.org/libffi/,libffi}, including the header files.
Failure to load that system will result in an error.
Variadic functions cannot at present accept or return structures by
value.
@subheading Examples
@lisp
(defcfun "strlen" :int
"Calculate the length of a string."
(n :string))
CFFI> (strlen "123")
@result{} 3
@end lisp
@lisp
(defcfun ("abs" c-abs) :int (n :int))
CFFI> (c-abs -42)
@result{} 42
@end lisp
Function without arguments:
@lisp
(defcfun "rand" :int)
CFFI> (rand)
@result{} 1804289383
@end lisp
Variadic function example:
@lisp
(defcfun "sprintf" :int
(str :pointer)
(control :string)
&rest)
CFFI> (with-foreign-pointer-as-string (s 100)
(sprintf s "%c %d %.2f %s" :char 90 :short 42 :float pi
:string "super-locrian"))
@result{} "A 42 3.14 super-locrian"
@end lisp
@subheading See Also
@seealso{foreign-funcall} @*
@seealso{foreign-funcall-pointer}
@c ===================================================================
@c FOREIGN-FUNCALL
@page
@node foreign-funcall, foreign-funcall-pointer, defcfun, Functions
@heading foreign-funcall
@subheading Syntax
@Macro{foreign-funcall name-and-options &rest arguments @res{} return-value}
arguments ::= @{ arg-type arg @}* [return-type]
name-and-options ::= name | ( name &key library convention)
@subheading Arguments and Values
@table @var
@item name
A Lisp string.
@item arg-type
A foreign type.
@item arg
An argument of type @var{arg-type}.
@item return-type
A foreign type, @code{:void} by default.
@item return-value
A lisp object.
@item library
A lisp symbol; not evaluated.
@item convention
One of @code{:cdecl} (default) or @code{:stdcall}.
@end table
@subheading Description
The @code{foreign-funcall} macro is the main primitive for calling
foreign functions.
If a foreign structure is to be passed or returned by value (that is,
the type is of the form @code{(:struct ...)}), then the cffi-libffi system
must be loaded, which in turn depends on
@uref{http://sourceware.org/libffi/,libffi}, including the header files.
Failure to load that system will result in an error.
Variadic functions cannot at present accept or return structures by
value.
@emph{Note: The return value of foreign-funcall on functions with a
:void return type is still undefined.}
@subheading Implementation-specific Notes
@itemize
@item
Corman Lisp does not support @code{foreign-funcall}. On
implementations that @strong{don't} support @code{foreign-funcall}
@code{cffi-sys::no-foreign-funcall} will be present in
@code{*features*}. Note: in these Lisps you can still use the
@code{defcfun} interface.
@end itemize
@subheading Examples
@lisp
CFFI> (foreign-funcall "strlen" :string "foo" :int)
@result{} 3
@end lisp
Given the C code:
@example
void print_number(int n)
@{
printf("N: %d\n", n);
@}
@end example
@lisp
CFFI> (foreign-funcall "print_number" :int 123456)
@print{} N: 123456
@result{} NIL
@end lisp
@noindent
Or, equivalently:
@lisp
CFFI> (foreign-funcall "print_number" :int 123456 :void)
@print{} N: 123456
@result{} NIL
@end lisp
@lisp
CFFI> (foreign-funcall "printf" :string (format nil "%s: %d.~%")
:string "So long and thanks for all the fish"
:int 42 :int)
@print{} So long and thanks for all the fish: 42.
@result{} 41
@end lisp
@subheading See Also
@seealso{defcfun} @*
@seealso{foreign-funcall-pointer}
@c ===================================================================
@c FOREIGN-FUNCALL-POINTER
@page
@node foreign-funcall-pointer, translate-camelcase-name, foreign-funcall, Functions
@heading foreign-funcall-pointer
@subheading Syntax
@Macro{foreign-funcall-pointer pointer options &rest arguments @res{} return-value}
arguments ::= @{ arg-type arg @}* [return-type]
options ::= ( &key convention )
@subheading Arguments and Values
@table @var
@item pointer
A foreign pointer.
@item arg-type
A foreign type.
@item arg
An argument of type @var{arg-type}.
@item return-type
A foreign type, @code{:void} by default.
@item return-value
A lisp object.
@item convention
One of @code{:cdecl} (default) or @code{:stdcall}.
@end table
@subheading Description
The @code{foreign-funcall} macro is the main primitive for calling
foreign functions.
@emph{Note: The return value of foreign-funcall on functions with a
:void return type is still undefined.}
@subheading Implementation-specific Notes
@itemize
@item
Corman Lisp does not support @code{foreign-funcall}. On
implementations that @strong{don't} support @code{foreign-funcall}
@code{cffi-sys::no-foreign-funcall} will be present in
@code{*features*}. Note: in these Lisps you can still use the
@code{defcfun} interface.
@end itemize
@subheading Examples
@lisp
CFFI> (foreign-funcall-pointer (foreign-symbol-pointer "abs") ()
:int -42 :int)
@result{} 42
@end lisp
@subheading See Also
@seealso{defcfun} @*
@seealso{foreign-funcall}
@c ===================================================================
@c TRANSLATE-CAMELCASE-NAME
@page
@node translate-camelcase-name, translate-name-from-foreign, foreign-funcall-pointer, Functions
@heading translate-camelcase-name
@subheading Syntax
@Function{translate-camelcase-name name &key upper-initial-p special-words @res{} return-value}
@subheading Arguments and Values
@table @var
@item name
Either a symbol or a string.
@item upper-initial-p
A generalized boolean.
@item special words
A list of strings.
@item return-value
If @var{name} is a symbol, this is a string, and vice versa.
@end table
@subheading Description
@code{translate-camelcase-name} is a helper function for
specializations of @code{translate-name-from-foreign} and
@code{translate-name-to-foreign}. It handles the common case of
converting between foreign camelCase names and lisp
names. @var{upper-initial-p} indicates whether the first letter of the
foreign name should be uppercase. @var{special-words} is a list of
strings that should be treated atomically in translation. This list is
case-sensitive.
@subheading Examples
@lisp
CFFI> (translate-camelcase-name some-xml-function)
@result{} "someXmlFunction"
CFFI> (translate-camelcase-name some-xml-function :upper-initial-p t)
@result{} "SomeXmlFunction"
CFFI> (translate-camelcase-name some-xml-function :special-words '("XML"))
@result{} "someXMLFunction"
CFFI> (translate-camelcase-name "someXMLFunction")
@result{} SOME-X-M-L-FUNCTION
CFFI> (translate-camelcase-name "someXMLFunction" :special-words '("XML"))
@result{} SOME-XML-FUNCTION
@end lisp
@subheading See Also
@seealso{translate-name-from-foreign} @*
@seealso{translate-name-to-foreign} @*
@seealso{translate-underscore-separated-name}
@c ===================================================================
@c TRANSLATE-NAME-FROM-FOREIGN
@page
@node translate-name-from-foreign, translate-name-to-foreign, translate-camelcase-name, Functions
@heading translate-name-from-foreign
@subheading Syntax
@Function{translate-name-from-foreign foreign-name package &optional varp @res{} symbol}
@subheading Arguments and Values
@table @var
@item foreign-name
A string denoting a foreign function.
@item package
A Lisp package
@item varp
A generalized boolean.
@item symbol
The Lisp symbol to be used a function name.
@end table
@subheading Description
@code{translate-name-from-foreign} is used by @ref{defcfun} to handle
the conversion of foreign names to lisp names. By default, it
translates using @ref{translate-underscore-separated-name}. However,
you can create specialized methods on this function to make
translating more closely match the foreign library's naming
conventions.
Specialize @var{package} on some package. This allows other packages
to load libraries with different naming conventions.
@subheading Examples
@lisp
CFFI> (defcfun "someXmlFunction" ...)
@result{} SOMEXMLFUNCTION
CFFI> (defmethod translate-name-from-foreign ((spec string)
(package (eql *package*))
&optional varp)
(let ((name (translate-camelcase-name spec)))
(if varp (intern (format nil "*~a*" name)) name)))
@result{} #<STANDARD-METHOD TRANSLATE-NAME-FROM-FOREIGN (STRING (EQL #<Package "SOME-PACKAGE">))>
CFFI> (defcfun "someXmlFunction" ...)
@result{} SOME-XML-FUNCTION
@end lisp
@subheading See Also
@seealso{defcfun} @*
@seealso{translate-camelcase-name} @*
@seealso{translate-name-to-foreign} @*
@seealso{translate-underscore-separated-name}
@c ===================================================================
@c TRANSLATE-NAME-TO-FOREIGN
@page
@node translate-name-to-foreign, translate-underscore-separated-name, translate-name-from-foreign, Functions
@heading translate-name-to-foreign
@subheading Syntax
@Function{translate-name-to-foreign lisp-name package &optional varp @res{} string}
@subheading Arguments and Values
@table @var
@item lisp-name
A symbol naming the Lisp function to be created.
@item package
A Lisp package
@item varp
A generalized boolean.
@item string
The string representing the foreign function name.
@end table
@subheading Description
@code{translate-name-to-foreign} is used by @ref{defcfun} to handle
the conversion of lisp names to foreign names. By default, it
translates using @ref{translate-underscore-separated-name}. However,
you can create specialized methods on this function to make
translating more closely match the foreign library's naming
conventions.
Specialize @var{package} on some package. This allows other packages
to load libraries with different naming conventions.
@subheading Examples
@lisp
CFFI> (defcfun some-xml-function ...)
@result{} "some_xml_function"
CFFI> (defmethod translate-name-to-foreign ((spec symbol)
(package (eql *package*))
&optional varp)
(let ((name (translate-camelcase-name spec)))
(if varp (subseq name 1 (1- (length name))) name)))
@result{} #<STANDARD-METHOD TRANSLATE-NAME-TO-FOREIGN (STRING (EQL #<Package "SOME-PACKAGE">))>
CFFI> (defcfun some-xml-function ...)
@result{} "someXmlFunction"
@end lisp
@subheading See Also
@seealso{defcfun} @*
@seealso{translate-camelcase-name} @*
@seealso{translate-name-from-foreign} @*
@seealso{translate-underscore-separated-name}
@c ===================================================================
@c TRANSLATE-UNDERSCORE-SEPARATED-NAME
@page
@node translate-underscore-separated-name, , translate-name-to-foreign, Functions
@heading translate-underscore-separated-name
@subheading Syntax
@Function{translate-underscore-separated-name name @res{} return-value}
@subheading Arguments and Values
@table @var
@item name
Either a symbol or a string.
@item return-value
If @var{name} is a symbol, this is a string, and vice versa.
@end table
@subheading Description
@code{translate-underscore-separated-name} is a helper function for
specializations of @ref{translate-name-from-foreign} and
@ref{translate-name-to-foreign}. It handles the common case of
converting between foreign underscore_separated names and lisp names.
@subheading Examples
@lisp
CFFI> (translate-underscore-separated-name some-xml-function)
@result{} "some_xml_function"
CFFI> (translate-camelcase-name "some_xml_function")
@result{} SOME-XML-FUNCTION
@end lisp
@subheading See Also
@seealso{translate-name-from-foreign} @*
@seealso{translate-name-to-foreign} @*
@seealso{translate-camelcase-name}
@c ===================================================================
@c CHAPTER: Libraries
@node Libraries, Callbacks, Functions, Top
@chapter Libraries
@menu
* Defining a library::
* Library definition style::
Dictionary
* close-foreign-library:: Close a foreign library.
* *darwin-framework-directories*:: Search path for Darwin frameworks.
* define-foreign-library:: Explain how to load a foreign library.
* *foreign-library-directories*:: Search path for shared libraries.
* load-foreign-library:: Load a foreign library.
* load-foreign-library-error:: Signalled on failure of its namesake.
* use-foreign-library:: Load a foreign library when needed.
@end menu
@node Defining a library, Library definition style, Libraries, Libraries
@section Defining a library
Almost all foreign code you might want to access exists in some kind
of shared library. The meaning of @dfn{shared library} varies among
platforms, but for our purposes, we will consider it to include
@file{.so} files on @sc{unix}, frameworks on Darwin (and derivatives
like Mac @acronym{OS X}), and @file{.dll} files on Windows.
Bringing one of these libraries into the Lisp image is normally a
two-step process.
@enumerate
@item
Describe to @cffi{} how to load the library at some future point,
depending on platform and other factors, with a
@code{define-foreign-library} top-level form.
@item
Load the library so defined with either a top-level
@code{use-foreign-library} form or by calling the function
@code{load-foreign-library}.
@end enumerate
@xref{Tutorial-Loading,, Loading foreign libraries}, for a working
example of the above two steps.
@node Library definition style, close-foreign-library, Defining a library, Libraries
@section Library definition style
Looking at the @code{libcurl} library definition presented earlier,
you may ask why we did not simply do this:
@lisp
(define-foreign-library libcurl
(t (:default "libcurl")))
@end lisp
@noindent
Indeed, this would work just as well on the computer on which I tested
the tutorial. There are a couple of good reasons to provide the
@file{.so}'s current version number, however. Namely, the versionless
@file{.so} is not packaged on most @sc{unix} systems along with the
actual, fully-versioned library; instead, it is included in the
``development'' package along with C headers and static @file{.a}
libraries.
The reason @cffi{} does not try to account for this lies in the
meaning of the version numbers. A full treatment of shared library
versions is beyond this manual's scope; see @ref{Versioning,, Library
interface versions, libtool, @acronym{GNU} Libtool}, for helpful
information for the unfamiliar. For our purposes, consider that a
mismatch between the library version with which you tested and the
installed library version may cause undefined
behavior.@footnote{Windows programmers may chafe at adding a
@sc{unix}-specific clause to @code{define-foreign-library}. Instead,
ask why the Windows solution to library incompatibility is ``include
your own version of every library you use with every program''.}
@impnote{Maybe some notes should go here about OS X, which I know
little about. --stephen}
@c ===================================================================
@c CLOSE-FOREIGN-LIBRARY
@page
@node close-foreign-library, *darwin-framework-directories*, Library definition style, Libraries
@heading close-foreign-library
@subheading Syntax
@Function{close-foreign-library library @res{} success}
@subheading Arguments and Values
@table @var
@item library
A symbol or an instance of @code{foreign-library}.
@item success
A Lisp boolean.
@end table
@subheading Description
Closes @var{library} which can be a symbol designating a library
define through @code{define-foreign-library} or an instance of
@code{foreign-library} as returned by @code{load-foreign-library}.
@c @subheading Examples
@c @xref{Tutorial-Loading,, Loading foreign libraries}.
@subheading See Also
@seealso{define-foreign-library} @*
@seealso{load-foreign-library} @*
@seealso{use-foreign-library}
@c ===================================================================
@c *DARWIN-FRAMEWORK-DIRECTORIES*
@page
@node *darwin-framework-directories*, define-foreign-library, close-foreign-library, Libraries
@heading *darwin-framework-directories*
@subheading Syntax
@Variable{*darwin-framework-directories*}
@subheading Value type
A list, in which each element is a string, a pathname, or a simple
Lisp expression.
@subheading Initial value
A list containing the following, in order: an expression corresponding
to Darwin path @file{~/Library/Frameworks/},
@code{#P"/Library/Frameworks/"}, and
@code{#P"/System/Library/Frameworks/"}.
@subheading Description
The meaning of ``simple Lisp expression'' is explained in
@ref{*foreign-library-directories*}. In contrast to that variable,
this is not a fallback search path; the default value described above
is intended to be a reasonably complete search path on Darwin systems.
@subheading Examples
@lisp
CFFI> (let ((lib (load-foreign-library '(:framework "OpenGL"))))
(foreign-library-pathname lib))
@result{} #P"/System/Library/Frameworks/OpenGL.framework/OpenGL"
@end lisp
@subheading See also
@seealso{*foreign-library-directories*} @*
@seealso{define-foreign-library}
@c ===================================================================
@c DEFINE-FOREIGN-LIBRARY
@page
@node define-foreign-library, *foreign-library-directories*, *darwin-framework-directories*, Libraries
@heading define-foreign-library
@subheading Syntax
@Macro{define-foreign-library name-and-options @{ load-clause @}* @res{} name}
name-and-options ::= name | (name &key convention search-path)
load-clause ::= (feature library &key convention search-path)
@subheading Arguments and Values
@table @var
@item name
A symbol.
@item feature
A feature expression.
@item library
A library designator.
@item convention
One of @code{:cdecl} (default) or @code{:stdcall}
@item search-path
A path or list of paths where the library will be searched if not found in
system-global directories. Paths specified in a load clause take priority over
paths specified as library option, with *foreign-library-directories* having
lowest priority.
@end table
@subheading Description
Creates a new library designator called @var{name}. The
@var{load-clause}s describe how to load that designator when passed to
@code{load-foreign-library} or @code{use-foreign-library}.
When trying to load the library @var{name}, the relevant function
searches the @var{load-clause}s in order for the first one where
@var{feature} evaluates to true. That happens for any of the
following situations:
@enumerate 1
@item
If @var{feature} is a symbol present in @code{common-lisp:*features*}.
@item
If @var{feature} is a list, depending on @code{(first @var{feature})},
a keyword:
@table @code
@item :and
All of the feature expressions in @code{(rest @var{feature})} are
true.
@item :or
At least one of the feature expressions in @code{(rest @var{feature})}
is true.
@item :not
The feature expression @code{(second @var{feature})} is not true.
@end table
@item
Finally, if @var{feature} is @code{t}, this @var{load-clause} is
picked unconditionally.
@end enumerate
Upon finding the first true @var{feature}, the library loader then
loads the @var{library}. The meaning of ``library designator'' is
described in @ref{load-foreign-library}.
Functions associated to a library defined by
@code{define-foreign-library} (e.g. through @code{defcfun}'s
@code{:library} option, will inherit the library's options. The
precedence is as follows:
@enumerate 1
@item
@code{defcfun}/@code{foreign-funcall} specific options;
@item
@var{load-clause} options;
@item
global library options (the @var{name-and-options} argument)
@end enumerate
@subheading Examples
@xref{Tutorial-Loading,, Loading foreign libraries}.
@subheading See Also
@seealso{close-foreign-library} @*
@seealso{load-foreign-library}
@c ===================================================================
@c *FOREIGN-LIBRARY-DIRECTORIES*
@page
@node *foreign-library-directories*, load-foreign-library, define-foreign-library, Libraries
@heading *foreign-library-directories*
@subheading Syntax
@Variable{*foreign-library-directories*}
@subheading Value type
A list, in which each element is a string, a pathname, or a simple
Lisp expression.
@subheading Initial value
The empty list.
@subheading Description
You should not have to use this variable.
Most, if not all, Lisps supported by @cffi{} have a reasonable default
search algorithm for foreign libraries. For example, Lisps for
@sc{unix} usually call
@uref{http://www.opengroup.org/onlinepubs/009695399/functions/dlopen.html,,
@code{dlopen(3)}}, which in turn looks in the system library
directories. Only if that fails does @cffi{} look for the named
library file in these directories, and load it from there if found.
Thus, this is intended to be a @cffi{}-only fallback to the library
search configuration provided by your operating system. For example,
if you distribute a foreign library with your Lisp package, you can
add the library's containing directory to this list and portably
expect @cffi{} to find it.
A @dfn{simple Lisp expression} is intended to provide functionality
commonly used in search paths such as
@acronym{ASDF}'s@footnote{@xref{Using asdf to load systems,,, asdf,
asdf: another system definition facility}, for information on
@code{asdf:*central-registry*}.}, and is defined recursively as
follows:@footnote{See @code{mini-eval} in @file{libraries.lisp} for
the source of this definition. As is always the case with a Lisp
@code{eval}, it's easier to understand the Lisp definition than the
english.}
@enumerate
@item
A list, whose @samp{first} is a function designator, and whose
@samp{rest} is a list of simple Lisp expressions to be evaluated and
passed to the so-designated function. The result is the result of the
function call.
@item
A symbol, whose result is its symbol value.
@item
Anything else evaluates to itself.
@end enumerate
@subheading Examples
@example
$ ls
@print{} liblibli.so libli.lisp
@end example
@noindent
In @file{libli.lisp}:
@lisp
(pushnew #P"/home/sirian/lisp/libli/" *foreign-library-directories*
:test #'equal)
(load-foreign-library '(:default "liblibli"))
@end lisp
@noindent
The following example would achieve the same effect:
@lisp
(pushnew '(merge-pathnames #p"lisp/libli/" (user-homedir-pathname))
*foreign-library-directories*
:test #'equal)
@result{} ((MERGE-PATHNAMES #P"lisp/libli/" (USER-HOMEDIR-PATHNAME)))
(load-foreign-library '(:default "liblibli"))
@end lisp
@subheading See also
@seealso{*darwin-framework-directories*} @*
@seealso{define-foreign-library}
@c ===================================================================
@c LOAD-FOREIGN-LIBRARY
@page
@node load-foreign-library, load-foreign-library-error, *foreign-library-directories*, Libraries
@heading load-foreign-library
@subheading Syntax
@Function{load-foreign-library library-designator @res{} library}
@subheading Arguments and Values
@table @var
@item library-designator
A library designator.
@item library-designator
An instance of @code{foreign-library}.
@end table
@subheading Description
Load the library indicated by @var{library-designator}. A @dfn{library
designator} is defined as follows:
@enumerate
@item
If a symbol, is considered a name previously defined with
@code{define-foreign-library}.
@item
If a string or pathname, passed as a namestring directly to the
implementation's foreign library loader. If that fails, search the
directories in @code{*foreign-library-directories*} with
@code{cl:probe-file}; if found, the absolute path is passed to the
implementation's loader.
@item
If a list, the meaning depends on @code{(first @var{library})}:
@table @code
@item :framework
The second list element is taken to be a Darwin framework name, which
is then searched in @code{*darwin-framework-directories*}, and loaded
when found.
@item :or
Each remaining list element, itself a library designator, is loaded in
order, until one succeeds.
@item :default
The name is transformed according to the platform's naming convention
to shared libraries, and the resultant string is loaded as a library
designator. For example, on @sc{unix}, the name is suffixed with
@file{.so}.
@end table
@end enumerate
If the load fails, signal a @code{load-foreign-library-error}.
@strong{Please note:} For system libraries, you should not need to
specify the directory containing the library. Each operating system
has its own idea of a default search path, and you should rely on it
when it is reasonable.
@subheading Implementation-specific Notes
On ECL platforms where its dynamic FFI is not supported (ie. when
@code{:dffi} is not present in @code{*features*}),
@code{cffi:load-foreign-library} does not work and you must use ECL's
own @code{ffi:load-foreign-library} with a constant string argument.
@subheading Examples
@xref{Tutorial-Loading,, Loading foreign libraries}.
@subheading See Also
@seealso{close-foreign-library} @*
@seealso{*darwin-framework-directories*} @*
@seealso{define-foreign-library} @*
@seealso{*foreign-library-directories*} @*
@seealso{load-foreign-library-error} @*
@seealso{use-foreign-library}
@c ===================================================================
@c LOAD-FOREIGN-LIBRARY-ERROR
@page
@node load-foreign-library-error, use-foreign-library, load-foreign-library, Libraries
@heading load-foreign-library-error
@subheading Syntax
@Condition{load-foreign-library-error}
@subheading Class precedence list
@code{load-foreign-library-error}, @code{error},
@code{serious-condition}, @code{condition}, @code{t}
@subheading Description
Signalled when a foreign library load completely fails. The exact
meaning of this varies depending on the real conditions at work, but
almost universally, the implementation's error message is useless.
However, @cffi{} does provide the useful restarts @code{retry} and
@code{use-value}; invoke the @code{retry} restart to try loading the
foreign library again, or the @code{use-value} restart to try loading
a different foreign library designator.
@subheading See also
@seealso{load-foreign-library}
@c ===================================================================
@c USE-FOREIGN-LIBRARY
@page
@node use-foreign-library, , load-foreign-library-error, Libraries
@heading use-foreign-library
@subheading Syntax
@Macro{use-foreign-library name}
@subheading Arguments and values
@table @var
@item name
A library designator; unevaluated.
@end table
@subheading Description
@xref{load-foreign-library}, for the meaning of ``library
designator''. This is intended to be the top-level form used
idiomatically after a @code{define-foreign-library} form to go ahead
and load the library. @c ; it also sets the ``current foreign library''.
Finally, on implementations where the regular evaluation rule is
insufficient for foreign library loading, it loads it at the required
time.@footnote{Namely, @acronym{CMUCL}. See
@code{use-foreign-library} in @file{libraries.lisp} for details.}
@c current foreign library is a concept created a few hours ago as of
@c this writing. It is not actually used yet, but probably will be.
@subheading Examples
@xref{Tutorial-Loading,, Loading foreign libraries}.
@subheading See also
@seealso{load-foreign-library}
@c ===================================================================
@c CHAPTER: Callbacks
@node Callbacks, The Groveller, Libraries, Top
@chapter Callbacks
@menu
Dictionary
* callback::
* defcallback::
* get-callback::
@end menu
@c ===================================================================
@c CALLBACK
@page
@node callback, defcallback, Callbacks, Callbacks
@heading callback
@subheading Syntax
@Macro{callback symbol @res{} pointer}
@subheading Arguments and Values
@table @var
@item symbol
A symbol denoting a callback.
@item pointer
@itemx new-value
A pointer.
@end table
@subheading Description
The @code{callback} macro is analogous to the standard CL special
operator @code{function} and will return a pointer to the callback
denoted by the symbol @var{name}.
@subheading Examples
@lisp
CFFI> (defcallback sum :int ((a :int) (b :int))
(+ a b))
@result{} SUM
CFFI> (callback sum)
@result{} #<A Mac Pointer #x102350>
@end lisp
@subheading See Also
@seealso{get-callback} @*
@seealso{defcallback}
@c ===================================================================
@c DEFCALLBACK
@page
@node defcallback, get-callback, callback, Callbacks
@heading defcallback
@subheading Syntax
@Macro{defcallback name-and-options return-type arguments &body body @res{} name}
name-and-options ::= name | (name &key convention)
arguments ::= (@{ (arg-name arg-type) @}*)
@subheading Arguments and Values
@table @var
@item name
A symbol naming the callback created.
@item return-type
The foreign type for the callback's return value.
@item arg-name
A symbol.
@item arg-type
A foreign type.
@item convention
One of @code{:cdecl} (default) or @code{:stdcall}.
@end table
@subheading Description
The @code{defcallback} macro defines a Lisp function that can be called
from C. The arguments passed to this function will be converted to the
appropriate Lisp representation and its return value will be converted
to its C representation.
This Lisp function can be accessed by the @code{callback} macro or the
@code{get-callback} function.
@strong{Portability note:} @code{defcallback} will not work correctly
on some Lisps if it's not a top-level form.
@subheading Examples
@lisp
(defcfun "qsort" :void
(base :pointer)
(nmemb :int)
(size :int)
(fun-compar :pointer))
(defcallback < :int ((a :pointer) (b :pointer))
(let ((x (mem-ref a :int))
(y (mem-ref b :int)))
(cond ((> x y) 1)
((< x y) -1)
(t 0))))
CFFI> (with-foreign-object (array :int 10)
;; @lispcmt{Initialize array.}
(loop for i from 0 and n in '(7 2 10 4 3 5 1 6 9 8)
do (setf (mem-aref array :int i) n))
;; @lispcmt{Sort it.}
(qsort array 10 (foreign-type-size :int) (callback <))
;; @lispcmt{Return it as a list.}
(loop for i from 0 below 10
collect (mem-aref array :int i)))
@result{} (1 2 3 4 5 6 7 8 9 10)
@end lisp
@subheading See Also
@seealso{callback} @*
@seealso{get-callback}
@c ===================================================================
@c GET-CALLBACK
@page
@node get-callback, , defcallback, Callbacks
@heading get-callback
@subheading Syntax
@Accessor{get-callback symbol @res{} pointer}
@subheading Arguments and Values
@table @var
@item symbol
A symbol denoting a callback.
@item pointer
A pointer.
@end table
@subheading Description
This is the functional version of the @code{callback} macro. It
returns a pointer to the callback named by @var{symbol} suitable, for
example, to pass as arguments to foreign functions.
@subheading Examples
@lisp
CFFI> (defcallback sum :int ((a :int) (b :int))
(+ a b))
@result{} SUM
CFFI> (get-callback 'sum)
@result{} #<A Mac Pointer #x102350>
@end lisp
@subheading See Also
@seealso{callback} @*
@seealso{defcallback}
@c ===================================================================
@c CHAPTER: The Groveller
@node The Groveller, Limitations, Callbacks, Top
@chapter The Groveller
@cffi{}-Grovel is a tool which makes it easier to write @cffi{}
declarations for libraries that are implemented in C. That is, it
grovels through the system headers, getting information about types
and structures, so you don't have to. This is especially important
for libraries which are implemented in different ways by different
vendors, such as the @sc{unix}/@sc{posix} functions. The @cffi{}
declarations are usually quite different from platform to platform,
but the information you give to @cffi{}-Grovel is the same. Hence,
much less work is required!
If you use @acronym{ASDF}, @cffi{}-Grovel is integrated, so that it
will run automatically when your system is building. This feature was
inspired by SB-Grovel, a similar @acronym{SBCL}-specific project.
@cffi{}-Grovel can also be used without @acronym{ASDF}.
@section Building FFIs with CFFI-Grovel
@cffi{}-Grovel uses a specification file (*.lisp) describing the
features that need groveling. The C compiler is used to retrieve this
data and write a Lisp file (*.cffi.lisp) which contains the necessary
@cffi{} definitions to access the variables, structures, constants, and
enums mentioned in the specification.
@c This is most similar to the SB-Grovel package, upon which it is
@c based. Unlike SB-Grovel, we do not currently support defining
@c regular foreign functions in the specification file; those are best
@c defined in normal Lisp code.
@cffi{}-Grovel provides an @acronym{ASDF} component for handling the
necessary calls to the C compiler and resulting file management.
@c See the included CFFI-Unix package for an example of how to
@c integrate a specification file with ASDF-built packages.
@menu
* Groveller Syntax:: How grovel files should look like.
* Groveller ASDF Integration:: ASDF components for grovel files.
* Groveller Implementation Notes:: Implementation notes.
@end menu
@node Groveller Syntax, Groveller ASDF Integration, The Groveller, The Groveller
@section Specification File Syntax
The specification files are read by the normal Lisp reader, so they
have syntax very similar to normal Lisp code. In particular,
semicolon-comments and reader-macros will work as expected.
There are several forms recognized by @cffi{}-Grovel:
@deffn {Grovel Form} progn &rest forms
Processes a list of forms. Useful for conditionalizing several
forms. For example:
@end deffn
@lisp
#+freebsd
(progn
(constant (ev-enable "EV_ENABLE"))
(constant (ev-disable "EV_DISABLE")))
@end lisp
@deffn {Grovel Form} include &rest files
Include the specified files (specified as strings) in the generated C
source code.
@end deffn
@deffn {Grovel Form} in-package symbol
Set the package to be used for the final Lisp output.
@end deffn
@deffn {Grovel Form} ctype lisp-name size-designator
Define a @cffi{} foreign type for the string in @var{size-designator},
e.g. @code{(ctype :pid "pid_t")}.
@end deffn
@deffn {Grovel Form} constant (lisp-name &rest c-names) &key type documentation optional
Search for the constant named by the first @var{c-name} string found
to be known to the C preprocessor and define it as @var{lisp-name}.
The @var{type} keyword argument specifies how to grovel the constant:
either @code{integer} (the default) or @code{double-float}. If
@var{optional} is true, no error will be raised if all the
@var{c-names} are unknown. If @var{lisp-name} is a keyword, the actual
constant will be a symbol of the same name interned in the current
package.
@end deffn
@deffn {Grovel Form} define name &optional value
Defines an additional C preprocessor symbol, which is useful for
altering the behavior of included system headers.
@end deffn
@deffn {Grovel Form} cc-flags &rest flags
Adds @var{cc-flags} to the command line arguments used for the C compiler
invocation.
@end deffn
@deffn {Grovel Form} cstruct lisp-name c-name slots
Define a @cffi{} foreign struct with the slot data specfied. Slots
are of the form @code{(lisp-name c-name &key type count (signed t))}.
@end deffn
@deffn {Grovel Form} cunion lisp-name c-name slots
Identical to @code{cstruct}, but defines a @cffi{} foreign union.
@end deffn
@deffn {Grovel Form} cstruct-and-class c-name slots
Defines a @cffi{} foreign struct, as with @code{cstruct} and defines a
@acronym{CLOS} class to be used with it. This is useful for mapping
foreign structures to application-layer code that shouldn't need to
worry about memory allocation issues.
@end deffn
@deffn {Grovel Form} cvar namespec type &key read-only
Defines a foreign variable of the specified type, even if that
variable is potentially a C preprocessor pseudo-variable. e.g.
@code{(cvar ("errno" errno) errno-values)}, assuming that errno-values
is an enum or equivalent to type @code{:int}.
The @var{namespec} is similar to the one used in @ref{defcvar}.
@end deffn
@deffn {Grovel Form} cenum name-and-opts &rest elements
Defines a true C enum, with elements specified as @code{((lisp-name
&rest c-names) &key optional documentation)}.
@var{name-and-opts} can be either a symbol as name, or a list
@code{(name &key base-type define-constants)}. If @var{define-constants}
is non-null, a Lisp constant will be defined for each enum member.
@end deffn
@deffn {Grovel Form} constantenum name-and-opts &rest elements
Defines an enumeration of pre-processor constants, with elements
specified as @code{((lisp-name &rest c-names) &key optional
documentation)}.
@var{name-and-opts} can be either a symbol as name, or a list
@code{(name &key base-type define-constants)}. If @var{define-constants}
is non-null, a Lisp constant will be defined for each enum member.
This example defines @code{:af-inet} to represent the value held by
@code{AF_INET} or @code{PF_INET}, whichever the pre-processor finds
first. Similarly for @code{:af-packet}, but no error will be
signalled if the platform supports neither @code{AF_PACKET} nor
@code{PF_PACKET}.
@end deffn
@lisp
(constantenum address-family
((:af-inet "AF_INET" "PF_INET")
:documentation "IPv4 Protocol family")
((:af-local "AF_UNIX" "AF_LOCAL" "PF_UNIX" "PF_LOCAL")
:documentation "File domain sockets")
((:af-inet6 "AF_INET6" "PF_INET6")
:documentation "IPv6 Protocol family")
((:af-packet "AF_PACKET" "PF_PACKET")
:documentation "Raw packet access"
:optional t))
@end lisp
@deffn {Grovel Form} bitfield name-and-opts &rest elements
Defines a bitfield, with elements specified as @code{((lisp-name
c-name) &key documentation)}. @var{name-and-opts} can be either a
symbol as name, or a list @code{(name &key base-type)}. For example:
@end deffn
@lisp
(bitfield flags-ctype
((:flag-a "FLAG_A")
:documentation "DOCU_A")
((:flag-b "FLAG_B")
:documentation "DOCU_B")
((:flag-c "FLAG_C")
:documentation "DOCU_C"))
@end lisp
@c ===================================================================
@c SECTION: Groveller ASDF Integration
@node Groveller ASDF Integration, Groveller Implementation Notes, Groveller Syntax, The Groveller
@section ASDF Integration
An example software project might contain four files; an
@acronym{ASDF} file, a package definition file, an implementation
file, and a @cffi{}-Grovel specification file.
The @acronym{ASDF} file defines the system and its dependencies.
Notice the use of @code{eval-when} to ensure @cffi{}-Grovel is present
and the use of @code{(cffi-grovel:grovel-file name &key cc-flags)}
instead of @code{(:file name)}.
@lisp
;;; @lispcmt{CFFI-Grovel is needed for processing grovel-file components}
(cl:eval-when (:load-toplevel :execute)
(asdf:operate 'asdf:load-op 'cffi-grovel))
(asdf:defsystem example-software
:depends-on (cffi)
:serial t
:components
((:file "package")
(cffi-grovel:grovel-file "example-grovelling")
(:file "example")))
@end lisp
The ``package.lisp'' file would contain several @code{defpackage}
forms, to remove circular dependencies and make building the project
easier. Note that you may or may not want to @code{:use} your
internal package.
@impnote{Mention that it's a not a good idea to :USE when names may
clash with, say, CL symbols.}
@lisp
(defpackage #:example-internal
(:use)
(:nicknames #:exampleint))
(defpackage #:example-software
(:export ...)
(:use #:cl #:cffi #:exampleint))
@end lisp
The internal package is created by Lisp code output from the C program
written by @cffi{}-Grovel; if your specification file is
exampleint.lisp, the exampleint.cffi.lisp file will contain the
@cffi{} definitions needed by the rest of your project.
@xref{Groveller Syntax}.
@node Groveller Implementation Notes, , Groveller ASDF Integration, The Groveller
@section Implementation Notes
@impnote{This info might not be up-to-date.}
For @code{foo-internal.lisp}, the resulting @code{foo-internal.c},
@code{foo-internal}, and @code{foo-internal.cffi.lisp} are all
platform-specific, either because of possible reader-macros in
foo-internal.lisp, or because of varying C environments on the host
system. For this reason, it is not helpful to distribute any of those
files; end users building @cffi{}-Grovel based software will need
@code{cffi}-Grovel anyway.
If you build with multiple architectures in the same directory
(e.g. with NFS/AFS home directories), it is critical to remove these
generated files or the resulting constants will be very incorrect.
@impnote{Maybe we should tag the generated names with something host
or OS-specific?}
@impnote{For now, after some experimentation with @sc{clisp} having no
long-long, it seems appropriate to assert that the generated @code{.c}
files are architecture and operating-system dependent, but
lisp-implementation independent. This way the same @code{.c} file
(and so the same @code{.grovel-tmp.lisp} file) will be shareable
between the implementations running on a given system.}
@c TODO: document the new wrapper stuff.
@c ===================================================================
@c CHAPTER: Limitations
@node Limitations, Platform-specific features, The Groveller, Top
@chapter Limitations
These are @cffi{}'s limitations across all platforms; for information
on the warts on particular Lisp implementations, see
@ref{Implementation Support}.
@itemize @bullet
@item
The tutorial includes a treatment of the primary, intractable
limitation of @cffi{}, or any @acronym{FFI}: that the abstractions
commonly used by C are insufficiently expressive.
@xref{Tutorial-Abstraction,, Breaking the abstraction}, for more
details.
@item
C @code{struct}s cannot be passed by value.
@end itemize
@node Platform-specific features, Glossary, Limitations, Top
@appendix Platform-specific features
Whenever a backend doesn't support one of @cffi{}'s features, a
specific symbol is pushed onto @code{common-lisp:*features*}. The
meanings of these symbols follow.
@table @var
@item cffi-sys::flat-namespace
This Lisp has a flat namespace for foreign symbols meaning that you
won't be able to load two different libraries with homograph functions
and successfully differentiate them through the @code{:library}
option to @code{defcfun}, @code{defcvar}, etc@dots{}
@item cffi-sys::no-foreign-funcall
The macro @code{foreign-funcall} is @strong{not} available. On such
platforms, the only way to call a foreign function is through
@code{defcfun}. @xref{foreign-funcall}, and @ref{defcfun}.
@item cffi-sys::no-long-long
The C @code{long long} type is @strong{not} available as a foreign
type.
However, on such platforms @cffi{} provides its own implementation of
the @code{long long} type for all of operations in chapters
@ref{Foreign Types}, @ref{Pointers} and @ref{Variables}. The
functionality described in @ref{Functions} and @ref{Callbacks} will
not be available.
32-bit Lispworks 5.0+ is an exception. In addition to the @cffi{}
implementation described above, Lispworks itself implements the
@code{long long} type for @ref{Functions}. @ref{Callbacks} are still
missing @code{long long} support, though.
@item cffi-sys::no-stdcall
This Lisp doesn't support the @code{stdcall} calling convention. Note
that it only makes sense to support @code{stdcall} on (32-bit) x86
platforms.
@end table
@node Glossary, Comprehensive Index, Platform-specific features, Top
@appendix Glossary
@table @dfn
@item aggregate type
A @cffi{} type for C data defined as an organization of data of simple
type; in structures and unions, which are themselves aggregate types,
they are represented by value.
@item foreign value
This has two meanings; in any context, only one makes sense.
When using type translators, the foreign value is the lower-level Lisp
value derived from the object passed to @code{translate-to-foreign}
(@pxref{translate-to-foreign}). This value should be a Lisp number or
a pointer (satisfies @code{pointerp}), and it can be treated like any
general Lisp object; it only completes the transformation to a true
foreign value when passed through low-level code in the Lisp
implementation, such as the foreign function caller or indirect memory
addressing combined with a data move.
In other contexts, this refers to a value accessible by C, but which
may only be accessed through @cffi{} functions. The closest you can
get to such a foreign value is through a pointer Lisp object, which
itself counts as a foreign value in only the previous sense.
@item simple type
A @cffi{} type that is ultimately represented as a builtin type;
@cffi{} only provides extra semantics for Lisp that are invisible to C
code or data.
@end table
@node Comprehensive Index, , Glossary, Top
@unnumbered Index
@printindex cp
@bye
| 208,647 | Common Lisp | .l | 5,219 | 37.851313 | 108 | 0.745734 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 8dd39572b17d07e61962704176cd7604570951abb484b9c170e6cf3594f07e00 | 1,038 | [
-1
] |
1,039 | Makefile | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/doc/Makefile | # -*- Mode: Makefile; tab-width: 3; indent-tabs-mode: t -*-
#
# Makefile --- Make targets for generating the documentation.
#
# Copyright (C) 2005-2007, Luis Oliveira <[email protected]>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use, copy,
# modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
all: manual spec
manual: cffi-manual.texinfo style.css
sh gendocs.sh -o manual --html "--css-include=style.css" cffi-manual "CFFI User Manual"
spec: cffi-sys-spec.texinfo style.css
sh gendocs.sh -o spec --html "--css-include=style.css" cffi-sys-spec "CFFI-SYS Interface Specification"
clean:
find . \( -name "*.info" -o -name "*.aux" -o -name "*.cp" -o -name "*.fn" -o -name "*.fns" -o -name "*.ky" -o -name "*.log" -o -name "*.pg" -o -name "*.toc" -o -name "*.tp" -o -name "*.vr" -o -name "*.dvi" -o -name "*.cps" -o -name "*.vrs" \) -exec rm {} \;
rm -rf manual spec dir
upload-docs: manual spec
rsync -av --delete -e ssh manual spec common-lisp.net:/project/cffi/public_html/
# scp -r manual spec common-lisp.net:/project/cffi/public_html/
# vim: ft=make ts=3 noet
| 2,039 | Common Lisp | .l | 38 | 52.368421 | 258 | 0.732331 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 30e9304987d83067bfa13f9a09861091eb7e9d058d3459ede4b1f01381786bd3 | 1,039 | [
-1
] |
1,040 | style.css | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/doc/style.css | body {font-family: century schoolbook, serif;
line-height: 1.3;
padding-left: 5em; padding-right: 1em;
padding-bottom: 1em; max-width: 60em;}
table {border-collapse: collapse}
span.roman { font-family: century schoolbook, serif; font-weight: normal; }
h1, h2, h3, h4, h5, h6 {font-family: Helvetica, sans-serif}
h4 { margin-top: 2.5em; }
dfn {font-family: inherit; font-variant: italic; font-weight: bolder }
kbd {font-family: monospace; text-decoration: underline}
/*var {font-family: Helvetica, sans-serif; font-variant: slanted}*/
var {font-variant: slanted;}
td {padding-right: 1em; padding-left: 1em}
sub {font-size: smaller}
.node {padding: 0; margin: 0}
.lisp { font-family: monospace;
background-color: #F4F4F4; border: 1px solid #AAA;
padding-top: 0.5em; padding-bottom: 0.5em; }
/* coloring */
.lisp-bg { background-color: #F4F4F4 ; color: black; }
.lisp-bg:hover { background-color: #F4F4F4 ; color: black; }
.symbol { font-weight: bold; color: #770055; background-color : transparent; border: 0px; margin: 0px;}
a.symbol:link { font-weight: bold; color : #229955; background-color : transparent; text-decoration: none; border: 0px; margin: 0px; }
a.symbol:active { font-weight: bold; color : #229955; background-color : transparent; text-decoration: none; border: 0px; margin: 0px; }
a.symbol:visited { font-weight: bold; color : #229955; background-color : transparent; text-decoration: none; border: 0px; margin: 0px; }
a.symbol:hover { font-weight: bold; color : #229955; background-color : transparent; text-decoration: none; border: 0px; margin: 0px; }
.special { font-weight: bold; color: #FF5000; background-color: inherit; }
.keyword { font-weight: bold; color: #770000; background-color: inherit; }
.comment { font-weight: normal; color: #007777; background-color: inherit; }
.string { font-weight: bold; color: #777777; background-color: inherit; }
.character { font-weight: bold; color: #0055AA; background-color: inherit; }
.syntaxerror { font-weight: bold; color: #FF0000; background-color: inherit; }
span.paren1 { font-weight: bold; color: #777777; }
span.paren1:hover { color: #777777; background-color: #BAFFFF; }
span.paren2 { color: #777777; }
span.paren2:hover { color: #777777; background-color: #FFCACA; }
span.paren3 { color: #777777; }
span.paren3:hover { color: #777777; background-color: #FFFFBA; }
span.paren4 { color: #777777; }
span.paren4:hover { color: #777777; background-color: #CACAFF; }
span.paren5 { color: #777777; }
span.paren5:hover { color: #777777; background-color: #CAFFCA; }
span.paren6 { color: #777777; }
span.paren6:hover { color: #777777; background-color: #FFBAFF; }
| 2,671 | Common Lisp | .l | 44 | 58.840909 | 137 | 0.718643 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | e86e672812506e473446ff5afb8df82e69a41349635d4b3687a3b99a765a404e | 1,040 | [
-1
] |
1,041 | gendocs_template | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/doc/gendocs_template | <?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- $Id: gendocs_template,v 1.7 2005/05/15 00:00:08 karl Exp $ -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<!--
This template was adapted from Texinfo:
http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs_template
-->
<head>
<title>%%TITLE%%</title>
<meta http-equiv="content-type" content='text/html; charset=utf-8' />
<!-- <link rel="stylesheet" type="text/css" href="/gnu.css" /> -->
<!-- <link rev="made" href="[email protected]" /> -->
<style>
/* CSS style taken from http://gnu.org/gnu.css */
html, body {
background-color: #FFFFFF;
color: #000000;
font-family: sans-serif;
}
a:link {
color: #1f00ff;
background-color: transparent;
text-decoration: underline;
}
a:visited {
color: #9900dd;
background-color: transparent;
text-decoration: underline;
}
a:hover {
color: #9900dd;
background-color: transparent;
text-decoration: none;
}
.center {
text-align: center;
}
.italic {
font-style: italic;
}
.bold {
font-weight: bold;
}
.quote {
margin-left: 40px;
margin-right: 40px;
}
.hrsmall {
width: 80px;
height: 1px;
margin-left: 20px;
}
.td_title {
border-color: #3366cc;
border-style: solid;
border-width: thin;
color: #3366cc;
background-color : #f2f2f9;
font-weight: bold;
}
.td_con {
padding-top: 3px;
padding-left: 8px;
padding-bottom: 3px;
color : #303030;
background-color : #fefefe;
font-size: smaller;
}
.translations {
background-color: transparent;
color: black;
font-family: serif;
font-size: smaller;
}
.fsflink {
font-size: smaller;
font-family: monospace;
color : #000000;
border-left: #3366cc thin solid;
border-bottom: #3366cc thin solid;
padding-left: 5px;
padding-bottom: 5px;
}
/*
* rtl stands for right-to-left layout, as in farsi/persian,
* arabic, etc. See also trans_rtl.
*/
.fsflink_rtl {
font-size: smaller;
font-family: monospace;
color : #000000;
border-right: #3366cc thin solid;
border-bottom: #3366cc thin solid;
padding-right: 5px;
padding-bottom: 5px;
}
.trans {
font-size: smaller;
color : #000000;
border-left: #3366cc thin solid;
padding-left: 20px;
}
.trans_rtl {
font-size: smaller;
color : #000000;
border-right: #3366cc thin solid;
padding-right: 20px;
}
img {
border: none 0;
}
td.side {
color: #3366cc;
/* background: #f2f2f9;
border-color: #3366cc;
border-style: solid;
border-width: thin; */
border-color: white;
border-style: none;
vertical-align: top;
width: 150px;
}
div.copyright {
font-size: 80%;
border: 2px solid #3366cc;
padding: 4px;
background: #f2f2f9;
border-style: solid;
border-width: thin;
}
.footnoteref {
font-size: smaller;
vertical-align: text-top;
}
</style>
</head>
<!-- This document is in XML, and xhtml 1.0 -->
<!-- Please make sure to properly nest your tags -->
<!-- and ensure that your final document validates -->
<!-- consistent with W3C xhtml 1.0 and CSS standards -->
<!-- See validator.w3.org -->
<body>
<h3>%%TITLE%%</h3>
<!-- <address>Free Software Foundation</address> -->
<address>last updated %%DATE%%</address>
<!--
<p>
<a href="/graphics/gnu-head.jpg">
<img src="/graphics/gnu-head-sm.jpg"
alt=" [image of the head of a GNU] "
width="129" height="122" />
</a>
<a href="/philosophy/gif.html">(no gifs due to patent problems)</a>
</p>
-->
<hr />
<p>This document <!--(%%PACKAGE%%)--> is available in the following formats:</p>
<ul>
<li><a href="%%PACKAGE%%.html">HTML
(%%HTML_MONO_SIZE%%K characters)</a> - entirely on one web page.</li>
<li><a href="html_node/index.html">HTML</a> - with one web page per
node.</li>
<li><a href="%%PACKAGE%%.html.gz">HTML compressed
(%%HTML_MONO_GZ_SIZE%%K gzipped characters)</a> - entirely on
one web page.</li>
<li><a href="%%PACKAGE%%.html_node.tar.gz">HTML compressed
(%%HTML_NODE_TGZ_SIZE%%K gzipped tar file)</a> -
with one web page per node.</li>
<li><a href="%%PACKAGE%%.info.tar.gz">Info document
(%%INFO_TGZ_SIZE%%K characters gzipped tar file)</a>.</li>
<li><a href="%%PACKAGE%%.txt">ASCII text
(%%ASCII_SIZE%%K characters)</a>.</li>
<li><a href="%%PACKAGE%%.txt.gz">ASCII text compressed
(%%ASCII_GZ_SIZE%%K gzipped characters)</a>.</li>
<li><a href="%%PACKAGE%%.dvi.gz">TeX dvi file
(%%DVI_GZ_SIZE%%K characters gzipped)</a>.</li>
<li><a href="%%PACKAGE%%.ps.gz">PostScript file
(%%PS_GZ_SIZE%%K characters gzipped)</a>.</li>
<li><a href="%%PACKAGE%%.pdf">PDF file
(%%PDF_SIZE%%K characters)</a>.</li>
<li><a href="%%PACKAGE%%.texi.tar.gz">Texinfo source
(%%TEXI_TGZ_SIZE%%K characters gzipped tar file)</a></li>
</ul>
<p>(This page was generated by the <a href="%%SCRIPTURL%%">%%SCRIPTNAME%%
script</a>.)</p>
<div class="copyright">
<p>
Return to <a href="/project/cffi/">CFFI's home page</a>.
</p>
<!--
<p>
Please send FSF & GNU inquiries to
<a href="mailto:[email protected]"><em>[email protected]</em></a>.
There are also <a href="/home.html#ContactInfo">other ways to contact</a>
the FSF.
<br />
Please send broken links and other corrections (or suggestions) to
<a href="mailto:[email protected]"><em>[email protected]</em></a>.
</p>
-->
<p>
Copyright (C) 2005 James Bielman <jamesjb at jamesjb.com><br />
Copyright (C) 2005 Luís Oliveira <loliveira at common-lisp.net>
<!--
<br />
Verbatim copying and distribution of this entire article is
permitted in any medium, provided this notice is preserved.
-->
</p>
<p>
Updated: %%DATE%%
<!-- timestamp start -->
<!-- $Date: 2005/05/15 00:00:08 $ $Author: karl $ -->
<!-- timestamp end -->
</p>
</div>
</body>
</html>
| 5,802 | Common Lisp | .l | 220 | 24.013636 | 80 | 0.671297 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | ba574b29d7935f9f3fb2d1b9c622e56ca08eff3e8e9fa4c670d5ad81a7cfcfbf | 1,041 | [
-1
] |
1,042 | shareable-vectors.txt | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/doc/shareable-vectors.txt |
# Shareable Byte Vectors
Function: make-shareable-byte-vector size
Create a vector of element type (UNSIGNED-BYTE 8) suitable for passing
to WITH-POINTER-TO-VECTOR-DATA.
;; Minimal implementation:
(defun make-shareable-byte-vector (size)
(make-array size :element-type '(unsigned-byte 8)))
Macro: with-pointer-to-vector-data (ptr-var vector) &body body
Bind PTR-VAR to a pointer to the data contained in a shareable byte
vector.
VECTOR must be a shareable vector created by MAKE-SHAREABLE-BYTE-VECTOR.
PTR-VAR may point directly into the Lisp vector data, or it may point
to a temporary block of foreign memory which will be copied to and
from VECTOR.
Both the pointer object in PTR-VAR and the memory it points to have
dynamic extent. The results are undefined if foreign code attempts to
access this memory outside this dynamic contour.
The implementation must guarantee the memory pointed to by PTR-VAR
will not be moved during the dynamic contour of this operator, either
by creating the vector in a static area or temporarily disabling the
garbage collector.
;; Minimal (copying) implementation:
(defmacro with-pointer-to-vector-data ((ptr-var vector) &body body)
(let ((vector-var (gensym))
(size-var (gensym)))
`(let* ((,vector-var ,vector)
(,size-var (length ,vector-var)))
(with-foreign-ptr (,ptr-var ,size-var)
(mem-write-vector ,vector-var ,ptr :uint8)
(prog1
(progn ,@body)
(mem-read-vector ,vector-var ,ptr-var :uint8 ,size-var))))))
| 1,537 | Common Lisp | .l | 32 | 44.25 | 72 | 0.746818 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 74c14a55c3e2528923792875aa753df51e332f7682de98ccfb3a293f9aff3fff | 1,042 | [
-1
] |
1,043 | allegro-internals.txt | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/CFFI/doc/allegro-internals.txt | July 2005
These details were kindly provided by Duane Rettig of Franz.
Regarding the following snippet of the macro expansion of
FF:DEF-FOREIGN-CALL:
(SYSTEM::FF-FUNCALL
(LOAD-TIME-VALUE (EXCL::DETERMINE-FOREIGN-ADDRESS
'("foo" :LANGUAGE :C) 2 NIL))
'(:INT (INTEGER * *)) ARG1
'(:DOUBLE (DOUBLE-FLOAT * *)) ARG2
'(:INT (INTEGER * *)))
"
... in Allegro CL, if you define a foreign call FOO with C entry point
"foo" and with :call-direct t in the arguments, and if other things are
satisfied, then if a lisp function BAR is compiled which has a call to
FOO, that call will not go through ff-funcall (and thus a large amount
of argument manipulation and processing) but will instead set up its
arguments directly on the stack, and will then perform the "call" more
or less directly, through the "entry vec" (a small structure which
keeps track of a foreign entry's address and status)."
This is the code that generates what the compiler expects to see:
(setq call-direct-form
(if* call-direct
then `(setf (get ',lispname 'sys::direct-ff-call)
(list ',external-name
,callback
,convention
',returning
',arg-types
,arg-checking
,entry-vec-flags))
else `(remprop ',lispname 'sys::direct-ff-call)))
Thus generating something like:
(EVAL-WHEN (COMPILE LOAD EVAL)
(SETF (GET 'FOO 'SYSTEM::DIRECT-FF-CALL)
(LIST '("foo" :LANGUAGE :C) T :C
'(:INT (INTEGER * *))
'((:INT (INTEGER * *))
(:FLOAT (SINGLE-FLOAT * *)))
T
2 ; this magic value is explained later
)))
"
(defun determine-foreign-address (name &optional (flags 0) method-index)
;; return an entry-vec struct suitable for the foreign-call of name.
;;
;; name is either a string, which is taken without conversion, or
;; a list consisting of a string to convert or a conversion function
;; call.
;; flags is an integer representing the flags to place into the entry-vec.
;; method-index, if non-nil, is a word-index into a vtbl (virtual table).
;; If method-index is true, then the name must be a string uniquely
;; represented by the index and by the flags field.
Note that not all architectures implement the :method-index argument
to def-foreign-call, but your interface likely won't support it
anyway, so just leave it nil. As for the flags, they are constants
stored into the entry-vec returned by d-f-a and are given here:
(defconstant ep-flag-call-semidirect 1) ; Real address stored in alt-address slot
(defconstant ep-flag-never-release 2) ; Never release the heap
(defconstant ep-flag-always-release 4) ; Always release the heap
(defconstant ep-flag-release-when-ok 8) ; Release the heap unless without-interrupts
(defconstant ep-flag-tramp-calls #x70) ; Make calls through special trampolines
(defconstant ep-flag-tramp-shift 4)
(defconstant ep-flag-variable-address #x100) ; Entry-point contains address of C var
(defconstant ep-flag-strings-convert #x200) ; Convert strings automatically
(defconstant ep-flag-get-errno #x1000) ;; [rfe5060]: Get errno value after call
(defconstant ep-flag-get-last-error #x2000) ;; [rfe5060]: call GetLastError after call
;; Leave #x4000 and #x8000 open for expansion
Mostly, you'll give the value 2 (never release the heap), but if you
give 4 or 8, then d-f-a will automatically set the 1 bit as well,
which takes the call through a heap-release/reacquire process.
Some docs for entry-vec are:
;; -- entry vec --
;; An entry-vec is an entry-point descriptor, usually a pointer into
;; a shared-library. It is represented as a 5-element struct of type
;; foreign-vector. The reason for this represntation is
;; that it allows the entry point to be stored in a table, called
;; the .saved-entry-points. table, and to be used by a foreign
;; function. When the location of the foreign function to which the entry
;; point refers changes, it is simply a matter of changing the value in entry
;; point vector and the foreign call code sees it immediately. There is
;; even an address that can be put in the entry point vector that denotes
;; a missing foreign function, thus lookup can happen dynamically.
(defstruct (entry-vec
(:type (vector excl::foreign (*)))
(:constructor make-entry-vec-boa ()))
name ; entry point name
(address 0) ; jump address for foreign code
(handle 0) ; shared-lib handle
(flags 0) ; ep-* flags
(alt-address 0) ; sometimes holds the real func addr
)
[...]
"
Regarding the arguments to SYSTEM::FF-FUNCALL:
'(:int (integer * *)) argN
"The type-spec is as it is given in the def-foreign-call
syntax, with a C type optionally followed by a lisp type,
followed optionally by a user-conversion function name[...]"
Getting the alignment:
CL-USER(2): (ff:get-foreign-type :int)
#S(FOREIGN-FUNCTIONS::IFOREIGN-TYPE
:ATTRIBUTES NIL
:SFTYPE
#S(FOREIGN-FUNCTIONS::SIZED-FTYPE-PRIM
:KIND :INT
:WIDTH 4
:OFFSET 0
:ALIGN 4)
...)
| 5,245 | Common Lisp | .l | 109 | 42.889908 | 86 | 0.690006 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 152e86960f7557c3fdb44a1b38c9a649e6b121179f01f505a1d24429a1334510 | 1,043 | [
-1
] |
1,071 | utf-32-with-le-bom.txt | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/babel/tests/utf-32-with-le-bom.txt |
UTF-8 encoded sample plain-text file
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
Markus Kuhn [ˈmaʳkʊs kuːn] <http://www.cl.cam.ac.uk/~mgk25/> — 2002-07-25
The ASCII compatible UTF-8 encoding used in this plain-text file
is defined in Unicode, ISO 10646-1, and RFC 2279.
Using Unicode/UTF-8, you can write in emails and source code things such as
Mathematics and sciences:
∮ E⋅da = Q, n → ∞, ∑ f(i) = ∏ g(i), ⎧⎡⎛┌─────┐⎞⎤⎫
⎪⎢⎜│a²+b³ ⎟⎥⎪
∀x∈ℝ: ⌈x⌉ = −⌊−x⌋, α ∧ ¬β = ¬(¬α ∨ β), ⎪⎢⎜│───── ⎟⎥⎪
⎪⎢⎜⎷ c₈ ⎟⎥⎪
ℕ ⊆ ℕ₀ ⊂ ℤ ⊂ ℚ ⊂ ℝ ⊂ ℂ, ⎨⎢⎜ ⎟⎥⎬
⎪⎢⎜ ∞ ⎟⎥⎪
⊥ < a ≠ b ≡ c ≤ d ≪ ⊤ ⇒ (⟦A⟧ ⇔ ⟪B⟫), ⎪⎢⎜ ⎲ ⎟⎥⎪
⎪⎢⎜ ⎳aⁱ-bⁱ⎟⎥⎪
2H₂ + O₂ ⇌ 2H₂O, R = 4.7 kΩ, ⌀ 200 mm ⎩⎣⎝i=1 ⎠⎦⎭
Linguistics and dictionaries:
ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeıʃn
Y [ˈʏpsilɔn], Yen [jɛn], Yoga [ˈjoːgɑ]
APL:
((V⍳V)=⍳⍴V)/V←,V ⌷←⍳→⍴∆∇⊃‾⍎⍕⌈
Nicer typography in plain text files:
╔══════════════════════════════════════════╗
║ ║
║ • ‘single’ and “double” quotes ║
║ ║
║ • Curly apostrophes: “We’ve been here” ║
║ ║
║ • Latin-1 apostrophe and accents: '´` ║
║ ║
║ • ‚deutsche‘ „Anführungszeichen“ ║
║ ║
║ • †, ‡, ‰, •, 3–4, —, −5/+5, ™, … ║
║ ║
║ • ASCII safety test: 1lI|, 0OD, 8B ║
║ ╭─────────╮ ║
║ • the euro symbol: │ 14.95 € │ ║
║ ╰─────────╯ ║
╚══════════════════════════════════════════╝
Combining characters:
STARGΛ̊TE SG-1, a = v̇ = r̈, a⃑ ⊥ b⃑
Greek (in Polytonic):
The Greek anthem:
Σὲ γνωρίζω ἀπὸ τὴν κόψη
τοῦ σπαθιοῦ τὴν τρομερή,
σὲ γνωρίζω ἀπὸ τὴν ὄψη
ποὺ μὲ βία μετράει τὴ γῆ.
᾿Απ᾿ τὰ κόκκαλα βγαλμένη
τῶν ῾Ελλήνων τὰ ἱερά
καὶ σὰν πρῶτα ἀνδρειωμένη
χαῖρε, ὦ χαῖρε, ᾿Ελευθεριά!
From a speech of Demosthenes in the 4th century BC:
Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν, ὦ ἄνδρες ᾿Αθηναῖοι,
ὅταν τ᾿ εἰς τὰ πράγματα ἀποβλέψω καὶ ὅταν πρὸς τοὺς
λόγους οὓς ἀκούω· τοὺς μὲν γὰρ λόγους περὶ τοῦ
τιμωρήσασθαι Φίλιππον ὁρῶ γιγνομένους, τὰ δὲ πράγματ᾿
εἰς τοῦτο προήκοντα, ὥσθ᾿ ὅπως μὴ πεισόμεθ᾿ αὐτοὶ
πρότερον κακῶς σκέψασθαι δέον. οὐδέν οὖν ἄλλο μοι δοκοῦσιν
οἱ τὰ τοιαῦτα λέγοντες ἢ τὴν ὑπόθεσιν, περὶ ἧς βουλεύεσθαι,
οὐχὶ τὴν οὖσαν παριστάντες ὑμῖν ἁμαρτάνειν. ἐγὼ δέ, ὅτι μέν
ποτ᾿ ἐξῆν τῇ πόλει καὶ τὰ αὑτῆς ἔχειν ἀσφαλῶς καὶ Φίλιππον
τιμωρήσασθαι, καὶ μάλ᾿ ἀκριβῶς οἶδα· ἐπ᾿ ἐμοῦ γάρ, οὐ πάλαι
γέγονεν ταῦτ᾿ ἀμφότερα· νῦν μέντοι πέπεισμαι τοῦθ᾿ ἱκανὸν
προλαβεῖν ἡμῖν εἶναι τὴν πρώτην, ὅπως τοὺς συμμάχους
σώσομεν. ἐὰν γὰρ τοῦτο βεβαίως ὑπάρξῃ, τότε καὶ περὶ τοῦ
τίνα τιμωρήσεταί τις καὶ ὃν τρόπον ἐξέσται σκοπεῖν· πρὶν δὲ
τὴν ἀρχὴν ὀρθῶς ὑποθέσθαι, μάταιον ἡγοῦμαι περὶ τῆς
τελευτῆς ὁντινοῦν ποιεῖσθαι λόγον.
Δημοσθένους, Γ´ ᾿Ολυνθιακὸς
Georgian:
From a Unicode conference invitation:
გთხოვთ ახლავე გაიაროთ რეგისტრაცია Unicode-ის მეათე საერთაშორისო
კონფერენციაზე დასასწრებად, რომელიც გაიმართება 10-12 მარტს,
ქ. მაინცში, გერმანიაში. კონფერენცია შეჰკრებს ერთად მსოფლიოს
ექსპერტებს ისეთ დარგებში როგორიცაა ინტერნეტი და Unicode-ი,
ინტერნაციონალიზაცია და ლოკალიზაცია, Unicode-ის გამოყენება
ოპერაციულ სისტემებსა, და გამოყენებით პროგრამებში, შრიფტებში,
ტექსტების დამუშავებასა და მრავალენოვან კომპიუტერულ სისტემებში.
Russian:
From a Unicode conference invitation:
Зарегистрируйтесь сейчас на Десятую Международную Конференцию по
Unicode, которая состоится 10-12 марта 1997 года в Майнце в Германии.
Конференция соберет широкий круг экспертов по вопросам глобального
Интернета и Unicode, локализации и интернационализации, воплощению и
применению Unicode в различных операционных системах и программных
приложениях, шрифтах, верстке и многоязычных компьютерных системах.
Thai (UCS Level 2):
Excerpt from a poetry on The Romance of The Three Kingdoms (a Chinese
classic 'San Gua'):
[----------------------------|------------------------]
๏ แผ่นดินฮั่นเสื่อมโทรมแสนสังเวช พระปกเกศกองบู๊กู้ขึ้นใหม่
สิบสองกษัตริย์ก่อนหน้าแลถัดไป สององค์ไซร้โง่เขลาเบาปัญญา
ทรงนับถือขันทีเป็นที่พึ่ง บ้านเมืองจึงวิปริตเป็นนักหนา
โฮจิ๋นเรียกทัพทั่วหัวเมืองมา หมายจะฆ่ามดชั่วตัวสำคัญ
เหมือนขับไสไล่เสือจากเคหา รับหมาป่าเข้ามาเลยอาสัญ
ฝ่ายอ้องอุ้นยุแยกให้แตกกัน ใช้สาวนั้นเป็นชนวนชื่นชวนใจ
พลันลิฉุยกุยกีกลับก่อเหตุ ช่างอาเพศจริงหนาฟ้าร้องไห้
ต้องรบราฆ่าฟันจนบรรลัย ฤๅหาใครค้ำชูกู้บรรลังก์ ฯ
(The above is a two-column text. If combining characters are handled
correctly, the lines of the second column should be aligned with the
| character above.)
Ethiopian:
Proverbs in the Amharic language:
ሰማይ አይታረስ ንጉሥ አይከሰስ።
ብላ ካለኝ እንደአባቴ በቆመጠኝ።
ጌጥ ያለቤቱ ቁምጥና ነው።
ደሀ በሕልሙ ቅቤ ባይጠጣ ንጣት በገደለው።
የአፍ ወለምታ በቅቤ አይታሽም።
አይጥ በበላ ዳዋ ተመታ።
ሲተረጉሙ ይደረግሙ።
ቀስ በቀስ፥ ዕንቁላል በእግሩ ይሄዳል።
ድር ቢያብር አንበሳ ያስር።
ሰው እንደቤቱ እንጅ እንደ ጉረቤቱ አይተዳደርም።
እግዜር የከፈተውን ጉሮሮ ሳይዘጋው አይድርም።
የጎረቤት ሌባ፥ ቢያዩት ይስቅ ባያዩት ያጠልቅ።
ሥራ ከመፍታት ልጄን ላፋታት።
ዓባይ ማደሪያ የለው፥ ግንድ ይዞ ይዞራል።
የእስላም አገሩ መካ የአሞራ አገሩ ዋርካ።
ተንጋሎ ቢተፉ ተመልሶ ባፉ።
ወዳጅህ ማር ቢሆን ጨርስህ አትላሰው።
እግርህን በፍራሽህ ልክ ዘርጋ።
Runes:
ᚻᛖ ᚳᚹᚫᚦ ᚦᚫᛏ ᚻᛖ ᛒᚢᛞᛖ ᚩᚾ ᚦᚫᛗ ᛚᚪᚾᛞᛖ ᚾᚩᚱᚦᚹᛖᚪᚱᛞᚢᛗ ᚹᛁᚦ ᚦᚪ ᚹᛖᛥᚫ
(Old English, which transcribed into Latin reads 'He cwaeth that he
bude thaem lande northweardum with tha Westsae.' and means 'He said
that he lived in the northern land near the Western Sea.')
Braille:
⡌⠁⠧⠑ ⠼⠁⠒ ⡍⠜⠇⠑⠹⠰⠎ ⡣⠕⠌
⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠙⠑⠁⠙⠒ ⠞⠕ ⠃⠑⠛⠔ ⠺⠊⠹⠲ ⡹⠻⠑ ⠊⠎ ⠝⠕ ⠙⠳⠃⠞
⠱⠁⠞⠑⠧⠻ ⠁⠃⠳⠞ ⠹⠁⠞⠲ ⡹⠑ ⠗⠑⠛⠊⠌⠻ ⠕⠋ ⠙⠊⠎ ⠃⠥⠗⠊⠁⠇ ⠺⠁⠎
⠎⠊⠛⠝⠫ ⠃⠹ ⠹⠑ ⠊⠇⠻⠛⠹⠍⠁⠝⠂ ⠹⠑ ⠊⠇⠻⠅⠂ ⠹⠑ ⠥⠝⠙⠻⠞⠁⠅⠻⠂
⠁⠝⠙ ⠹⠑ ⠡⠊⠑⠋ ⠍⠳⠗⠝⠻⠲ ⡎⠊⠗⠕⠕⠛⠑ ⠎⠊⠛⠝⠫ ⠊⠞⠲ ⡁⠝⠙
⡎⠊⠗⠕⠕⠛⠑⠰⠎ ⠝⠁⠍⠑ ⠺⠁⠎ ⠛⠕⠕⠙ ⠥⠏⠕⠝ ⠰⡡⠁⠝⠛⠑⠂ ⠋⠕⠗ ⠁⠝⠹⠹⠔⠛ ⠙⠑
⠡⠕⠎⠑ ⠞⠕ ⠏⠥⠞ ⠙⠊⠎ ⠙⠁⠝⠙ ⠞⠕⠲
⡕⠇⠙ ⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠁⠎ ⠙⠑⠁⠙ ⠁⠎ ⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲
⡍⠔⠙⠖ ⡊ ⠙⠕⠝⠰⠞ ⠍⠑⠁⠝ ⠞⠕ ⠎⠁⠹ ⠹⠁⠞ ⡊ ⠅⠝⠪⠂ ⠕⠋ ⠍⠹
⠪⠝ ⠅⠝⠪⠇⠫⠛⠑⠂ ⠱⠁⠞ ⠹⠻⠑ ⠊⠎ ⠏⠜⠞⠊⠊⠥⠇⠜⠇⠹ ⠙⠑⠁⠙ ⠁⠃⠳⠞
⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲ ⡊ ⠍⠊⠣⠞ ⠙⠁⠧⠑ ⠃⠑⠲ ⠔⠊⠇⠔⠫⠂ ⠍⠹⠎⠑⠇⠋⠂ ⠞⠕
⠗⠑⠛⠜⠙ ⠁ ⠊⠕⠋⠋⠔⠤⠝⠁⠊⠇ ⠁⠎ ⠹⠑ ⠙⠑⠁⠙⠑⠌ ⠏⠊⠑⠊⠑ ⠕⠋ ⠊⠗⠕⠝⠍⠕⠝⠛⠻⠹
⠔ ⠹⠑ ⠞⠗⠁⠙⠑⠲ ⡃⠥⠞ ⠹⠑ ⠺⠊⠎⠙⠕⠍ ⠕⠋ ⠳⠗ ⠁⠝⠊⠑⠌⠕⠗⠎
⠊⠎ ⠔ ⠹⠑ ⠎⠊⠍⠊⠇⠑⠆ ⠁⠝⠙ ⠍⠹ ⠥⠝⠙⠁⠇⠇⠪⠫ ⠙⠁⠝⠙⠎
⠩⠁⠇⠇ ⠝⠕⠞ ⠙⠊⠌⠥⠗⠃ ⠊⠞⠂ ⠕⠗ ⠹⠑ ⡊⠳⠝⠞⠗⠹⠰⠎ ⠙⠕⠝⠑ ⠋⠕⠗⠲ ⡹⠳
⠺⠊⠇⠇ ⠹⠻⠑⠋⠕⠗⠑ ⠏⠻⠍⠊⠞ ⠍⠑ ⠞⠕ ⠗⠑⠏⠑⠁⠞⠂ ⠑⠍⠏⠙⠁⠞⠊⠊⠁⠇⠇⠹⠂ ⠹⠁⠞
⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠁⠎ ⠙⠑⠁⠙ ⠁⠎ ⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲
(The first couple of paragraphs of "A Christmas Carol" by Dickens)
Compact font selection example text:
ABCDEFGHIJKLMNOPQRSTUVWXYZ /0123456789
abcdefghijklmnopqrstuvwxyz £©µÀÆÖÞßéöÿ
–—‘“”„†•…‰™œŠŸž€ ΑΒΓΔΩαβγδω АБВГДабвгд
∀∂∈ℝ∧∪≡∞ ↑↗↨↻⇣ ┐┼╔╘░►☺♀ fi�⑀₂ἠḂӥẄɐː⍎אԱა
Greetings in various languages:
Hello world, Καλημέρα κόσμε, コンニチハ
Box drawing alignment tests: █
▉
╔══╦══╗ ┌──┬──┐ ╭──┬──╮ ╭──┬──╮ ┏━━┳━━┓ ┎┒┏┑ ╷ ╻ ┏┯┓ ┌┰┐ ▊ ╱╲╱╲╳╳╳
║┌─╨─┐║ │╔═╧═╗│ │╒═╪═╕│ │╓─╁─╖│ ┃┌─╂─┐┃ ┗╃╄┙ ╶┼╴╺╋╸┠┼┨ ┝╋┥ ▋ ╲╱╲╱╳╳╳
║│╲ ╱│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╿ │┃ ┍╅╆┓ ╵ ╹ ┗┷┛ └┸┘ ▌ ╱╲╱╲╳╳╳
╠╡ ╳ ╞╣ ├╢ ╟┤ ├┼─┼─┼┤ ├╫─╂─╫┤ ┣┿╾┼╼┿┫ ┕┛┖┚ ┌┄┄┐ ╎ ┏┅┅┓ ┋ ▍ ╲╱╲╱╳╳╳
║│╱ ╲│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╽ │┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▎
║└─╥─┘║ │╚═╤═╝│ │╘═╪═╛│ │╙─╀─╜│ ┃└─╂─┘┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▏
╚══╩══╝ └──┴──┘ ╰──┴──╯ ╰──┴──╯ ┗━━┻━━┛ ▗▄▖▛▀▜ └╌╌┘ ╎ ┗╍╍┛ ┋ ▁▂▃▄▅▆▇█
▝▀▘▙▄▟
| 30,488 | Common Lisp | .l | 162 | 42.209877 | 79 | 0.498583 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 12ac0c569d6f7e6d2e41e25cc6aaee4838088b6897d24ce2a3de8c4c8e4c9d3b | 1,071 | [
-1
] |
1,075 | gen-test-files.sh | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/babel/tests/gen-test-files.sh | #!/bin/sh
# -*- indent-tabs-mode: nil -*-
#
# gen-test-files.sh --- Generates test files with iconv.
#
# Copyright (C) 2007, Luis Oliveira <[email protected]>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use, copy,
# modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
INPUT_FILE="utf-8.txt"
INPUT_ENC="utf-8"
CHARSETS=('ebcdic-us' 'ascii' 'iso-8859-1' 'utf-16' 'utf-32')
echo "Converting $INPUT_FILE..."
for c in ${CHARSETS[@]}; do
echo " ${c}.txt";
iconv -c -f $INPUT_ENC -t $c $INPUT_FILE > ${c}.txt;
iconv -f $c -t 'utf-8' ${c}.txt > ${c}.txt-utf8;
done
| 1,534 | Common Lisp | .l | 35 | 42.428571 | 68 | 0.740815 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | bc1b9dbb38fc2beb340b2561e78128792f3acb7e3a5cba73d9795c4e9965beb3 | 1,075 | [
-1
] |
1,077 | Makefile | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/babel/doc/Makefile | # -*- Mode: Makefile; tab-width: 4; indent-tabs-mode: t -*-
MANUAL := "babel"
SYSTEM := "babel"
PACKAGES := babel babel-encodings
TITLE := "Babel Manual"
CSS := "default"
export LISP ?= sbcl
export SBCL_OPTIONS ?= --noinform
.PHONY: all clean html pdf upload
all:
texinfo-docstrings all $(SYSTEM) $(MANUAL) $(TITLE) $(CSS) $(PACKAGES)
pdf:
texinfo-docstrings pdf $(SYSTEM) $(MANUAL) $(TITLE) $(CSS) $(PACKAGES)
html:
texinfo-docstrings html $(SYSTEM) $(MANUAL) $(TITLE) $(CSS) $(PACKAGES)
upload:
# rsync -av --delete -e ssh manual common-lisp.net:/project/FOO/public_html/
# scp -r manual common-lisp.net:/project/cffi/public_html/
clean:
find . \( -name "*.pdf" -o -name "*.html" -o -name "*.info" -o -name "*.aux" -o -name "*.cp" -o -name "*.fn" -o -name "*.fns" -o -name "*.ky" -o -name "*.log" -o -name "*.pg" -o -name "*.toc" -o -name "*.tp" -o -name "*.vr" -o -name "*.dvi" -o -name "*.cps" -o -name "*.vrs" \) -exec rm {} \;
rm -rf include manual
# vim: ft=make ts=4 noet
| 994 | Common Lisp | .l | 22 | 43.545455 | 293 | 0.63136 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 62c1b9b1c6951a0c8c8f86a47ffe3ec6ea8264f0871ba4f31566c8780ddbf653 | 1,077 | [
-1
] |
1,078 | babel.texinfo | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/babel/doc/babel.texinfo | \input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename babel.info
@settitle Babel Manual
@c @exampleindent 2
@c @documentencoding utf-8
@c %**end of header
@c for install-info
@c @dircategory %%INFO-CATEGORY%%
@c @direntry
@c * babel: %%PROJECT-DESCRIPTION%%
@c @end direntry
@include macros.texinfo
@c Show types, functions, and concepts in the same index.
@syncodeindex tp cp
@syncodeindex fn cp
@copying
@c Copyright @copyright{} 2084 John Doe <[email protected]>
@include license.texinfo
@end copying
@titlepage
@title Babel Manual
@subtitle draft version
@c @author John Doe
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
@ifnottex
@node Top
@top babel
@insertcopying
@end ifnottex
@c Top Menu
@menu
* First Chapter::
* Comprehensive Index::
@end menu
@node First Chapter
@chapter First Chapter
Bla bla bla, bla bla bla.
@section Conditions
@include include/condition-babel-character-out-of-range.texinfo
@include include/condition-babel-encodings-character-out-of-range.texinfo
@include include/condition-babel-encodings-end-of-input-in-character.texinfo
@include include/condition-babel-encodings-invalid-utf8-continuation-byte.texinfo
@include include/condition-babel-encodings-invalid-utf8-starter-byte.texinfo
@include include/condition-babel-encodings-overlong-utf8-sequence.texinfo
@include include/condition-babel-end-of-input-in-character.texinfo
@include include/condition-babel-invalid-utf8-continuation-byte.texinfo
@include include/condition-babel-invalid-utf8-starter-byte.texinfo
@include include/condition-babel-overlong-utf8-sequence.texinfo
@include include/constant-babel-unicode-char-code-limit.texinfo
@section More stuff
@include include/fun-babel-encodings-get-character-encoding.texinfo
@include include/fun-babel-encodings-list-character-encodings.texinfo
@include include/fun-babel-encodings-lookup-mapping.texinfo
@include include/fun-babel-list-character-encodings.texinfo
@include include/macro-babel-encodings-with-checked-simple-vector.texinfo
@include include/macro-babel-encodings-with-simple-vector.texinfo
@include include/type-babel-simple-unicode-string.texinfo
@include include/type-babel-unicode-char.texinfo
@include include/type-babel-unicode-string.texinfo
@include include/var-babel-encodings-star-default-character-encoding-star.texinfo
@include include/var-babel-encodings-star-suppress-character-coding-errors-star.texinfo
@include include/var-babel-star-default-character-encoding-star.texinfo
@include include/var-babel-star-default-eol-style-star.texinfo
@c @include include/fun-somepackage-somefunction.texinfo
@c @include include/macro-somepackage-somemacro.texinfo
@c @node First Section
@c @section First Section
@c @include include/fun-somepackage-somefunction.texinfo
@c @include include/fun-somepackage-somefunction.texinfo
@c We call this node ``Comprehensive Index'' so that texinfo's HTML
@c output doesn't generate an index.html that'd overwrite the manual's
@c initial page.
@node Comprehensive Index
@unnumbered Index
@printindex cp
@bye
| 3,094 | Common Lisp | .l | 81 | 36.604938 | 87 | 0.826698 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 719009ef4bdfa37f2f826d5d791b5facd724c53892e39e0188dd36b98209a009 | 1,078 | [
-1
] |
1,079 | release.sh | cac-t-u-s_om-sharp/src/api/foreign-interface/ffi/babel/scripts/release.sh | #!/bin/bash
### Configuration
PROJECT_NAME='babel'
ASDF_FILE="$PROJECT_NAME.asd"
HOST="common-lisp.net"
RELEASE_DIR="/project/$PROJECT_NAME/public_html/releases"
VERSION_FILE="VERSION"
VERSION_FILE_DIR="/project/$PROJECT_NAME/public_html"
set -e
### Process options
FORCE=0
VERSION=""
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
echo "No help, sorry. Read the source."
exit 0
;;
-f|--force)
FORCE=1
shift
;;
-v|--version)
VERSION="$2"
shift 2
;;
*)
echo "Unrecognized argument '$1'"
exit 1
;;
esac
done
### Check for unrecorded changes
if darcs whatsnew; then
echo -n "Unrecorded changes. "
if [ "$FORCE" -ne 1 ]; then
echo "Aborting."
echo "Use -f or --force if you want to make a release anyway."
exit 1
else
echo "Continuing anyway."
fi
fi
### Determine new version number
if [ -z "$VERSION" ]; then
CURRENT_VERSION=$(grep :version $ASDF_FILE | cut -d\" -f2)
dots=$(echo "$CURRENT_VERSION" | tr -cd '.')
count=$(expr length "$dots" + 1)
declare -a versions
for i in $(seq $count); do
new=""
for j in $(seq $(expr $i - 1)); do
p=$(echo "$CURRENT_VERSION" | cut -d. -f$j)
new="$new$p."
done
part=$(expr 1 + $(echo "$CURRENT_VERSION" | cut -d. -f$i))
new="$new$part"
for j in $(seq $(expr $i + 1) $count); do new="$new.0"; done
versions[$i]=$new
done
while true; do
echo "Current version is $CURRENT_VERSION. Which will be next one?"
for i in $(seq $count); do echo " $i) ${versions[$i]}"; done
echo -n "? "
read choice
if ((choice > 0)) && ((choice <= ${#versions[@]})); then
VERSION=${versions[$choice]}
break
fi
done
fi
### Do it
TARBALL_NAME="${PROJECT_NAME}_${VERSION}"
TARBALL="$TARBALL_NAME.tar.gz"
SIGNATURE="$TARBALL.asc"
echo "Updating $ASDF_FILE with new version: $VERSION"
sed -e "s/:version \"$CURRENT_VERSION\"/:version \"$VERSION\"/" \
"$ASDF_FILE" > "$ASDF_FILE.tmp"
mv "$ASDF_FILE.tmp" "$ASDF_FILE"
darcs record -m "update $ASDF_FILE for version $VERSION"
echo "Tagging the tree..."
darcs tag "$VERSION"
echo "Creating distribution..."
darcs dist -d "$TARBALL_NAME"
echo "Signing tarball..."
gpg -b -a "$TARBALL"
echo "Copying tarball to web server..."
scp "$TARBALL" "$SIGNATURE" "$HOST:$RELEASE_DIR"
echo "Uploaded $TARBALL and $SIGNATURE."
echo "Updating ${PROJECT_NAME}_latest links..."
ssh $HOST ln -sf "$TARBALL" "$RELEASE_DIR/${PROJECT_NAME}_latest.tar.gz"
ssh $HOST ln -sf "$SIGNATURE" "$RELEASE_DIR/${PROJECT_NAME}_latest.tar.gz.asc"
if [ "$VERSION_FILE" ]; then
echo "Uploading $VERSION_FILE..."
echo -n "$VERSION" > "$VERSION_FILE"
scp "$VERSION_FILE" "$HOST":"$VERSION_FILE_DIR"
rm "$VERSION_FILE"
fi
while true; do
echo -n "Clean local tarball and signature? [y] "
read -n 1 response
case "$response" in
y|'')
echo
rm "$TARBALL" "$SIGNATURE"
break
;;
n)
break
;;
*)
echo "Invalid response '$response'. Try again."
;;
esac
done
echo "Pushing changes..."
darcs push
| 3,399 | Common Lisp | .l | 117 | 22.940171 | 78 | 0.570639 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 8f2c6e9d20a594c42fbf5470007ccaa7ab4a6791671bae050f57f983d00b0181 | 1,079 | [
-1
] |
1,184 | clixdoc.xsl | cac-t-u-s_om-sharp/src/lisp-externals/Yason/clixdoc.xsl | <?xml version="1.0" encoding="iso-8859-1" ?>
<!--
;;; Copyright (c) 2008, Hans Hübner. All rights reserved.
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;; * Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;; * Redistributions in binary form must reproduce the above
;;; copyright notice, this list of conditions and the following
;;; disclaimer in the documentation and/or other materials
;;; provided with the distribution.
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:clix="http://bknr.net/clixdoc"
exclude-result-prefixes="clix">
<xsl:output method="html"
indent="yes"
omit-xml-declaration="yes"
doctype-public="-//W3C//DTD HTML 4.0 Strict//EN" />
<xsl:template match="clix:current-release"><xsl:value-of select="$current-release"/></xsl:template>
<xsl:template match="/clix:documentation">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><xsl:value-of select="clix:title"/></title>
<meta name="description"><xsl:attribute name="content"><xsl:value-of select="clix:short-description"/></xsl:attribute></meta>
<style type="text/css">
body { background-color: #ffffff; max-width: 50em; margin-left: 2em; }
blockquote { margin-left: 2em; margin-right: 2em; }
pre { padding:5px; background-color:#e0e0e0 }
pre.none { padding:5px; background-color:#ffffff }
h3, h4, h5 { text-decoration: underline; }
a { text-decoration: none; padding: 1px 2px 1px 2px; }
a:visited { text-decoration: none; padding: 1px 2px 1px 2px; }
a:hover { text-decoration: none; padding: 1px 1px 1px 1px; border: 1px solid #000000; }
a:focus { text-decoration: none; padding: 1px 2px 1px 2px; border: none; }
a.none { text-decoration: none; padding: 0; }
a.none:visited { text-decoration: none; padding: 0; }
a.none:hover { text-decoration: none; border: none; padding: 0; }
a.none:focus { text-decoration: none; border: none; padding: 0; }
a.noborder { text-decoration: none; padding: 0; }
a.noborder:visited { text-decoration: none; padding: 0; }
a.noborder:hover { text-decoration: none; border: none; padding: 0; }
a.noborder:focus { text-decoration: none; border: none; padding: 0; }
</style>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="clix:title">
<h1><xsl:value-of select="."/></h1>
</xsl:template>
<xsl:template match="clix:short-description"/>
<xsl:template match="clix:function">
<p>
<xsl:choose>
<xsl:when test="@generic = 'true'">[Generic function]</xsl:when>
<xsl:when test="@specialized = 'true'">[Method]</xsl:when>
<xsl:when test="@macro = 'true'">[Macro]</xsl:when>
<xsl:otherwise>[Function]</xsl:otherwise>
</xsl:choose>
<br/>
<a class="none">
<xsl:attribute name="name">
<xsl:value-of select="translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
</xsl:attribute>
<b><xsl:value-of select="@name"/></b>
<xsl:value-of select="' '"/>
<i><xsl:apply-templates select="clix:lambda-list"/></i>
<xsl:if test="clix:returns">
=>
<i><xsl:value-of select="clix:returns"/></i>
</xsl:if>
</a>
<blockquote>
<xsl:apply-templates select="clix:description"/>
</blockquote>
</p>
</xsl:template>
<xsl:template match="clix:reader">
<p>
<xsl:choose>
<xsl:when test="@generic = 'true'">[Generic reader]</xsl:when>
<xsl:when test="@specialized = 'true'">[Specialized reader]</xsl:when>
<xsl:otherwise>[Reader]</xsl:otherwise>
</xsl:choose>
<br/>
<a class="none">
<xsl:attribute name="name">
<xsl:value-of select="translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
</xsl:attribute>
<b><xsl:value-of select="@name"/></b>
<xsl:value-of select="' '"/>
<i><xsl:apply-templates select="clix:lambda-list"/></i>
<xsl:if test="clix:returns">
=>
<i><xsl:value-of select="clix:returns"/></i>
</xsl:if>
</a>
<blockquote>
<xsl:apply-templates select="clix:description"/>
</blockquote>
</p>
</xsl:template>
<xsl:template match="clix:writer">
<p>
<xsl:choose>
<xsl:when test="@generic = 'true'">[Generic writer]</xsl:when>
<xsl:when test="@specialized = 'true'">[Specialized writer]</xsl:when>
<xsl:otherwise>[Writer]</xsl:otherwise>
</xsl:choose>
<br/>
<a class="none">
<xsl:attribute name="name">
<xsl:value-of select="translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
</xsl:attribute>
<tt>(setf (</tt><b><xsl:value-of select="@name"/></b>
<xsl:value-of select="' '"/>
<i><xsl:apply-templates select="clix:lambda-list"/></i><tt>) <i>new-value</i>)</tt>
<xsl:if test="clix:returns">
=>
<i><xsl:value-of select="clix:returns"/></i>
</xsl:if>
</a>
<blockquote>
<xsl:apply-templates select="clix:description"/>
</blockquote>
</p>
</xsl:template>
<xsl:template match="clix:accessor">
<p>
<xsl:choose>
<xsl:when test="@generic = 'true'">[Generic accessor]</xsl:when>
<xsl:when test="@specialized = 'true'">[Specialized accessor]</xsl:when>
<xsl:otherwise>[Accessor]</xsl:otherwise>
</xsl:choose>
<br/>
<a class="none">
<xsl:attribute name="name">
<xsl:value-of select="translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
</xsl:attribute>
<b><xsl:value-of select="@name"/></b>
<xsl:value-of select="' '"/>
<i><xsl:apply-templates select="clix:lambda-list"/></i>
=>
<i><xsl:value-of select="clix:returns"/></i>
<br/>
<tt>(setf (</tt><b><xsl:value-of select="@name"/></b>
<xsl:value-of select="' '"/>
<i><xsl:apply-templates select="clix:lambda-list"/></i><tt>) <i>new-value</i>)</tt>
</a>
<blockquote>
<xsl:apply-templates select="clix:description"/>
</blockquote>
</p>
</xsl:template>
<xsl:template match="clix:special-variable">
<p>
[Special variable]<br/>
<a class="none">
<xsl:attribute name="name">
<xsl:value-of select="translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
</xsl:attribute>
<b><xsl:value-of select="@name"/></b>
</a>
<blockquote>
<xsl:apply-templates select="clix:description"/>
</blockquote>
</p>
</xsl:template>
<xsl:template match="clix:class">
<p>
[Standard class]<br/>
<a class="none">
<xsl:attribute name="name">
<xsl:value-of select="translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
</xsl:attribute>
<b><xsl:value-of select="@name"/></b>
</a>
<blockquote>
<xsl:apply-templates select="clix:description"/>
</blockquote>
</p>
</xsl:template>
<xsl:template match="clix:condition">
<p>
[Condition type]<br/>
<a class="none">
<xsl:attribute name="name">
<xsl:value-of select="translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
</xsl:attribute>
<b><xsl:value-of select="@name"/></b>
</a>
<blockquote>
<xsl:apply-templates select="clix:description"/>
</blockquote>
</p>
</xsl:template>
<xsl:template match="clix:symbol">
<p>
[Symbol]<br/>
<a class="none">
<xsl:attribute name="name">
<xsl:value-of select="translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
</xsl:attribute>
<b><xsl:value-of select="@name"/></b>
</a>
<blockquote>
<xsl:apply-templates select="clix:description"/>
</blockquote>
</p>
</xsl:template>
<xsl:template match="clix:constant">
<p>
[Constant]<br/>
<a class="none">
<xsl:attribute name="name">
<xsl:value-of select="translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
</xsl:attribute>
<b><xsl:value-of select="@name"/></b>
</a>
<blockquote>
<xsl:apply-templates select="clix:description"/>
</blockquote>
</p>
</xsl:template>
<xsl:template match="clix:listed-constant">
<a class="none">
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
<b><xsl:value-of select="@name"/></b>
</a>
<br/>
</xsl:template>
<xsl:template match="clix:constants">
<!-- Display a list of constants with a common description -->
<p>
[Constants]<br/>
<xsl:apply-templates select="clix:listed-constant"/>
<blockquote>
<xsl:apply-templates select="clix:description"/>
</blockquote>
</p>
</xsl:template>
<xsl:template match="clix:logical-pathname-host">
<p>
[Logical Pathname Host]<br/>
<a class="none">
<xsl:attribute name="name">
<xsl:value-of select="translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
</xsl:attribute>
<b><xsl:value-of select="@name"/></b>
</a>
<blockquote>
<xsl:apply-templates select="clix:description"/>
</blockquote>
</p>
</xsl:template>
<xsl:template match="clix:qualifier">
<!-- method qualifier -->
<tt><xsl:value-of select="text()"/></tt>
</xsl:template>
<xsl:template match="clix:lkw">
<!-- lambda list keyword -->
<tt>&<xsl:value-of select="text()"/></tt>
</xsl:template>
<xsl:template match="clix:arg">
<!-- argument reference -->
<code><i><xsl:value-of select="text()"/></i></code>
</xsl:template>
<xsl:template name="internal-reference">
<!-- internal reference -->
<xsl:param name="name"/>
<code>
<a>
<xsl:attribute name="href">
#<xsl:value-of select="translate($name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
</xsl:attribute>
<xsl:value-of select="$name"/>
</a>
</code>
</xsl:template>
<xsl:template match="clix:ref">
<xsl:call-template name="internal-reference">
<xsl:with-param name="name"><xsl:value-of select="."/></xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="clix:hyperspec">
<a>
<xsl:attribute name="href">http://www.lispworks.com/documentation/HyperSpec/Body/<xsl:value-of select="@link"/></xsl:attribute>
<xsl:value-of select="."/>
</a>
</xsl:template>
<xsl:template match="clix:chapter">
<h3>
<a class="none">
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
<xsl:value-of select="@title"/>
</a>
</h3>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="clix:subchapter">
<h4>
<a>
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
<xsl:value-of select="@title"/>
</a>
</h4>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="clix:abstract">
<h3>Abstract</h3>
<blockquote>
<xsl:apply-templates/>
</blockquote>
</xsl:template>
<xsl:template match="clix:contents">
<h3>Contents</h3>
<ol>
<xsl:for-each select="//clix:chapter">
<li>
<a>
<xsl:attribute name="href">#<xsl:value-of select="@name"/></xsl:attribute>
<xsl:value-of select="@title"/>
</a>
<xsl:if test="clix:subchapter">
<ol>
<xsl:for-each select="clix:subchapter">
<li>
<a>
<xsl:attribute name="href">#<xsl:value-of select="@name"/></xsl:attribute>
<xsl:value-of select="@title"/>
</a>
</li>
</xsl:for-each>
</ol>
</xsl:if>
</li>
</xsl:for-each>
</ol>
</xsl:template>
<xsl:template match="clix:index">
<ul>
<xsl:for-each select="(//clix:function | //clix:reader | //clix:writer | //clix:accessor | //clix:class | //clix:condition | //clix:constant | //clix:listed-constant | //clix:special-variable | //clix:symbol)">
<xsl:sort select="@name"/>
<li>
<xsl:call-template name="internal-reference">
<xsl:with-param name="name"><xsl:value-of select="@name"/></xsl:with-param>
</xsl:call-template>
</li>
</xsl:for-each>
</ul>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*[not(namespace-uri())]"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
| 14,079 | Common Lisp | .l | 376 | 30.742021 | 216 | 0.607112 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | ff81225510147688635280440db8c4fd5c24d7b357520835bc1c4fa0462dba45 | 1,184 | [
-1
] |
1,185 | doc.html | cac-t-u-s_om-sharp/src/lisp-externals/Yason/doc.html | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta><title>YASON - A JSON encoder/decoder for Common Lisp</title><meta name="description" content="
YASON is a JSON encoding and decoding library for Common Lisp. It
provides for functions to read JSON strings into Lisp data
structures and for serializing Lisp data structures as JSON
strings.
"></meta><style type="text/css">
body { background-color: #ffffff; max-width: 50em; margin-left: 2em; }
blockquote { margin-left: 2em; margin-right: 2em; }
pre { padding:5px; background-color:#e0e0e0 }
pre.none { padding:5px; background-color:#ffffff }
h3, h4, h5 { text-decoration: underline; }
a { text-decoration: none; padding: 1px 2px 1px 2px; }
a:visited { text-decoration: none; padding: 1px 2px 1px 2px; }
a:hover { text-decoration: none; padding: 1px 1px 1px 1px; border: 1px solid #000000; }
a:focus { text-decoration: none; padding: 1px 2px 1px 2px; border: none; }
a.none { text-decoration: none; padding: 0; }
a.none:visited { text-decoration: none; padding: 0; }
a.none:hover { text-decoration: none; border: none; padding: 0; }
a.none:focus { text-decoration: none; border: none; padding: 0; }
a.noborder { text-decoration: none; padding: 0; }
a.noborder:visited { text-decoration: none; padding: 0; }
a.noborder:hover { text-decoration: none; border: none; padding: 0; }
a.noborder:focus { text-decoration: none; border: none; padding: 0; }
</style></head><body>
<h1 xmlns="">YASON - A JSON encoder/decoder for Common Lisp</h1>
<h3 xmlns="">Abstract</h3>
<blockquote xmlns="">
YASON is a Common Lisp library for encoding and decoding data in
the <a xmlns="http://www.w3.org/1999/xhtml" href="http://json.org/">JSON</a> interchange format. JSON
is used as a lightweight alternative to XML. YASON has the sole
purpose of encoding and decoding data and does not impose any
object model on the Common Lisp application that uses it.
</blockquote>
<h3 xmlns="">Contents</h3>
<ol xmlns="">
<li><a href="#intro">Introduction</a></li>
<li><a href="#install">Download and Installation</a></li>
<li><a href="#json-package">Using JSON as package name</a></li>
<li><a href="#mapping">Mapping between JSON and CL datatypes</a></li>
<li>
<a href="#parsing">Parsing JSON data</a><ol><li><a href="#parser-dict">Parser dictionary</a></li></ol>
</li>
<li>
<a href="#encoding">Encoding JSON data</a><ol>
<li><a href="#dom-encoder">Encoding a JSON DOM</a></li>
<li><a href="#stream-encoder">Encoding JSON in streaming mode</a></li>
<li><a href="#app-encoders">Application specific encoders</a></li>
</ol>
</li>
<li><a href="#index">Symbol index</a></li>
<li><a href="#license">License</a></li>
<li><a href="#ack">Acknowledgements</a></li>
</ol>
<h3 xmlns=""><a class="none" name="intro">Introduction</a></h3>
<p>
<a href="http://json.org/">JSON</a> is an established
alternative to XML as a data interchange format for web
applications. YASON implements reading and writing of JSON
formatted data in Common Lisp. It does not attempt to provide a
mapping between CLOS objects and YASON, but can be used to
implement such mappings.
</p>
<p>
<a href="http://common-lisp.net/project/cl-json/">CL-JSON</a> is
another Common Lisp package that can be used to work with JSON
encoded data. It takes a more integrated approach, providing
for library internal mappings between JSON objects and CLOS
objects. YASON was created as a lightweight, documented
alternative with a minimalistic approach and extensibilty.
</p>
<h3 xmlns=""><a class="none" name="install">Download and Installation</a></h3>
<p>
YASON has its permanent home at <a href="http://common-lisp.net/project/yason/">common-lisp.net</a>.
It can be obtained by downloading the <a href="https://github.com/downloads/hanshuebner/yason/yason.tar.gz">release
tarball</a>. The current release is 0.6.2.
</p>
<p>
You may also check out the current development version from its
<a href="http://github.com/hanshuebner/yason/">git
repository</a>. If you have suggestions regarding YASON, please
email me at <i>[email protected]</i>.
</p>
<p>
YASON is written in ANSI Common Lisp. It depends on UNIT-TEST,
TRIVIAL-GRAY-STREAMS and ALEXANDRIA open source libraries. The
recommended way to install YASON and its dependencies is through
the excellent <a href="http://www.quicklisp.org/">Quicklisp</a>
library management system.
</p>
<p>
YASON lives in the <b>:yason</b> package and creates a package
nickname <b>:json</b>. Applications will not normally
<b>:use</b> this package, but rather use qualified names to
access YASON's symbols. For that reason, YASON's symbols do not
contain the string "JSON" themselves. See below for usage
samples.
</p>
<h3 xmlns=""><a class="none" name="json-package">Using JSON as package name</a></h3>
Versions of YASON preceding the v0.6.0 release provided a package
nickname "JSON" for the "YASON" package. This made it impossible
to load both YASON and CL-JSON into the same image, because
CL-JSON uses the "JSON" package name as well.
<p>
As CL-JSON's use of "JSON" as package name has a much longer
history and loading of both CL-JSON and YASON into the same
image has become more common, the "JSON" nickname was removed
from the YASON package with the v0.6.0 release. Users will need
to change their applications so that the "JSON" nickname is no
longer used to refer to the "YASON" package. It is understood
that this is a disruptive change, but as there is no
all-encompassing workaround, this step was felt to be the right
one to make
</p>
<h3 xmlns=""><a class="none" name="mapping">Mapping between JSON and CL datatypes</a></h3>
By default, YASON performs the following mappings between JSON and
CL datatypes:
<table border="1">
<thead>
<tr>
<th>JSON<br></br>datatype</th>
<th>CL<br></br>datatype</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td>object</td>
<td>hash-table<br></br>:test #'equal</td>
<td>
Keys are strings by default (see
<code xmlns=""><a href="#*parse-object-key-fn*">*parse-object-key-fn*</a></code>). Set
<code xmlns=""><a href="#*parse-object-as*">*parse-object-as*</a></code> to <b>:alist</b> in
order to have YASON parse objects as alists or to
<b>:plist</b> to parse them as plists. When using plists,
you probably want to also set
<code xmlns=""><a href="#*parse-object-key-fn*">*parse-object-key-fn*</a></code> to a function
that interns the object's keys to symbols.
</td>
</tr>
<tr>
<td>array</td>
<td>list</td>
<td>
Can be changed to read to vectors (see
<code xmlns=""><a href="#*parse-json-arrays-as-vectors*">*parse-json-arrays-as-vectors*</a></code>).
</td>
</tr>
<tr>
<td>string</td>
<td>string</td>
<td>
JSON escape characters are recognized upon reading. Upon
writing, known escape characters are used, but non-ASCII
Unicode characters are written as is.
</td>
</tr>
<tr>
<td>number</td>
<td>number</td>
<td>
Parsed with READ, printed with PRINC. This is not a
faithful implementation of the specification.
</td>
</tr>
<tr>
<td>true</td>
<td>t</td>
<td>
Can be changed to read as TRUE (see
<code xmlns=""><a href="#*parse-json-booleans-as-symbols*">*parse-json-booleans-as-symbols*</a></code>).
</td>
</tr>
<tr>
<td>false</td>
<td>nil</td>
<td>
Can be changed to read as FALSE (see
<code xmlns=""><a href="#*parse-json-booleans-as-symbols*">*parse-json-booleans-as-symbols*</a></code>).
</td>
</tr>
<tr>
<td>null</td>
<td>nil</td>
<td></td>
</tr>
</tbody>
</table>
<h3 xmlns=""><a class="none" name="parsing">Parsing JSON data</a></h3>
<p>
JSON data is always completely parsed into an equivalent
in-memory representation. Upon reading, some translations are
performed by default to make it easier for the Common Lisp
program to work with the data; see <code xmlns=""><a href="#mapping">mapping</a></code>
for details. If desired, the parser can be configured to
preserve the full semantics of the JSON data read.
</p>
For example
<pre>CL-USER> (defvar *json-string* "[{\"foo\":1,\"bar\":[7,8,9]},2,3,4,[5,6,7],true,null]")
*JSON-STRING*
CL-USER> (let* ((result (yason:parse *json-string*)))
(print result)
(alexandria:hash-table-plist (first result)))
(#<HASH-TABLE :TEST EQUAL :COUNT 2 {5A4420F1}> 2 3 4 (5 6 7) T NIL)
("bar" (7 8 9) "foo" 1)
CL-USER> (defun maybe-convert-to-keyword (js-name)
(or (find-symbol (string-upcase js-name) :keyword)
js-name))
MAYBE-CONVERT-TO-KEYWORD
CL-USER> :FOO ; intern the :FOO keyword
:FOO
CL-USER> (let* ((yason:*parse-json-arrays-as-vectors* t)
(yason:*parse-json-booleans-as-symbols* t)
(yason:*parse-object-key-fn* #'maybe-convert-to-keyword)
(result (yason:parse *json-string*)))
(print result)
(alexandria:hash-table-plist (aref result 0)))
#(#<HASH-TABLE :TEST EQUAL :COUNT 2 {59B4EAD1}> 2 3 4 #(5 6 7) YASON:TRUE NIL)
("bar" #(7 8 9) :FOO 1)</pre>
<p>
The second example modifies the parser's behaviour so that JSON
arrays are read as CL vectors, JSON booleans will be read as the
symbols TRUE and FALSE and JSON object keys will be looked up in
the <b>:keyword</b> package. Interning strings coming from an
external source is not recommended practice.
</p>
<h4 xmlns=""><a name="parser-dict">Parser dictionary</a></h4>
<p xmlns="">[Function]<br><a class="none" name="parse"><b>parse</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">input &key (object-key-fn
*parse-object-as-key-fn*) (object-as *parse-object-as*)
(json-arrays-as-vectors *parse-json-arrays-as-vectors*)
(json-booleans-as-symbols *parse-json-booleans-as-symbols*)
(json-nulls-as-keyword *parse-json-null-as-keyword*)</clix:lambda-list></i>
=>
<i>object</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Parse <code><i>input</i></code>, which must be a string or
a stream, as JSON. Returns the Lisp representation of the
JSON structure parsed.
<p xmlns="http://www.w3.org/1999/xhtml">
The keyword arguments <code xmlns=""><i>object-key-fn</i></code>,
<code xmlns=""><i>object-as</i></code>,
<code xmlns=""><i>json-arrays-as-vectors</i></code>,
<code xmlns=""><i>json-booleans-as-symbols</i></code>, and
<code xmlns=""><i>json-null-as-keyword</i></code> may be used
to specify different values for the parsing parameters
from the current bindings of the respective special
variables.
</p>
</clix:description></blockquote></p>
<p xmlns="">
[Special variable]<br><a class="none" name="*parse-json-arrays-as-vectors*"><b>*parse-json-arrays-as-vectors*</b></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
If set to a true value, JSON arrays will be parsed as
vectors, not as lists. NIL is the default.
</clix:description></blockquote></p>
<p xmlns="">
[Special variable]<br><a class="none" name="*parse-object-as*"><b>*parse-object-as*</b></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Can be set to <b xmlns="http://www.w3.org/1999/xhtml">:hash-table</b> to parse objects as hash
tables, <b xmlns="http://www.w3.org/1999/xhtml">:alist</b> to parse them as alists or
<b xmlns="http://www.w3.org/1999/xhtml">:plist</b> to parse them as plists. <b xmlns="http://www.w3.org/1999/xhtml">:hash-table</b>
is the default.
</clix:description></blockquote></p>
<p xmlns="">
[Special variable]<br><a class="none" name="*parse-json-booleans-as-symbols*"><b>*parse-json-booleans-as-symbols*</b></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
If set to a true value, JSON booleans will be read as the
symbols TRUE and FALSE instead of T and NIL, respectively.
NIL is the default.
</clix:description></blockquote></p>
<p xmlns="">
[Special variable]<br><a class="none" name="*parse-json-null-as-keyword*"><b>*parse-json-null-as-keyword*</b></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
If set to a true value, JSON null will be read as the
keyword :NULL, instead of NIL.
NIL is the default.
</clix:description></blockquote></p>
<p xmlns="">
[Special variable]<br><a class="none" name="*parse-object-key-fn*"><b>*parse-object-key-fn*</b></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Function to call to convert a key string in a JSON array to
a key in the CL hash produced. IDENTITY is the default.
</clix:description></blockquote></p>
<h3 xmlns=""><a class="none" name="encoding">Encoding JSON data</a></h3>
YASON provides two distinct modes to encode JSON data:
applications can either create an in-memory representation of the
data to be serialized, then have YASON convert it to JSON in one
go, or they can use a set of macros to serialze the JSON data
element-by-element, allowing fine-grained control over the layout
of the generated data.
<p>
Optionally, the JSON that is produced can be indented.
Indentation requires the use of a
<code xmlns=""><a href="#json-output-stream">JSON-OUTPUT-STREAM</a></code> as serialization target.
With the stream serializer, such a stream is automatically used.
If indentation is desired with the DOM serializer, such a stream
can be obtained by calling the
<code xmlns=""><a href="#make-json-output-stream">MAKE-JSON-OUTPUT-STREAM</a></code> function with the
target output string as argument. Please be aware that indented
output not requires more space, but is also slower and should
not be enabled in performance critical applications.
</p>
<h4 xmlns=""><a name="dom-encoder">Encoding a JSON DOM</a></h4>
<p>
In this mode, an in-memory structure is encoded in JSON
format. The structure must consist of objects that are
serializable using the <code xmlns=""><a href="#encode">ENCODE</a></code> function.
YASON defines a number of encoders for standard data types
(see <code xmlns=""><a href="#mapping">MAPPING</a></code>), but the application can
define additional methods (e.g. for encoding CLOS objects).
</p>
For example:
<pre>CL-USER> (yason:encode
(list (alexandria:plist-hash-table
'("foo" 1 "bar" (7 8 9))
:test #'equal)
2 3 4
'(5 6 7)
t nil)
*standard-output*)
[{"foo":1,"bar":[7,8,9]},2,3,4,[5,6,7],true,null]
(#<HASH-TABLE :TEST EQUAL :COUNT 2 {59942D21}> 2 3 4 (5 6 7) T NIL)</pre>
<h4 xmlns=""><a name="dom-encoder-dict">DOM encoder dictionary</a></h4>
<p xmlns="">[Generic function]<br><a class="none" name="encode"><b>encode</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">object &optional
stream</clix:lambda-list></i>
=>
<i>object</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Encode <code><i>object</i></code> in JSON format and
write to <code><i>stream</i></code>. May be specialized
by applications to perform specific rendering. Stream
defaults to *STANDARD-OUTPUT*.
</clix:description></blockquote></p>
<p xmlns="">[Function]<br><a class="none" name="encode-alist"><b>encode-alist</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">object &optional (stream
*standard-output*)</clix:lambda-list></i>
=>
<i>object</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Encodes <code><i>object</i></code>, an alist, in JSON
format and write to <code><i>stream</i></code>.
</clix:description></blockquote></p>
<p xmlns="">[Function]<br><a class="none" name="encode-plist"><b>encode-plist</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">object &optional (stream
*standard-output*)</clix:lambda-list></i>
=>
<i>object</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Encodes <code><i>object</i></code>, a plist, in JSON
format and write to <code><i>stream</i></code>.
</clix:description></blockquote></p>
<p xmlns="">[Function]<br><a class="none" name="make-json-output-stream"><b>make-json-output-stream</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">stream &key (indent t)</clix:lambda-list></i>
=>
<i>stream</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Creates a <code><a href="#json-output-stream">json-output-stream</a></code> instance
that wraps the supplied <code><i>stream</i></code> and
optionally performs indentation of the generated JSON
data. The <code><i>indent</i></code> argument is
described in <code><a href="#with-output">WITH-OUTPUT</a></code>. Note that
if the <code><i>indent</i></code> argument is NIL, the
original stream is returned in order to avoid the
performance penalty of the indentation algorithm.
</clix:description></blockquote></p>
<h4 xmlns=""><a name="stream-encoder">Encoding JSON in streaming mode</a></h4>
<p>
In this mode, the JSON structure is generated in a stream.
The application makes explicit calls to the encoding library
in order to generate the JSON structure. It provides for more
control over the generated output, and can be used to generate
arbitary JSON without requiring that there exists a directly
matching Lisp data structure. The streaming API uses the
<code xmlns=""><a href="#encode">encode</a></code> function, so it is possible to
intermix the two (see <code xmlns=""><a href="#app-encoders">app-encoders</a></code> for an
example).
</p>
For example:
<pre>CL-USER> (yason:with-output (*standard-output*)
(yason:with-array ()
(dotimes (i 3)
(yason:encode-array-element i))))
[0,1,2]
NIL
CL-USER> (yason:with-output (*standard-output*)
(yason:with-object ()
(yason:encode-object-element "hello" "hu hu")
(yason:with-object-element ("harr")
(yason:with-array ()
(dotimes (i 3)
(yason:encode-array-element i))))))
{"hello":"hu hu","harr":[0,1,2]}
NIL</pre>
<h4 xmlns=""><a name="stream-encoder-dict">Streaming encoder dictionary</a></h4>
<p xmlns="">[Macro]<br><a class="none" name="with-output"><b>with-output</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">(stream &key indent) &body body</clix:lambda-list></i>
=>
<i>result*</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Set up a JSON streaming encoder context on
<code><i>stream</i></code>, then evaluate
<code><i>body</i></code>. <code><i>indent</i></code>
can be set to T to enable indentation with a default
indentation width or to an integer specifying the desired
indentation width. By default, indentation is switched
off.
</clix:description></blockquote></p>
<p xmlns="">[Macro]<br><a class="none" name="with-output-to-string*"><b>with-output-to-string*</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">(&key indent) &body body</clix:lambda-list></i>
=>
<i>result*</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Set up a JSON streaming encoder context, then evaluate
<code><i>body</i></code>. Return a string with the
generated JSON output. See
<code><a href="#with-output">WITH-OUTPUT</a></code> for the description of
the <code><i>indent</i></code> keyword argument.
</clix:description></blockquote></p>
<p xmlns="">
[Condition type]<br><a class="none" name="no-json-output-context"><b>no-json-output-context</b></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
This condition is signalled when one of the stream
encoding functions is used outside the dynamic context of
a <code><a href="#with-output">WITH-OUTPUT</a></code> or
<code><a href="#with-output-to-string*">WITH-OUTPUT-TO-STRING*</a></code> body.
</clix:description></blockquote></p>
<p xmlns="">[Macro]<br><a class="none" name="with-array"><b>with-array</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">() &body body</clix:lambda-list></i>
=>
<i>result*</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Open a JSON array, then run <code><i>body</i></code>.
Inside the body, <code><a href="#encode-array-element">ENCODE-ARRAY-ELEMENT</a></code>
must be called to encode elements to the opened array.
Must be called within an existing JSON encoder context
(see <code><a href="#with-output">WITH-OUTPUT</a></code> and
<code><a href="#with-output-to-string*">WITH-OUTPUT-TO-STRING*</a></code>).
</clix:description></blockquote></p>
<p xmlns="">[Function]<br><a class="none" name="encode-array-element"><b>encode-array-element</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">object</clix:lambda-list></i>
=>
<i>object</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Encode <code><i>object</i></code> as next array element to
the last JSON array opened
with <code><a href="#with-array">WITH-ARRAY</a></code> in the dynamic
context. <code><i>object</i></code> is encoded using the
<code><a href="#encode">ENCODE</a></code> generic function, so it must be of
a type for which an <code><a href="#encode">ENCODE</a></code> method is
defined.
</clix:description></blockquote></p>
<p xmlns="">[Function]<br><a class="none" name="encode-array-elements"><b>encode-array-elements</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">&rest objects</clix:lambda-list></i>
=>
<i>result*</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Encode <code><i>objects</i></code>, a series of JSON
encodable objects, as the next array elements in a JSON
array opened with
<code><a href="#with-array">WITH-ARRAY</a></code>. ENCODE-ARRAY-ELEMENTS
uses <code><a href="#encode-array-element">ENCODE-ARRAY-ELEMENT</a></code>, which must
be applicable to each object in the list
(i.e. <code><a href="#encode">ENCODE</a></code> must be defined for each
object type). Additionally, this must be called within a
valid stream context.
</clix:description></blockquote></p>
<p xmlns="">[Macro]<br><a class="none" name="with-object"><b>with-object</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">() &body body</clix:lambda-list></i>
=>
<i>result*</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Open a JSON object, then run <code><i>body</i></code>.
Inside the body,
<code><a href="#encode-object-element">ENCODE-OBJECT-ELEMENT</a></code> or
<code><a href="#with-object-element">WITH-OBJECT-ELEMENT</a></code> must be called to
encode elements to the object. Must be called within an
existing JSON encoder
<code><a href="#with-output">WITH-OUTPUT</a></code> and
<code><a href="#with-output-to-string*">WITH-OUTPUT-TO-STRING*</a></code>.
</clix:description></blockquote></p>
<p xmlns="">[Macro]<br><a class="none" name="with-object-element"><b>with-object-element</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">(key) &body body</clix:lambda-list></i>
=>
<i>result*</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Open a new encoding context to encode a JSON object
element. <code><i>key</i></code> is the key of the
element. The value will be whatever
<code><i>body</i></code> serializes to the current JSON
output context using one of the stream encoding functions.
This can be used to stream out nested object structures.
</clix:description></blockquote></p>
<p xmlns="">[Function]<br><a class="none" name="encode-object-element"><b>encode-object-element</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">key value</clix:lambda-list></i>
=>
<i>value</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Encode <code><i>key</i></code> and
<code><i>value</i></code> as object element to the last
JSON object opened with <code><a href="#with-object">WITH-OBJECT</a></code>
in the dynamic context. <code><i>key</i></code> and
<code><i>value</i></code> are encoded using the
<code><a href="#encode">ENCODE</a></code> generic function, so they both
must be of a type for which an <code><a href="#encode">ENCODE</a></code>
method is defined.
</clix:description></blockquote></p>
<p xmlns="">[Function]<br><a class="none" name="encode-object-elements"><b>encode-object-elements</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">&rest elements</clix:lambda-list></i>
=>
<i>result*</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Encodes the parameters into JSON in the last object opened
with <code><a href="#with-object">WITH-OBJECT</a></code> using
<code><a href="#encode-object-element">ENCODE-OBJECT-ELEMENT</a></code>. The parameters
should consist of alternating key/value pairs, and this
must be called within a valid stream context.
</clix:description></blockquote></p>
<p xmlns="">[Generic function]<br><a class="none" name="encode-slots"><b>encode-slots</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">object</clix:lambda-list></i>
=>
<i>result*</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Encodes all of the slots of <code><i>object</i></code>,
presumably a CLOS object, to the current stream
context. Must be defined for an object to use
<code><a href="#encode-object">ENCODE-OBJECT</a></code> on that object.
</clix:description></blockquote></p>
<p xmlns="">[Generic function]<br><a class="none" name="encode-object"><b>encode-object</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">object</clix:lambda-list></i>
=>
<i>result*</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Encodes <code><i>object</i></code>, presumably a CLOS
object, by invoking <code><a href="#encode-slots">ENCODE-SLOTS</a></code>, to
the current stream context.
</clix:description></blockquote></p>
<p xmlns="">
[Standard class]<br><a class="none" name="json-output-stream"><b>json-output-stream</b></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
Instances of this class are used to wrap an output stream
that is used as a serialization target in the stream
encoder and optionally in the DOM encoder if indentation
is desired. The class name is not exported, use
<code><a href="#make-json-output-stream">make-json-output-stream</a></code> to create a
wrapper stream if required.
</clix:description></blockquote></p>
<h4 xmlns=""><a name="app-encoders">Application specific encoders</a></h4>
Suppose your application uses structs to represent its data and
you want to encode these structs using JSON in order to send
them to a client application. Suppose further that your structs
also include internal information that you do not want to send.
Here is some code that illustrates how one could implement a
serialization function:
<pre>CL-USER> (defstruct user name age password)
USER
CL-USER> (defmethod yason:encode ((user user) &optional (stream *standard-output*))
(yason:with-output (stream)
(yason:with-object ()
(yason:encode-object-element "name" (user-name user))
(yason:encode-object-element "age" (user-age user)))))
#<STANDARD-METHOD YASON:ENCODE (USER) {5B40A591}>
CL-USER> (yason:encode (list (make-user :name "horst" :age 27 :password "puppy")
(make-user :name "uschi" :age 28 :password "kitten")))
[{"name":"horst","age":27},{"name":"uschi","age":28}]
(#S(USER :NAME "horst" :AGE 27 :PASSWORD "puppy")
#S(USER :NAME "uschi" :AGE 28 :PASSWORD "kitten"))</pre>
As you can see, the streaming API and the DOM encoder can be
used together. <code xmlns=""><a href="#encode">ENCODE</a></code> invokes itself
recursively, so any application defined method will be called
while encoding in-memory objects as appropriate.
<h3 xmlns=""><a class="none" name="index">Symbol index</a></h3>
<ul xmlns="">
<li><code><a href="#*parse-json-arrays-as-vectors*">*parse-json-arrays-as-vectors*</a></code></li>
<li><code><a href="#*parse-json-booleans-as-symbols*">*parse-json-booleans-as-symbols*</a></code></li>
<li><code><a href="#*parse-json-null-as-keyword*">*parse-json-null-as-keyword*</a></code></li>
<li><code><a href="#*parse-object-as*">*parse-object-as*</a></code></li>
<li><code><a href="#*parse-object-key-fn*">*parse-object-key-fn*</a></code></li>
<li><code><a href="#encode">encode</a></code></li>
<li><code><a href="#encode-alist">encode-alist</a></code></li>
<li><code><a href="#encode-array-element">encode-array-element</a></code></li>
<li><code><a href="#encode-array-elements">encode-array-elements</a></code></li>
<li><code><a href="#encode-object">encode-object</a></code></li>
<li><code><a href="#encode-object-element">encode-object-element</a></code></li>
<li><code><a href="#encode-object-elements">encode-object-elements</a></code></li>
<li><code><a href="#encode-plist">encode-plist</a></code></li>
<li><code><a href="#encode-slots">encode-slots</a></code></li>
<li><code><a href="#json-output-stream">json-output-stream</a></code></li>
<li><code><a href="#make-json-output-stream">make-json-output-stream</a></code></li>
<li><code><a href="#no-json-output-context">no-json-output-context</a></code></li>
<li><code><a href="#parse">parse</a></code></li>
<li><code><a href="#with-array">with-array</a></code></li>
<li><code><a href="#with-object">with-object</a></code></li>
<li><code><a href="#with-object-element">with-object-element</a></code></li>
<li><code><a href="#with-output">with-output</a></code></li>
<li><code><a href="#with-output-to-string*">with-output-to-string*</a></code></li>
</ul>
<h3 xmlns=""><a class="none" name="license">License</a></h3>
<pre class="none">Copyright (c) 2008-2012 Hans Huebner and contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
- Neither the name BKNR nor the names of its contributors may be
used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</pre>
<h3 xmlns=""><a class="none" name="ack">Acknowledgements</a></h3>
Thanks go to Edi Weitz for being a great inspiration. This
documentation as been generated with a hacked-up version of his <a href="http://weitz.de/documentation-template/">DOCUMENTATION-TEMPLATE</a>
software. Thanks to David Lichteblau for coining YASON's name.
</body></html>
| 34,803 | Common Lisp | .l | 591 | 50.976311 | 220 | 0.646648 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | e775fa5e61050906d651b54ff14848504d50b158ec2bb6656aff294f81bce192 | 1,185 | [
-1
] |
1,186 | doc.xml | cac-t-u-s_om-sharp/src/lisp-externals/Yason/doc.xml | <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="clixdoc.xsl"?>
<clix:documentation xmlns:clix="http://bknr.net/clixdoc"
xmlns="http://www.w3.org/1999/xhtml">
<clix:title>YASON - A JSON encoder/decoder for Common Lisp</clix:title>
<clix:short-description>
YASON is a JSON encoding and decoding library for Common Lisp. It
provides for functions to read JSON strings into Lisp data
structures and for serializing Lisp data structures as JSON
strings.
</clix:short-description>
<clix:abstract>
YASON is a Common Lisp library for encoding and decoding data in
the <a href="http://json.org/">JSON</a> interchange format. JSON
is used as a lightweight alternative to XML. YASON has the sole
purpose of encoding and decoding data and does not impose any
object model on the Common Lisp application that uses it.
</clix:abstract>
<clix:contents/>
<clix:chapter name="intro" title="Introduction">
<p>
<a href="http://json.org/">JSON</a> is an established
alternative to XML as a data interchange format for web
applications. YASON implements reading and writing of JSON
formatted data in Common Lisp. It does not attempt to provide a
mapping between CLOS objects and YASON, but can be used to
implement such mappings.
</p>
<p>
<a href="http://common-lisp.net/project/cl-json/">CL-JSON</a> is
another Common Lisp package that can be used to work with JSON
encoded data. It takes a more integrated approach, providing
for library internal mappings between JSON objects and CLOS
objects. YASON was created as a lightweight, documented
alternative with a minimalistic approach and extensibilty.
</p>
</clix:chapter>
<clix:chapter name="install" title="Download and Installation">
<p>
YASON has its permanent home at <a
href="http://common-lisp.net/project/yason/">common-lisp.net</a>.
It can be obtained by downloading the <a
href="https://github.com/downloads/hanshuebner/yason/yason.tar.gz">release
tarball</a>. The current release is <clix:current-release/>.
</p>
<p>
You may also check out the current development version from its
<a href="http://github.com/hanshuebner/yason/">git
repository</a>. If you have suggestions regarding YASON, please
email me at <i>[email protected]</i>.
</p>
<p>
YASON is written in ANSI Common Lisp. It depends on UNIT-TEST,
TRIVIAL-GRAY-STREAMS and ALEXANDRIA open source libraries. The
recommended way to install YASON and its dependencies is through
the excellent <a href="http://www.quicklisp.org/">Quicklisp</a>
library management system.
</p>
<p>
YASON lives in the <b>:yason</b> package and creates a package
nickname <b>:json</b>. Applications will not normally
<b>:use</b> this package, but rather use qualified names to
access YASON's symbols. For that reason, YASON's symbols do not
contain the string "JSON" themselves. See below for usage
samples.
</p>
</clix:chapter>
<clix:chapter name="json-package" title="Using JSON as package name">
Versions of YASON preceding the v0.6.0 release provided a package
nickname "JSON" for the "YASON" package. This made it impossible
to load both YASON and CL-JSON into the same image, because
CL-JSON uses the "JSON" package name as well.
<p>
As CL-JSON's use of "JSON" as package name has a much longer
history and loading of both CL-JSON and YASON into the same
image has become more common, the "JSON" nickname was removed
from the YASON package with the v0.6.0 release. Users will need
to change their applications so that the "JSON" nickname is no
longer used to refer to the "YASON" package. It is understood
that this is a disruptive change, but as there is no
all-encompassing workaround, this step was felt to be the right
one to make
</p>
</clix:chapter>
<clix:chapter name="mapping" title="Mapping between JSON and CL datatypes">
By default, YASON performs the following mappings between JSON and
CL datatypes:
<table border="1">
<thead>
<tr>
<th>JSON<br/>datatype</th>
<th>CL<br/>datatype</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td>object</td>
<td>hash-table<br/>:test #'equal</td>
<td>
Keys are strings by default (see
<clix:ref>*parse-object-key-fn*</clix:ref>). Set
<clix:ref>*parse-object-as*</clix:ref> to <b>:alist</b> in
order to have YASON parse objects as alists or to
<b>:plist</b> to parse them as plists. When using plists,
you probably want to also set
<clix:ref>*parse-object-key-fn*</clix:ref> to a function
that interns the object's keys to symbols.
</td>
</tr>
<tr>
<td>array</td>
<td>list</td>
<td>
Can be changed to read to vectors (see
<clix:ref>*parse-json-arrays-as-vectors*</clix:ref>).
</td>
</tr>
<tr>
<td>string</td>
<td>string</td>
<td>
JSON escape characters are recognized upon reading. Upon
writing, known escape characters are used, but non-ASCII
Unicode characters are written as is.
</td>
</tr>
<tr>
<td>number</td>
<td>number</td>
<td>
Parsed with READ, printed with PRINC. This is not a
faithful implementation of the specification.
</td>
</tr>
<tr>
<td>true</td>
<td>t</td>
<td>
Can be changed to read as TRUE (see
<clix:ref>*parse-json-booleans-as-symbols*</clix:ref>).
</td>
</tr>
<tr>
<td>false</td>
<td>nil</td>
<td>
Can be changed to read as FALSE (see
<clix:ref>*parse-json-booleans-as-symbols*</clix:ref>).
</td>
</tr>
<tr>
<td>null</td>
<td>nil</td>
<td></td>
</tr>
</tbody>
</table>
</clix:chapter>
<clix:chapter name="parsing" title="Parsing JSON data">
<p>
JSON data is always completely parsed into an equivalent
in-memory representation. Upon reading, some translations are
performed by default to make it easier for the Common Lisp
program to work with the data; see <clix:ref>mapping</clix:ref>
for details. If desired, the parser can be configured to
preserve the full semantics of the JSON data read.
</p>
For example
<pre>CL-USER> (defvar *json-string* "[{\"foo\":1,\"bar\":[7,8,9]},2,3,4,[5,6,7],true,null]")
*JSON-STRING*
CL-USER> (let* ((result (yason:parse *json-string*)))
(print result)
(alexandria:hash-table-plist (first result)))
(#<HASH-TABLE :TEST EQUAL :COUNT 2 {5A4420F1}> 2 3 4 (5 6 7) T NIL)
("bar" (7 8 9) "foo" 1)
CL-USER> (defun maybe-convert-to-keyword (js-name)
(or (find-symbol (string-upcase js-name) :keyword)
js-name))
MAYBE-CONVERT-TO-KEYWORD
CL-USER> :FOO ; intern the :FOO keyword
:FOO
CL-USER> (let* ((yason:*parse-json-arrays-as-vectors* t)
(yason:*parse-json-booleans-as-symbols* t)
(yason:*parse-object-key-fn* #'maybe-convert-to-keyword)
(result (yason:parse *json-string*)))
(print result)
(alexandria:hash-table-plist (aref result 0)))
#(#<HASH-TABLE :TEST EQUAL :COUNT 2 {59B4EAD1}> 2 3 4 #(5 6 7) YASON:TRUE NIL)
("bar" #(7 8 9) :FOO 1)</pre>
<p>
The second example modifies the parser's behaviour so that JSON
arrays are read as CL vectors, JSON booleans will be read as the
symbols TRUE and FALSE and JSON object keys will be looked up in
the <b>:keyword</b> package. Interning strings coming from an
external source is not recommended practice.
</p>
<clix:subchapter name="parser-dict" title="Parser dictionary">
<clix:function name="parse">
<clix:lambda-list>input &key (object-key-fn
*parse-object-as-key-fn*) (object-as *parse-object-as*)
(json-arrays-as-vectors *parse-json-arrays-as-vectors*)
(json-booleans-as-symbols *parse-json-booleans-as-symbols*)
(json-nulls-as-keyword *parse-json-null-as-keyword*)</clix:lambda-list>
<clix:returns>object</clix:returns>
<clix:description>
Parse <clix:arg>input</clix:arg>, which must be a string or
a stream, as JSON. Returns the Lisp representation of the
JSON structure parsed.
<p>
The keyword arguments <clix:arg>object-key-fn</clix:arg>,
<clix:arg>object-as</clix:arg>,
<clix:arg>json-arrays-as-vectors</clix:arg>,
<clix:arg>json-booleans-as-symbols</clix:arg>, and
<clix:arg>json-null-as-keyword</clix:arg> may be used
to specify different values for the parsing parameters
from the current bindings of the respective special
variables.
</p>
</clix:description>
</clix:function>
<clix:special-variable name="*parse-json-arrays-as-vectors*">
<clix:description>
If set to a true value, JSON arrays will be parsed as
vectors, not as lists. NIL is the default.
</clix:description>
</clix:special-variable>
<clix:special-variable name="*parse-object-as*">
<clix:description>
Can be set to <b>:hash-table</b> to parse objects as hash
tables, <b>:alist</b> to parse them as alists or
<b>:plist</b> to parse them as plists. <b>:hash-table</b>
is the default.
</clix:description>
</clix:special-variable>
<clix:special-variable name="*parse-json-booleans-as-symbols*">
<clix:description>
If set to a true value, JSON booleans will be read as the
symbols TRUE and FALSE instead of T and NIL, respectively.
NIL is the default.
</clix:description>
</clix:special-variable>
<clix:special-variable name="*parse-json-null-as-keyword*">
<clix:description>
If set to a true value, JSON null will be read as the
keyword :NULL, instead of NIL.
NIL is the default.
</clix:description>
</clix:special-variable>
<clix:special-variable name="*parse-object-key-fn*">
<clix:description>
Function to call to convert a key string in a JSON array to
a key in the CL hash produced. IDENTITY is the default.
</clix:description>
</clix:special-variable>
</clix:subchapter>
</clix:chapter>
<clix:chapter name="encoding" title="Encoding JSON data">
YASON provides two distinct modes to encode JSON data:
applications can either create an in-memory representation of the
data to be serialized, then have YASON convert it to JSON in one
go, or they can use a set of macros to serialze the JSON data
element-by-element, allowing fine-grained control over the layout
of the generated data.
<p>
Optionally, the JSON that is produced can be indented.
Indentation requires the use of a
<clix:ref>JSON-OUTPUT-STREAM</clix:ref> as serialization target.
With the stream serializer, such a stream is automatically used.
If indentation is desired with the DOM serializer, such a stream
can be obtained by calling the
<clix:ref>MAKE-JSON-OUTPUT-STREAM</clix:ref> function with the
target output string as argument. Please be aware that indented
output not requires more space, but is also slower and should
not be enabled in performance critical applications.
</p>
<clix:subchapter name="dom-encoder" title="Encoding a JSON DOM">
<p>
In this mode, an in-memory structure is encoded in JSON
format. The structure must consist of objects that are
serializable using the <clix:ref>ENCODE</clix:ref> function.
YASON defines a number of encoders for standard data types
(see <clix:ref>MAPPING</clix:ref>), but the application can
define additional methods (e.g. for encoding CLOS objects).
</p>
For example:
<pre>CL-USER> (yason:encode
(list (alexandria:plist-hash-table
'("foo" 1 "bar" (7 8 9))
:test #'equal)
2 3 4
'(5 6 7)
t nil)
*standard-output*)
[{"foo":1,"bar":[7,8,9]},2,3,4,[5,6,7],true,null]
(#<HASH-TABLE :TEST EQUAL :COUNT 2 {59942D21}> 2 3 4 (5 6 7) T NIL)</pre>
<clix:subchapter name="dom-encoder-dict" title="DOM encoder dictionary">
<clix:function name="encode" generic="true">
<clix:lambda-list>object &optional
stream</clix:lambda-list>
<clix:returns>object</clix:returns>
<clix:description>
Encode <clix:arg>object</clix:arg> in JSON format and
write to <clix:arg>stream</clix:arg>. May be specialized
by applications to perform specific rendering. Stream
defaults to *STANDARD-OUTPUT*.
</clix:description>
</clix:function>
<clix:function name="encode-alist">
<clix:lambda-list>object &optional (stream
*standard-output*)</clix:lambda-list>
<clix:returns>object</clix:returns>
<clix:description>
Encodes <clix:arg>object</clix:arg>, an alist, in JSON
format and write to <clix:arg>stream</clix:arg>.
</clix:description>
</clix:function>
<clix:function name="encode-plist">
<clix:lambda-list>object &optional (stream
*standard-output*)</clix:lambda-list>
<clix:returns>object</clix:returns>
<clix:description>
Encodes <clix:arg>object</clix:arg>, a plist, in JSON
format and write to <clix:arg>stream</clix:arg>.
</clix:description>
</clix:function>
<clix:function name="make-json-output-stream">
<clix:lambda-list>stream &key (indent t)</clix:lambda-list>
<clix:returns>stream</clix:returns>
<clix:description>
Creates a <clix:ref>json-output-stream</clix:ref> instance
that wraps the supplied <clix:arg>stream</clix:arg> and
optionally performs indentation of the generated JSON
data. The <clix:arg>indent</clix:arg> argument is
described in <clix:ref>WITH-OUTPUT</clix:ref>. Note that
if the <clix:arg>indent</clix:arg> argument is NIL, the
original stream is returned in order to avoid the
performance penalty of the indentation algorithm.
</clix:description>
</clix:function>
</clix:subchapter>
</clix:subchapter>
<clix:subchapter name="stream-encoder" title="Encoding JSON in streaming mode">
<p>
In this mode, the JSON structure is generated in a stream.
The application makes explicit calls to the encoding library
in order to generate the JSON structure. It provides for more
control over the generated output, and can be used to generate
arbitary JSON without requiring that there exists a directly
matching Lisp data structure. The streaming API uses the
<clix:ref>encode</clix:ref> function, so it is possible to
intermix the two (see <clix:ref>app-encoders</clix:ref> for an
example).
</p>
For example:
<pre>CL-USER> (yason:with-output (*standard-output*)
(yason:with-array ()
(dotimes (i 3)
(yason:encode-array-element i))))
[0,1,2]
NIL
CL-USER> (yason:with-output (*standard-output*)
(yason:with-object ()
(yason:encode-object-element "hello" "hu hu")
(yason:with-object-element ("harr")
(yason:with-array ()
(dotimes (i 3)
(yason:encode-array-element i))))))
{"hello":"hu hu","harr":[0,1,2]}
NIL</pre>
<clix:subchapter name="stream-encoder-dict" title="Streaming encoder dictionary">
<clix:function name="with-output" macro="true">
<clix:lambda-list>(stream &key indent) &body body</clix:lambda-list>
<clix:returns>result*</clix:returns>
<clix:description>
Set up a JSON streaming encoder context on
<clix:arg>stream</clix:arg>, then evaluate
<clix:arg>body</clix:arg>. <clix:arg>indent</clix:arg>
can be set to T to enable indentation with a default
indentation width or to an integer specifying the desired
indentation width. By default, indentation is switched
off.
</clix:description>
</clix:function>
<clix:function name="with-output-to-string*" macro="true">
<clix:lambda-list>(&key indent) &body body</clix:lambda-list>
<clix:returns>result*</clix:returns>
<clix:description>
Set up a JSON streaming encoder context, then evaluate
<clix:arg>body</clix:arg>. Return a string with the
generated JSON output. See
<clix:ref>WITH-OUTPUT</clix:ref> for the description of
the <clix:arg>indent</clix:arg> keyword argument.
</clix:description>
</clix:function>
<clix:condition name="no-json-output-context">
<clix:description>
This condition is signalled when one of the stream
encoding functions is used outside the dynamic context of
a <clix:ref>WITH-OUTPUT</clix:ref> or
<clix:ref>WITH-OUTPUT-TO-STRING*</clix:ref> body.
</clix:description>
</clix:condition>
<clix:function name="with-array" macro="true">
<clix:lambda-list>() &body body</clix:lambda-list>
<clix:returns>result*</clix:returns>
<clix:description>
Open a JSON array, then run <clix:arg>body</clix:arg>.
Inside the body, <clix:ref>ENCODE-ARRAY-ELEMENT</clix:ref>
must be called to encode elements to the opened array.
Must be called within an existing JSON encoder context
(see <clix:ref>WITH-OUTPUT</clix:ref> and
<clix:ref>WITH-OUTPUT-TO-STRING*</clix:ref>).
</clix:description>
</clix:function>
<clix:function name="encode-array-element">
<clix:lambda-list>object</clix:lambda-list>
<clix:returns>object</clix:returns>
<clix:description>
Encode <clix:arg>object</clix:arg> as next array element to
the last JSON array opened
with <clix:ref>WITH-ARRAY</clix:ref> in the dynamic
context. <clix:arg>object</clix:arg> is encoded using the
<clix:ref>ENCODE</clix:ref> generic function, so it must be of
a type for which an <clix:ref>ENCODE</clix:ref> method is
defined.
</clix:description>
</clix:function>
<clix:function name="encode-array-elements">
<clix:lambda-list>&rest objects</clix:lambda-list>
<clix:returns>result*</clix:returns>
<clix:description>
Encode <clix:arg>objects</clix:arg>, a series of JSON
encodable objects, as the next array elements in a JSON
array opened with
<clix:ref>WITH-ARRAY</clix:ref>. ENCODE-ARRAY-ELEMENTS
uses <clix:ref>ENCODE-ARRAY-ELEMENT</clix:ref>, which must
be applicable to each object in the list
(i.e. <clix:ref>ENCODE</clix:ref> must be defined for each
object type). Additionally, this must be called within a
valid stream context.
</clix:description>
</clix:function>
<clix:function name="with-object" macro="true">
<clix:lambda-list>() &body body</clix:lambda-list>
<clix:returns>result*</clix:returns>
<clix:description>
Open a JSON object, then run <clix:arg>body</clix:arg>.
Inside the body,
<clix:ref>ENCODE-OBJECT-ELEMENT</clix:ref> or
<clix:ref>WITH-OBJECT-ELEMENT</clix:ref> must be called to
encode elements to the object. Must be called within an
existing JSON encoder
<clix:ref>WITH-OUTPUT</clix:ref> and
<clix:ref>WITH-OUTPUT-TO-STRING*</clix:ref>.
</clix:description>
</clix:function>
<clix:function name="with-object-element" macro="true">
<clix:lambda-list>(key) &body body</clix:lambda-list>
<clix:returns>result*</clix:returns>
<clix:description>
Open a new encoding context to encode a JSON object
element. <clix:arg>key</clix:arg> is the key of the
element. The value will be whatever
<clix:arg>body</clix:arg> serializes to the current JSON
output context using one of the stream encoding functions.
This can be used to stream out nested object structures.
</clix:description>
</clix:function>
<clix:function name="encode-object-element">
<clix:lambda-list>key value</clix:lambda-list>
<clix:returns>value</clix:returns>
<clix:description>
Encode <clix:arg>key</clix:arg> and
<clix:arg>value</clix:arg> as object element to the last
JSON object opened with <clix:ref>WITH-OBJECT</clix:ref>
in the dynamic context. <clix:arg>key</clix:arg> and
<clix:arg>value</clix:arg> are encoded using the
<clix:ref>ENCODE</clix:ref> generic function, so they both
must be of a type for which an <clix:ref>ENCODE</clix:ref>
method is defined.
</clix:description>
</clix:function>
<clix:function name="encode-object-elements">
<clix:lambda-list>&rest elements</clix:lambda-list>
<clix:returns>result*</clix:returns>
<clix:description>
Encodes the parameters into JSON in the last object opened
with <clix:ref>WITH-OBJECT</clix:ref> using
<clix:ref>ENCODE-OBJECT-ELEMENT</clix:ref>. The parameters
should consist of alternating key/value pairs, and this
must be called within a valid stream context.
</clix:description>
</clix:function>
<clix:function name="encode-slots" generic="true">
<clix:lambda-list>object</clix:lambda-list>
<clix:returns>result*</clix:returns>
<clix:description>
Encodes all of the slots of <clix:arg>object</clix:arg>,
presumably a CLOS object, to the current stream
context. Must be defined for an object to use
<clix:ref>ENCODE-OBJECT</clix:ref> on that object.
</clix:description>
</clix:function>
<clix:function name="encode-object" generic="true">
<clix:lambda-list>object</clix:lambda-list>
<clix:returns>result*</clix:returns>
<clix:description>
Encodes <clix:arg>object</clix:arg>, presumably a CLOS
object, by invoking <clix:ref>ENCODE-SLOTS</clix:ref>, to
the current stream context.
</clix:description>
</clix:function>
<clix:class name="json-output-stream">
<clix:description>
Instances of this class are used to wrap an output stream
that is used as a serialization target in the stream
encoder and optionally in the DOM encoder if indentation
is desired. The class name is not exported, use
<clix:ref>make-json-output-stream</clix:ref> to create a
wrapper stream if required.
</clix:description>
</clix:class>
</clix:subchapter>
</clix:subchapter>
<clix:subchapter name="app-encoders" title="Application specific encoders">
Suppose your application uses structs to represent its data and
you want to encode these structs using JSON in order to send
them to a client application. Suppose further that your structs
also include internal information that you do not want to send.
Here is some code that illustrates how one could implement a
serialization function:
<pre>CL-USER> (defstruct user name age password)
USER
CL-USER> (defmethod yason:encode ((user user) &optional (stream *standard-output*))
(yason:with-output (stream)
(yason:with-object ()
(yason:encode-object-element "name" (user-name user))
(yason:encode-object-element "age" (user-age user)))))
#<STANDARD-METHOD YASON:ENCODE (USER) {5B40A591}>
CL-USER> (yason:encode (list (make-user :name "horst" :age 27 :password "puppy")
(make-user :name "uschi" :age 28 :password "kitten")))
[{"name":"horst","age":27},{"name":"uschi","age":28}]
(#S(USER :NAME "horst" :AGE 27 :PASSWORD "puppy")
#S(USER :NAME "uschi" :AGE 28 :PASSWORD "kitten"))</pre>
As you can see, the streaming API and the DOM encoder can be
used together. <clix:ref>ENCODE</clix:ref> invokes itself
recursively, so any application defined method will be called
while encoding in-memory objects as appropriate.
</clix:subchapter>
</clix:chapter>
<clix:chapter name="index" title="Symbol index">
<clix:index/>
</clix:chapter>
<clix:chapter name="license" title="License">
<pre class="none">Copyright (c) 2008-2012 Hans Huebner and contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
- Neither the name BKNR nor the names of its contributors may be
used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</pre>
</clix:chapter>
<clix:chapter name="ack" title="Acknowledgements">
Thanks go to Edi Weitz for being a great inspiration. This
documentation as been generated with a hacked-up version of his <a
href="http://weitz.de/documentation-template/">DOCUMENTATION-TEMPLATE</a>
software. Thanks to David Lichteblau for coining YASON's name.
</clix:chapter>
</clix:documentation>
| 27,477 | Common Lisp | .l | 589 | 38.466893 | 96 | 0.654414 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 631f4ef00703671d84131a60e01e6f7b343d30a04f4d89e23ec23469eb42fcfa | 1,186 | [
-1
] |
1,380 | sound-silence.tif | cac-t-u-s_om-sharp/resources/icons/boxes/sound-silence.tif | II* 8 а
а
<?xpacket begin='яЛП' id='W5M0MpCehiHzreSzNTczkc9d'?><x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='XMP toolkit 2.9-9, framework 1.6'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:iX='http://ns.adobe.com/iX/1.0/'>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end='w'?> ў , ђ М ( М сссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссс сссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссс сссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссс сссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссс сссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссс сссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссс OZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZWOZW сссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссс сссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссс сссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссс сссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссс сссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссс сссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссссс | 2,478 | Common Lisp | .l | 7 | 353 | 2,185 | 0.743828 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 63d58949f8dcedc0d85a7f7f598115d8fa3c32874e3a1c5a551a1bf7076e6710 | 1,380 | [
-1
] |
1,381 | import-xml.tif | cac-t-u-s_om-sharp/resources/icons/boxes/import-xml.tif | MM * : Ð
Ð
<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?><x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='XMP toolkit 2.9-9, framework 1.6'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:iX='http://ns.adobe.com/iX/1.0/'>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end='w'?> þ ( R ¼ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ"""ÿ"""ÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ"""ÿ"""ÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ"""ÿ"""ÿ3™fÿ3™fÿ3™fÿ3™fÿ"""ÿ"""ÿ"""ÿ"""ÿ"""ÿ3™fÿ3™fÿ3™fÿ3™fÿ"""ÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿ3™fÿ3™fÿðððÿðððÿðððÿðððÿ3™fÿ3™fÿ"""ÿ3™fÿ3™fÿðððÿðððÿðððÿðððÿ3™fÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿðððÿ3 ™ÿðððÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿðððÿðððÿðððÿðððÿðððÿ3™fÿ"""ÿ"""ÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿ3 ™ÿ3 ™ÿ3 ™ÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿ ÿ3 ™ÿ ÿðððÿðððÿðððÿ3™fÿ3™fÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿ3 ™ÿðððÿ3 ™ÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿ ÿðððÿðððÿ3 ™ÿ ÿðððÿðððÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿ3 ™ÿðððÿ3 ™ÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿ3 ™ÿ3 ™ÿ ÿðððÿðððÿ3 ™ÿ ÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿ3 ™ÿðððÿ3 ™ÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿ ÿðððÿðððÿ3 ™ÿ ÿðððÿ3 ™ÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿ3 ™ÿ3 ™ÿðððÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿðððÿðððÿðððÿðððÿðððÿ3 ™ÿ ÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿ3 ™ÿ3 ™ÿ3 ™ÿðððÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿðððÿ3 ™ÿ ÿðððÿðððÿðððÿðððÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿ3 ™ÿ3 ™ÿðððÿ3 ™ÿðððÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿ3 ™ÿðððÿðððÿ ÿ3 ™ÿðððÿðððÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿ3 ™ÿ3 ™ÿðððÿðððÿ3 ™ÿ3 ™ÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿ ÿ ÿ3 ™ÿðððÿðððÿ ÿ3 ™ÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿ3 ™ÿ3 ™ÿðððÿ3 ™ÿ3 ™ÿðððÿ3 ™ÿðððÿðððÿ"""ÿ"""ÿðððÿ3 ™ÿðððÿðððÿ ÿ3 ™ÿðððÿ ÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿ3 ™ÿ3 ™ÿðððÿðððÿ3 ™ÿðððÿ3 ™ÿðððÿðððÿ"""ÿ"""ÿðððÿðððÿðððÿðððÿðððÿðððÿ ÿ3 ™ÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿ3 ™ÿðððÿðððÿ3 ™ÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿÿÿÿ ÿÿÿ ÿÿÿ 666ÿÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿ3 ™ÿ3 ™ÿ3 ™ÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿÿÿÿ ÿÿÿ ÿÿÿ 666ÿ666ÿÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿðððÿ3 ™ÿ33fÿðððÿ33fÿ33fÿ33fÿðððÿ33fÿðððÿðððÿ33fÿðððÿðððÿ33fÿðððÿ33fÿ33fÿ33fÿ666ÿ666ÿ666ÿ666ÿ666ÿ666ÿÿÿÿ """ÿ3™fÿðððÿðððÿ3 ™ÿ3 ™ÿ3 ™ÿ33fÿ33fÿðððÿ33fÿðððÿ33fÿ33fÿðððÿ33fÿðððÿ33fÿðððÿ33fÿðððÿ33fÿ33fÿ33fÿ666ÿ666ÿ666ÿ666ÿ666ÿ666ÿ666ÿ"""ÿ3™fÿðððÿðððÿ3 ™ÿ3 ™ÿ3 ™ÿ33fÿ33fÿ33fÿðððÿ33fÿ33fÿ33fÿðððÿ33fÿðððÿ33fÿðððÿ33fÿðððÿ33fÿ33fÿ33fÿ666ÿ666ÿ666ÿ666ÿ666ÿ666ÿ666ÿ"""ÿ3™fÿðððÿðððÿðððÿðððÿðððÿ33fÿ33fÿðððÿ33fÿðððÿ33fÿ33fÿðððÿ33fÿ33fÿ33fÿðððÿ33fÿðððÿ33fÿ33fÿ33fÿ666ÿ666ÿ666ÿ666ÿ666ÿ666ÿÿÿÿ """ÿ3™fÿðððÿðððÿ3™fÿ3™fÿ3™fÿ33fÿðððÿ33fÿ33fÿ33fÿðððÿ33fÿðððÿ33fÿ33fÿ33fÿðððÿ33fÿðððÿðððÿðððÿ33fÿÿÿÿ ÿÿÿ ÿÿÿ 666ÿ666ÿÿÿÿ ÿÿÿ """ÿ3™fÿ3™fÿ3™fÿ"""ÿ"""ÿ"""ÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿÿÿÿ ÿÿÿ ÿÿÿ 666ÿÿÿÿ ÿÿÿ ÿÿÿ """ÿ"""ÿ"""ÿ"""ÿ"""ÿÿÿÿ ÿÿÿ 33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ | 3,488 | Common Lisp | .l | 7 | 497.285714 | 3,193 | 0.721344 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 8a3a1908e17382f3f4ba1418524b9dd5fc58decd90c42e8100903bc97fec677c | 1,381 | [
-1
] |
1,383 | shell.tif | cac-t-u-s_om-sharp/resources/icons/boxes/shell.tif | MM * : Р
Р
<?xpacket begin='п»ї' id='W5M0MpCehiHzreSzNTczkc9d'?><x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='XMP toolkit 2.9-9, framework 1.6'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:iX='http://ns.adobe.com/iX/1.0/'>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end='w'?> ю ( R ј яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя 333я333я333я333я333я333я333я333я333я333я333я333я333я333я333я333я333я333я333я333я333я333я333я333яяяя яяя яяя яяя яяя яяя wwwяооояооояооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяЄЄЄяяяя яяя яяя DDDяЭЭЭяяяя ооояооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяяяя ооояяяя wwwяяяя яяя fffяооояЭЭЭя"""я333я333я333я333я"""я"""я"""я"""я"""я"""я"""я"""я"""я"""я"""я"""яяяяяяя я€€€яяяя wwwяяяя яяя fffяооояЄЄЄяDDDяUUUяUUUяUUUяUUUяUUUяUUUяUUUяUUUяUUUяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я"""яfffяяяя wwwяяяя яяя fffяоооя™™™яDDDяUUUяUUUяwwwяUUUяUUUяUUUяUUUяUUUяUUUяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я"""яfffяяяя wwwяяяя яяя fffяоооя™™™яDDDяUUUяUUUяЄЄЄяЭЭЭя™™™яUUUяUUUяUUUяUUUяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я"""яfffяяяя wwwяяяя яяя fffяоооя™™™яDDDяUUUяUUUяUUUяfffяЭЭЭя»»»яUUUяUUUяUUUяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я"""яfffяяяя wwwяяяя яяя fffяоооя™™™яDDDяUUUяUUUяЄЄЄяЭЭЭя™™™яUUUяUUUяUUUяUUUяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я"""яfffяяяя wwwяяяя яяя fffяоооя™™™яDDDяUUUяUUUяwwwяUUUяUUUяUUUяUUUяUUUяUUUяDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я"""я"""я"""яяfffяяяя wwwяяяя яяя fffяоооя™™™яDDDяUUUяUUUяUUUяUUUяUUUяUUUя™™™я™™™я™™™я™™™яDDDяDDDяDDDя333я333я333я333я333я"""я"""я"""я"""яяfffяяяя wwwяяяя яяя fffяоооя™™™яDDDяUUUяUUUяUUUяUUUяUUUяUUUяUUUяUUUяUUUяDDDяDDDя333я333я333я333я333я333я333я"""я"""я"""я"""яяfffяяяя wwwяяяя яяя fffяоооя™™™яDDDяUUUяUUUяUUUяUUUяUUUяUUUяUUUяDDDяDDDяDDDя333я333я333я333я333я333я333я333я"""я"""я"""я"""яяfffяяяя wwwяяяя яяя fffяоооя™™™яDDDяUUUяUUUяUUUяUUUяUUUяDDDяDDDяDDDяDDDяDDDя333я333я333я333я333я333я333я333я"""я"""я"""я"""яяfffяяяя wwwяяяя яяя fffяоооя™™™яDDDяUUUяUUUяUUUяUUUяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я333я333я333я333я"""я"""я"""я"""яяfffяяяя wwwяяяя яяя fffяоооя™™™яDDDяUUUяUUUяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я333я333я333я333я"""я"""я"""я"""яяfffяяяя wwwяяяя яяя fffяоооя™™™яDDDяUUUяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я333я333я333я333я"""я"""я"""я"""яяfffяяяя wwwяяяя яяя fffяоооя™™™я333яDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я333я333я333я333я"""я"""я"""я"""яяfffяяяя wwwяяяя яяя fffяоооя™™™я333яDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я333я333я333я333я"""я"""я"""я"""яяfffяяяя wwwяяяя яяя fffяоооя™™™я333яDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я333я333я333я333я"""я"""я"""я"""яяfffяяяя wwwяяяя яяя fffяоооя™™™я333яDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я333я333я333я333я"""я"""я"""я"""яяfffяяяя wwwяяяя яяя fffяоооя™™™я333яDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я333я333я333я333я"""я"""я"""я"""яяfffяяяя wwwяяяя яяя fffяоооя™™™я333яDDDяDDDяDDDяDDDяDDDяDDDяDDDя333я333я333я333я333я333я333я333я"""я"""я"""я"""я"""я"""я"""яяUUUяяяя wwwяяяя яяя fffяооояЄЄЄяUUUяfffяfffяfffяfffяfffяfffяfffяfffяfffяfffяfffяwwwяUUUяUUUяUUUяUUUяUUUяUUUяUUUяUUUяUUUяUUUяDDDя€€€яяяя wwwяяяя яяя fffяооояооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭя™ММя™™МяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяооояЭЭЭяяяя wwwяяяя яяя fffяооояяяя ооояяяя ооояяяя ооояяяя ооояяяя ооояяяя оооя»»»я™™™яяяя ооояяяя ооояяяя ооояяяя ооояяяя ооояяяя ооояяяя wwwяяяя яяя UUUяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяЭЭЭяwwwяяяя яяя яяя я я я я я я я я я я я я я я я я я я я я я я я я я я я яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя | 4,608 | Common Lisp | .l | 7 | 657.285714 | 4,313 | 0.781569 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | b5ec01adbfadaaf3f1454e99c825c8d8f6670be40a2ceb8c688b3b33e7ef88ff | 1,383 | [
-1
] |
1,384 | sequencer-file.png | cac-t-u-s_om-sharp/resources/icons/boxes/sequencer-file.png | âPNG
IHDR szzÙ sRGB ÆŒÈ #iTXtXML:com.adobe.xmp <?xpacket begin="Ôªø" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.5.0">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""/>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>3ŸÖe <IDATxúÏ÷flKZa«Ò˛2…µµÅsòyt9€ÓÇ2i≠f·ÖwëŒyÿEÓ"wc.µ.§iªÒÍ∞ÜÕÄ8ΩjÇfi,˝Ïy»\hÍzöfi»9<p^>øû) Sì¨Ô…F£Åq*óÀ»ÂrÉò†R© üœ#ôL"åÖ`Ë"“È4b±¢—Ë»f Z6õ.^´’áGB0
–ÈtFF0ãE$ ‘ÎuP≠VâDÆD0îJ%ƒ„qÿÌvòL&çFX,<?¡@Àd2ÖBx<pπ\p:ùp80õÕ}Ã˝J•R¬Øcb Vc:Ì6>Å∑ZÒŒf√˙Í*^Íı}3¨≠¡≤µÖ YO_˝cæûû‚fi¥œóµ–iµ–Ît{A¢kfD"|>>fëO£Q=ÜœÔ√¡··–|~?‘Jld«ò æêŸ~ˇŒ6_∞±>ºM√Óä¶Ò~gá
†’j·√Ó.’j<”hÜF◊ΩZY¡ ˘Íò Xwm¿èÛs,(XêÀ°·8íOÛx™RbQ…ëî‰XN*Ö䨢N&„œãvÄ2P∏π9xºpÔÔˇŒÌ˛#Ø◊ôDÇè{{lw‡€Ÿ$≥≥‡flZÖ;˝™à≈p±–filoC.}N&ÿ¸#)ñóñÑˇÖˇˇ&¸õQÃp;äoGqoCüv€‰Åæwª|‹=◊l6o0,\BÙBnl–ã–ˆv≠¯óM ˇˇ ¢˙%7° IENDÆB`Ç | 2,993 | Common Lisp | .l | 10 | 92.3 | 430 | 0.567308 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 2b9d6139854bad4228e4d8f34593a6bce00798252811fd38cf3b7e8cdde69c11 | 1,384 | [
-1
] |
1,385 | midi-filter.tif | cac-t-u-s_om-sharp/resources/icons/boxes/midi-filter.tif | MM * : Р
Р
<?xpacket begin='п»ї' id='W5M0MpCehiHzreSzNTczkc9d'?><x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='XMP toolkit 2.9-9, framework 1.6'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:iX='http://ns.adobe.com/iX/1.0/'>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end='w'?> ю ( R ј яяя яяя яяя яяя я я я я яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя я япппяпппяпппяпппяпппя я яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя яяя я япппяпппяпппя япппяпппяпппя я яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя яяя япппяпппя япппяпппяпппя япппяпппя яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя япппяпппяпппяпппяпппяпппяпппяпппяпппяпппяпппя яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя япппяпппя япппяпппяпппяпппяпппя япппяпппя яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя япппяпппяпппяпппяпппяпппяпппяпппяпппяпппяпппя яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя япппяпппяпппяпппяпппяпппяпппяпппяпппяпппяпппя я я я я я я я яяяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя япппяпппяпппяпппяпппяпппяпппяпппяпппяпппяпппя я я япппя я япппя яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя япппяпппяпппяпппяпппяпппяпппяпппяпппя япппя я япппя я япппя яяяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя яяя я япппяпппяпппяпппяпппяпппяпппя я япппя я япппя я япппя яяяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя яяя яяя я япппяпппяпппяпппяпппя я я япппя я япппя я япппя яяяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя яяя яяя япппя я я я я япппяпппя япппя я япппя я япппя яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя япппя я япппя я япппяпппя япппя я япппя я япппя яяяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя яяя яяя япппя я япппя я япппяпппя япппя я япппя я япппя яяяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя яяя яяя япппяпппя япппяпппя япппяпппя япппяпппя япппяпппя япппя яяяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя яяя яяя япппяпппя япппяпппя япппяпппя япппяпппя япппяпппя япппя яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя япппяпппя япппяпппя япппяпппя япппяпппя япппяпппя япппя яяяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя яяя яяя япппяпппя япппяпппя япппяпппя япппяпппя япппяпппя япппя яяяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя яяя яяя я я я я я я я я я я я я я я я я я яяяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя DDDяяяя яяя яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя DDDяяяя яяя я яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя я я я я я я я я я я я я я я я яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя DDDяяяя яяя я яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя DDDяяяя яяя яяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя DDDяяяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя яяя | 4,608 | Common Lisp | .l | 7 | 657.285714 | 4,313 | 0.677461 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | b6847a59bfe26ab7c3b2512e7dd04a8ed9bd9edd0845c5ec8c2b27012e55a556 | 1,385 | [
-1
] |
1,386 | export-xml.tif | cac-t-u-s_om-sharp/resources/icons/boxes/export-xml.tif | MM * : Ð
Ð
<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?><x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='XMP toolkit 2.9-9, framework 1.6'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:iX='http://ns.adobe.com/iX/1.0/'>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end='w'?> þ ( R ¼ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ"""ÿ"""ÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ"""ÿ"""ÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ"""ÿ"""ÿ3™fÿ3™fÿ3™fÿ3™fÿ"""ÿ"""ÿ"""ÿ"""ÿ"""ÿ3™fÿ3™fÿ3™fÿ3™fÿ"""ÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿ3™fÿ3™fÿðððÿðððÿðððÿðððÿ3™fÿ3™fÿ"""ÿ3™fÿ3™fÿðððÿðððÿðððÿðððÿ3™fÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿðððÿ3 ™ÿðððÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿðððÿðððÿðððÿðððÿðððÿ3™fÿ"""ÿ"""ÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿ3 ™ÿ3 ™ÿ3 ™ÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿ ÿ3 ™ÿ ÿðððÿðððÿðððÿ3™fÿ3™fÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿ3 ™ÿðððÿ3 ™ÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿ ÿðððÿðððÿ3 ™ÿ ÿðððÿðððÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿ3 ™ÿðððÿ3 ™ÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿ3 ™ÿ3 ™ÿ ÿðððÿðððÿ3 ™ÿ ÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿ3 ™ÿðððÿ3 ™ÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿ ÿðððÿðððÿ3 ™ÿ ÿðððÿ3 ™ÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿ3 ™ÿ3 ™ÿðððÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿðððÿðððÿðððÿðððÿðððÿ3 ™ÿ ÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿ3 ™ÿ3 ™ÿ3 ™ÿðððÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿðððÿ3 ™ÿ ÿðððÿðððÿðððÿðððÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿ3 ™ÿ3 ™ÿðððÿ3 ™ÿðððÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿ3 ™ÿðððÿðððÿ ÿ3 ™ÿðððÿðððÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿ3 ™ÿ3 ™ÿðððÿðððÿ3 ™ÿ3 ™ÿðððÿðððÿðððÿ"""ÿ"""ÿðððÿ ÿ ÿ3 ™ÿðððÿðððÿ ÿ3 ™ÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿ3 ™ÿ3 ™ÿðððÿ3 ™ÿ3 ™ÿðððÿ3 ™ÿðððÿðððÿ"""ÿ"""ÿðððÿ3 ™ÿðððÿðððÿ ÿ3 ™ÿðððÿ ÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿ3 ™ÿ3 ™ÿðððÿðððÿ3 ™ÿðððÿ3 ™ÿðððÿðððÿ"""ÿ"""ÿðððÿðððÿðððÿðððÿðððÿðððÿ ÿ3 ™ÿðððÿ3™fÿ"""ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿ3 ™ÿðððÿðððÿ3 ™ÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿ3 ™ÿ3 ™ÿ3 ™ÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿÿÿÿ ÿÿÿ ÿÿÿ 666ÿÿÿÿ ÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿðððÿðððÿ3 ™ÿ33fÿðððÿ33fÿ33fÿ33fÿðððÿ33fÿðððÿðððÿ33fÿðððÿðððÿ33fÿðððÿ33fÿ33fÿ33fÿÿÿÿ ÿÿÿ ÿÿÿ 666ÿ666ÿÿÿÿ ÿÿÿ """ÿ3™fÿðððÿðððÿ3 ™ÿ3 ™ÿ3 ™ÿ33fÿ33fÿðððÿ33fÿðððÿ33fÿ33fÿðððÿ33fÿðððÿ33fÿðððÿ33fÿðððÿ33fÿ33fÿ33fÿ666ÿ666ÿ666ÿ666ÿ666ÿ666ÿÿÿÿ """ÿ3™fÿðððÿðððÿ3 ™ÿ3 ™ÿ3 ™ÿ33fÿ33fÿ33fÿðððÿ33fÿ33fÿ33fÿðððÿ33fÿðððÿ33fÿðððÿ33fÿðððÿ33fÿ33fÿ33fÿ666ÿ666ÿ666ÿ666ÿ666ÿ666ÿ666ÿ"""ÿ3™fÿðððÿðððÿðððÿðððÿðððÿ33fÿ33fÿðððÿ33fÿðððÿ33fÿ33fÿðððÿ33fÿ33fÿ33fÿðððÿ33fÿðððÿ33fÿ33fÿ33fÿ666ÿ666ÿ666ÿ666ÿ666ÿ666ÿ666ÿ"""ÿ3™fÿðððÿðððÿ3™fÿ3™fÿ3™fÿ33fÿðððÿ33fÿ33fÿ33fÿðððÿ33fÿðððÿ33fÿ33fÿ33fÿðððÿ33fÿðððÿðððÿðððÿ33fÿ666ÿ666ÿ666ÿ666ÿ666ÿ666ÿÿÿÿ """ÿ3™fÿ3™fÿ3™fÿ"""ÿ"""ÿ"""ÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿÿÿÿ ÿÿÿ ÿÿÿ 666ÿ666ÿÿÿÿ ÿÿÿ """ÿ"""ÿ"""ÿ"""ÿ"""ÿÿÿÿ ÿÿÿ 33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿ33fÿÿÿÿ ÿÿÿ ÿÿÿ 666ÿÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ ÿÿÿ | 3,488 | Common Lisp | .l | 7 | 497.285714 | 3,193 | 0.721344 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 67cd3532c9bfacec26ddc30c5c741a5c13211725055ccc3762e488072c874d5e | 1,386 | [
-1
] |
1,387 | lisp-f-file.png | cac-t-u-s_om-sharp/resources/icons/boxes/lisp-f-file.png | âPNG
IHDR szzÙ sRGB ÆŒÈ #iTXtXML:com.adobe.xmp <?xpacket begin="Ôªø" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.1.2">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""/>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>,„ñ7 FIDATxú‘ñ…K[Q≈˝w¨j£m§©q®m‘Öä(Jjk’A≈î:ƒ9à&ïä&∆.¥qaÌRÎчÄäÇF]8QJUú¡âÇߘª%èbõ‰=*]íì7øwfl˘Œ}ñÔ?<ÓRº∫∫Ç+⁄⁄⁄¬““z{{q' €€€X^^∆ƒƒ∫∫∫\Çê¿
a6õ1::äëëß!$ -..Ú??99¡––êSí¨¨¨pÄÎÎkß!$X__«¯¯8NOO9¿··!Üááˇ!)¿ÊÊ&∆∆∆`2ôP^^çFΩ^è˙˙˙[!$ Õœœ£ØØhooG[[ZZZ†”ÈBH@ù∞∞∞¿'bzzökjjäOáhÄ˝˝}.gΩ=ò(ĵµ54ç–Ò†—ùôöå(.(<]/).ÊYp¥Ü€ _;;ä˚^^∏w¡ê3…ºΩπó˚˚fifl”/RR099)‡ÚÚ´´´x¶T")>˙⁄ZËkj<, ±±‹`·äèâAyªÆFfz:666ƒògf25ïfl˘«∫:a°4váelƒ¨^SXàR∂ıVˇ:-çÔä∂≤Ú∆„p`ooüöõ˘÷Vkµ∞X,ºlRQ†VsOzóóá˜˘˘¸;eEïúåÖÇÔ秮ÌŒBïî‰ñ∫ªªq~~Ó>¿≈≈üaZÏ' ,l˝NüV9Úflzzƒe`Üe ’ÓOÌ(hé~ßœñ
:†‹†RimmΩÄD ∑ÌÄ°±Q|ÊÊÊn,˛∑G`üzåíd¿ıHïC€†ôßB≤ÌÅ:6rVØŒÕ≈C??^À∂e‰2¿¡¡>≥»XU≥R°≈H4˜ï••ÇWÁ‰†™¨LŸôôºÿ{@ø∏–[Õ+ï
Å>>àäà@Tx82AAÇD>0P|}ë≈™x``@\XE9»~ì•\éßÏ\àãéF\L4BYÁGÜѸˆLt< yå∑¯¬^Hvvv§9
IT¡ÜÜTWUÒp
¬h0@[Q!¯Fvù˙ü∂}wwW∫„ÿ∂hÆœŒŒ∏?>>Êfi∫ÕGGG7º‰ bıˇ ¸K›9¿/ ˇˇ 7EH;≤ÄÉz IENDÆB`Ç | 3,259 | Common Lisp | .l | 11 | 108 | 539 | 0.541216 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | 7abd389da9291eea49d1b9fdd8384d25171511ef12eab426afb36d1b6034887a | 1,387 | [
-1
] |
1,388 | icon-lib.png | cac-t-u-s_om-sharp/resources/icons/pack-browser/icon-lib.png | âPNG
IHDR j|˛ sRGB ÆŒÈ ‰iTXtXML:com.adobe.xmp <?xpacket begin="Ôªø" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.1.2">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:exif="http://ns.adobe.com/exif/1.0/">
<exif:PixelXDimension>44</exif:PixelXDimension>
<exif:PixelYDimension>40</exif:PixelYDimension>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>‚\
¬ ßIDATxúÑ—?Ha ¥)Anh®¶ß#Zr∑∆∂Ü∆†≈I®ÕA2˚wßüÓOüÁyßùWwäZË“êê
∑t»m4IùAEAÔ[ºfl˚è7ˆ˛Oå}•Ìq©.·"&b≤ªß¸É«™˛PµJØÀ/;‚nÒxûÜR]ufiÃ_m‘1≠†M_'™´"∆˚œ~’Yi’àfih4Qi]l…îTB–Ö €ï› ΩÍ‘¶+K’Uuˇ|PˆWÑanñÌ"êçäL±'ªÀ^ô*+gëíU\
‡÷3o@Wf3ØK∏Ω√°´@‰ıQ7„ŒÜlêoè^Y)Yyù3Ÿ`∫üjf£ü#¯6t`∫ˇ¥•ÔjÖdåÏÄ)⁄ìj" ¶83'Êu!$b/;V©“ Õr&ÌI˜)2êç2*∑Œô߀lêú…¯≤Q …ŒÒ= SÕt?ÛF{h¿vSM a2ph≈8&OÊ»e$c &â0eêÅ£H¸2~πwãÄ19˙é2lbóì;[#;vS‡f˛«5ˇé ˇˇ
◊j‹7Ŷ¢ IENDÆB`Ç | 3,037 | Common Lisp | .l | 15 | 61.733333 | 428 | 0.579487 | cac-t-u-s/om-sharp | 167 | 14 | 31 | GPL-3.0 | 9/19/2024, 11:25:22 AM (Europe/Amsterdam) | cad5bd2acbeddbf7851617e35da1663ee8728763c5b0b486452f8b0e0ff47c64 | 1,388 | [
-1
] |
1,389 | omaudiolib.dll | cac-t-u-s_om-sharp/resources/lib/win32/omaudiolib.dll | MZ░ ЪЪ ╦ @ ╨ ╢ м!╦Lм!This program cannot be run in DOS mode.
$ Ят1⌡╣╣_х╣╣_х╣╣_х╪млх╖╣_х▌К\иё╣_х▌К[и╬╣_х▌К^и╠╣_х▌КZи╜╣_хhJ▒х╢╣_хhJ■х╒╣_х╣╣^хш╢_х"КVи╦╣_х"К_и╢╣_х'К═х╢╣_х╣╣хх╢╣_х"К]и╢╣_хRich╣╣_х PE L юb Ю "! Р
ъe p @ ╟ L Э h ю п п ─∙ ─O ЭO ═O @ \ .text |П
Р
`.rdata Ч+
,
Ж
@ @.data x= @ 8 " @ ю.gfids @ ─ Z @ @.tls ░ \ @ ю_RDATA Ю ═ ^ @ @.rsrc п ю p @ @.reloc ─∙ п √ t @ B hЮ{ЪHh0Щ
гЬ{ гЭ{ г | Х-N Yцлллллллллллh|ЪHh`Щ
г | ХN YцлллллллллллллллhпЩ
ХФM Yцллллh Ч
ХжM YцллллhЧ
ХфM Yцллллh Ъ
Х╤M Yцллллh╧(|ХЯа h─Ъ
Х≈M ┐дцлллU▀Л┐ЛjЪ╛█EЬPЪ░▀MЬ▀UЭ┴
8|┴<|Х1`
Р
≤IР^хР
H|▀Е]цлллллллллj j j j Ъh╟Ъ
ё4|Х#M Yцлh0 ХM Yцллллh`|ЪHh` ХШL Yцлллллллллhx|ЪHhp г░| ХяL Yцллллллллллллллл▀ ┐И▀╘ 0u┐хЪПа┘юuQХ╤L Yцлллллллллллллллб лллллллллллллU▀ЛV▀ЯХ% ЖEthh VХ,H ┐д▀ф^]б ллллллллллU▀ЛjЪhw└
d║ PSVW║@3еP█EТdё ▀ЫгEЭ ▀÷╟ г┤░ p'┘шt)█╥≤ VЪ(Vг┤╟ ЪD┘шt▀▀кЪPЪ╥т Ъ`┐д█┤≤ PЪ╛▀оХ╡ ▀MТd┴
Y_^[▀Е]ц┐ИИ(ЪЪЪллллллллU▀ЛV▀ЯWю█FPгHfж ▀E┐юPЪ ┐д▀ф^]б лл▀I╦|┘иEацллU▀ЛV▀Я█FгHPЪ┐дЖEtjVХG ┐д▀ф^]б лллллллллллллллWю▀аfжAгA░гTцлллллллл█AгHPЪYцллллллллллллллU▀ЛV▀ЯWю█FPгHfж ▀E┐юPЪ ┐дгT▀ф^]б ллллллллллллU▀ЛV▀ЯЪ╤x Ъ`┐д▀нХ4ЧЪЪЖEth VХ;F ┐д▀ф^]б лллллллллЪqЪ`YцлллллU▀Л▀E▀я┘ю~j▀M─╧■ t+─╨■ uU▀JаЮP▀Ej ▀│▀E█│PХ0W ┐д]б аЮP▀Eф┌■ ▀I▀│▀E█│▀JP▀E▀│▀E█│PХёo
┐д]б ллллллU▀ЛСU .─FSVW▀ы÷ЖдD▀╗ ▀u┘Ж▌² ▀U─╨■ ┘█ ─╩■ ▀E▀K▀│▀E█<│▀J▀E▀│▀E█│t?.└Gф┐■ ÷ЖдD{V▀оХ47 ┐д_^[]б █╣ PRWХo
┐д_^[]б .└GV▀о÷ЖдD{ХЛ9 ┐д_^[]б Х]8 ┐д_^[]б лллU▀Л─╧■ ▀UV▀Р┘Д СUС].с÷ЖдDzQС$RЪuЪuХу ^]б ▀IС\з▀Efnб┐Й[ю▀│▀EС^ь█│┬⌠ ┐Ч|j█rаН▀фВь█┌─ (б(кСYСXй(сС(аСXяСYA(кСAСXй(б(сСYAСXяСA(аСYAСA┐а┐Нu╙┘рx fD (бСYС(ц┐аСXп┐ЙyФ^]б лU▀ЛQSVW▀Ы3Ж(цСEЭ97~`▀]Wи .└G÷ЖдD{E─©■ u<▀G▀M.а▀╟█┬÷ЖдDz█² Pj QХаT ┐дК
▀с(хХ: СEЭWиF;7|╘_^[▀Е]б U▀ЛQV▀Я─╬■ u]W3Ъ9>~-▀MS▀]аЦаА┴MЭ▀FSj ▀╦аPХdT ▀MЭG┐д;>|Д[┐} _u▀E;Fu╦ ┬├■ ^▀Е]б 3ю┬├■ ^▀Е]б ллллллллллллЪ1Ъ`YцллллллU▀ЛСM.
└G÷ЖдD{C─╧■ u:▀I▀E.
─F▀│▀E█│÷ЖдDz▀EаЮPj QХцS ┐д]б ▀UХ9 ]б ллллU▀Л┐ЛV▀ЯW▀>┐Ъ }K█F3р┴F9~$▀ES▀]█<┘ D ▀⌠▀Fо┴░B;|П[▀▀F_г┬ ф├■ ^▀Е]б ЪvЪ`█╫ PЪ\┐д┴F┘юu≈WюгEТTh°б█EТfжEЬPгEЬ░ХЪR л┐ИИFШЪЪллллллU▀ЛjЪh╖└
d║ PV║@3еP█EТdё ▀Яj┐ЛгEЭ Wюг╓гFЮРD$j ХRo ▀▌h г├h ┘иt▀jЪ▀▌h ┘иt▀jЪ▀нХЫЪЪЖEthp VХA ┐д▀ф▀MТd┴
Y^▀Е]б ллллллллл▀ ┘иt▀jЪцлллU▀Л┐ЛVW▀ЫгEЬ j ▀Р┴}ЭХ≤@ ▀┐д▀U┴EЭ┼г ╦(┴H┬Pг@ г@ ф@ ┴▀г_^▀Е]ц┐ИИФЧЪЪллллллV▀ЯХH Ъ6Ъ`┐д^цлллллллллллVW▀Ы█OХ$ Ъw▀5`Ъж┐д▀оХ Ъ7Ъж┐д_^цлллллVW▀Ы3Ж9w~;D ▀▀╟▀AЬ┐И╘ 0u┐хЪПа┘юu QХRD ┐дF;w|тгG _^ц┴w_^цллллU▀ЛV▀Р┐хЪ3рВu;ПvЪП╞u│Ч ^r2ЖаtЪП▀AЭ;аrЪП+х┐ЫsЪП┐Ы#vЪП▀х┴M]И╧? U▀Л▀U▀│╢ ▀HЬ┴┐юЬВа 0u ╧ Па▀б]б лллллU▀ЛjЪh╖└
d║ PV║@3еP█EТdё ▀ЯгEЭ гХХи] ▀▌П ┘иt3▀√Ь +яjаЗХЪЪЪг├П ┐дг├Т г├Ь ▀нХуf ЖEth VХл> ┐д▀ф▀MТd┴
Y^▀Е]б лллллллллллллЪ1гA Ъ`Yцлллллллллллллллг╛ыWюгA╛ы▀аРAгA гA гA( гA,ЪЪЪЪфA0 гA гA гA гA$ фA4гA8 гAL гAPЪЪЪЪфAT гA< |