class Coltrane::Theory::Chord
It describe a chord
Attributes
notes[R]
quality[R]
root_note[R]
Public Class Methods
new(notes: nil, root_note: nil, quality: nil, name: nil)
click to toggle source
# File lib/coltrane/theory/chord.rb, line 11 def initialize(notes: nil, root_note: nil, quality: nil, name: nil) if notes notes = NoteSet[*notes] if notes.is_a?(Array) @notes = notes @root_note = notes.first @quality = ChordQuality.new(notes: notes) elsif root_note && quality @notes = quality.notes_for(root_note) @root_note = root_note @quality = quality elsif name @root_note, @quality, @notes = parse_from_name(name) else raise WrongKeywordsError, '[notes:] || [root_note:, quality:] || [name:]' end end
Public Instance Methods
+(other)
click to toggle source
# File lib/coltrane/theory/chord.rb, line 73 def +(other) case other when Note, NoteSet, Interval then Chord.new(notes: notes + other) when Chord then Chord.new(notes: notes + other.notes) end end
-(other)
click to toggle source
# File lib/coltrane/theory/chord.rb, line 80 def -(other) case other when Note, NoteSet, Interval, Numeric then Chord.new(notes: notes - other) when Chord then Chord.new(notes: notes - other.notes) end end
==(other)
click to toggle source
# File lib/coltrane/theory/chord.rb, line 29 def ==(other) (notes & other.notes).size == notes.size end
Also aliased as: eql?
hash()
click to toggle source
# File lib/coltrane/theory/chord.rb, line 41 def hash notes.hash end
intervals()
click to toggle source
# File lib/coltrane/theory/chord.rb, line 49 def intervals IntervalSequence.new(NoteSet.new(notes)) end
invert(n = 1)
click to toggle source
# File lib/coltrane/theory/chord.rb, line 65 def invert(n = 1) Chord.new(notes: notes.rotate(n)) end
name()
click to toggle source
# File lib/coltrane/theory/chord.rb, line 35 def name "#{root_note}#{quality}" end
Also aliased as: to_s
next_inversion()
click to toggle source
# File lib/coltrane/theory/chord.rb, line 61 def next_inversion Chord.new(notes: notes.rotate(1)) end
pretty_name()
click to toggle source
# File lib/coltrane/theory/chord.rb, line 45 def pretty_name "#{root_note.pretty_name}#{quality.name}" end
previous_inversion()
click to toggle source
# File lib/coltrane/theory/chord.rb, line 69 def previous_inversion Chord.new(notes: notes.rotate(-1)) end
scales()
click to toggle source
# File lib/coltrane/theory/chord.rb, line 57 def scales Scale.having_chord(name) end
size()
click to toggle source
# File lib/coltrane/theory/chord.rb, line 53 def size notes.size end
Protected Instance Methods
parse_from_name(name)
click to toggle source
# File lib/coltrane/theory/chord.rb, line 89 def parse_from_name(name) chord_name, bass = name.match?(/\/9/) ? [name, nil] : name.split('/') chord_regex = /([A-Z](?:#|b)?)(.*)/ _, root_name, quality_name = chord_name.match(chord_regex).to_a root = Note[root_name] quality = ChordQuality.new(name: quality_name, bass: bass) notes = quality.notes_for(root) notes << Note[bass] unless bass.nil? [root, quality, notes] end