Class: Coltrane::Chord

Inherits:
Object
  • Object
show all
Defined in:
lib/coltrane/chord.rb

Overview

It describe a chord

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#notesObject (readonly)

Returns the value of attribute notes.



6
7
8
# File 'lib/coltrane/chord.rb', line 6

def notes
  @notes
end

#qualityObject (readonly)

Returns the value of attribute quality.



6
7
8
# File 'lib/coltrane/chord.rb', line 6

def quality
  @quality
end

#root_noteObject (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

#intervalsObject



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

#nameObject Also known as: to_s



26
27
28
# File 'lib/coltrane/chord.rb', line 26

def name
  "#{root_note}#{quality}"
end

#next_inversionObject



48
49
50
# File 'lib/coltrane/chord.rb', line 48

def next_inversion
  Chord.new(notes.rotate(1))
end

#pretty_nameObject



32
33
34
# File 'lib/coltrane/chord.rb', line 32

def pretty_name
  "#{root_note.pretty_name}#{quality.name}"
end

#previous_inversionObject



56
57
58
# File 'lib/coltrane/chord.rb', line 56

def previous_inversion
  Chord.new(notes.rotate(-1))
end

#scalesObject



44
45
46
# File 'lib/coltrane/chord.rb', line 44

def scales
  Scale.having_chord(name)
end

#sizeObject



40
41
42
# File 'lib/coltrane/chord.rb', line 40

def size
  notes.size
end