SPB Git

Repository Public

modules-and-projects.md 5.0 KB 154 lines markdown

1<!--2ORIX Sonata3File: Documentation/manual/modules-and-projects.md4Author: Simon-Pierre Boucher5Contact: contact@spboucher.ai6-->7# Modules and projects89## Modules1011A file without a composition is a module. Another file brings its definitions into scope with12`import`:1314```sonata,module=motifs15// motifs.sonata16const home = D41718fn answer(p: Pitch) -> Pitch {19    return p + 7st20}2122pattern call(p: Pitch) {23    play p duration 1/824    play p + 2st duration 1/825    play p + 3st duration 1/426}27```2829```sonata30import motifs3132composition "Uses a Module" {33    instrument flute: Flute {34        call(home)35        call(answer(home))36    }37}38```3940* A module path is dotted: `import lib.motifs` reads the file `lib/motifs.sonata`.41* Paths are relative to the folder of the file being compiled. For a lone file that is the42  folder it is in. In a project the main source is `src/main.sonata`, so `import motifs` reads43  `src/motifs.sonata`.44* Everything at the top level of a module becomes visible without a prefix. Defining the same45  name in two of your files is an error (S2002).46* Import cycles are refused (I7002), as is a module that cannot be found (I7001).4748```sonata,error=I700149import not.there5051composition "Missing Module" {52    instrument piano: GrandPiano {53        play C454    }55}56```5758## The standard library5960Three modules are part of the compiler and always in scope; importing them is allowed and61changes nothing.6263| Module | Contents |64|---|---|65| `std.music` | note values (`whole`, `half`, `quarter`, `eighth`, `sixteenth`), named intervals (`major_third`, `perfect_fifth`, …), dynamics (`pp`, `mp`, `mf`, `f`, `ff`, …), `scale_run`, `up_down`, and the patterns `arpeggio`, `strum`, `rhythm` |66| `std.instruments` | the named instruments: [Standard instruments](reference/std-instruments.md) |67| `std.effects` | `split_level(n)` |6869The standard library is itself written in Sonata (`StandardLibrary/std/`). A definition of70yours with the same name as a standard one replaces it in your project.7172```sonata73composition "Standard Library" {74    instrument piano: GrandPiano {75        default velocity mp76        arpeggio(up_down(scale_run(C4, major, 1)), step: sixteenth)77        chord [C4, C4 + major_third, C4 + perfect_fifth] duration half velocity ff78    }79}80```8182## What a program can reach8384A Sonata program can read the modules it imports and name audio files of its project. That is85all. The language has no way to open other files, use the network or start a process, so86opening a composition you received cannot do anything except make sound. Module and asset87paths that leave the project — through `..`, an absolute path or a symbolic link — are88refused.8990## Projects9192The app saves your work as a **project**: a folder with the extension `.sonataproject` that93Finder shows as a single document.9495```text96Aurora.sonataproject/97  project.json     name, identifier, format version, main source, list of imported audio98  studio.json      what you changed in the Studio: mixer settings, note edits, loop range99  src/             your sources; src/main.sonata is the entry100  instruments/     instrument definitions saved from the Instrument Lab101  assets/          imported audio files102```103104* **The code is the piece.** Everything musical is in `src/`. `studio.json` holds only105  explicit adjustments made in the Studio (see [Studio](studio.md)); deleting it returns the106  project to exactly what the code says.107* **Sources** are plain text. You can edit them with any editor and keep the project in a108  version-control system.109* **Add a module** with the **+** button at the right of the editor's tabs. A module named110  `motifs` is the file `src/motifs.sonata` and is imported with `import motifs`.111* The app also opens and saves a single `.sonata` file, without a project around it. A lone112  file has no studio settings and no imported audio.113114Outside the project, the app keeps data it can rebuild or that belongs to your machine:115116| What | Where |117|---|---|118| Rendered previews and waveforms (safe to delete) | `~/Library/Caches/ai.spboucher.orix.sonata/` |119| Copies of the sources taken when saving (the 20 most recent) | `~/Library/Application Support/ORIX Sonata/Backups/` |120121No secret is ever written into a project, and the app sends nothing anywhere.122123## Audio files in a project124125An `audio` track places imported audio files on the timeline:126127```sonata128composition "With Audio" {129    tempo 100bpm130    audio field {131        gain -6dB132        clip "rain.wav" at 0bars133        clip "rain.wav" at 4bars gain -3dB fade_in 500ms fade_out 2s134    }135    instrument piano: GrandPiano {136        play C4 duration 1bar137    }138}139```140141The path is relative to the project's `assets` folder. The compiler checks the path and the142placement; the audio itself is read when the piece is played or rendered, so a missing file143is reported at that moment, by name. WAV, AIFF and FLAC files are read.144145From the command line, a project is compiled by naming it:146147```text148sonata check Aurora.sonataproject149sonata render Aurora.sonataproject --output aurora.wav150```151152The exact layout and the rules of the format are in153`Documentation/spec/project-format.md`.154
Files main
Menu

Theme