Music 220b: Winter 2001
Fernando Lopez-Lezcano, instructor
Christopher Burns, teaching assistant
Tamara Smyth, teaching assistant
Week 3: tricks for CLM instrument design
Some useful tricks when you're writing instruments:
Parameters which can be either constants or envelopes
Often it helps to design instrument interfaces which accept either constant values or envelopes (grani has numerous examples of this feature). You can use the following chunk of code to convert any constant into an envelope with a constant value; then make sure your instrument handles the envelope correctly....
(let* ((parameter-env (make-env :envelope (if (listp parameter) parameter (list 0 parameter 1 parameter))))))
The (listp) function returns true if parameter is a list (presumably, a user-specified envelope); if that's not the case, the else-clause creates a simple envelope using the (list) function. You might need to specify :duration or other key parameters in order to make this into a real working envelope....
Default parameters outside of (definstrument)
In a number of instruments (for example grani), you'll see code like:
(defparameter grani-grains 0) ... (definstrument grani (start-time duration amplitude file &key (grains grani-grains) ...
We could just specify (grains 0) as the first key parameter; but there's a good reason not to. Let's say we're going to make ten calls to grani, all of which set grains to 15. We can specify this by hand each time, or, we can bind the grani-grains variable to 15 and let the be the default value for all ten calls. It's easier to type and easier to read:
(let* ((grani-grains 15)) (grani ...) ...)
Course resources main page
220b main page