How tonaljs/tonal works
Tonal is a pure-function TypeScript music-theory library, with smaller packages and optional format integrations. The main user workflow is to supply musical names, notes, or chart data and receive structured theory results—such as chord/scale analysis, voicings, patterns, or musical-time values. Charts and MIDI/ iReal integrations extend that workflow; the site also documents capabilities through interactive apps. Edges rely on README examples and explicit imports in sampled files or the SOURCE INDEX; unsampled app and tokenizer internals are not inferred.
Main entry points: tonal/index.ts Tonal API · voicing/index.ts Voicing tools · key/index.ts Key analysis · chord/index.ts Chord operations
Components 34
Pitch foundations
- Note operations
packages/note/index.ts - Interval operations
packages/interval/index.ts - MIDI numbers
packages/midi/index.ts - Pitch class sets
packages/pcset/index.ts
Harmony analysis
- Chord operations
packages/chord/index.ts - Chord composition
packages/chord/compose.ts - Chord degrees
packages/chord/degrees.ts - Chord spelling
packages/chord/spell.ts - Chord substitutes
packages/chord/substitutes.ts - Chord tensions
packages/chord/tensions.ts - Chord detection
packages/chord-detect/index.ts - Scale operations
packages/scale/index.ts - Scale ranking
packages/scale/rank.ts - Key analysis
packages/key/index.ts - Chord in key
packages/key/analyze.ts - Key detection
packages/key/detect.ts - Key substitutes
packages/key/substitutes.ts
Composition tools
- Progression tools
packages/progression/index.ts - Progression keys
packages/progression/keys.ts - Progression patterns
packages/progression/patterns.ts - Voicing tools
packages/voicing/index.ts - Voicing notes
packages/voicing/notes.ts - Voicing placement
packages/voicing/place.ts - Voicing spacing
packages/voicing/spacing.ts - Voicing templates
packages/voicing/templates.ts - Voicing tones
packages/voicing/tones.ts - Voice leading
packages/voice-leading/index.ts - Note patterns
packages/pattern/index.ts
Time and charts
- Rhythm patterns
packages/rhythm-pattern/index.ts - Musical time
packages/time/index.ts - Beat maps
packages/beat-map/index.ts - Chord charts
packages/chart/index.ts
Other components
- Tool builder
- Tonal API
packages/tonal/index.ts
Connections 26
- Tool builder → Tonal API: calls functions
README.md - Tonal API → Note operations: exposes
README.md - Tonal API → Chord operations: exposes
README.md - Tonal API → Scale operations: exposes
README.md - Tonal API → Key analysis: exposes
README.md - Tonal API → Voicing tools: exposes
README.md - Tonal API → Note patterns: exposes
README.md - Tonal API → Rhythm patterns: exposes
README.md - Tonal API → Chord charts: exposes
README.md - Tonal API → Musical time: exposes
README.md - Note operations → MIDI numbers: converts through
packages/note/index.ts - Chord operations → Chord detection: detects with
packages/chord/index.ts - Scale operations → Chord operations: queries chords
packages/scale/index.ts - Key analysis → Chord in key: analyzes with
packages/key/index.ts - Key analysis → Key substitutes: finds substitutes
packages/key/index.ts - Key analysis → Key detection: detects with
packages/key/index.ts - Progression tools → Progression keys: uses
packages/progression/index.ts - Progression tools → Progression patterns: uses
packages/progression/index.ts - Voicing tools → Voicing notes: selects notes
packages/voicing/index.ts - Voicing tools → Voicing templates: resolves templates
packages/voicing/index.ts - Voicing tools → Voicing tones: chooses tones
packages/voicing/index.ts - Voicing tools → Voicing placement: places voices
packages/voicing/index.ts - Voicing notes → Voicing spacing: uses spacing
packages/voicing/notes.ts - Voicing placement → Voice leading: uses metrics
packages/voicing/place.ts - Chord charts → Chord operations: reads chords
packages/chart/index.ts - Chord charts → Musical time: uses meter
packages/chart/index.ts