Skip to content
NOT-REAL-GAMESPublic

About

The programming language for audio.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Sonic

An audio programming language and native DAW. The source is the song: synthesis, effects, notes, arrangement, routing, and automation live in .sonic files. The DAW edits those same files, and the command line can play or render them independently.

Sonic includes custom sample-by-sample DSP, polyphonic instruments, microtonal notes, WAV samples, reusable pattern generators, a piano roll, step sequencer, mixer, effects, buses, and automation. Oscillators, envelopes, filters, delays, and rhythm generators are written in Sonic's standard library.

Sonic's native dockable workspace

Run

Install Rust 1.92.0 or newer. On Debian/Ubuntu, install the native build dependencies:

sudo apt-get install build-essential pkg-config libasound2-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libegl1-mesa-dev
cargo run -p sonic-daw -- examples/demo/song.sonic

Windows uses the MSVC Rust toolchain and Visual Studio C++ build tools. macOS uses the Xcode command-line tools and requires macOS 14.2 or newer for the selected CoreAudio backend. Native builds and packaging are configured for Linux x64, Windows x64, and macOS Apple Silicon and Intel in CI.

The first build downloads the Rust dependencies. For sustained audio work, use --release:

cargo run --release -p sonic-daw -- examples/demo/song.sonic

Write an instrument

Choose New, then click the empty instrument slot. Its coding window opens automatically. Insert the synth template or write your own script:

instrument lead {
    polyphony = 32;
    release = 300ms;
    let tone = saw(freq);
    let envelope = adsr(gate, 5ms, 100ms, 0.5, 250ms);
    out = tone * envelope * velocity * 0.2;
}

Every edit schedules compilation immediately. The first valid script attaches to the channel automatically. Subsequent valid changes activate on the next bar, or the next beat if selected. Add notes in the piano roll or step sequencer, then press Play. An empty slot stays silent; an invalid edit keeps the last valid sound playing.

When a loop ends before the next selected beat or bar, queued edits apply at the loop wrap so short loops remain live-editable.

View the empty instrument coding window.

Instrument scripts are real source files. Save writes all open source modules, including drafts. Export compiles the current referenced source; a referenced invalid script must be fixed before exporting. Unattached drafts do not block export.

Save checks edited files against their last loaded or saved disk versions. If another editor changes a file, Sonic keeps your buffers open and offers Save a copy, Overwrite reviewed disk files, or Keep editing. Overwrite approval expires when the reviewed source or disk contents change. The dialog shows bounded excerpts near the first difference; the complete editor buffers and disk files remain available.

Save As copies reachable modules, open drafts, and sample assets to a fresh project folder, including known references in temporarily invalid source. It rewrites relocated file references while preserving surrounding code and comments, and refuses occupied destination paths. Keep modules and assets inside the project directory; missing or outside references must be repaired before relocation. Saving under another entry name in the same folder reuses only unchanged, conflict-free shared modules; choose a new folder for an independent copy.

Customize the workspace

Drag panel tabs to create split regions, combine editors into a tab group, or float a group inside the workspace. Channels, arrangement, inspector, piano roll, sequencer, automation, source, and instrument editors all participate.

Right-click a tab for Float in workspace, Dock in main window, or Pop out to OS window. A separate OS window can move to another monitor; its Dock in main window button brings the editor back. Instrument code keeps compiling live in every layout. Save, undo/redo, and transport shortcuts work in pop-outs too.

Use View to hide or reopen panels and Reset workspace layout to restore the defaults. Closing an editor preserves its unsaved source. Each song remembers its splits, tab groups, floating panels, and native window geometry in its optional .sonic-ui.json preferences file.

View an instrument in a separate native window.

The arrangement previews notes across every repetition of a clip. Both the arrangement and piano roll have zoom controls: Ctrl/Cmd+wheel zooms time around the pointer, Ctrl/Cmd+Shift+wheel adjusts track height or pitch zoom, Shift+wheel pans time, and middle-drag pans both axes. Plain wheel scrolls tracks or pitches. Fit arrangement and Fit view restore an overview; navigation settings are remembered per song.

Arrangement panning follows the captured drag even outside the grid. Escape stops the gesture, and switching tabs or windows cancels an interrupted clip drag so navigation stays responsive.

Choose a pattern in the arrangement and use Add clip on the selected channel, or double-click empty timeline space to place it on that row. Drag a clip to move it; drag its right edge to change the number of whole pattern repetitions. Duplicate and Delete are also available from the clip's context menu. With the arrangement focused, Ctrl/Cmd+D duplicates the selected clip and Delete removes it. Copies share the same source pattern, so editing its notes updates every instance. Each arrangement edit is one source undo step.

The piano roll has a Velocity drawer below the notes. Pull its divider up to open or enlarge it, or down to collapse it; the Velocity button toggles it too. Drag a velocity stem to edit a note, or a selected stem to adjust the selection together in one undo step. Note-length handles extend beyond the right edge and show a resize cursor, making short notes easier to resize.

Command line

cargo run -p sonic-cli -- new my-song
cargo run -p sonic-cli -- new my-demo --demo
cargo run -p sonic-cli -- check examples/demo/song.sonic
cargo run -p sonic-cli -- check examples/demo/song.sonic --json
cargo run --release -p sonic-cli -- play examples/demo/song.sonic
cargo run --release -p sonic-cli -- play examples/generators/song.sonic --watch --loop --boundary beat
cargo run -p sonic-cli -- devices
cargo run --release -p sonic-cli -- render examples/demo/song.sonic -o afterimage.wav

Rendering needs no audio device. Export defaults to stereo 48 kHz, 24-bit PCM WAV with a two-second tail; change these with --sample-rate and --tail. Native playback lets releases and effects decay for two seconds after the score ends; looping wraps at the score boundary. Playback accepts --device, --seconds, and --loop.

Use --watch to live-code from an external editor: saving the song, an imported module, or a referenced WAV automatically compiles a new revision. Valid changes apply at the next bar by default; select --boundary beat for faster activation. Invalid changes report diagnostics and retain working audio. Missing files can be created or repaired while watching. The watcher stays alive after the song ends and starts the latest valid revision when it changes; --seconds limits the entire session, including an initially invalid project.

Project files

my-song/
  song.sonic                 # Arrangement, notes, channels, effects, routing
  instruments/lead.sonic    # Instrument and custom processor source
  assets/kick.wav           # Relative sample assets
  song.sonic-ui.json        # Optional window/selection preferences only

Code and visual edits share undo/redo. Visual controls update source expressions while preserving surrounding comments. The piano roll and step sequencer share the same notes. Generated notes display their provenance; Bake to notes creates a literal pattern for the selected clip while keeping the generator available.

In the piano roll, Shift-click toggles notes in a selection, and dragging empty grid space selects a region. Drag selected notes to move them together, or drag a note's right edge to resize the group. Alt-drag tunes continuously while retaining each note's microtonal interval. With the piano roll focused, Ctrl/Cmd+A selects all notes, Ctrl/Cmd+D duplicates the group, and Delete removes it. Each group edit is one undo step. Duplicates go after the selected span, or before it when only that side fits; every duplicated note must start inside the pattern.

New imports appear in the source editor even when their code contains errors, so they can be repaired in place. Visual effect controls use parameter types and argument positions supplied by the language, including positional calls and custom boolean/integer parameters. Editing clip or automation controls preserves untouched fractional timing and comments.

Read the language reference, architecture, and platform verification checklist. The Afterimage demo combines a custom feedback filter, polyphonic pad, original kick sample, Euclidean hats, a delay bus, and gain automation. A smaller DSP example is also included.

Notes accept fractional MIDI (60.5), exact frequency (432Hz), and offsets such as A3 + 27Hz (247 Hz). The piano roll and note inspector retain this tuning. Try the microtonal example.

During score construction, transpose(pitch, semitones) shifts any of these pitches by a unitless semitone interval, including fractions: transpose(pitch=A3 + 27Hz, semitones=0.5) raises 247 Hz by half a semitone. frequency(pitch) returns a value in hertz for ratio tuning; frequency(pitch=A3 + 27Hz) * 1.5 produces 370.5 Hz. Both helpers also work in generator arguments, defaults, and constants.

Write your own reusable composition helpers with typed parameters, bounded loops, and compile-time conditionals:

generator octave(root: pitch = C4, gap: beats = 1beat) {
    assert(gap > 0beat, "gap must be positive");
    note(root, at=0beat, duration=0.5beat);
    note(root + 12, at=gap, duration=0.5beat);
}
pattern melody(length=1bar) {
    octave(A3 + 27Hz); // 247 Hz followed by 494 Hz
}

The Lattice example imports nested generators from a separate module. The stock step and euclid helpers use the same language mechanism.

Development

cargo fmt --all --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
cargo build --workspace --release

Tests cover source transactions, compiler diagnostics and budgets, timing, DSP state, sample loading, rendering parity, live swaps, and the real CLI workflow. Hardware playback is an explicit ignored smoke test; see the verification checklist.

This first version focuses on synthesis and sequencing. Recording, external MIDI, plugin hosting, tempo maps, networking, and migration of state inside edited DSP algorithms are future work. Cold renders are reproducible for a given engine build and configuration; playback state retained through live edits is not a recording of those edits.

About

The programming language for audio.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages