A library for music theory, written in SWIFT.
- Swift 4.0+
- iOS 8.0+
Create the framework and then drag and drop to your app. Make sure to add it to "Link Frameworks and Libraries" in your project's General settings
SwiftMusicology will give you access to several fairly simple enums and structs which can be used to define nearly any music related data that is based on Westen tonal relationships. For most people, the most commonly used of these data structures will be the Pitch, Key, Scale and Chord structs.
It should be noted that all data types conform to Codableand CustomStringConvertable protocols. Furthermore, Pitch, and Accidental structs are RawPresentable with Int, as well as ExpressibleByIntegerLiteral.
- Intervals are the semitones between pitches and thus the basic building blocks of Western music theory. They are
IntegerLiteralso you can add or subsctract them between themselves,PitchesorNoteTypes. You can define a custom interval with its quality, degree and semitone properties. Finally minor, major, perfect, augmented and diminished intervals, up to 2 octaves, are predefined for convenience.
- All keys can be defined with
Keystruct. It has aKeyTypewhere you can set the base key like C, D, A#, or Fb. All keys must be initialised with anAccidentalwhich can be.natural,.flat,sharpor something more custom such as.sharps(amount: 3). Pitches are created with with aKeyand octave. You may also createPitches with MIDI note number. TherawValueof a pitch is its MIDI note number. In theory these are from 0-127; however, they are not limited and thus may go beyond this range in both directions.- The
Pitch,Key,Accidentalstructs have had custom operators defined for==,+and-in order to make calulations easier. - Both of these structs can be defined with strings as well, though, for specificity's sake, it is advisable to not do so.
// Standard method of definition
let gFlat = Key(type: g, accidental: .flat)
let a4 = Pitch(key: Key(type: .a), octave: 4)
// Definition with strings.
let dSharp: Key = "d#" // Is the equivalent of `Key(type: .a, accidental: .sharp)`
let aFlat3: Pitch = "ab3" // or "a♭3" or "Ab3" is Pitch(key: (type: .a, accidental: .flat), octave: 3)ScaleTypeenum exists as a covenient shortcut providing a substantial amount of predefined scales for the user such that you don't have to do the heavy lifting or defining each scale every time you want to use it. Various scales are available, from the standard major/minor to more exotic scales such as Promethean Neopolitan or Six Tone Symmetrical. You are also able to create a customScaleTypein the following manner:ScaleType.custom(intervals: [Interval], description: String)Scaledefines a scale with aScaleTypeand rootKey. You are then able to generate notes of that scale in an octave range, as well as generate the scale'sHarmonicFieldwhich are all the possible triad, tetrad or extended chords in a scale.
let gLocrian = Scale(type: .locrian, key: Key(type: .g))ChordTypeis a struct withChordParts which are the basic blocks of building chords. You can define any chord existing withChordType. Thirds, fifths, sixths, sevenths and other extensions are parts of theChordTypeas separate structs which also conform to theChordPartprotocol.Chorddefines chords with type and a root key. This allows you to generate the notes of any chord in any octave range as well as in any inversion.
let m13 = ChordType(third: .minor, seventh: .dominant, extensions: [ChordExtensionType(type: .thirteenth)])
let dm13 = Chord(type: m13, key: Key(type: .d))- Tempo is a helper struct to define timings in your music app which consists of a
TimeSignatureand beats per minute.TimeSignatureis the number of beats per measure and theNoteValueof each beat.NoteValuedefines the note's duration in a beat. It could be whole note, half note, quarter note, 8th, 16th, 32nd, or 64th note.
Unit Tests are still being written. However, the library has currently been tested and is a fully operational battlesh... framework.