In this chapter you'll build a complete synth, one step at a time, and play it: a sawtooth wave through a resonant filter, with an envelope that shapes each note's loudness and brightness. It's the classic design of analogue synthesizers, and a good way to learn the editor and the most useful nodes.
Here is what it will sound like when it's finished, playing a phrase that starts soft and grows louder:
And here is how its parts fit together. Each arrow is a connection, coloured by the type of value it carries:

You'll need Sonido running (see chapter 1). Each step below ends with a screenshot of the synth so far, so you can check your work.
Open an editor for a new synth:
(so:edit-synth "my first synth")
lisp
A window opens with nothing in it but a grey background. The window belongs to the synth "my first synth": everything you do in it is saved to that synth at once, and closing the window stops editing it.
Press and hold the right mouse button anywhere in the window. A menu of node categories opens. Without letting go, move the mouse over "sources", then "oscillators", then onto "sawtooth oscillator", and let go of the button.

The new node appears stuck to the mouse pointer, so you can carry it to a good spot. Click the left button to put it down.

There's a quicker way to find a node when you know its name: just start typing. A search box opens, listing every node whose name contains what you've typed. Choose one with the arrow keys and press Enter, or click it, and it's added just as from the menu. Escape closes the box.

Add three more nodes, from the menu or by searching:
To move a node after you've put it down, drag it by its title bar. (Dragging anywhere else on a node works its knobs, buttons and text fields.)
The note input and waveform output each have a text field with a name in it: "note", and "waveform". These are the names the synth's inputs and outputs will have when you play it, or use it inside another synth. "note" is right, but call the output "audio": click in its text field, delete "waveform" with Backspace, type audio, and press Enter.
Now connect the nodes. Press the left button on the note input's "note" output (the small light blue circle on its right edge), drag to the "note" input on the left of the note to frequency node, and let go. A curve follows the mouse, and as it nears an input of the right type it snaps onto it:


A connection only goes between connectors of the same type, which have the same colour, so you can't connect a note to a waveform by mistake. Make two more connections:

As soon as the last connection is made, you'll hear a buzzing tone that doesn't stop:
While you edit a synth, you hear it. This synth has a note input, whose knob is set to C4 (middle C), so the oscillator plays middle C, at 261.6 Hz, for as long as the editor is open.
To turn a knob, press the left button on it and drag up to turn it up, or down to turn it down. Try these, and listen:
The oscillator's frequency knob disappeared when you connected its frequency input: the connection sets the frequency now. Put the knobs back where they were (C4, transpose 0, detune 0.00, amplitude 0.50) before going on.
The oscillator draws a little graph of the wave it makes, but a scope shows the real thing as it plays. Add a "scope", from analysis, then audio.
The scope needs to go between the oscillator and the output, so the sound passes through it. Here's a quick way to move a connection: press on the output node's "waveform" input, where the connection from the oscillator ends. Dragging from a connected input picks up the end of its connection, so the curve now follows the mouse. Drop it on the scope's waveform input. Then connect the scope's waveform output to the output node's input. Drag the output node a little further right to make room if you need to.

The scope shows the sawtooth wave: it rises steadily and then falls straight back, which gives it its bright, buzzy sound. It's the richest of the basic waveforms. Sonido has an oscillator for each of them, under sources, then oscillators:

A sine wave is pure and soft, a triangle wave a little brighter, and a square wave hollow, like a clarinet. A sawtooth has every harmonic, which makes it good for brass, strings and, as here, for filtering.
A synth that drones forever isn't much use for playing tunes. Notes need to start when a key is pressed and fade when it's let go, and that is the job of an envelope.
First, make some room. Drag the oscillator, the scope and the output to the right, leaving a gap of about the oscillator's width between the note to frequency node and the oscillator. To move several nodes together, select them all first: drag a box around them on empty background, or hold Shift and click each one. Selected nodes have white borders, and dragging the title of any of them moves them all.
Add a "trigger input", from inputs, below the note input. Its name is already "trigger". Then add an "adsr", from controls, then envelopes, to the right of the trigger input.
Connect:
The drone stops: the oscillator's amplitude now comes from the envelope, which is at 0 until something triggers it.
The trigger input has a button. Press it, hold it down, and let it go: you hear a note, which starts when you press the button, holds while you hold it, and fades away when you let go.
An ADSR envelope has four stages, named after their knobs:

The fifth knob, curve, sets the shape of the stages, from straight lines (0) to steep curves that start fast and slow down (1); leave it as it is. The graph under the knobs shows the envelope's shape.
Set the knobs to about attack 8ms, decay 350ms, sustain 0.60 and release 300ms. They don't need to be exact. A quick attack makes a note start crisply, and the decay makes each note start a little louder than it holds.

On a keyboard, a key struck harder plays louder. The keyboard sends how hard each key was struck as the note's velocity, and the synth should use it.
Add a "factor input", from inputs, between the note input and the adsr, a little to the right. Its name is "factor": click in its text field and change it to "velocity". Its knob sets the velocity the synth uses when nothing else sets it, such as when you press the trigger button; turn it to about 0.80.
Then add a "factor multiplier", from arithmetic, to the right of the velocity input. It multiplies two factors together: when the velocity is 0.5, the envelope's 1 becomes 0.5, its sustain level of 0.6 becomes 0.3, and so on.
Connect:
That last connection replaces the one from the adsr: an input takes only one connection, so connecting another output to it replaces the old one.

This phrase was played with each note harder than the last, and then softer again at the end:
The sawtooth is bright and buzzy all the way through each note. Real instruments are brighter as a note starts and mellower as it fades, and a filter that follows the envelope does just that.
A low-pass filter lets the low frequencies in a sound through and takes away the high ones, above its cutoff frequency. With the cutoff low, the sawtooth sounds dark and muffled; with it high, bright. Sonido's ladder filter works the way the Moog synthesizer's filter does: it cuts steeply above the cutoff, and its resonance knob makes it ring at the cutoff, giving the sound a vocal, "wah" quality.

Drag the scope and the output well to the right and down, to make room. Add a "ladder filter", from filters, then resonant, between the oscillator and the scope, and a "factor to frequency" converter, from converters, then from factor, below and to the right of the factor multiplier.
Connect:
The adsr's output now goes to two inputs. An output can go to as many inputs as you like.
The factor to frequency converter maps a factor onto a range of frequencies: 0 becomes its low frequency, 1 its high frequency, and the values between are spread evenly in pitch. Set its low knob to about 150 Hz and its high knob to about 4 kHz. Now when the envelope rises to 1 at the start of a note, the filter opens to 4 kHz, and as the envelope falls, it closes towards 150 Hz.
On the ladder filter, set the resonance to about 0.40 and the drive to about 0.20. The drive overloads the filter a little, which warms the sound.

Compare it with step 3: each note now starts with a bright "pluck" that mellows as it holds.
A synth is easier to understand, for others and for you later, with a note or two explaining it. Add a "comment", the last entry in the menu's main list. Click in it and type what the synth is, then press Escape (in a comment, Enter starts a new line). The comment box grows to fit what you type.


Add comments next to the parts of the synth that need explaining too: what the envelope does, what the scope shows. Comments play no part in the sound.

While the editor is open, hold down the trigger input's button to play a note. The button lights up while it's held, and the scope shows the filtered wave:

(so:perform "my first synth")
lisp
Now each key plays a note: its note number goes to the synth's "note" input, how hard it was struck to its "velocity" input, and its "trigger" input is held on until you let the key go. That's why the inputs had to be named note, velocity and trigger. Each key plays a note of its own, so you can play chords. (so:perform nil) stops.
For the pitch wheel to bend the notes, add a factor input called "pitch bend". It's 0.5 with the wheel in the middle, and you could connect it to the note to frequency node's detune input.
You can play your synth from a Lisp program, too:
(in-package :sonido-lang) (play my-first-synth :note c3 :velocity 0.6 :duration half-note)
lisp
The synth is named without quotes, with a dash for each space. Each keyword argument sets the input of that name, and the trigger input is held on for the note's duration. The recordings in this chapter were all played this way. A later chapter teaches sonido-lang.
Every saved synth with an output can be a single node inside another synth: right-click, and look under "synths". Here, in another synth, a clock presses "my first synth"'s trigger twice a second, and its audio goes to the other synth's waveform output:

The synth node has an input for each of the synth's inputs, with a knob (or, for the trigger, a button) for when the input isn't connected, and an output for each of its outputs, all with the names you gave them.
Your synth is saved in ~/.local/sonido/synths/my-first-synth.lisp, rewritten with every change. It's Lisp code: a defsynth form that makes each node, with its settings, connections and place on the screen. It starts like this:
(defsynth "my first synth"
(let* ((note-synth-input-1
(make-note-synth-input :name "note" :default 60 :x 0.3 :y 9.8))
(note-to-frequency-converter-1
(make-note-to-frequency-converter :note-source
(cons note-synth-input-1 :get-value)
:transpose-factor 1/2 :detune-factor 1/2 :x
18.4 :y 9.4))
...
lisp
You can also get a synth's code from Lisp while it's being edited, with (so:synth-code "my first synth").