Skip to main content

A comprehensive music theory library built around algorithmic approaches

Project description

Chordelia

Chordelia is a Python toolkit for music theory, composition, notation, and playback. It focuses on theory-correct results, immutable value objects, and deterministic score conversion.

Why Chordelia

  • Theory-correct spellings for scales, intervals, and chord construction.
  • Immutable, copy-constructor style APIs that compose cleanly.
  • Sequence to Score normalization for a single canonical timeline model.
  • Built-in SVG sheet rendering plus optional LilyPond backend integration.
  • Optional audio and MIDI workflows layered on top of the same score model.

Installation

pip install chordelia

Optional extras:

pip install chordelia[audio]
pip install chordelia[midi]
pip install chordelia[all]

Python requirement: 3.10+

Tested in CI: 3.10-3.13. Preview support: 3.14 (non-blocking CI signal).

Quick Feature Tour

1) Build a song form from one motif

from fractions import Fraction
from chordelia import *

scale = Scale("E4", ScaleType.HARMONIC_MINOR)
set_global_scale_context(scale)
degrees = (1, 3, 4, 5, 4, 3, 2, 1)
half = Fraction(1, 2)

a = Sequence(tuple((scale.degree(d), half) for d in degrees))

chord_hit = scale.chord_for_degree("V")
b = a.shift(2)
c = Sequence(((chord_hit, half), a.shift(4)))

song = Sequence((a, b, c, a))
score = Score.from_sequenceable(song, tempo=120, time_signature=(4, 4), key_signature="E minor")

Movement contract quick check:

with with_global_scale_context(scale):
	print(Note("E4").shift(2))   # G4 (diatonic)

print(Note("E4").transpose(1))  # F4 (one semitone)

Use shift(...) for diatonic scale-step movement and transpose(...) for chromatic semitone movement.

Seeded random workflow quick check:

rng = Random(seed=202606)
scale = rng.scale()
motif = MotifVariationSequenceAlgorithm(motif_beats=2)
phrase = rng.sequence(8, algorithm=motif, scale=scale)
progression = [rng.chord(scale=scale).name for _ in range(4)]

print(len(phrase.entries))

For weighted algorithm selection, stateful motif reuse, and global-singleton randomization recipes, see Cookbook. For Random.sequence(...), pass algorithm-specific per-call tuning values as direct keyword arguments.

The resulting Score is the canonical shared boundary for both rendering and MIDI export.

2) Compose sequential and simultaneous parts explicitly

from chordelia import ParallelSequence, Sequence

lead = Sequence((("E4", 1), ("G4", 1), ("A4", 2)))
bass = Sequence((("E3", 4),))

arrangement = ParallelSequence(
	(
		("lead", lead, 0),
		("bass", bass, 0),
	),
	name="song",
)

score = Score.from_parallel_sequences(arrangement, tempo=120, time_signature=(4, 4))

Sequence remains the canonical sequential model. Use ParallelSequence when simultaneous layering and per-child offsets are the primary intent.

3) Target immutable deep updates with named paths

updated = arrangement.replace_child_by_path("lead", lead.transpose(12))
updated_score = Score.from_sequenceable(updated)

Named child paths are dot-separated and immutable replacement returns a new composition tree.

4) Render that same song as sheet music

# Continue from block 1 in the same Python session.
SheetMusic(score, scale=scale).to_file("song.svg")

5) Export and play that same song via MIDI

# Continue from block 1 in the same Python session.
MidiFile(score).to_file("song.mid")

MidiPlayback().play_score(score, blocking=True)

Note: immutable composition models (Sequence, ParallelSequence) are separate from future runtime channel controls tracked in Interactive Live Song Channels Plan.

Documentation

Start here:

In-depth tutorials:

Guides and reference:

Additional runnable examples: examples

Contributing

Contributions are welcome. Include tests for behavior changes and keep docs aligned with final API behavior.

License

MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chordelia-0.4.0rc3.tar.gz (96.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chordelia-0.4.0rc3-py3-none-any.whl (106.6 kB view details)

Uploaded Python 3

File details

Details for the file chordelia-0.4.0rc3.tar.gz.

File metadata

  • Download URL: chordelia-0.4.0rc3.tar.gz
  • Upload date:
  • Size: 96.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for chordelia-0.4.0rc3.tar.gz
Algorithm Hash digest
SHA256 63a429be16cb6e5554f13b0d7a9007b387006027baa45f10b963d63dc40a16be
MD5 31205f6abcf8d933c5546c221febd88b
BLAKE2b-256 9eeee56841d242db75446d6effda5d264b6546ab5891633b04a573a1afbba297

See more details on using hashes here.

Provenance

The following attestation bundles were made for chordelia-0.4.0rc3.tar.gz:

Publisher: python-publish.yml on lzulauf/chordelia

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chordelia-0.4.0rc3-py3-none-any.whl.

File metadata

  • Download URL: chordelia-0.4.0rc3-py3-none-any.whl
  • Upload date:
  • Size: 106.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for chordelia-0.4.0rc3-py3-none-any.whl
Algorithm Hash digest
SHA256 9315cafc304400a8bc530536a0d6bfc6bf29372413d3796f05b94d45f2104906
MD5 ef6ce3f5e850894f096ef20f39b15774
BLAKE2b-256 77ee0ca69bb01cad61cd07258a0ba6218aa06fe198b9c5273a9f2528147eba7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for chordelia-0.4.0rc3-py3-none-any.whl:

Publisher: python-publish.yml on lzulauf/chordelia

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page