-
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ChordType Overhaul #47
Changes from 37 commits
711e946
2d37b04
1f869bf
77341be
f5f294c
7d0f3cb
628a9fd
7794566
7762217
114ff8a
b554d7b
710b2c7
11b505e
0291ee2
8e29e13
4b396af
d26cf86
c322081
06e5387
cbbdf41
df52266
efd2232
7b81e68
6f43be3
3b605ed
1b693af
34d3419
d7b880d
73a1d6a
25a314d
381610d
ba83d1c
2b83b8c
6a593f7
51ed102
41c0ea2
5f84fa4
00b2e79
d6c6e20
77ff946
32d3635
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import Foundation | |
/// | ||
/// A representation of a chord as a set of note classes, with a root note class, | ||
/// and an inversion defined by the lowest note in the chord. | ||
public struct Chord: Equatable { | ||
public struct Chord: Equatable, Codable { | ||
/// Root note class of the chord | ||
public let root: NoteClass | ||
|
||
|
@@ -30,7 +30,7 @@ public struct Chord: Equatable { | |
|
||
/// Try to initialize a chord from an array of notes. | ||
/// | ||
/// If the array does not fit into a known chord type, this initialier will fail. | ||
/// If the array does not fit into a known chord type, this initializer will fail. | ||
/// - Parameter notes: Note array | ||
public init?(notes: [Note]) { | ||
var set = NoteSet() | ||
|
@@ -97,9 +97,9 @@ public struct Chord: Equatable { | |
if let index = key.primaryTriads.firstIndex(where: { $0 == self }) { | ||
let romanNumeral = capitalRomanNumerals[index] | ||
switch type { | ||
case .majorTriad: return romanNumeral | ||
case .minorTriad: return romanNumeral.lowercased() | ||
case .diminishedTriad: return "\(romanNumeral.lowercased())°" | ||
case .major: return romanNumeral | ||
case .minor: return romanNumeral.lowercased() | ||
case .dim: return "\(romanNumeral.lowercased())°" | ||
default: return nil | ||
} | ||
} | ||
|
@@ -155,7 +155,7 @@ extension Chord: CustomStringConvertible { | |
/// Useful for custom rendering of slash notation | ||
public var bassNote: NoteClass { | ||
switch inversion { | ||
case 1...4: | ||
case 1...type.intervals.count: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switch and Case Statement Alignment Violation: Case statements should vertically align with their enclosing switch statement. (switch_case_alignment) |
||
if let bass = root.canonicalNote.shiftUp(type.intervals[inversion - 1]) { | ||
return bass.noteClass | ||
} | ||
|
@@ -251,15 +251,12 @@ extension Chord { | |
} | ||
} | ||
|
||
// Sorts anti-alphabetical, but the net effect is to pefer flats to sharps | ||
// Sorts anti-alphabetical, but the net effect is to prefer flats to sharps | ||
returnArray.sort { $0.root.letter > $1.root.letter } | ||
|
||
// order the array by least number of accidentals | ||
returnArray.sort { $0.accidentalCount < $1.accidentalCount } | ||
|
||
// order the array preferring root position | ||
returnArray.sort { $0.inversion < ($1.inversion > 0 ? 1 : 0) } | ||
|
||
// prefer root notes not being uncommon enharmonics | ||
returnArray.sort { ($0.root.canonicalNote.isUncommonEnharmonic ? 1 : 0) < ($1.root.canonicalNote.isUncommonEnharmonic ? 1 : 0) } | ||
|
||
|
@@ -278,6 +275,12 @@ extension Chord { | |
} | ||
} | ||
|
||
// prefer fewer number of characters (favor less complex chords in ranking) | ||
returnArray.sort { $0.slashDescription.count < $1.slashDescription.count } | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace) |
||
// order the array preferring root position | ||
returnArray.sort { $0.inversion < ($1.inversion > 0 ? 1 : 0) } | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace) |
||
return returnArray | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch and Case Statement Alignment Violation: Case statements should vertically align with their enclosing switch statement. (switch_case_alignment)