class Coltrane::Theory::Progression

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

Attributes

chords[R]
notation[R]
scale[R]

Public Class Methods

find(*chords) click to toggle source
# File lib/coltrane/theory/progression.rb, line 12
def self.find(*chords)
  chords
    .yield_self { |chords|
      next chords if chords[0].is_a?(Chord)
      chords.map {|c| Chord.new(name: c) }
    }
    .yield_self { |chords|
      NoteSet[*chords.map(&:root_note)]
      .yield_self { |root_notes|
        Scale.having_notes(*root_notes).strict_scales
      }
      .reduce([]) { |memo, scale|
        memo + [Progression.new(chords: chords, scale: scale)]
      }
    }
    .yield_self { |progressions| ProgressionSet.new(*progressions) }
end
new(notation = nil, chords: nil, roman_chords: nil, key: nil, scale: nil) click to toggle source
# File lib/coltrane/theory/progression.rb, line 30
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

Public Instance Methods

interval_sequence() click to toggle source
# File lib/coltrane/theory/progression.rb, line 50
def interval_sequence
  @interval_sequence ||= IntervalSequence(notes: @root_notes)
end
notes() click to toggle source
# File lib/coltrane/theory/progression.rb, line 68
def notes
  NoteSet[*chords.map(&:notes).map(&:notes).flatten]
end
notes_out() click to toggle source
# File lib/coltrane/theory/progression.rb, line 72
def notes_out
  notes - scale.notes
end
notes_out_size() click to toggle source
# File lib/coltrane/theory/progression.rb, line 76
def notes_out_size
  notes_out.size
end
roman_chords() click to toggle source
# File lib/coltrane/theory/progression.rb, line 58
def roman_chords
  @roman_chords ||= chords.map do |c|
    RomanChord.new(chord: c, scale: scale)
  end
end
root_notes() click to toggle source
# File lib/coltrane/theory/progression.rb, line 54
def root_notes
  @root_notes ||= @chords.map(&:root_note)
end