Skip to content

Commit

Permalink
Added 6 sus chords
Browse files Browse the repository at this point in the history
  • Loading branch information
aure committed Apr 11, 2024
1 parent 58651a5 commit e2ba83f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
28 changes: 21 additions & 7 deletions Sources/Tonic/ChordType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ public enum ChordType: String, CaseIterable, Codable {
/// Suspended 4 Triad: Perfect Fourth, Perfect Fifth
case suspendedFourthTriad

/// Sixth: Major Third, Perfect Fifth, Major Sixth
/// Major Sixth: Major Third, Perfect Fifth, Major Sixth
case sixth

/// Minor Sixth: Minor Third, Perfect Fifth, Major Sixth
case minorSixth

/// Major Sixth Suspended Second: Major Second, Perfect Fifth, Major Sixth
case sixthSuspendedSecond

/// Major Sixth Suspended Fourth: Major Fourth, Perfect Fifth, Major Sixth
case sixthSuspendedFourth

/// Half Diminished Seventh: Minor Third, Diminished Fifth, Minor Seventh
case halfDiminishedSeventh

Expand All @@ -41,12 +47,12 @@ public enum ChordType: String, CaseIterable, Codable {
/// Dominant Seventh: Major Third, Perfect Fifth, Minor Seventh
case dominantSeventh

/// Dominant Seventh Suspendend Fourth: Perfect Fourth, Perfect Fifth, Minor Seventh
case dominantSeventhSuspendedFourth

/// Dominant Seventh Suspendend Second: Major Second, Perfect Fifth, Minor Seventh
case dominantSeventhSuspendedSecond

/// Dominant Seventh Suspendend Fourth: Perfect Fourth, Perfect Fifth, Minor Seventh
case dominantSeventhSuspendedFourth

/// Major Seventh: Major Third, Perfect Fifth, Major Seventh
case majorSeventh

Expand Down Expand Up @@ -146,6 +152,8 @@ public enum ChordType: String, CaseIterable, Codable {
/// Half Diminished Ninth: Minor Third, Diminished Fifth, Minor Seventh, Minor Ninth, Perfect Eleventh, Diminished Thirteenth
case halfDiminishedFlatThirteenth



public var intervals: [Interval] {
switch self {
case .majorTriad: return [.M3, .P5]
Expand All @@ -157,11 +165,13 @@ public enum ChordType: String, CaseIterable, Codable {
case .suspendedFourthTriad: return [.P4, .P5]
case .sixth: return [.M3, .P5, .M6]
case .minorSixth: return [.m3, .P5, .M6]
case .sixthSuspendedSecond: return [.M2, .P5, .M6]
case .sixthSuspendedFourth: return [.P4, .P5, .M6]
case .halfDiminishedSeventh: return [.m3, .d5, .m7]
case .diminishedSeventh: return [.m3, .d5, .d7]
case .dominantSeventh: return [.M3, .P5, .m7]
case .dominantSeventhSuspendedFourth: return [.P4, .P5, .m7]
case .dominantSeventhSuspendedSecond: return [.M2, .P5, .m7]
case .dominantSeventhSuspendedFourth: return [.P4, .P5, .m7]
case .majorSeventh: return [.M3, .P5, .M7]
case .minorSeventh: return [.m3, .P5, .m7]
case .minorMajorSeventh: return [.m3, .P5, .M7]
Expand Down Expand Up @@ -212,11 +222,13 @@ extension ChordType: CustomStringConvertible {
case .suspendedFourthTriad: return "sus4"
case .sixth: return "6"
case .minorSixth: return "m6"
case .sixthSuspendedSecond: return "6sus2"
case .sixthSuspendedFourth: return "6sus4"
case .halfDiminishedSeventh: return "ø7"
case .diminishedSeventh: return "°7"
case .dominantSeventh: return "7"
case .dominantSeventhSuspendedFourth: return "7sus4"
case .dominantSeventhSuspendedSecond: return "7sus2"
case .dominantSeventhSuspendedFourth: return "7sus4"
case .majorSeventh: return "maj7"
case .minorSeventh: return "m7"
case .minorMajorSeventh: return "mMaj7"
Expand Down Expand Up @@ -267,11 +279,13 @@ extension ChordType: CustomStringConvertible {
case .suspendedFourthTriad: return "“4"
case .sixth: return "6"
case .minorSixth: return "m6"
case .sixthSuspendedSecond: return "6sus2"
case .sixthSuspendedFourth: return "6sus4"
case .halfDiminishedSeventh: return "Ø7"
case .diminishedSeventh: return "º7"
case .dominantSeventh: return "7"
case .dominantSeventhSuspendedFourth: return "7sus4"
case .dominantSeventhSuspendedSecond: return "7sus2"
case .dominantSeventhSuspendedFourth: return "7sus4"
case .majorSeventh: return "^7"
case .minorSeventh: return "m7"
case .minorMajorSeventh: return "m^7"
Expand Down
31 changes: 23 additions & 8 deletions Tests/TonicTests/ChordTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,42 @@ class ChordTests: XCTestCase {
XCTAssertEqual(c7.map { $0.description }, ["C7"])
}

func test7sus4() {
let notes: [Int8] = [60, 65, 67, 70]
let pitchSet = PitchSet(pitches: notes.map { Pitch($0) } )
let c7sus4 = Chord.getRankedChords(from: pitchSet)
XCTAssertEqual(c7sus4.map { $0.description }, ["C7sus4", "F9sus4"])
}

func test7sus2() {
let notes: [Int8] = [60, 62, 67, 70]
let pitchSet = PitchSet(pitches: notes.map { Pitch($0) } )
let c7sus2 = Chord.getRankedChords(from: pitchSet)
XCTAssertEqual(c7sus2.map { $0.description }, ["C7sus2"])
}

func test7sus4() {
let notes: [Int8] = [60, 65, 67, 70]
let pitchSet = PitchSet(pitches: notes.map { Pitch($0) } )
let c7sus4 = Chord.getRankedChords(from: pitchSet)
XCTAssertEqual(c7sus4.map { $0.description }, ["C7sus4", "B♭6sus2", "F9sus4"])
}

func test9sus4() {
let notes: [Int8] = [60, 65, 67, 74]
let pitchSet = PitchSet(pitches: notes.map { Pitch($0) } )
let c9sus4 = Chord.getRankedChords(from: pitchSet)
XCTAssertEqual(c9sus4.map { $0.description }, ["C9sus4", "G7sus4"])
XCTAssertEqual(c9sus4.map { $0.description }, ["C9sus4", "G7sus4", "F6sus2"])
}

func test6sus2() {
let notes: [Int8] = [60, 62, 67, 69]
let pitchSet = PitchSet(pitches: notes.map { Pitch($0) } )
let chord = Chord.getRankedChords(from: pitchSet)
XCTAssertEqual(chord.map { $0.description }, ["C6sus2", "G9sus4", "D7sus4"])
}

func test6sus4() {
let notes: [Int8] = [60, 65, 67, 69]
let pitchSet = PitchSet(pitches: notes.map { Pitch($0) } )
let chord = Chord.getRankedChords(from: pitchSet)
XCTAssertEqual(chord.map { $0.description }, ["C6sus4", "Fadd9"])
}


func testAugmentedDiminishededChordsPreferNoInversions() {
let notes: [Int8] = [60, 64, 68]
let pitchSet = PitchSet(pitches: notes.map { Pitch($0) } )
Expand Down

0 comments on commit e2ba83f

Please sign in to comment.