Latest 1.2.2
Homepage https://github.com/cemolcay/MusicTheory
License MIT
Platforms ios 8.0, osx 10.9, watchos 2.0, tvos 9.0, requires ARC
Frameworks Foundation
Authors

MusicTheory Build Status

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

Requirements

  • Swift 4.0+
  • iOS 8.0+
  • macOS 10.9+
  • tvOS 9.0+
  • watchOS 2.0+

Install

pod 'MusicTheorySwift'

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

  • All keys can be defined with Key struct.
  • It has a KeyType where you can set the base key like C, D, A, G, and an Accitental where it can be .natural, .flat, sharp or more specific like .sharps(amount: 3).
  • You can create Pitches with a Key and octave.
  • Also, you can create Pitches with MIDI note number. rawValue of a pitch is its MIDI note number.
  • Pitch, Key, Accidental structs are equatable, + and - custom operators defined for making calulations 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)

Interval

  • Intervals are halfsteps between pitches.
  • They are IntegerLiteral and you can make add/subsctract 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.

ScaleType and Scale

  • ScaleType enum defines a lot of readymade scales.
  • Also, you can create a custom scale type by ScaleType.custom(intervals: [Interval], description: String)
  • Scale defines a scale with a scale type and root key.
  • You can generate notes of scale in an octave range.
  • Also you can generate HarmonicField of 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)

ChordType and Chord

  • ChordType is a struct with ChordParts which are building blocks of chords.
  • You can define any chord existing with ChordType.
  • Thirds, fifths, sixths, sevenths and extensions are parts of the ChordType.
  • Each of them also structs which conforms ChordPart protocol.
  • Chord defines 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 ChordProgression enum.
  • 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 and TimeSignature

  • Tempo is a helper struct to define timings in your music app.
  • TimeSignature is number of beats in per measure and NoteValue of each beat.
  • You can calculate notes duration in any tempo by ther NoteValue.
  • Note value defines the note’s duration in a beat. It could be whole note, half note, quarter note, 8th, 16th or 32nd note.

Documentation

Full documentation are 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)
StepBud (iOS, AUv3)

Latest podspec

{
    "name": "MusicTheorySwift",
    "version": "1.2.2",
    "summary": "A music theory library with `Note`, `Interval`, `Tone`, `Scale` and `Chord` representations in swift enums.",
    "description": "MusicTheory [![Build Status](https://travis-ci.org/cemolcay/MusicTheory.svg?branch=master)](https://travis-ci.org/cemolcay/MusicTheory)n===nnA music theory library with `Key`, `Pitch`, `Interval`, `Scale` and `Chord` representations in swift enums.nnRequirementsn----n* Swift 5.0+n* iOS 8.0+n* macOS 10.9+n* tvOS 9.0+n* watchOS 2.0+nnInstalln----nn```npod 'MusicTheorySwift'n```nnUsagen----nn`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`.nnAll data types conforms `Codable`, `CustomStringConvertable`.n`Pitch`, and `Accident` structs are `RawPresentable` with `Int` as well as `ExpressibleByIntegerLiteral` that you can represent them directly with `Int`s.nn#### `Pitch` and `Key`nn- All keys can be defined with `Key` struct.n- It has a `KeyType` where you can set the base key like C, D, A, G, and an `Accitental` where it can be `.natural`, `.flat`, `sharp` or more specific like `.sharps(amount: 3)`.n- You can create `Pitch`es with a `Key` and octave.n- Also, you can create `Pitch`es with MIDI note number. `rawValue` of a pitch is its MIDI note number.n- `Pitch`, `Key`, `Accidental` structs are equatable, `+` and `-` custom operators defined for making calulations easier.n- Also, there are other helper functions or properties like frequency of a note.nn``` swiftnlet dFlat = Key(type: d, accidental: .flat)nlet c4 = Pitch(key: Key(type: .c), octave: 4)n```nn#### `Interval`nn- Intervals are halfsteps between pitches.n- They are `IntegerLiteral` and you can make add/subsctract them between themselves, notes or note types.n- You can build up a custom interval with its quality, degree and semitone properties.n- You can build scales or chords from intervals.n- Minor, major, perfect, augmented and diminished intervals up to 2 octaves are predefined.nn#### `ScaleType` and `Scale`nn- `ScaleType` enum defines a lot of readymade scales.n- Also, you can create a custom scale type by `ScaleType.custom(intervals: [Interval], description: String)`n- `Scale` defines a scale with a scale type and root key.n- You can generate notes of scale in an octave range.n- Also you can generate `HarmonicField` of a scale.n- Harmonic field is all possible triad, tetrad or extended chords in a scale.nn``` swiftnlet c = Key(type: .c)nlet maj: ScaleType = .majornlet cMaj = Scale(type: maj, key: c)n```nn#### `ChordType` and `Chord`nn- `ChordType` is a struct with `ChordPart`s which are building blocks of chords.n- You can define any chord existing with `ChordType`.n- Thirds, fifths, sixths, sevenths and extensions are parts of the `ChordType`.n- Each of them also structs which conforms `ChordPart` protocol.n- `Chord` defines chords with type and a root key.n- You can generate notes of chord in any octave range.n- You can generate inversions of any chord.nn``` swiftnlet m13 = ChordType(nthird: .minor,nseventh: .dominant,nextensions: [nChordExtensionType(type: .thirteenth)n])nlet cm13 = Chord(type: m13, key: Key(type: .c))n```nn- You can generate chord progressions with `ChordProgression` enum.n- For any scale, in any harmonic field, for any inversion.nn``` swiftnlet progression = ChordProgression.i_ii_vi_ivnlet cSharpHarmonicMinorTriadsProgression = progression.chords(nfor: cSharpHarmonicMinor,nharmonicField: .triad,ninversion: 0)n```nn#### `Tempo` and `TimeSignature`nn- Tempo is a helper struct to define timings in your music app.n- TimeSignature is number of beats in per measure and `NoteValue` of each beat.n- You can calculate notes duration in any tempo by ther `NoteValue`.n- Note value defines the note's duration in a beat. It could be whole note, half note, quarter note, 8th, 16th or 32nd note.nnDocumentationn----nn[Full documentation are here](https://cemolcay.github.io/MusicTheory/)nnUnit Testsn----nnYou can find unit tests in `MusicTheoryTests` target.nPress `u2318+U` for running tests.nnAppStoren----nnThis library battle tested in my apps for iOS, macOS, watchOS and tvOS, check them out!n[KeyBud](https://itunes.apple.com/us/app/keybud-music-theory-app/id1203856335?mt=8) (iOS, watchOS, tvOS, macOS)n[FretBud](https://itunes.apple.com/us/app/fretbud-chord-scales-for-guitar-bass-and-more/id1234224249?mt=8) (iOS, watchOS, tvOS)n[ChordBud](https://itunes.apple.com/us/app/chordbud-chord-progressions/id1313017378?mt=8) (iOS)n[ArpBud](https://itunes.apple.com/us/app/arpbud-midi-sequencer-more/id1349342326?ls=1&mt=8) (iOS)n[ScaleBud](https://itunes.apple.com/us/app/scalebud-auv3-midi-keyboard/id1409125865?ls=1&mt=8) (iOS, AUv3)",
    "homepage": "https://github.com/cemolcay/MusicTheory",
    "license": "MIT",
    "authors": {
        "cemolcay": "[email protected]"
    },
    "social_media_url": "http://twitter.com/cemolcay",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/cemolcay/MusicTheory.git",
        "tag": "1.2.2"
    },
    "source_files": "Source/*.{swift}",
    "frameworks": "Foundation",
    "requires_arc": true
}

Pin It on Pinterest

Share This