About this Book - Programming for Musicians and Digital Artists: Creating music with ChucK (2015)

Programming for Musicians and Digital Artists: Creating music with ChucK (2015)

About this Book

We wrote this book to teach novice programmers how to code in ChucK. Thus, we start at the very beginning, so don’t be afraid. We will teach programming through musical examples. We believe that being able to “hear” what your code is doing will aid you in learning the key concepts, as well as make the process enjoyable. If you are an experienced programmer, you may be able to skip a couple of the beginning chapters depending on your level, but note that ChucK is quite different from other languages. We promise that there is something to learn here for everyone.

If you’re an advanced programmer who is already familiar with another language, “What’s different about ChucK?,” later in this front matter, gives a strategy for approaching ChucK from your vantage point.

How the book is organized

Throughout the chapters there are suggested composition exercises to expand what you have learned. In a way, you can view each chapter as “unlocking” new parts of the language you can use in your compositions.

In chapter 0 (computer scientists almost always number from zero), we tell you why ChucK is different from other languages, and how we, and many others have used it in myriad music and art projects.

The next two chapters are for the beginning programmer, introducing key concepts needed to be able to begin coding. Chapter 1 begins with the basics of computer science, languages, and ChucK, including variables, types, conditional statements, and looping structures. Of course, we also make sound and music using ChucK. Chapter 2 introduces the libraries (tools) built into ChucK, and shows how random numbers and mathematical calculations can be used to make more expressive programs and songs.

In chapter 3 we introduce arrays, and show how to more easily make, store, and play melodies, and control other parameters in ChucK.

In chapter 4 we introduce how to use sound files in ChucK and how you can use them to create soundscapes and even a cool electronic dance piece.

Chapter 5 introduces the concept of functions and how they can be used in modularizing and organizing your code, which can result in even more expressive compositions and more orderly programs.

Chapter 6 dives deeper into Unit Generators (UGens), ChucK’s built-in audio processing and synthesis objects. Here you will learn about more oscillators, envelope generators, FM synthesis, physical modeling synthesis, and audio effects. Chapter 7 continues this, introducing many physical, modal (resonant), and particle synthesis UGens.

Chapter 8 introduces multithreading and concurrency and you will learn how to make your programs “juggle” multiple things at the same time, all in perfect synchrony.

Chapter 9 introduces object-oriented programming (OOP) and how you can create your own Objects and Classes to use in your code.

Chapter 10 covers Events, which allow ChucK programs to signal each other. Events also allow ChucK to respond to signals and data from the “outside world.” This lets us begin to think of ChucK as a live performance tool, by introducing how you can use your keyboard and mouse for real-time control over your compositions.

Chapter 11 goes into ways that ChucK can communicate with other programs, computers, and control devices. We briefly cover how MIDI can be used with ChucK, both using an external MIDI device (such as a keyboard) to play ChucK as a synthesizer, and how ChucK can control other synthesizers, both software and external hardware synths. We also introduce Open Sound Control (OSC), which is another standard way for music programs and devices to communicate. We then look at Serial Input/Output, which allows us to talk to even more devices.

The appendixes cover lots of details and include more examples of ChucK’s features and capabilities. Appendix A covers installing and running the miniAudicle Integrated Development Environment (IDE), and Appendix G covers how to use ChucK in the command line (text-only interface).

Appendix B documents all of the library functions built into ChucK. Appendix C documents all of the built-in UGens. Appendix G covers ChucK on the command line. Appendix D covers OSC. Appendix E covers File I/O, and Appendix F covers Serial I/O. Appendix H discusses ways to extend the ChucK language itself with new UGens.

For those Interested in Instant Gratification

If you’re impatient and want to see the power of what ChucK can do (even without understanding exactly how), once you’ve installed the miniAudicle (appendix A) and run your first two programs (“Hello World” and “Hello Sine”, section 1.2), you could type in and run the end-of-chapter example of listing 6.15. Inspired by this powerful ChucK flourish, you can then go back and systematically work through the book.

For Programmers Familiar with other Languages

Appendix A talks about how to install and run the miniAudicle IDE (Integrated Development Environment), and how to install and run ChucK for the command line (Terminal, Command, etc.). If you haven’t already installed ChucK and/or miniAudicle on your machine, you should begin atappendix A.

Section 1.2 (“Your first ChucK programs”) shows the miniAudicle, and introduces you to the ChucK operator and ChucK’s way of dealing with time. If you’re a command-line type, consult appendix G (“ChucK on the command line”) for instructions.

What’s Different About Chuck?

On the surface, ChucK looks like a lot of other languages such as Java and Objective C, with a few main differences. First and most important, the ChucK operator (=>) is used for assignment, connecting audio Unit Generators (UGens) together, and other things. Designed to look like an arrow indicating direction, the ChucK operator encourages left to right flow of audio connections, assignment and time, among others. There is no use of the single equals (=) sign in ChucK, so if you’re familiar with languages that use a syntax like:

float temp = 0.0; in ChucK you’ll need to get used to 0.0 => float temp;

Another thing about ChucK that will likely be new to you is how ChucK deals with time. You as the programmer have to explicitly control time in your code, so we’d recommend you look over section 1.4 (“Time in ChucK: It’s about now”) carefully. The time and dur datatypes are fundamental to, and what’s so different about, ChucK, and you won’t be able to program successfully (or hear any sound) unless you learn about them.

From there, you could motivate yourself with a couple of examples of the power of ChucK by typing in and running examples, such as listing 3.8 and/or listing 6.15.

You should then go back and work through chapter 4 to learn about how ChucK deals with sound files. You’ll finish that chapter with the drum machines of listing 4.11.

If you’re satisfied you have a grasp of the examples so far, you’re probably ready to jump directly into part 2 (beginning with chapter 6), learning about all of the powerful UGens available in ChucK. From there on it’s all new, so keep reading and running the examples. The next fundamentally new ChucK thing you’ll encounter will be covered in chapter 8 where you’ll learn about sporking (like forking) shreds (like threads, but ChucK-ian). Objects and classes (chapter 9) might look pretty familiar to you, as might events (chapter 10), but ChucK is unique in that events can be generated by lots of external devices (Joysticks, MIDI, Open Sound Control), so that should look quite different to you. Chapter 11 finishes up with MIDI, OSC, and Serial, for advanced users/programmers.

There are quite comprehensive appendixes at the end with references to pretty much everything in ChucK, so remember that you can look some things up there as well as in the index.

About the code

All source code in the book is in a typeface like this, which sets it off from the surrounding text. In many listings, the code is annotated to point out the key concepts, and numbered bullets are sometimes used in the text to provide additional information about the code.

In the ebook, certain terms in text and code appear in color, just as they would as you type into the miniAudicle editor window. This is the miniAudicle recognizing those reserved words and coloring them by type.

Just about all of the code shown in the book can be found in various forms in the sample source code that accompanies this book. The sample code can be downloaded free of charge from the Manning website at www.manning.com/ProgrammingforMusicians andDigitalArtists.

The accompanying sample code (including related audio files) is installed automatically when you install ChucK. On a Mac it can be found in /Library/ChucK/ examples/book/digital-artists/, while on Windows it is located at C:\Program Files\ChucK\examples\book\digital-artists\. On Linux, if you follow the installation procedure described in appendix A, the sample code can be found in /usr/local/ share/doc/chuck/examples/book/digital-artists/.

All of the sample code from this book can be accessed directly in miniAudicle by navigating to File > Open Example and locating book/digital-artists in the Example Browser.

Note

ChucK works on Mac OS X 10.5+ or later, Windows XP or later, or a suitable Linux system.

Author Online

Purchase of Programming for Musicians and Digital Artists includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the authors and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/ProgrammingforMusiciansandDigitalArtists. This page provides information on how to get on the forum once you’re registered, what kind of help is available, and the rules of conduct on the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialog between individual readers and between readers and the authors can take place. It’s not a commitment to any specific amount of participation on the part of the authors, whose contributions to the AO remain voluntary (and unpaid). We suggest you ask the authors challenging questions lest their interest stray!