A music theory library with
Chord representations in swift enums.
- Swift 4.0+
- iOS 8.0+
- macOS 10.9+
- tvOS 9.0+
- watchOS 2.0+
Swift Package Manager
let package = Package( name: ... dependencies: [ .package(url: "https://github.com/cemolcay/MusicTheory.git") ], targets: ... )
MusicTheory adds a bunch of basic enums and structs that you can define pretty much any music related data. Most importants are
All data types conforms
Accident structs are
Int as well as
ExpressibleByIntegerLiteral that you can represent them directly with
- All keys can be defined with
- It has a
KeyTypewhere you can set the base key like C, D, A, G, and an
Accidentalwhere it can be
sharpor more specific like
- You can create
Pitches with a
- Also, you can create
Pitches with MIDI note number.
rawValueof a pitch is its MIDI note number.
Accidentalstructs are equatable,
-custom operators defined for making calculations easier.
- Also, there are other helper functions or properties like frequency of a note.
- You can define them with directly string representations as well.
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)
- Intervals are halfsteps between pitches.
- They are
IntegerLiteraland you can make add/substract them between themselves, notes or note types.
- You can build up a custom interval with its quality, degree and semitone properties.
- You can build scales or chords from intervals.
- Minor, major, perfect, augmented and diminished intervals up to 2 octaves are predefined.
ScaleTypeenum defines a lot of readymade scales.
- Also, you can create a custom scale type by
ScaleType.custom(intervals: [Interval], description: String)
Scaledefines a scale with a scale type and root key.
- You can generate notes of scale in an octave range.
- Also you can generate
HarmonicFieldof a scale.
- Harmonic field is all possible triad, tetrad or extended chords in a scale.
let c = Key(type: .c) let maj: ScaleType = .major let cMaj = Scale(type: maj, key: c)
ChordTypeis a struct with
ChordParts which are building blocks of chords.
- You can define any chord existing with
- Thirds, fifths, sixths, sevenths and extensions are parts of the
- Each of them also structs which conforms
Chorddefines chords with type and a root key.
- You can generate notes of chord in any octave range.
- You can generate inversions of any chord.
let m13 = ChordType( third: .minor, seventh: .dominant, extensions: [ ChordExtensionType(type: .thirteenth) ]) let cm13 = Chord(type: m13, key: Key(type: .c))
- You can generate chord progressions with
- For any scale, in any harmonic field, for any inversion.
let progression = ChordProgression.i_ii_vi_iv let cSharpHarmonicMinorTriadsProgression = progression.chords( for: cSharpHarmonicMinor, harmonicField: .triad, inversion: 0)
- Tempo is a helper struct to define timings in your music app.
- TimeSignature is number of beats in per measure and
NoteValueof each beat.
- You can calculate notes duration in any tempo by ther
- Note value defines the note's duration in a beat. It could be whole note, half note, quarter note, 8th, 16th or 32nd note.
- Harmonic functions is a utility for finding related notes or chords in a scale when composing.
- You can create recommendation engines or chord generators with that.
- You can experiment with the library right away in the Xcode Playgrounds!
- After cloning the project, build it for the Mac target,
- Go to playground page in the project,
- Make sure the macOS platform is selected,
- And make sure the "Build Active Scheme" option is selected in the playground settings.
- There are some recipes ready in the playground page, you can just run them right away.
You can find unit tests in
⌘+U for 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)
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)