Class: Coltrane::Chord
- Inherits:
-
Object
- Object
- Coltrane::Chord
- Defined in:
- lib/coltrane/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
-
#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
Constructor Details
#initialize(notes: nil, root_note: nil, quality: nil, name: nil) ⇒ Chord
Returns a new instance of Chord.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/coltrane/chord.rb', line 8 def initialize(notes: nil, root_note: nil, quality: nil, name: nil) if !notes.nil? notes = NoteSet[*notes] if notes.is_a?(Array) @notes = notes @root_note = notes.first @quality = ChordQuality.new(notes: notes) elsif !root_note.nil? && !quality.nil? @notes = quality.notes_for(root_note) @root_note = root_note @quality = quality elsif !name.nil? @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.
6 7 8 |
# File 'lib/coltrane/chord.rb', line 6 def notes @notes end |
#quality ⇒ Object (readonly)
Returns the value of attribute quality.
6 7 8 |
# File 'lib/coltrane/chord.rb', line 6 def quality @quality end |
#root_note ⇒ Object (readonly)
Returns the value of attribute root_note.
6 7 8 |
# File 'lib/coltrane/chord.rb', line 6 def root_note @root_note end |
Instance Method Details
#intervals ⇒ Object
36 37 38 |
# File 'lib/coltrane/chord.rb', line 36 def intervals IntervalSequence.new(NoteSet.new(notes)) end |
#invert(n = 1) ⇒ Object
52 53 54 |
# File 'lib/coltrane/chord.rb', line 52 def invert(n = 1) Chord.new(notes.rotate(n)) end |
#name ⇒ Object Also known as: to_s
26 27 28 |
# File 'lib/coltrane/chord.rb', line 26 def name "#{root_note}#{quality}" end |
#next_inversion ⇒ Object
48 49 50 |
# File 'lib/coltrane/chord.rb', line 48 def next_inversion Chord.new(notes.rotate(1)) end |
#pretty_name ⇒ Object
32 33 34 |
# File 'lib/coltrane/chord.rb', line 32 def pretty_name "#{root_note.pretty_name}#{quality.name}" end |
#previous_inversion ⇒ Object
56 57 58 |
# File 'lib/coltrane/chord.rb', line 56 def previous_inversion Chord.new(notes.rotate(-1)) end |
#scales ⇒ Object
44 45 46 |
# File 'lib/coltrane/chord.rb', line 44 def scales Scale.having_chord(name) end |
#size ⇒ Object
40 41 42 |
# File 'lib/coltrane/chord.rb', line 40 def size notes.size end |