Skip to content

Your First Project

On this page you turn the beat from the last pages into a piece: a file that plays the same every time, which you run from the terminal and get as a WAV file.

Work in the hello project from Your First Sound.

Open the hello folder and check that it contains resonon.toml and src/main.non. Evaluate STOP; in VSCode if the earlier beat is playing. The terminal run starts independently of that live session; it needs no variables from previous evaluations.

resonon new hello made this folder:

hello/
├── resonon.toml
├── src/
│ └── main.non
├── README.md
├── LICENSE
├── AGENTS.md
└── .gitignore
  • resonon.toml names the project and the version of resonon it is written for. Resonon finds a project by this file, so the code in src/ can find its kits and packages on any machine.
  • src/main.non is the piece. It runs when the project opens, in the editor and in resonon run.
  • AGENTS.md tells a coding agent where to start. See Work with Coding Agents.

Until now you ran lines one at a time, and the session kept them. A piece is a file that makes the session again each time the project opens. Replace what is in src/main.non with this:

use "std/instruments" { Sampler, Kit };
use "std/effects" { Filter, FilterType, Delay };
fn setup() {
set_project_title("hello");
set_bpm(120);
session.create_track("drums");
session.create_track("bass");
}
let drums = session.track("drums");
drums.set_instrument(Sampler(Kit("CR-78")));
drums << [bd _ sd _, hh hh hh hh];
drums.set_effects(#[Filter("lowpass", FilterType.lowpass, 1200), Delay("delay", 0.25, 0.4)]);
let bass = session.track("bass");
bass.set_instrument(Sampler(Kit("TR-808")));
bass << [bd _ _ bd, _ _ bd _];

It is the beat you built, with a setup() function at the top:

  • set_project_title("hello") names the piece. set_bpm(120) sets its tempo: 120 BPM, and four beats in each cycle.
  • setup() runs when the project opens, before the rest of the file. The tracks are at the top level, so that their names stay defined after setup() returns.

Put the render in a script, not in the piece. The piece runs again each time the project opens, and a render in it runs each time too. Make a folder scripts in the project, and in it a file bounce.non with this line:

render(8);

render(8) plays 8 cycles of the master output into a WAV file, faster than real time.

Save both files. In a terminal, in the hello folder, run:

Terminal window
resonon run scripts/bounce.non

Resonon opens the project as the editor does: it restores the saved session if present, calls setup() and runs src/main.non. Then it evaluates scripts/bounce.non and exits. The file is in a new folder in the project:

renders/hello_<date>_<time>/master.wav

Open it in any audio player. It is 16 seconds long: 8 cycles of 2 seconds.

The script path is relative to the folder you run the command in. resonon run stops after the script, so a line like PLAY; in a script plays nothing that you can hear: the program ends at once. To hear a piece while you work on it, use VSCode, as before.

The script can use the names that src/main.non defines. Change the line in scripts/bounce.non so that each track gets its own file, next to the mix:

render(#[drums, bass, session.master], 8);

Run resonon run scripts/bounce.non again. A new folder has drums.wav, bass.wav and master.wav. Every run makes a new folder, so a render never writes over another one.