Repository Public
1<!--2ORIX Sonata3File: Documentation/manual/cli.md4Author: Simon-Pierre Boucher5Contact: contact@spboucher.ai6-->7# Command line89`sonata` is the command-line tool. It uses the same compiler, the same engines and the same10renderer as the app, so a piece sounds identical from both and a render is bit-for-bit the11same every time.1213```text14sonata check <file> [--json]15sonata build <file> [--emit ast|ir|graph|timeline|score] [--output <path>] [--force]16sonata render <file> --output <path> [options]17sonata play <file>18sonata fmt <file>... [--check] [--stdout]19sonata inspect <file> [--json]20sonata export <file> --output <path.mid|path.musicxml> [--force]21sonata import <file.mid> [--instrument <Name>] [--output <path>] [--force]22sonata test [<dir-or-file>...] [--json]23sonata benchmark [<file>] [--seconds <n>] [--json]24sonata docs [engines|effects|nodes|<name>] [--json]25sonata version26```2728`<file>` is a `.sonata` source or a `.sonataproject` folder. A lone file resolves its imports29from its own folder; a file inside a project, or the project itself, from the project.3031## Conventions3233* **Results go to standard output, diagnostics to standard error.** With `--json`, one JSON34 document goes to standard output and nothing else does.35* **Files are written atomically** (a temporary file, then a rename): an interrupted command36 never leaves a half-written file.37* **Nothing is replaced silently.** Writing to a path that exists fails unless you add38 `--force`. (`sonata fmt` rewrites the files you name: that is its purpose.)39* **Ctrl-C** stops a render or a playback cleanly.4041| Exit code | Meaning |42|---|---|43| 0 | success |44| 1 | the source has errors, or a check or test failed |45| 2 | wrong usage |46| 3 | a file could not be read or written |47| 4 | internal error |48| 130 | interrupted |4950## check5152Compiles and reports. Errors show the place, the source line and, when there is one, a53suggestion.5455```text56$ sonata check aurora.sonata57aurora.sonata: ok — "Aurora", 2 tracks, 8 notes, 3.000 s5859$ sonata check typo.sonata60typo.sonata:2:23: error[S2001]: unknown instrument 'GrandPiana'612 | instrument piano: GrandPiana {62 | ^^^^^^^^^^63 help: did you mean 'GrandPiano'?64typo.sonata: 1 error(s), 0 warning(s)65```6667`--json` gives the same information for tools: `ok`, counts, a `summary` of the piece and a68list of diagnostics, each with `code`, `severity`, `message`, `file`, `line`, `column`,69`end_line`, `end_column`, byte offsets `start` and `end`, and, when available, `suggestion`70and a `fix` (the replacement text and its range).7172## build7374Compiles and prints one of the intermediate forms as JSON.7576| `--emit` | Contents |77|---|---|78| `ast` | the syntax tree of the file |79| `ir` (default) | the Musical IR: tracks, notes with exact positions and seconds, tempo map, automation, routing |80| `graph` | the mixing graph at the project sample rate, with latencies |81| `timeline` | what the Studio draws: notes in seconds, bars and beats, mixer state |82| `score` | the notation model: measures, voices, ties, tuplets, spelled pitches |8384## render8586Renders to an audio file. The format follows the extension of `--output` unless `--format`87says otherwise.8889| Option | Meaning | Default |90|---|---|---|91| `--format wav\|aiff\|flac` | file format | from the extension |92| `--bits 16\|24\|32` | integer sample size (`32` with `--float` is 32-bit float) | 24 |93| `--float` | floating-point samples (WAV and AIFF) | off |94| `--rate <Hz>` | 44100, 48000, 88200, 96000, 176400 or 192000 | the project's |95| `--from <s>`, `--to <s>` | render a range, in seconds | the whole piece |96| `--no-tail` | stop at the last note instead of letting releases and reverbs ring | tails on |97| `--no-dither` | no dither when writing 16 or 24 bits | TPDF dither on |98| `--normalize peak\|lufs`, `--target <value>` | scale to a true-peak level (dBTP) or a loudness (LUFS) | off |99| `--stems` | also write one file per track and bus | off |100101```text102$ sonata render aurora.sonata --output aurora.flac --bits 16 --stems103aurora.flac: 4.364 s, 48000 Hz, 2 ch, peak -8.82 dBFS, true peak -8.82 dBTP, -16.7 LUFS104aurora - piano.flac: 4.364 s, 48000 Hz, 2 ch, peak -18.13 dBFS, true peak -18.13 dBTP, -36.9 LUFS105aurora - strings.flac: 4.364 s, 48000 Hz, 2 ch, peak -9.05 dBFS, true peak -9.02 dBTP, -16.8 LUFS106rendered in 0.14 s (32x real time)107```108109Every file is listed with its measured duration, peak, true peak and integrated loudness. More110in [Exports](exports.md).111112## play113114Renders the piece to a temporary file and plays it with the system's audio player, at the115level the composition's master produces. Ctrl-C stops. For live playback with meters and hot116reload, use the app.117118## fmt119120Rewrites files in the canonical style. `--check` changes nothing and exits with 1 if a file121would change (for use in automated checks); `--stdout` prints the result instead of writing122it. A file with syntax errors is reported and left as it is.123124## inspect125126A summary of the compiled piece.127128```text129$ sonata inspect aurora.sonata130"Aurora" — 3.000 s, 48000 Hz, seed 42131key D minor, A4 = 440 Hz132tempo 120 bpm at 0133id track instrument model notes gain effects1340 piano GrandPiano piano 7 -8.0dB reverb1351 strings ConcertStrings bowed_string 1 0.0dB1368 notes, 4 voices at most, graph of 9 nodes, latency 240 frames137```138139`--json` adds the tempo map, the signatures, the buses, the master and the compile times.140141## export and import142143`sonata export piece.sonata --output piece.mid` writes a Standard MIDI File;144`--output piece.musicxml` writes MusicXML. Approximations (a microtone rounded to a semitone145in MIDI, for instance) are printed as warnings.146147`sonata import song.mid` reads a MIDI file and prints Sonata source, or writes it with148`--output`. The result is ordinary code: each MIDI track becomes an instrument track played by149`--instrument` (GrandPiano by default), simultaneous notes of equal length become chords, and150overlapping notes are spread over `voice` blocks.151152## test153154Compiles every `.sonata` file under the folders given (the current folder by default) and155checks the expectations written in its comments:156157| Comment | Checks |158|---|---|159| `// expect: ok` | compiles without error (the default) |160| `// expect: error` or `// expect: error S2001` | fails, with that code if given |161| `// expect: notes 42` | the number of notes |162| `// expect: tracks 3` | the number of tracks |163| `// expect: duration 12.5s` | the musical length, within a millisecond |164| `// expect: deterministic` | two renders of the beginning are bit-identical |165166```text167$ sonata test Examples168ok Examples/accelerando_study.sonata169ok Examples/acid_line.sonata170…17137 file(s), 0 failure(s)172```173174## benchmark175176Measures the audio engine on your machine: the time taken by each audio callback (mean,177median, 99th percentile, maximum) against the time available, and the number of missed178deadlines. Without a file it runs a ladder of simultaneous voices; with a file it measures179that piece. The numbers describe that machine at that moment — they are measurements, not180guarantees. See [Performance](performance.md).181182## docs183184Prints the reference from the same tables the compiler validates against.185186```text187$ sonata docs # every engine, effect and patch node188$ sonata docs delay # parameters, units, ranges, defaults and presets of one189$ sonata docs --json # the whole registry as JSON190```191