Structures for the creation, analysis, and performance of music in Swift. Check out the documentation.
Overview
Music is a package for anyone who wants to create, analyze, and perform music in pure Swift.
Usage
🎶 Pitch
The Pitch module provides types for structuring and transforming the frequency domain.
Basic Types
let a440: Frequency = 440 // Hz
let middleC: Pitch = 60 // MIDI note number
let e = middleC + 4 // e above middle c
let microtone = e - 0.25 // eighth-tone below the e above middle c
let anyE = Pitch.Class(e) // pitch class 4
let anyGSharp = anyE.inverse // pitch class 8
let majorThird: DiatonicInterval = .M3
let minorSixth = majorThird.inverse
let AAA3 = DiatonicInterval(.triple, .augmented, .third)
let noSuchThing = DiatonicInterval(.major, .fifth) ❌ will not compile!
♬ Duration
The Duration module provides types for structuring and transforming the time domain.
Basic Types
let crotchet = Duration(1,4)
let waltz = Meter(3,4)
let stayinAlive = Tempo(100, subdivision: 4)
🎚️ Dynamics
The Dynamic module provides ways to describe musical loudness in a highly subjective way.
let loud: Dynamic = .ff
let quiet: Dynamic = .p
let interp = Dynamic.Interpolation(from: .p, to: .ff)
🥁 Articulations
The Articulation type provides an interface to describe the way in which a given musical entity is performed.
let short: Articulation = .staccato
let sweet: Articulation = .tenuto
let hard: Articulation = .marcato
let hereIAm: Articulation = .accent
💾 MusicModel
The Model brings all of elements together from the modules contained in this package.
let builder = Model.Builder()
let performer = Performer(name: "Pat")
let instrument = Instrument(name: "Euphonium")
let voiceID = builder.createVoice(performer: performer, instrument: instrument)
let pitch: Pitch = 60
let articulation: Articulation = .tenuto
let dynamic: Dynamic = .fff
let note = Rhythm<Event>(1/>1, [event([pitch, dynamic, articulation])])
let rhythmID = builder.createRhythm(note, voiceID: voiceID, offset: .zero)
let model = builder.build()
Requirements
In order to use the Music package, you’ll need a few things:
Music
Structures for the creation, analysis, and performance of music in Swift. Check out the documentation.
Overview
Music
is a package for anyone who wants to create, analyze, and perform music in pure Swift.Usage
🎶 Pitch
The
Pitch
module provides types for structuring and transforming the frequency domain.Basic Types
Set Operations
Row Transformations
Diatonic Intervals
♬ Duration
The
Duration
module provides types for structuring and transforming the time domain.Basic Types
🎚️ Dynamics
The
Dynamic
module provides ways to describe musical loudness in a highly subjective way.🥁 Articulations
The
Articulation
type provides an interface to describe the way in which a given musical entity is performed.💾 MusicModel
The
Model
brings all of elements together from the modules contained in this package.Requirements
In order to use the
Music
package, you’ll need a few things:Installation
In order to use the
Music
modules in your own projects, add it to thedependencies
section of yourPackage.swift
file:Development
To contribute to the
Music
package, clone thegit
repository:If you use the Xcode IDE on macOS, you can use SwiftPM to generate an
.xcodeproj
file:Inspiration
Here are some libraries in other languages that have been influential to the design of the
Music
package: