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
└── .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 is the file that resonon run runs.

Until now you ran lines one at a time, and the session kept them. A piece must do everything by itself, from the top. Replace what is in src/main.non with this:

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

It is the beat you built, with two new lines at the top and one at the end:

  • set_project_title("hello") names the piece. set_bpm(120) sets its tempo: 120 BPM, and four beats in each cycle.
  • render(8) plays 8 cycles of the master output into a WAV file, faster than real time.

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

Terminal window
resonon run

Resonon runs src/main.non from the top 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.

resonon run works from any folder inside the project. It runs the file once and stops, so a line like PLAY; in a piece plays nothing that you can hear: the program ends at once. To hear a piece while you work on it, select its lines in VSCode and press Cmd+Enter, as before.

Change the last line so that each track gets its own file, next to the mix:

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

Run resonon run 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.