Overview Clamps Packages CM Dictionary Clamps Dictionary Fomus
Next: Gui , Previous: of-incudine-dsps , Up: Incudine Extensions , Home: General

Clamps Packages

incudine-bufs

clamps-cuda-bufs clamps-cuda-dsps

incudine-bufs implements a registry for buffers in Clamps on top of Incudine's infrastructure for buffers.

The standard way to add a buffer to the registry is using the command clamps-buffer-load. The command takes a relative or absolute filename and a :path key as arguments. The :path is a list of pathnames of directories to search. Its default value is *​sfile-path​*. The user can push pathnames to that variable to add user- or application-specific locations to search for soundfiles.

If a buffer of that name has already been loaded, clamps-buffer-load simply returns that buffer. Otherwise it loads the file into an incudine:buffer struct, assigns an unused integer id to it, updates the registry and returns the loaded buffer:

(clamps-buffer-load
 "69-Flute.nv.ff.1A4.wav"
 :path (list (asdf:system-relative-pathname :clamps "extra/snd/")))
;; => #<incudine:buffer :FRAMES 112345 :CHANNELS 2 :SR 48000.0>

The buffer gets registered under its filename, full pathname and its id. A buffer can be retrieved from the registry using find-buffer with any of the registered values as argument.

In case a buffer has already been loaded (e.g. with Incudine's #'buffer-load function), the function add-buffer takes a buffer instead of a filename as argument and registers the buffer in the same way as clamps-buffer-load. list-buffers lists all buffers and their ids, buffer-id returns the id of a buffer, remove-buffer removes a buffer from the registry using its id, filename or the buffer itself as argument and remove-all-buffers removes all buffers from the registry.

(defvar *73-flute-nv*
  (incudine:buffer-load
   (asdf:system-relative-pathname
    :clamps
    "extra/snd/sfz/Flute-nv/samples/73-Flute.nv.ff.1Db5.wav")))
;; => *73-flute-nv*

(add-buffer *73-flute-nv*)
;; => #<incudine:buffer :FRAMES 114210 :CHANNELS 2 :SR 48000.0>

(list-buffers)
;; => ((0 "69-Flute.nv.ff.1A4.wav" #<incudine:buffer :FRAMES 112345 :CHANNELS 2 :SR 48000.0>)
;;     (1 "73-Flute.nv.ff.1Db5.wav" #<incudine:buffer :FRAMES 114210 :CHANNELS 2 :SR 48000.0>))


(find-buffer "69-Flute.nv.ff.1A4.wav")
;; => #<incudine:buffer :FRAMES 112345 :CHANNELS 2 :SR 48000.0>, t

(buffer-id "69-Flute.nv.ff.1A4.wav")
;; => 0

(find-buffer 0)
;; => #<incudine:buffer :FRAMES 112345 :CHANNELS 2 :SR 48000.0>, t

(buffer-name (find-buffer "69-Flute.nv.ff.1A4.wav"))
;; => "69-Flute.nv.ff.1A4.wav"

;; compare to incudine's built-in function buffer-file:
(buffer-file (find-buffer "69-Flute.nv.ff.1A4.wav"))
;; => #P"/home/orm/work/snd/sfz/transverse-flute/export/69-Flute.nv.ff.1A4.wav"

(mapcar #'third (list-buffers))
;;  => (#<incudine:buffer :FRAMES 112345 :CHANNELS 2 :SR 48000.0>
;;      #<incudine:buffer :FRAMES 114210 :CHANNELS 2 :SR 48000.0>)

(buffer-id #P"/home/orm/work/snd/sfz/transverse-flute/export/69-Flute.nv.ff.1A4.wav")
;; => 0

(buffer-id (find-buffer "73-Flute.nv.ff.1Db5.wav"))
;; => 1

(buffer-id "73-Flute.nv.ff.1Db5.wav")
;; => 1

(buffer-id *73-flute-nv*)
;; => 1

(remove-buffer 0)
;; => t

(list-buffers)
;; => ((1 "73-Flute.nv.ff.1Db5.wav" #<incudine:buffer :FRAMES 114210 :CHANNELS 2 :SR 48000.0>))

(remove-buffer *73-flute-nv*)
;; => t

(list-buffers)
;; => nil

;; The buffer *73-flute-nv* is removed from the registry, but not
;; removed from clamps/incudine:

(find-buffer *73-flute-nv*)
;; => nil

*73-flute-nv*
;; => #<incudine:buffer :FRAMES 114210 :CHANNELS 2 :SR 48000.0>

Note

The buffer containing "69-Flute.nv.ff.1A4.wav" also still exists after evaluating the code above, but if nothing points to it anymore, it will eventually get garbage collected. If the space of the buffer should get explicitely freed, use Incudine's #'free method with the buffer as argument.