Class: Coltrane::Progression

Inherits:
Object
  • Object
show all
Extended by:
ClassicProgressions
Defined in:
lib/coltrane/progression.rb

Overview

Allows the creation of chord progressions using standard notations. Ex: Progression.new(‘I-IV-V’, key: ‘Am’)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notation = nil, chords: nil, roman_chords: nil, key: nil, scale: nil) ⇒ Progression

Returns a new instance of Progression.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/coltrane/progression.rb', line 19

def initialize(notation=nil, chords: nil, roman_chords: nil, key: nil, scale: nil)
  if notation.nil? && chords.nil? && roman_chords.nil? || key.nil? && scale.nil?
    raise WrongKeywordsError,
      '[chords:, [scale: || key:]] '\
      '[roman_chords:, [scale: || key:]] '\
      '[notation:, [scale: || key:]] '\
  end

  @scale  = scale || Scale.from_key(key)
  @chords =
    if !chords.nil?
      chords
    elsif !roman_chords.nil?
      roman_chords.map(&:chord)
    elsif !notation.nil?
      @notation = notation
      notation.split('-').map {|c| RomanChord.new(c, scale: @scale).chord }
    end
end

Instance Attribute Details

#chordsObject (readonly)

Returns the value of attribute chords.



9
10
11
# File 'lib/coltrane/progression.rb', line 9

def chords
  @chords
end

#notationObject (readonly)

Returns the value of attribute notation.



9
10
11
# File 'lib/coltrane/progression.rb', line 9

def notation
  @notation
end

#scaleObject (readonly)

Returns the value of attribute scale.



9
10
11
# File 'lib/coltrane/progression.rb', line 9

def scale
  @scale
end

Class Method Details

.find(*chords) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/coltrane/progression.rb', line 11

def self.find(*chords)
  chords.map! { |c| Chord.new(name: c) } if chords[0].is_a?(String)
  scales = Scale.having_chords(*chords).scales
  scales.reduce([]) do |memo, scale|
    memo + [Progression.new(chords: chords, scale: scale)]
  end
end

Instance Method Details

#interval_sequenceObject



39
40
41
# File 'lib/coltrane/progression.rb', line 39

def interval_sequence
  @interval_sequence ||= IntervalSequence(notes: @root_notes)
end

#roman_chordsObject



47
48
49
50
51
# File 'lib/coltrane/progression.rb', line 47

def roman_chords
  @roman_chords ||= chords.map do |c|
    RomanChord.new(chord: c, scale: scale)
  end
end

#root_notesObject



43
44
45
# File 'lib/coltrane/progression.rb', line 43

def root_notes
  @root_notes ||= @chords.map(&:root_note)
end