CL-Collider:SuperCollider 的 Common Lisp 客户端
1. 项目介绍
CL-Collider 是一个实验性项目,旨在为 Common Lisp 提供一个 SuperCollider 客户端。SuperCollider 是一个实时音频合成器、音频处理环境以及一种用于音频编程的编程语言。CL-Collider 允许 Common Lisp 程序员利用 SuperCollider 的强大功能,通过 Lisp 代码来控制 SuperCollider 服务器。
2. 项目快速启动
环境准备
- SuperCollider:确保已经安装了 SuperCollider。
- Common Lisp:安装 ClozureCL 或 SBCL。
- Quicklisp:用于管理 Lisp 库。
快速启动代码
首先,你需要启动 SuperCollider 服务器,然后加载 CL-Collider。
(ql:quickload :cl-collider)
(in-package :sc-user)
(named-readtables:in-readtable :sc)
接下来,配置 SuperCollider 服务器的路径。
(setf *sc-synth-program* "/path/to/scsynth")
(setf *sc-plugin-paths* (list "/path/to/plugin_path" "/path/to/extension_plugin_path"))
(setf *sc-synthdefs-path* "/path/to/synthdefs_path")
然后,连接到 SuperCollider 服务器。
(setf *s* (make-external-server "localhost" :port 48800))
(server-boot *s*)
示例:播放一个音符
(defvar *synth*)
(setf *synth* (play (sin-osc.ar [320 321] 0 0.2)))
示例:停止播放
(free *synth*)
示例:退出 SuperCollider 服务器
(server-quit *s*)
3. 应用案例和最佳实践
创建合成器定义
(defsynth sine-wave ((note 60))
(let* ((freq (midicps note))
(sig (sin-osc.ar [freq (+ freq 2)] 0 0.2)))
(out.ar 0 sig)))
创建代理
(proxy :sinesynth (sin-osc.ar [440 441] 0 0.2))
(proxy :sinesynth (with-controls ((lfo-speed 4))
(sin-osc.ar (* [440 441] (range (lf-pulse.ar [lfo-speed (+ lfo-speed 0.2)]) 0 1)) 0 0.2))
:fade 8.0)
(ctrl :sinesynth :lfo-speed 8)
(ctrl :sinesynth :gate 0)
创建音乐序列
(defsynth saw-synth ((note 60) (dur 4.0))
(let* ((env (env-gen.kr (env [0 0.2 0] [(* dur 0.2) (* dur 0.8)]) :act :free))
(freq (midicps note))
(sig (lpf.ar (saw.ar freq env) (* freq 2))))
(out.ar 0 [sig sig])))
(defun make-melody (time n &optional (offset 0))
(when (> n 0)
(at time (synth 'saw-synth :note (+ offset (alexandria:random-elt '(62 65 69 72)))))
(let ((next-time (+ time (alexandria:random-elt '(0 1 2 1.5)))))
(callback next-time #'make-melody next-time (- n 1) offset))))
(make-melody (quant 4) 16)
(make-melody (+ 4 (quant 4)) 16 12)
4. 典型生态项目
sc-extensions
:扩展库。cl-patterns
:模式/序列库。bdef
:文件/缓冲区管理/便利库。sc-vst
:VST插件支持库。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考