MusicTheory Documentation

Structure Chord

public struct Chord  

A custom musical chord.

As someone familiar with music theory might expect, a custom chord has its component notes and a root note. The chord's quality is determined by these notes.

%11 Chord Chord CustomStringConvertible CustomStringConvertible Chord->CustomStringConvertible

Conforms To

CustomStringConvertible

Initializers

init(_:​notes:​over:​)

public init(_ root: Note, notes: Set<Note>, over slash: Note? = nil)  

Create a chord by specifying root, notes, and slash.

init(_:​_:​over:​)

public init(_ root: Note, _ quality: Quality, over slash: Note? = nil)  

Create a chord by specifying root, quality, and slash.

init(_:​)

public init(_ name: String) throws  

Create a chord directly from it's name.

Create a chord by using it's name directly.

let myChord = try! Chord("Cmaj9/G")
print(myChord.description)
// This is a slash chord named Cmaj9/G over G, with root note C,
// and component notes D, E, G, B, which are respectively major second,
// major third, perfect fifth, major seventh above the root.

If a chord is failed to create, it will print the error message in terminal. For full reference of available chords, go to doc:Chords-Reference

Properties

root

public let root: Note

slash

public let slash: Note? 

is​Recognized

public var isRecognized: Bool  

If this is a currently supported chord.

all​Notes

public var allNotes: Set<Note>  

All notes in the chord, including root and slash.

summary

public var summary: String  

Summary of the chord.

description

public var description: String  

The name of a chord.

The following code generate a chord with name "Esus4"

let chord = Chord(root: .E, [.E, .A, .B])

Methods

contains(note:​)

public func contains(note: Note) -> Bool  

Check if a note is in the chord.

is​In(scale:​)

public func isIn(scale: Scale) -> Bool  

Check if the chord is in a certain scale.