AA. VV. - The SuperCollider Book [Beginner's Tutorial]

71

description

The most important reference book for SuperCollider, a programming language designed for music purposes.Over 700 pages from basic issues to advanced topics.Here only the first 55 pages of the beginner's tutorial, for those interested to try the powerful features of this software.

Transcript of AA. VV. - The SuperCollider Book [Beginner's Tutorial]

Page 1: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 2: AA. VV. - The SuperCollider Book [Beginner's Tutorial]

The SuperCollider Book

edited by Scott Wilson, David Cottle, and Nick Collins

The MIT Press

Cambridge, Massachusetts

London, England

Page 3: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 4: AA. VV. - The SuperCollider Book [Beginner's Tutorial]

Foreword ixJames McCartneyIntroduction xiiiScott Wilson, David Cottle, and Nick Collins

Tutorials 1

1 Beginner’s Tutorial 3David Cottle

2 The Unit Generator 55Joshua Parmenter

3 Composition with SuperCollider 81Scott Wilson and Julio d’Escriván

4 Ins and Outs: SuperCollider and External Devices 105Stefan Kersten, Marije A. J. Baalman, and Till Bovermann

Advanced Tutorials 125

5 Programming in SuperCollider 127Iannis Zannos

6 Events and Patterns 179Ron Kuivila

7 Just-in-Time Programming 207Julian Rohrhuber and Alberto de Campo

8 Object Modeling 237Alberto de Campo, Julian Rohrhuber, and Till Bovermann

Contents

Page 5: AA. VV. - The SuperCollider Book [Beginner's Tutorial]

vi Contents

Platforms and GUI 271

9 Mac OSX GUI 273Jan Trützschler von Falkenstein

10 SwingOSC 305Hanns Holger Rutz

11 SuperCollider on Windows 339Christopher Frauenberger

12 “Collision with the Penguin”: SuperCollider on Linux 355Stefan Kersten and Marije A. J. Baalman

Practical Applications 379

13 Sonification and Auditory Display in SuperCollider 381Alberto de Campo, Julian Rohrhuber, Till Bovermann, and Christopher Frauenberger

14 Spatialization with SuperCollider 409Marije A. J. Baalman and Scott Wilson

15 Machine Listening in SuperCollider 439Nick Collins

16 Microsound 463Alberto de Campo

17 Alternative Tunings with SuperCollider 505Fabrice Mogini

18 Non-Real-Time Synthesis and Object-Oriented Composition 537Brian Willkie and Joshua Parmenter

Projects and Perspectives 573

19 A Binaural Simulation of Varèse’s Poème Électronique 575Stefan Kersten, Vincenzo Lombardo, Fabrizio Nunnari, and Andrea Valle

20 High-Level Structures for Live Performance: dewdrop_lib and chucklib 589

James Harkins21 Interface Investigations 613

Thor Magnusson22 SuperCollider in Japan 629

Takeko Akamatsu23 Dialects, Constraints, and Systems within Systems 635

Julian Rohrhuber, Tom Hall, and Alberto de Campo

Page 6: AA. VV. - The SuperCollider Book [Beginner's Tutorial]

vii Contents

Developer Topics 657

24 The SuperCollider Language Implementation 659Stefan Kersten

25 Writing Unit Generator Plug-ins 691Dan Stowell

26 Inside scsynth 721Ross Bencina

Appendix: Syntax of the SuperCollider Language 741Iannis ZannosSubject Index 745Code Index 751

Page 7: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 8: AA. VV. - The SuperCollider Book [Beginner's Tutorial]

Foreword

James McCartney

Why use a computer programming language for composing music? Specifically, why use SuperCollider? There are several very high-level language environments for a udio besides SuperCollider, such as Common Music, Kyma, Nyquist, and Patch-work. These all demonstrate very interesting work in this area and are worth look-ing into. SuperCollider, though, has the unique combination of being free, well supported, and designed for real time. It is a language for describing sound pro-cesses. SuperCollider is very good at allowing one to create nice sounds with m inimal effort, but more important, it allows one to represent musical concepts as objects, to transform them via functions or methods, to compose transformations into higher-level building blocks, and to design interactions for manipulating music in real time, from the top-level structure of a piece down to the level of the waveform. You can build a library of classes and functions that become building blocks for your w orking style and in this way make a customized working environment. With SuperCollider, one can create many things: very long or infinitely long pieces, infinite variations of structure or surface detail, algorithmic mass production of synthesis voices, sonifica-tion of empirical data or mathematical formulas, to name a few. It has also been used as a vehicle for live coding and networked performances. Because of this open-endedness, early on, I often felt it difficult to know how best to write the documenta-tion. There were too many possible approaches and applications.

Thus, I am pleased that there will now be a book on SuperCollider, and the best part of it for me is that I have not had to do much of the hard work to get it done. Since I made SuperCollider open source, it has taken on a life of its own and become a community-sustained project as opposed to being a project sustained by a single author. Many people have stepped up and volunteered to undertake tasks of docu-mentation, porting to other operating systems, interfacing to hardware and soft-ware, writing new unit generators, extending the class library, maintaining a Web site, mailing lists, and a wiki, fixing bugs, and, finally, writing and editing the chap-ters of this book. All of these efforts have resulted in more features, better documen-tation, and a more complete, robust, and bugfree program.

Page 9: AA. VV. - The SuperCollider Book [Beginner's Tutorial]

x James McCartney

SuperCollider came about as the latest in a series of software synthesis languages that I have written over the years. I have been interested in writing software to syn-thesize electronic music ever since I was in high school. At that time, I had written on a piece of notebook paper a set of imaginary subroutine calls in BASIC for imple-menting all of the common analog synthesizer modules. Of course, doing audio synthesis in BASIC on the hardware of that time was completely impractical, but the idea had become a goal of mine. When I graduated college, I went to have a look at E-mu in California and found that it was operating out of a two-story house. I fig-ured that the synthesizer industry was a lot smaller than I had imagined and that I should rethink my career plans.

The first software synthesizer I wrote was a graphical patching environment called Synfonix that generated samples for the Ensoniq Mirage sampling keyboard using a Macintosh computer. I attempted to sell this program but sold only two copies, one to Ivan Tcherepnin at Harvard and another to Mark Polishook. A business lesson I learned from this is not to sell a product that requires purchasers to already own two niche products. The intersection of two small markets is near zero.

In 1990, I wrote a program called Synth-O-Matic that I used personally but never meant to distribute, even though one copy I gave to a friend got circulated. I created this program after learning CSound and deciding that I never wanted to actually have to use CSound’s assembly-language-like syntax. Synth-O-Matic had a more expression-oriented syntax for writing signal flow graphs and a graphical user inter-face for editing wave tables. I used this program on and off, but it was quite slow so I stopped using it, for the most part, in favor of hardware synthesizers.

It wasn’t until the PowerPC came out that it became practical to do floating-point signal processing in real time on a personal computer. At the time I had been work-ing on music for a modern dance piece, using Synth-O-Matic to do granular s ynthesis. It was taking a long time to generate the sound, and I was running behind schedule to get the piece done. On the day in March 1994 when the first PowerPC-based ma-chine came out, I went and bought the fastest one. I recompiled my code, and it ran 32 times faster. I was then able to complete the piece on time. I noticed that my code was now running faster than real time, so I began working on a program designed to do real-time synthesis. Around this time I got a note in the mail from Curtis Roads, who had apparently gotten one of the circulating copies of Synth-O-Matic, encouraging me to further develop the program. So I took the Synth-O-Matic engine and combined it with the Pyrite scripting language object which I had written for MAX. This became SuperCollider version 1, which was released in March 1996. The first two orders were from John Bischoff and Chris Brown of The Hub.

The name “SuperCollider” has an amusing origin. During the early 1990s I worked in the Astronomy Department of the University of Texas at Austin on the Hubble Space Telescope Astrometry Science Team, writing software for data a nalysis

Page 10: AA. VV. - The SuperCollider Book [Beginner's Tutorial]

xi Foreword

and telescope observation planning. On the floors below my office was the Physics Department, some of the members of which were involved in the Superconducting Super Collider project. In 1993, Congress cut the funding for the project, and there were many glum faces around the building after that. I had been thinking about this merging, or “collision,” if you will, of a real-time synthesis engine with a high-level garbage collected language, and it seemed to me that it was an experiment that would likely fail, so I named it after the failed Big Science project of the day. Except that the experiment didn’t fail. To my surprise, it actually worked rather well.

The version 1 language was dynamically typed, with a C-like syntax, closures bor-rowed from Scheme, and a limited amount of polymorphism. After using version 1 for a couple of years, and especially after a project on which I was invited by Iannis Zannos to work on a concert in an indoor swimming pool in Berlin, I realized that it had severe limitations on its ability to scale up to create large working environ-ments. So I began working on version 2, which borrowed heavily from Smalltalk. It was for the most part the same as the language described in this book except for the synthesis engine and class library, which have changed a great deal.

The goal of SuperCollider version 2 and beyond was to create a language for de-scribing real-time interactive sound processes. I wanted to create a way to de-scribe categories of sound processes that could be parameterized or customized. The main idea of SuperCollider is to algorithmically compose objects to create sound-generating processes. Unit generators, a concept invented by Max Matthews for his Music N languages, are very much like objects and are a natural fit for a purely o bject-oriented Smalltalk-like language.

In 2001 I was working on version 3 of SuperCollider, and because of the architec-ture of the server, it was looking like it really should be open source, so that anyone could modify it however they liked. I was (barely) making a living at the time selling SuperCollider, so the decision to give it away was a difficult one to make. But finan-cially it was looking like I would need a “real” job soon, anyway. I was also worried that the period of self-employment on my résumé would begin looking suspect to potential employers. Ultimately, I did get a job, so I was able to open source the program. On the day that I made all of my previously copyright-protected programs free, my Web site experienced an eightfold increase in traffic. So obviously there was a lot of interest in an open source audio language and engine, especially one that is free.

I hope that this book will enable and inspire the reader to apply this tool in useful and interesting ways. And I hope to hear and enjoy the results!

Page 11: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 12: AA. VV. - The SuperCollider Book [Beginner's Tutorial]

Introduction

Scott Wilson, David Cottle, and Nick Collins

Welcome to The SuperCollider Book. We’re delighted to present a collection of tu-torials, essays, and projects that highlight one of the most exciting and powerful audio environments. SuperCollider (SC to its friends) is a domain-specific program-ming language specialized for sound but with capabilities to rival any general- purpose language. Though it is technically a blend of Smalltalk, C, and ideas from a number of other programming languages, many users simply accept SuperCollider as its own wonderful dialect, a superlative tool for real-time audio adventures. In-deed, for many artists, SuperCollider is the first programming language they learn, and they do so without fear because the results are immediately engaging; you can learn a little at a time in such a way that you hardly notice that you’re programming until it’s too late and you’re hooked! The potential applications in real-time interac-tion, installations, electroacoustic pieces, generative music, audiovisuals, and a host of other possibilities make up for any other qualms. On top of that, it’s free, power-ful, and open source, and has one of the most supportive and diverse user and devel-oper communities around.

Pathways

This book will be your companion to SuperCollider; some of you will already have experience and be itching to turn to the many and varied chapters further on from this point. We’ll let you follow the book in any order you choose! But we would like to take care to welcome any newcomers and point them straight in the direction of chapter 1, which provides a friendly introduction to the basics. For those on Win-dows or Linux it may be read together with chapter 11 or 12, respectively, which cover some of the cross-platform installation issues. From there we suggest begin-ners continue through until chapter 4, as this path will provide you with some basic skills and knowledge which can serve as a foundation for further learning.

For more advanced users, we suggest you look at the more “topics”-oriented chapters which follow. These chapters aren’t designed to be read in any particular

Page 13: AA. VV. - The SuperCollider Book [Beginner's Tutorial]

xiv Scott Wilson, David Cottle, and Nick Collins

order, so proceed with those of particular interest and relevance to you and your pursuits. Naturally we have referred to other chapters for clarification where neces-sary and have tried to avoid duplication of materials except where absolutely crucial for clarity.

These “topics” chapters are divided into sections titled Advanced Tutorials, Plat-forms and GUI, and Practical Applications. They begin with chapter 5, “Program-ming in SuperCollider,” which provides a detailed overview of SuperCollider as a programming language. This may be of interest to beginners with a computer science background who’d rather approach SC from a language design and theory perspec-tive than through the more user-friendly approach in chapter 1. Chapters on a v ariety of subjects follow, including sonification, spatialization, microsound, GUIs, machine listening, alternative tunings, and non-real-time synthesis.

Following these chapters is a section for intermediate and advanced users titled Projects and Perspectives. The material therein provides examples of how Super-Collider has been used in the real world. These chapters also provide some philo-sophical insight into issues of language design and its implications (most specifically in chapter 23, “Dialects, Constraints, and Systems-Within-Systems”). This sort of intellectual pursuit has been an important part of SuperCollider’s development; SC is a language that self-consciously aims for good design, and to allow and encourage elegance, and even beauty, in the user’s code. Although this might seem a little ab-stract at first, we feel that this sets SC apart from other computer music environ-ments and that as users advance, awareness of such things can improve their code.

Finally, there is a section titled Developer Topics, which provides detailed “under the hood” information on SC. These chapters are for advanced users seeking a deeper understanding of the SC and its workings and for those wishing to extend SC, for instance, by writing custom unit generator plug-ins.

Code Examples and Text Conventions

Initially SuperCollider was Mac only, but as an open source project since 2001, it has widened its scope to cover all major platforms, with only minor differences be-tween them. Most code in this book should run on all platforms with the same re-sults, and we will note places where there are different mechanisms in place; most of the time, the code itself will already have taken account of any differences auto-matically. For instance, SC includes cross-platform GUI classes such as View, Slider, and Window. These will automatically redirect to the correct GUI implementation, either Cocoa (on Mac OSX; see chapter 9) or SwingOSC (on all platforms; see chap-ter 10). However, there are some differences in the programming editor environ-ments (such as available menu items) and the keyboard shortcuts. You are referred

Page 14: AA. VV. - The SuperCollider Book [Beginner's Tutorial]

xv Introduction

as well to the extensive Help system that comes with the SuperCollider application; a Help file on keyboard Shortcuts for the various platforms is prominently linked from the main Help page.

Just to note, when you come across keyboard shortcuts in the text, they’ll appear like this: [enter] designates the “enter” (and not the “return”) key, [ctrl+a] means the control key plus the “a” key, and so on. Furthermore, all text appearing in the �������� will almost always be valid SuperCollider code (very occasionally there may be exceptions for didactic purposes, such as here). You will also encounter some special SuperCollider terms (e.g., Synth, SynthDef, and Array) that aren’t in code font and are discussed in a friendly manner; this is because they are ubiquitous concepts and it would be exhausting to have them in the code font every time. You may also see them appearing with a capital letter (i.e., Synths), or all lower case (synths), depend-ing again on how formal we are being. Anyway, if you’re new to SuperCollider, don’t worry about this at all; chapter 1 will start you on the righteous path, and you’ll soon be chatting about Synths and UGens like the rest of us.

The Book Web Site

This brings us to the accompanying Web site for the book (<http://supercolliderbook .net>), which contains all the code reproduced within, ready to run, as well as down-load links to the application itself, its source code, and all sorts of third-party extras, extensions, libraries, and examples. A standardized version of SuperCollider is used for the book, SuperCollider 3.4, for which all book code should work without trou-ble. Of course, the reader may find it productive to download newer versions of SuperCollider as they become available, and it is our intention to provide updated versions of the example code where needed. Although we can make no hard prom-ises, in this fast-paced world of operating system shifts, that the code in this book will remain eternally correct—the ongoing development and improvement of envi-ronments such as SuperCollider are a big part of what makes them so exciting—we’ve done our best to present you with a snapshot of SuperCollider that should retain a core validity in future years.

Final Thoughts

Please be careful with audio examples; there is of course the potential to make noises that can damage your hearing if you’re not sensible with volume levels. Until you become accustomed to the program, we suggest you start each example with the volume all the way down, and then slowly raise it to a comfortable level. (And if you’re not getting any sound, remember to check if you’ve left the monitors off or

Page 15: AA. VV. - The SuperCollider Book [Beginner's Tutorial]

xvi Scott Wilson, David Cottle, and Nick Collins

the computer audio muted.) Some examples may use audio input and have the po-tential to feedback unless your monitoring arrangements are correct. The easiest way to deal with such examples is to monitor via headphones.

We couldn’t possibly cover everything concerning SuperCollider, and there are many online resources to track down new developments and alternative viewpoints, including mailing lists, forums, and a host of artists, composers, technology devel-opers, and SuperCollider maniacs with interesting pages. We have provided a few of the most important links (at the time of writing) below, but Wikigoopedigle, or whatever your contemporary equivalent is, will allow you to search out the current SuperCollider 15.7 as necessary.

We’re sure you’ll have fun as you explore this compendium, and we’re also sure you’ll be inspired to some fantastic art and science as you go. Enjoy exploring the SuperCollider world first charted by James McCartney but since expanded immea-surably by everyone who partakes in this infinitely flexible open source project.

Primary Web ResourcesMain community home page: <http://supercollider.sourceforge.net>Application download and project site: <http://sourceforge.net/projects/s upercollider>James McCartney’s home page: <http://www.audiosynth.com>The venerable swiki site: <http://swiki.hfbk-hamburg.de:8888/MusicTechnology/6>

Acknowledgments

We owe a debt of gratitude to the chapter contributors and to the wider S uperCollider community, who have supported this project. SC’s community is one of its greatest strengths, and innumerable phone calls, e-mails, chats over cups of tea at the SC Symposium, and many other interactions, have contributed to making this book and SC itself stronger. We apologize to all who have put up with our insistent editing and acknowledge the great efforts of the developers to prepare a stable SuperCollider 3.4 version for this book. A thousand thank-yous:

������ ���������������������������������

Thanks to all at MIT Press who have assisted in the handling of our proposal and manuscript for this book.

Thank you to friends, family, and colleagues who had to deal with us while we were immersed in the lengthy task of organizing, editing, and assembling this book. Editing may seem like a solitary business, but from their perspective we’re quite sure it was a team effort!

Page 16: AA. VV. - The SuperCollider Book [Beginner's Tutorial]

xvii Introduction

Many thanks to our students, who have served as guinea pigs for pedagogical ap-proaches, tutorial materials, experimental developments, and harebrained ideas. Now back to your exercise wheels!

Finally, the editors would like to thank each other for support during the period of gestation. At the time of writing, we’ve been working on this project for 2 years to bring the final manuscript to fruition. Though Scott and Nick have met on many occasions (and were co-organizers of the 2006 SuperCollider Symposium at the Uni-versity of Birmingham), neither has ever met David in person (we sometimes wonder if he really exists!); but you should see the number of e-mails we’ve sent each other. For many months, in the heat of the project, David modified his routine to include a 3 A.M. e-mail check to keep up with those using GMT, which imparts a celestially imposed 8-hour advantage. In any case, although it has at times been exhausting, seeing this book through to fruition has been a pleasure, and we hope it brings you pleasure to read it and learn about SC.

Page 17: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 18: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 19: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 20: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 21: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 22: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 23: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 24: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 25: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 26: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 27: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 28: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 29: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 30: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 31: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 32: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 33: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 34: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 35: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 36: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 37: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 38: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 39: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 40: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 41: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 42: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 43: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 44: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 45: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 46: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 47: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 48: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 49: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 50: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 51: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 52: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 53: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 54: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 55: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 56: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 57: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 58: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 59: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 60: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 61: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 62: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 63: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 64: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 65: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 66: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 67: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 68: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 69: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 70: AA. VV. - The SuperCollider Book [Beginner's Tutorial]
Page 71: AA. VV. - The SuperCollider Book [Beginner's Tutorial]