SuperCollider Synthdefs that can play chords

I can play chords with Sonic Pi synths:

use_synth :dsaw

play 60

play(note: chord(:c3, :major))

No problem. When I write my own ones though they play single notes fine, then they crash when I play chords:


play 60

play(note: chord(:c3, :major))

The error is:

Thread death!
Unable to normalise argument with key note: and value (ring <SonicPi::Chord...

So I am learning SuperCollider and figure this must be my problem and look at passing arrays as parameters and stuff. Nothing I try works. Then I read the source code to SuperCollider synths in github and they all seem to be single note synths.

I took the source of sonic-pi-rodeo renamed it an ran it and it did indeed fail with the same error on a chord.

Is there an example of how to write a SuperCollider synth that accepts chords as well as notes for me to look at?

I’m not sure about the answer to your question, but in the meantime, you can always use a workaround to play each note separately:


chord(:c3, :major).each do |note|
  play note

yeah, but if the plan is to get more synths bundled with Sonic Pi using Supercollider that’s not really sustainable and if you are trying to do more complex synthesis then not having all the notes available in your SynthDef might be limiting, perhaps?

So it would appear that the issue is the munging of notes in the heart of Sonic Pi

I have been adding synths by loading them with load_synthdefs - I might need to actually compile them in to get them to play chords

Is that right @ethancrawford @samaaron ?

Hi @gordonguthrie,

by default, Sonic Pi doesn’t mess around with any args for synths that aren’t built-in. This is because it’s impossible to know whether an arg which shares the same name, such as :note is accidental or not. If it’s accidental, it might be that the arg has completely different semantics to that of Sonic Pi’s built-in synths.

For Sonic Pi’s built-in synths there is metadata describing each of the args - their names, docs and some checker functions (checking bounds etc.). This is unfortunately not something we’ve yet worked on making easy to extend for user-defined synths.

The built-in synth metadata is stored in the synthinfo.rb files. For example, here’s a link to the :square synth:

It should be possible to hack and extend this file with metadata for your synth. However, we really should look at ways for people to bundle similar metadata with their own synths. I’m thinking a toml file or similar would be sensible for such a thing.

That makes sense.

I am slowly writing a manual for writing SuperCollider synths with SonicPi, as and when I get a dev enivronment up I will have a look at it…

1 Like

This is fab, thanks so much for working on this - it will be a really valuable resource.

I am using my literate code reader so I can just write well-commented SuperCollider code and it will generate the manual pages automatically from the source

I don’t know anything unless I write it down, and I can’t remember anything from one day to the next so I might as well document my own learning SuperCollider as I go along :wink: