lib/coltrane/representation/guitar/chord.rb in coltrane-3.3.3 vs lib/coltrane/representation/guitar/chord.rb in coltrane-3.4.0

- old
+ new

@@ -15,10 +15,36 @@ .fetch_descendant_chords .sort .reverse end + def self.find_by_notation(guitar, chord_notation) + chord_notation + .split('-') + .map + .with_index do |n, i| + next if n == 'x' + n = Guitar::Note.new(guitar.strings[i], n.to_i).pitch.pitch_class + end + .yield_self do |notes| + notes + .map + .with_index do |note, index| + begin + Theory::Chord.new(notes: notes.rotate(index)) + rescue Theory::ChordNotFoundError + next + end + end + .compact + .yield_self do |chords| + raise(Theory::ChordNotFoundError) if chords.empty? + chords.compact.uniq &:name + end + end + end + def initialize(target_chord, guitar_notes: [], free_fingers: 4, barre: nil, guitar:) @@ -181,6 +207,6 @@ end.flatten + [(Guitar::Note.new(next_string, nil) if include_mute_note)].compact end end end end -end \ No newline at end of file +end