Universal music theory library for iOS, iPadOS, macOS, tvOS and watchOS in Swift
A music theory library with
Key,
Pitch,
Interval,
Scaleand
Chordrepresentations in swift enums.
pod 'MusicTheorySwift'
let package = Package( name: ... dependencies: [ .package(url: "https://github.com/cemolcay/MusicTheory.git") ], targets: ... )
MusicTheoryadds a bunch of basic enums and structs that you can define pretty much any music related data. Most importants are
Pitch,
Key,
Scaleand
Chord.
All data types conforms
Codable,
CustomStringConvertable.
Pitch, and
Accidentstructs are
RawPresentablewith
Intas well as
ExpressibleByIntegerLiteralthat you can represent them directly with
Ints.
Pitchand
Key
Keystruct.
KeyTypewhere you can set the base key like C, D, A, G, and an
Accidentalwhere it can be
.natural,
.flat,
sharpor more specific like
.sharps(amount: 3).
Pitches with a
Keyand octave.
Pitches with MIDI note number.
rawValueof a pitch is its MIDI note number.
Pitch,
Key,
Accidentalstructs are equatable,
+and
-custom operators defined for making calculations easier.
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
IntegerLiteraland you can make add/substract them between themselves, notes or note types.
ScaleTypeand
Scale
ScaleTypeenum defines a lot of readymade scales.
ScaleType.custom(intervals: [Interval], description: String)
Scaledefines a scale with a scale type and root key.
HarmonicFieldof a scale.
let c = Key(type: .c) let maj: ScaleType = .major let cMaj = Scale(type: maj, key: c)
ChordTypeand
Chord
ChordTypeis a struct with
ChordParts which are building blocks of chords.
ChordType.
ChordType.
ChordPartprotocol.
Chorddefines chords with type and a root key.
let m13 = ChordType( third: .minor, seventh: .dominant, extensions: [ ChordExtensionType(type: .thirteenth) ]) let cm13 = Chord(type: m13, key: Key(type: .c))
ChordProgressionenum.
let progression = ChordProgression.i_ii_vi_iv let cSharpHarmonicMinorTriadsProgression = progression.chords( for: cSharpHarmonicMinor, harmonicField: .triad, inversion: 0)
Tempoand
TimeSignature
NoteValueof each beat.
NoteValue.
HarmonicFunctions
You can find unit tests in
MusicTheoryTeststarget.
⌘+Ufor running tests.
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)
StepBud (iOS, AUv3)
RhythmBud (iOS, AUv3)
ArpBud 2 (iOS, AUv3)
ChordBud 2 (iOS, AUv3)