Class: Coltrane::Theory::Progression
- Inherits:
-
Object
- Object
- Coltrane::Theory::Progression
- Extended by:
- NotableProgressions
- Includes:
- Changes
- Defined in:
- lib/coltrane/theory/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
-
#chords ⇒ Object
readonly
Returns the value of attribute chords.
-
#notation ⇒ Object
readonly
Returns the value of attribute notation.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(notation = nil, chords: nil, roman_chords: nil, key: nil, scale: nil) ⇒ Progression
constructor
A new instance of Progression.
- #interval_sequence ⇒ Object
- #notes ⇒ Object
- #notes_out ⇒ Object
- #notes_out_size ⇒ Object
- #roman_chords ⇒ Object
- #root_notes ⇒ Object
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.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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 |
Instance Attribute Details
#chords ⇒ Object (readonly)
Returns the value of attribute chords.
10 11 12 |
# File 'lib/coltrane/theory/progression.rb', line 10 def chords @chords end |
#notation ⇒ Object (readonly)
Returns the value of attribute notation.
10 11 12 |
# File 'lib/coltrane/theory/progression.rb', line 10 def notation @notation end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
10 11 12 |
# File 'lib/coltrane/theory/progression.rb', line 10 def scale @scale end |
Class Method Details
.find(*chords) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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 |
Instance Method Details
#interval_sequence ⇒ Object
50 51 52 |
# File 'lib/coltrane/theory/progression.rb', line 50 def interval_sequence @interval_sequence ||= IntervalSequence(notes: @root_notes) end |
#notes ⇒ Object
68 69 70 |
# File 'lib/coltrane/theory/progression.rb', line 68 def notes NoteSet[*chords.map(&:notes).map(&:notes).flatten] end |
#notes_out ⇒ Object
72 73 74 |
# File 'lib/coltrane/theory/progression.rb', line 72 def notes_out notes - scale.notes end |
#notes_out_size ⇒ Object
76 77 78 |
# File 'lib/coltrane/theory/progression.rb', line 76 def notes_out_size notes_out.size end |
#roman_chords ⇒ Object
58 59 60 61 62 |
# 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 ⇒ Object
54 55 56 |
# File 'lib/coltrane/theory/progression.rb', line 54 def root_notes @root_notes ||= @chords.map(&:root_note) end |