Command line
sonata is the command-line tool. It uses the same compiler, the same engines and the same
renderer as the app, so a piece sounds identical from both and a render is bit-for-bit the
same every time.
sonata check <file> [--json]
sonata build <file> [--emit ast|ir|graph|timeline|score] [--output <path>] [--force]
sonata render <file> --output <path> [options]
sonata play <file>
sonata fmt <file>... [--check] [--stdout]
sonata inspect <file> [--json]
sonata export <file> --output <path.mid|path.musicxml> [--force]
sonata import <file.mid> [--instrument <Name>] [--output <path>] [--force]
sonata test [<dir-or-file>...] [--json]
sonata benchmark [<file>] [--seconds <n>] [--json]
sonata docs [engines|effects|nodes|<name>] [--json]
sonata version<file> is a .sonata source or a .sonataproject folder. A lone file resolves its imports
from its own folder; a file inside a project, or the project itself, from the project.
Conventions
- Results go to standard output, diagnostics to standard error. With
--json, one JSON document goes to standard output and nothing else does. - Files are written atomically (a temporary file, then a rename): an interrupted command never leaves a half-written file.
- Nothing is replaced silently. Writing to a path that exists fails unless you add
--force. (sonata fmtrewrites the files you name: that is its purpose.) - Ctrl-C stops a render or a playback cleanly.
| Exit code | Meaning |
|---|---|
| 0 | success |
| 1 | the source has errors, or a check or test failed |
| 2 | wrong usage |
| 3 | a file could not be read or written |
| 4 | internal error |
| 130 | interrupted |
check
Compiles and reports. Errors show the place, the source line and, when there is one, a suggestion.
$ sonata check aurora.sonata
aurora.sonata: ok — "Aurora", 2 tracks, 8 notes, 3.000 s
$ sonata check typo.sonata
typo.sonata:2:23: error[S2001]: unknown instrument 'GrandPiana'
2 | instrument piano: GrandPiana {
| ^^^^^^^^^^
help: did you mean 'GrandPiano'?
typo.sonata: 1 error(s), 0 warning(s)--json gives the same information for tools: ok, counts, a summary of the piece and a
list of diagnostics, each with code, severity, message, file, line, column,
end_line, end_column, byte offsets start and end, and, when available, suggestion
and a fix (the replacement text and its range).
build
Compiles and prints one of the intermediate forms as JSON.
--emit |
Contents |
|---|---|
ast |
the syntax tree of the file |
ir (default) |
the Musical IR: tracks, notes with exact positions and seconds, tempo map, automation, routing |
graph |
the mixing graph at the project sample rate, with latencies |
timeline |
what the Studio draws: notes in seconds, bars and beats, mixer state |
score |
the notation model: measures, voices, ties, tuplets, spelled pitches |
render
Renders to an audio file. The format follows the extension of --output unless --format
says otherwise.
| Option | Meaning | Default |
|---|---|---|
--format wav|aiff|flac |
file format | from the extension |
--bits 16|24|32 |
integer sample size (32 with --float is 32-bit float) |
24 |
--float |
floating-point samples (WAV and AIFF) | off |
--rate <Hz> |
44100, 48000, 88200, 96000, 176400 or 192000 | the project's |
--from <s>, --to <s> |
render a range, in seconds | the whole piece |
--no-tail |
stop at the last note instead of letting releases and reverbs ring | tails on |
--no-dither |
no dither when writing 16 or 24 bits | TPDF dither on |
--normalize peak|lufs, --target <value> |
scale to a true-peak level (dBTP) or a loudness (LUFS) | off |
--stems |
also write one file per track and bus | off |
$ sonata render aurora.sonata --output aurora.flac --bits 16 --stems
aurora.flac: 4.364 s, 48000 Hz, 2 ch, peak -8.82 dBFS, true peak -8.82 dBTP, -16.7 LUFS
aurora - piano.flac: 4.364 s, 48000 Hz, 2 ch, peak -18.13 dBFS, true peak -18.13 dBTP, -36.9 LUFS
aurora - strings.flac: 4.364 s, 48000 Hz, 2 ch, peak -9.05 dBFS, true peak -9.02 dBTP, -16.8 LUFS
rendered in 0.14 s (32x real time)Every file is listed with its measured duration, peak, true peak and integrated loudness. More in Exports.
play
Renders the piece to a temporary file and plays it with the system's audio player, at the level the composition's master produces. Ctrl-C stops. For live playback with meters and hot reload, use the app.
fmt
Rewrites files in the canonical style. --check changes nothing and exits with 1 if a file
would change (for use in automated checks); --stdout prints the result instead of writing
it. A file with syntax errors is reported and left as it is.
inspect
A summary of the compiled piece.
$ sonata inspect aurora.sonata
"Aurora" — 3.000 s, 48000 Hz, seed 42
key D minor, A4 = 440 Hz
tempo 120 bpm at 0
id track instrument model notes gain effects
0 piano GrandPiano piano 7 -8.0dB reverb
1 strings ConcertStrings bowed_string 1 0.0dB
8 notes, 4 voices at most, graph of 9 nodes, latency 240 frames--json adds the tempo map, the signatures, the buses, the master and the compile times.
export and import
sonata export piece.sonata --output piece.mid writes a Standard MIDI File;
--output piece.musicxml writes MusicXML. Approximations (a microtone rounded to a semitone
in MIDI, for instance) are printed as warnings.
sonata import song.mid reads a MIDI file and prints Sonata source, or writes it with
--output. The result is ordinary code: each MIDI track becomes an instrument track played by
--instrument (GrandPiano by default), simultaneous notes of equal length become chords, and
overlapping notes are spread over voice blocks.
test
Compiles every .sonata file under the folders given (the current folder by default) and
checks the expectations written in its comments:
| Comment | Checks |
|---|---|
// expect: ok |
compiles without error (the default) |
// expect: error or // expect: error S2001 |
fails, with that code if given |
// expect: notes 42 |
the number of notes |
// expect: tracks 3 |
the number of tracks |
// expect: duration 12.5s |
the musical length, within a millisecond |
// expect: deterministic |
two renders of the beginning are bit-identical |
$ sonata test Examples
ok Examples/accelerando_study.sonata
ok Examples/acid_line.sonata
…
37 file(s), 0 failure(s)benchmark
Measures the audio engine on your machine: the time taken by each audio callback (mean, median, 99th percentile, maximum) against the time available, and the number of missed deadlines. Without a file it runs a ladder of simultaneous voices; with a file it measures that piece. The numbers describe that machine at that moment — they are measurements, not guarantees. See Performance.
docs
Prints the reference from the same tables the compiler validates against.
$ sonata docs # every engine, effect and patch node
$ sonata docs delay # parameters, units, ranges, defaults and presets of one
$ sonata docs --json # the whole registry as JSON