https://github.com/fwcd/swift-music-theory
Music theory library written in pure Swift
https://github.com/fwcd/swift-music-theory
linux music music-theory swift
Last synced: 11 months ago
JSON representation
Music theory library written in pure Swift
- Host: GitHub
- URL: https://github.com/fwcd/swift-music-theory
- Owner: fwcd
- License: mit
- Created: 2020-09-19T15:21:25.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-10-16T00:27:45.000Z (over 1 year ago)
- Last Synced: 2024-12-01T14:11:50.839Z (over 1 year ago)
- Topics: linux, music, music-theory, swift
- Language: Swift
- Homepage: https://fwcd.github.io/swift-music-theory/documentation/musictheory
- Size: 96.7 KB
- Stars: 5
- Watchers: 4
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Music Theory Library for Swift
[](https://github.com/fwcd/swift-music-theory/actions/workflows/build.yml)
[](https://fwcd.github.io/swift-music-theory/documentation/musictheory)
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](https://github.com/swiftwasm).
## Examples
```swift
// 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
```swift
import MusicTheory
```