Chapter 5. Functions: making your own tools
This chapter covers
- Writing and using functions in ChucK
- Defining and naming functions
- Function arguments and return types
- Functions that can call themselves
- Using functions for sound and music composition
Now that you’ve had fun building a drum machine using the SndBuf UGen, it’s time to learn how to write and use functions. You’ve already used a number of functions, which we’ve also called methods, ranging from changing the .freq and .gain of oscillators, to using Std.mtof() for converting MIDI note numbers into frequencies, to generating random numbers using Math.random2() and Math.random2f(). All of these are examples of functions.
Often in writing programs you need to do the same types of things ...
Get Programming for Musicians and Digital Artists now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.