LogoCarmen

Programmatic Music Composition

A flexible and expressive language to define musical structures, from simple melodies to complex multi-movement scores.

Get started with:

cargo install carmen-lang

Features

Expressive Musical Notation

Define pitches, durations, chords, rests, and dynamics with a clear and concise syntax.

Hierarchical Structure

Organize your music into sequences, multi-voice parts, staves, timelines, movements, and scores.

Programmatic Control

Use variables, functions, conditionals (if/else), and loops (for, while) to generate and manipulate musical material.

Powerful Transformations

Leverage built-in functions for music theory operations like transposition (T), inversion (I), and more.

Multiple Export Formats

Export your compositions to various formats, including plain text summaries and LilyPond for beautiful sheet music engraving.

Developer Tools

Includes tools for tokenizing, parsing, and inspecting the Abstract Syntax Tree (AST) of Carmen code for debugging and analysis.

Examples

Basic Melody
// Simple melody with rests and dynamics
let melody = [
    1/4 c4 mf,
    1/8 d4,
    1/8 e4,
    1/2 f4 p,
    1/4 ~
];
Multi-Voice Bach Chorale
let voice_1 = [
    1/12 [~, g4, a, b, d5, c, c, e, d, d, g, fs, g, d, b4, g, a, b, c5, d, e, d, c, b4, a, b, g],
    1/12 [fs4, g],
    3/12 a4,
    1/12 [g4, c5, b4, a],
];

let voice_2 = [
    1/12 [~, b3, d4],
    1/4 [d4, e, g, e, b3, a, d4],
    1/2 c4,
    1/4 [a3, fs4]
];

score "BVW 147" {
    @composer "J S Bach";
    @title "BVW 147";
    @key_signature "G";
    @time_signature 3/4;
    @tempo 100;

    timeline {
        part "Violin" {
            @clef "treble";
            voice_1;
        };
        part "Violin 2" {
            @clef "treble";
            voice_2;
        };
    };
};
Musical Transformations
// Define a theme and apply transformations
let theme = 1/4 [c4, d, e, f];

// Apply transformations
let transposed = theme |> transpose(7);      // Transpose up a perfect fifth

// Pitch class set analysis
let chord_set = {0, 4, 7};                       // C major triad as pitch classes
let normal = chord_set |> normal_form();         // Get normal form
let prime = chord_set |> prime_form();           // Get prime form
let ic_vec = chord_set |> ic_vector();           // Get interval class vector
let inverted = chord_set |> invert(2);           // Get inversions
Multi-Staff Piano Score
score "Piano Piece" {
    @composer "Carmen User";
    @tempo 120;
    @time_signature 4/4;

    timeline {
        part "Piano" {
            staff 0 {
                @clef "treble";
                [1/4 c5, 1/8 d5, 1/2 e5];
            };

            staff 1 {
                @clef "bass";
                [1/4 c3, 1/8 g3, 1/2 e4];
            };
        };
    };
};

Getting Started

Ready to start composing with code? Install Carmen and start creating your own music.

cargo install carmen-lang