Repository Public
1<!--2ORIX Sonata3File: Documentation/manual/getting-started.md4Author: Simon-Pierre Boucher5Contact: contact@spboucher.ai6-->7# Getting started89Sonata is a language for writing music as a program. You describe notes, instruments and a10mix in text; the compiler turns that text into sound. This chapter takes you from an empty11document to a short piece you can hear, see and export. Nothing here needs an account or a12network connection.1314## Your first note1516A piece of music is a `composition`. It contains tracks; each track is an instrument that17plays notes. This is a complete program:1819```sonata20composition "First Note" {21 instrument piano: GrandPiano {22 play A423 }24}25```2627`A4` is the A above middle C (440 Hz). With nothing else written, the note lasts a quarter28note at 120 beats per minute: half a second, plus the natural decay of the piano.2930In the app, create a new project (**File › New**), replace the text with the program above31and press **Play** (⌘↩). The status badge in the toolbar reads *Compiling*, then *Playing*.32With the command line:3334```text35sonata play first.sonata36```3738## Several notes3940Statements in a track run one after the other. Each `play` places a note at the *cursor* and41moves the cursor by the note's duration. `rest` moves the cursor without playing.4243```sonata44composition "A Phrase" {45 tempo 96bpm46 instrument piano: GrandPiano {47 play D4 duration 1/848 play F4 duration 1/849 play A4 duration 1/450 rest 1/451 play G4 duration 1/4 velocity 0.552 play D4 duration 1/253 }54}55```5657Durations are fractions of a whole note: `1/4` is a quarter note, `1/8` an eighth, `1/2` a58half. `velocity` is how hard the note is played, from 0 to 1 (the default is 0.8).5960## Chords and a second instrument6162A list of notes in square brackets is a chord. A composition can hold as many instruments as63you like; every track starts at the beginning and they play together.6465```sonata66composition "Two Hands" {67 tempo 96bpm68 key D minor6970 instrument piano: GrandPiano {71 gain -3dB72 chord [D3, A3, D4] duration 1/273 chord [F3, A3, C4] duration 1/274 chord [G3, Bb3, D4] duration 1/275 chord [A3, C#4, E4] duration 1/276 }7778 instrument strings: ConcertStrings {79 gain -9dB80 articulation legato81 play D5 duration 1/182 play E5 duration 1/283 play C#5 duration 1/284 }85}86```8788`gain` sets the level of a track in decibels. `GrandPiano` and `ConcertStrings` are two of the8983 instruments of the standard library; the full list is in90[Standard instruments](reference/std-instruments.md).9192## Hear it, see it9394* **Play** (⌘↩) compiles if needed and starts playback; **Stop** is ⌘. and **Return to95 Start** is ⇧⌘↩.96* Under the editor, the **master waveform** is drawn from the audio the piece really97 produces: the app renders the composition in the background after each successful98 compilation. Click in it to move the playhead.99* The **console** under the editor lists errors and warnings. Clicking one moves the cursor100 to the place in the code. The line at the right shows what the compiler measured: compile101 time, number of notes, tracks, simultaneous voices and graph nodes.102* While the piece plays, keep typing: a successful compilation replaces the running program103 with a short crossfade and the playhead keeps its position. If the code has an error, the104 last valid version keeps playing and the badge says *Playing last valid*.105106## When something is wrong107108The compiler tells you where and, when it can, how to fix it:109110```sonata,error=S2001111composition "Typo" {112 instrument piano: GrandPiana {113 play A4114 }115}116```117118```text119typo.sonata:2:23: error[S2001]: unknown instrument 'GrandPiana'1202 | instrument piano: GrandPiana {121 | ^^^^^^^^^^122 help: did you mean 'GrandPiano'?123```124125In the app, the console shows the same message with a button that applies the correction.126More in [Diagnostics](diagnostics.md).127128## Save and export129130* **File › Save** writes a `.sonataproject`: a folder holding your sources, the studio131 settings and any imported audio. See [Modules and projects](modules-and-projects.md).132* **Composition › Render to Audio File…** (⌘E) writes WAV, AIFF or FLAC.133* **Composition › Export MIDI…** and **Export MusicXML…** write the notes for other programs.134135From the command line:136137```text138sonata check piece.sonata139sonata render piece.sonata --output piece.wav140```141142Details are in [Exports](exports.md) and [Command line](cli.md).143144## Where to go next145146* [Tutorial](tutorial.md) builds a complete piece step by step.147* [Syntax](syntax.md) and [Types and units](types-and-units.md) explain how the language reads.148* [Rhythm](rhythm.md) and [Harmony](harmony.md) cover the musical vocabulary.149* The **Library** space lists every instrument and effect; the examples in `Examples/` are150 complete pieces you can open, play and change.151