Mapping MIDI Channels to Multiple Instruments in SuperCollider

Published by . [Permalink]

Being able to control a polyphonic instrument in MIDI is good, but being able to control multiple instruments is even better. SuperCollider offers a lot of flexibility when it comes to timbre. For my personal workflow, I like to try out a lot of different sounds to see what best in the mix. Thus when thinking about how I want to use the MIDI controller in connection with SuperCollider, it makes sense to me to be able to switch between instruments fluidly.

Finding some sounds

If you do not want to start from scratch, there are a number of excellent resources for finding SuperCollider =SynthDef=s:

  • GitHub is a service that hosts millions of software projects created and maintained by developers around the world. The source code for SuperCollider itself is hosted on GitHub in addition to hundreds of other projects written in the SuperCollider language.
  • SuperCollider Code is a community-driven website which allows users to post snippets of their SuperCollider code. These snippets use tagging, which makes it easy to search for specific timbres. The website also hosts the SuperCollider documentation.
  • patchstorage has a few SuperCollider patches, but seems to have rather limited activity currently.

To start, I copied a few SynthDefs:

  • The first channel is for the simple sine wave SynthDef.
  • I attached the second channel to a piano SynthDef which uses MdaPiano, a generator provided by sc3-plugins.
  • The third channel provides an Electric Piano timber found on
  • The fourth channel is used for an organ instrument meant to emulate a classic Hammond organ.

I considered these sounds to be a good starting point for emulating many classic keyboard instruments.

Switching instruments

To allow these different timbres to be selected, I made a few changes to the function defined in the previous post. First, I created a second array with sixteen elements to hold the names of the different `SynthDef`s.

var keys, instruments;
keys = Array.newClear(128);

instruments = Array.newClear(16);
instruments.put(0, \sinpk);
instruments.put(1, \piano);
instruments.put(2, \rhodey_sc);
instruments.put(3, \hammond);

I then modified the NoteOn function such that the correct instrument is selected based on its position in the `instruments` array.

~noteOnFunc = {arg val, num, chan, src;
	var node;
	node =;
	if (node.notNil, {
		keys.put(num, nil);
	node = Synth(, [\freq, num.midicps, \vel, val]);
	[num, chan].postln;
	keys.put(num, node);

Now I could select the appropriate instrument by simply changing the MIDI channel on my controller.

A quick demo

Putting it all together, I created a simple track to demonstrate these different timbers (accompanied with some mandolin):

The past few posts have worked through some building blocks for using SuperCollider as a platform for creativity. As I wrote in “The Paradox of Creativity”, I find the creative process to be best when applied to areas that are challenging. I believe it is for this reason that I find SuperCollider to be such an interesting platform: it provides the pieces for expansive sonic possibilities, but it takes a bit of effort and curiosity to make the most of it.

A portrait of Carl Colglazier

I'm .

Rooted in a dual education in computer science and communication, I make meaningful information accessible with new media, social computing, and computational social science. I also post on , YouTube, and GitHub.