Skip to content
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

Merged
merged 41 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
711e946
WIP minor major ninth not passing yet
maksutovic Apr 11, 2024
2d37b04
Added Minor Major Ninth chord type
maksutovic Apr 12, 2024
1f869bf
Added Major and Dominant Ninth Flat Five refactor of Flat Fifth to Fl…
maksutovic Apr 12, 2024
77341be
WIP on new ranked chords algo
maksutovic Apr 18, 2024
f5f294c
New algo working replacing old one
maksutovic Apr 19, 2024
7d0f3cb
A few sus chords do not work due to algo being too eager to find thir…
maksutovic Apr 19, 2024
628a9fd
remade ranked chord algo with interval strategy
maksutovic Apr 19, 2024
7794566
Fixed bug in Note.noteNumber causing infinite loop
maksutovic Apr 19, 2024
7762217
Added isDouble as computed property to Accidental
maksutovic Apr 19, 2024
114ff8a
Improved getRankedChords algorithm
maksutovic Apr 19, 2024
b554d7b
Merge branch 'main' into main
maksutovic Apr 19, 2024
710b2c7
WIP cleaning up chord list refining examples and descriptions
maksutovic Apr 20, 2024
11b505e
test cleanup other typo cleanup
maksutovic Apr 25, 2024
0291ee2
adding eleventh and thirteenth cases, more to do
maksutovic Apr 25, 2024
8e29e13
Adding more 13th cases
maksutovic Apr 27, 2024
4b396af
WIP Refactoring Chord type case names
maksutovic May 12, 2024
d26cf86
WIP: Refactored chord type names
maksutovic May 12, 2024
c322081
Adding missing 9th and 11th cases
maksutovic May 12, 2024
06e5387
added missing 13th cases, standardized description notation
maksutovic Aug 11, 2024
cbbdf41
added missing cases for chord font descriptions
maksutovic Aug 11, 2024
df52266
added exhaustive list of sus chords revamping tests
maksutovic Aug 12, 2024
efd2232
Don't add chord types if they have already been added
maksutovic Aug 19, 2024
7b81e68
omitted 11ths from sus4 13 chords, omitted 9ths from sus2 13 chords
maksutovic Aug 19, 2024
6f43be3
WIP better tests for new chords
maksutovic Aug 19, 2024
3b605ed
Allows for all inversions for a given chord
maksutovic Aug 24, 2024
1b693af
Improved ranking by favoring less complex chords in getRankedChords
maksutovic Aug 24, 2024
34d3419
Fixed erroneous 13(add11) intervals and formatting
maksutovic Aug 24, 2024
d7b880d
updated tests
maksutovic Aug 24, 2024
73a1d6a
Prioritizing hash values from simpler accidentals
maksutovic Aug 25, 2024
25a314d
[WIP]: Optimizing ordering of chord types by simplicity and/or popula…
maksutovic Aug 25, 2024
381610d
Fixed m7 vs M6 spelling with notes initializer
maksutovic Aug 25, 2024
ba83d1c
Fixed add9 and 6/9 spelling with notes initializer
maksutovic Aug 25, 2024
2b83b8c
chore: formatting
maksutovic Oct 18, 2024
6a593f7
add deprecated labels for generateAllChord and getAllChordsForNoteSet
maksutovic Oct 18, 2024
51ed102
corrected Note init
maksutovic Oct 18, 2024
41c0ea2
tests for dom9flat5, 9sus4, seventh naming, 13th naming
maksutovic Oct 18, 2024
5f84fa4
Resolved merge conflicts using local versions
maksutovic Oct 18, 2024
00b2e79
Merge branch 'main' into max
aure Dec 18, 2024
d6c6e20
Fixed various things having to do with the switch to Yamaha standard …
aure Dec 18, 2024
77ff946
Fixed tests
aure Dec 18, 2024
32d3635
Update tests to macos-13
aure Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 112 additions & 112 deletions Sources/Tonic/Chord+Shortcuts.swift

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions Sources/Tonic/Chord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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:
Copy link

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)

Copy link

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)

if let bass = root.canonicalNote.shiftUp(type.intervals[inversion - 1]) {
return bass.noteClass
}
Expand Down Expand Up @@ -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) }

Expand All @@ -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 }

Copy link

Choose a reason for hiding this comment

The 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) }

Copy link

Choose a reason for hiding this comment

The 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
}

Expand Down
Loading
Loading