swift-music-theory

Music theory library written in pure Swift

MIT License

Stars
4

Music Theory Library for Swift

A minimal library for Western music theory in pure Swift, defining notes, scales, chords, intervals, progressions and more.

Since no external dependencies are needed, it runs on Linux, macOS and any other platform supporting Swift 5.7+, including the browser with SwiftWasm.

Examples

// Creating (octaved) notes
Note(.c, 3)             // -> C3
Note(.d.flat, 2)        // -> Db2

// Applying diatonic intervals
Note(.c, 3) + .majorThird // -> E3
Note(.d, 2) + .octave     // -> D3

// Applying chromatic intervals
Note(.f, 2) + .semitone
Note(.g.sharp, 0) + .semitones(3)

// Creating scales
MajorScale(key: Note(.e, 2)).notes       // -> [E2, F#2, G#2, A2, B2, C#3, D#3]
MinorScale(key: Note(.c, 1)).notes       // -> [C1, D1, Eb1, F1, G1, Ab1, Bb1]
MinorBluesScale(key: Note(.g, 0)).notes  // -> [G0, Bb0, C1, Db1, D1, F1]

To experiment with the library yourself, simply run swift run --repl to open an interactive shell and enter

import MusicTheory
Badges
Extracted from project README
Build Docs