Class: Coltrane::Theory::Chord
- Inherits:
-
Object
- Object
- Coltrane::Theory::Chord
- Includes:
- ChordSubstitutions
- Defined in:
- lib/coltrane/theory/chord.rb
Overview
It describe a chord
Instance Attribute Summary collapse
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#quality ⇒ Object
readonly
Returns the value of attribute quality.
-
#root_note ⇒ Object
readonly
Returns the value of attribute root_note.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(notes: nil, root_note: nil, quality: nil, name: nil) ⇒ Chord
constructor
A new instance of Chord.
- #intervals ⇒ Object
- #invert(n = 1) ⇒ Object
- #name ⇒ Object (also: #to_s)
- #next_inversion ⇒ Object
- #pretty_name ⇒ Object
- #previous_inversion ⇒ Object
- #scales ⇒ Object
- #size ⇒ Object
Methods included from ChordSubstitutions
Constructor Details
#initialize(notes: nil, root_note: nil, quality: nil, name: nil) ⇒ Chord
Returns a new instance of Chord.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 |
Instance Attribute Details
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
8 9 10 |
# File 'lib/coltrane/theory/chord.rb', line 8 def notes @notes end |
#quality ⇒ Object (readonly)
Returns the value of attribute quality.
8 9 10 |
# File 'lib/coltrane/theory/chord.rb', line 8 def quality @quality end |
#root_note ⇒ Object (readonly)
Returns the value of attribute root_note.
8 9 10 |
# File 'lib/coltrane/theory/chord.rb', line 8 def root_note @root_note end |
Instance Method Details
#+(other) ⇒ Object
73 74 75 76 77 78 |
# 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) ⇒ Object
80 81 82 83 84 85 |
# 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) ⇒ Object Also known as: eql?
29 30 31 |
# File 'lib/coltrane/theory/chord.rb', line 29 def ==(other) (notes & other.notes).size == notes.size end |
#hash ⇒ Object
41 42 43 |
# File 'lib/coltrane/theory/chord.rb', line 41 def hash notes.hash end |
#intervals ⇒ Object
49 50 51 |
# File 'lib/coltrane/theory/chord.rb', line 49 def intervals IntervalSequence.new(NoteSet.new(notes)) end |
#invert(n = 1) ⇒ Object
65 66 67 |
# File 'lib/coltrane/theory/chord.rb', line 65 def invert(n = 1) Chord.new(notes: notes.rotate(n)) end |
#name ⇒ Object Also known as: to_s
35 36 37 |
# File 'lib/coltrane/theory/chord.rb', line 35 def name "#{root_note}#{quality}" end |
#next_inversion ⇒ Object
61 62 63 |
# File 'lib/coltrane/theory/chord.rb', line 61 def next_inversion Chord.new(notes: notes.rotate(1)) end |
#pretty_name ⇒ Object
45 46 47 |
# File 'lib/coltrane/theory/chord.rb', line 45 def pretty_name "#{root_note.pretty_name}#{quality.name}" end |
#previous_inversion ⇒ Object
69 70 71 |
# File 'lib/coltrane/theory/chord.rb', line 69 def previous_inversion Chord.new(notes: notes.rotate(-1)) end |
#scales ⇒ Object
57 58 59 |
# File 'lib/coltrane/theory/chord.rb', line 57 def scales Scale.having_chord(name) end |
#size ⇒ Object
53 54 55 |
# File 'lib/coltrane/theory/chord.rb', line 53 def size notes.size end |