Class: Coltrane::Progression

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

Overview

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

Constant Summary

Constants included from NotableProgressions

NotableProgressions::PROGRESSIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Changes

#bird_changes, #coltrane_changes

Constructor Details

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

Returns a new instance of Progression.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/coltrane/progression.rb', line 24

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 || 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
18
19
20
21
22
# File 'lib/coltrane/progression.rb', line 11

def self.find(*chords)
  chords.map! { |c| Chord.new(name: c) } if chords[0].is_a?(String)

  root_notes = NoteSet[*chords.map(&:root_note)]

  scales = Scale.having_notes(*root_notes)[:scales]
  progressions = scales.reduce([]) do |memo, scale|
    memo + [Progression.new(chords: chords, scale: scale)]
  end

  progressions.sort_by(&:notes_out_size)
end

Instance Method Details

#interval_sequenceObject



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

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

#notesObject



62
63
64
# File 'lib/coltrane/progression.rb', line 62

def notes
  NoteSet[*chords.map(&:notes).map(&:notes).flatten]
end

#notes_outObject



66
67
68
# File 'lib/coltrane/progression.rb', line 66

def notes_out
  notes - scale.notes
end

#notes_out_sizeObject



70
71
72
# File 'lib/coltrane/progression.rb', line 70

def notes_out_size
  notes_out.size
end

#roman_chordsObject



52
53
54
55
56
# File 'lib/coltrane/progression.rb', line 52

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

#root_notesObject



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

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