Skip to content

Your First Sound

On this page you make a project, play a drum beat from VSCode, and change it while it plays.

You need resonon and the VSCode extension installed — see Installation.

Check resonon --version and that the extension is enabled. Use a new hello project for this page. If you already have a live session, evaluate RESET; on its own before the first beat, then remove that line. The session should be silent.

A piece lives in a project: a folder with a resonon.toml in it. Open a terminal and make one:

Terminal window
resonon new hello

Open the hello folder in VSCode, and open src/main.non. The generated piece is ready to play:

use "std/instruments" { Sampler, Kit };
// Set up the piece. It runs when the project opens and on Reset Project.
// Create each track here, once: a name that exists is an error.
fn setup() {
set_bpm(120);
session.create_track("drums");
}
// The rest of the file runs after setup(), and again on each file run.
// session.track() looks up a track that setup() created.
let drums = session.track("drums");
drums.set_instrument(Sampler(Kit("TR-909")));
drums << [bd _ bd _, _ sd _ sd, ch*8];

Press Cmd+Shift+Enter (Ctrl+Shift+Enter on Windows and Linux). This is Run File Live: it evaluates the whole file into the session. The first time, the extension starts a resonon server and connects to it. Then press F5 to play. You hear a kick, a snare and hi-hats repeat each bar. To change the loop, edit the drums << [...] line and execute that line with Cmd+Enter.

fn setup() runs when the project opens, and on RESONON: Reset Project. Run File Live does not call it. See The entry file’s lifecycle.

The following steps build a beat one line at a time. Evaluate RESET; on its own to stop and clear the first loop. Then delete the file contents and write the following steps into it.

Write this line, put the cursor on it, and press Cmd+Enter:

print("Hello, RESONON!");

The RESONON item in the status bar shows the server it is connected to. The text appears in the Output panel: press Cmd+Shift+U and pick RESONON.

Cmd+Enter runs the lines you select. With nothing selected, it runs the line the cursor is on.

Write these lines under the first one, select them, and press Cmd+Enter:

use "std/instruments" { Sampler, Kit };
let drums = session.create_track("drums");
drums.set_instrument(Sampler(Kit("TR-909")));
drums << [bd sd bd sd];
PLAY;

You hear a kick and a snare, looping.

  • use brings Sampler and Kit in from the standard library.
  • session.create_track("drums") makes a track, like a channel on a mixer. Its sound goes to the master output. session is the running session: it holds every track.
  • Sampler(Kit("TR-909")) is a drum sampler loaded with the TR-909 kit, which comes with resonon. .set_instrument() puts it on the track.
  • [bd sd bd sd] is a pattern: bass drum, snare, bass drum, snare. << sends it to the track. The pattern fills one cycle — one bar — and repeats.
  • PLAY; starts the transport.

The server keeps everything you run, so drums is still there. Send it a new pattern:

drums << [bd _ sd _, ch ch ch ch];

_ is a rest. The comma plays two patterns at the same time: the kick and snare, and four hi-hats over them. You did not stop the music and you did not make the track again. This is live coding: change a line, run it, listen.

STOP;

The beat stops, and the play head goes back to the start. Shift+F5 does the same from the keyboard. Press F5 and the beat plays again from the start.

The session is the document; code and the UI edit it together. Save the project session to keep tracks, device chains, mixer settings and arrangement. Put patterns and callbacks at the top level of the entry file, so that opening the project attaches them again after it restores the saved session. Run Selection Live evaluates only the selection. Run File Live evaluates the whole entry file into the running session. Session undo covers UI gestures. Code evaluations are not undo steps: correct the source and run it again. Use text undo in the editor to change the source. See The entry file’s lifecycle.