用于在 Swift 中创建、分析和演奏音乐的结构。 请查看文档。
Music
是一个为任何希望完全使用 Swift 创建、分析和演奏音乐的人提供的包。
Pitch
模块提供了用于构建和转换频域的类型。
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 set: Pitch.Class.Collection = [8,0,4,6]
set.normalForm // => [4,6,8,0]
set.primeForm // => [0,2,4,8]
let pcs: Pitch.Class.Collection = [0,11,3,4,8,7,9,5,6,1,2,10]
pcs.retrograde // => [10,2,1,6,5,9,7,8,4,3,11,0]
pcs.inversion // => [0,1,9,8,4,5,3,7,6,11,10,2]
let majorThird: DiatonicInterval = .M3
let minorSixth = majorThird.inverse
let AAA3 = DiatonicInterval(.triple, .augmented, .third)
let noSuchThing = DiatonicInterval(.major, .fifth) ❌ will not compile!
Duration
模块提供了用于构建和转换时域的类型。
let crotchet = Duration(1,4)
let waltz = Meter(3,4)
let stayinAlive = Tempo(100, subdivision: 4)
Dynamic
模块提供了以高度主观的方式描述音乐响度的方法。
let loud: Dynamic = .ff
let quiet: Dynamic = .p
let interp = Dynamic.Interpolation(from: .p, to: .ff)
Articulation
类型提供了一个接口来描述给定音乐实体演奏的方式。
let short: Articulation = .staccato
let sweet: Articulation = .tenuto
let hard: Articulation = .marcato
let hereIAm: Articulation = .accent
Model
将此包中包含的模块中的所有元素组合在一起。
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()
为了使用 Music
包,您需要一些东西
为了在您自己的项目中使用 Music
模块,请将其添加到 Package.swift
文件的 dependencies
部分
let package = Package(
name: ...,
products: [ ... ],
dependencies: [
...,
.package(url: "https://github.com/dn-m/Music", from: "0.17.1")
],
targets: [ ... ]
)
要为 Music
包做出贡献,请克隆 git
存储库
git clone https://github.com/dn-m/Music && cd Music
如果您在 macOS 上使用 Xcode IDE,则可以使用 SwiftPM 生成 .xcodeproj
文件
swift package generate-xcodeproj
以下是用其他语言编写的一些库,它们对 Music
包的设计产生了影响