lib/coltrane/representation/guitar/chord.rb in coltrane-3.2.0 vs lib/coltrane/representation/guitar/chord.rb in coltrane-3.3.0
- old
+ new
@@ -37,23 +37,23 @@
def <=>(other)
rank <=> other.rank
end
def rank
- +completeness * 10_000 +
- +fullness * 1000 +
- -spreadness * 100 +
- +easyness * 1
+ +completeness * 10_000 +
+ +fullness * 1_000 +
+ -spreadness * 10 +
+ -discontinuity * 1 +
+ +easyness * 1
end
def analysis
- {
- completeness: completeness,
- fullness: fullness,
- easyness: easyness,
- spreadness: spreadness
- }
+ %i[completeness discontinuity fullness spreadness easyness]
+ .reduce({}) do |output, criteria|
+ output.merge(criteria => send(criteria).round(2))
+ end
+ .merge(rank: rank.round(4))
end
def spreadness
fret_range.size.to_f / MAX_FRET_SPAN
end
@@ -68,10 +68,14 @@
def fullness
(guitar.strings.size.to_f - frets.count(nil)) / guitar.strings.size
end
+ def discontinuity
+ voicing.discontinuity
+ end
+
def barre?
!@barre.nil?
end
def fetch_descendant_chords
@@ -151,15 +155,17 @@
def fret_expansion_range
(lowest_possible_fret..highest_possible_fret).to_a +
[(0 unless barre?)].compact
end
- def to_s
- guitar_notes.map { |n| n.fret.nil? ? 'x' : n.fret }.join('-')
+ def to_s(debug = false)
+ guitar_notes.map {
+ |n| n.fret.nil? ? 'x' : n.fret
+ }.join('-') + (debug ? ' ' + analysis.to_s : '')
end
def voicing
- Coltrane::Voicing.new(pitches: guitar_notes.map(&:pitch).compact)
+ Theory::Voicing.new(pitches: guitar_notes.map(&:pitch).compact)
end
private
attr_writer :barre
\ No newline at end of file