cemolcay / MusicTheory

Universal music theory library for iOS, iPadOS, macOS, tvOS and watchOS in Swift
MIT License
442 stars 50 forks source link
chords interval ios ipados mac music-theory note scale swift

MusicTheory

A music theory library with Key, Pitch, Interval, Scale and Chord representations in swift enums.

Requirements

Install

CocoaPods

pod 'MusicTheorySwift'

Swift Package Manager

let package = Package(
  name: ...
  dependencies: [
    .package(url: "https://github.com/cemolcay/MusicTheory.git")
  ],
  targets: ...
)

Usage

MusicTheory adds a bunch of basic enums and structs that you can define pretty much any music related data. Most importants are Pitch, Key, Scale and Chord.

All data types conforms Codable, CustomStringConvertable.
Pitch, and Accident structs are RawPresentable with Int as well as ExpressibleByIntegerLiteral that you can represent them directly with Ints.

Pitch and Key

let dFlat = Key(type: d, accidental: .flat)
let c4 = Pitch(key: Key(type: .c), octave: 4)
let aSharp: Key = "a#" // Key(type: .a, accidental: .sharp)
let gFlat3: Pitch = "gb3" // or "g♭3" or "Gb3" is Pitch(key: (type: .g, accidental: .flat), octave: 3)

Interval

ScaleType and Scale

let c = Key(type: .c)
let maj: ScaleType = .major
let cMaj = Scale(type: maj, key: c)

ChordType and Chord

let m13 = ChordType(
  third: .minor,
  seventh: .dominant,
  extensions: [
    ChordExtensionType(type: .thirteenth)
  ])
let cm13 = Chord(type: m13, key: Key(type: .c))
let progression = ChordProgression.i_ii_vi_iv
let cSharpHarmonicMinorTriadsProgression = progression.chords(
  for: cSharpHarmonicMinor,
  harmonicField: .triad,
  inversion: 0)

Tempo and TimeSignature

HarmonicFunctions

Playgrounds

Documentation

Full documentation is here

Unit Tests

You can find unit tests in MusicTheoryTests target.
Press ⌘+U for running tests.

AppStore

This library battle tested in my apps for iOS, macOS, watchOS and tvOS, check them out!
KeyBud (iOS, watchOS, tvOS, macOS)
FretBud (iOS, watchOS, tvOS)
ChordBud (iOS)
ArpBud (iOS)
ScaleBud (iOS, AUv3, M1)
StepBud (iOS, AUv3, M1)
RhythmBud (iOS, AUv3, M1)
ArpBud 2 (iOS, AUv3, M1)
ChordBud 2 (iOS, AUv3, M1)
LoopBud (iOS, AUv3, M1)
Euclid Goes to Party (iOS, AUv3, M1)
SnakeBud (iOS, AUv3, M1)
MelodyBud (iOS, AUv3, M1)
ScaleBud 2 (iOS, AUv3, M1)
ShiftBud (iOS, AUv3, M1)
PolyBud (iOS, AUv3, M1)
PatternBud (iOS, AUv3, M1)
MIDI Motion (iOS, watchOS)
Textquencer (iOS, AUv3, M1)
In Theory (iOS, AUv3, M1)
BrainBud (iOS, AUv3, M1)
Binarhythmic (iOS, AUv3, M1)
Auto Bass (iOS, AUv3, M1)
BounceBud (iOS, AUv3, M1)
MuseBud (iOS, AUv3, M1)
Auto Fills (iOS, AUv3, M1)
Kebarp (iOS, AUv3, M1)
FuncBud (iOS, AUv3, M1)
Note to Be (iOS, AUv3, M1)